1 From b9371866799d67a80be0ea9e01bd41987db22f26 Mon Sep 17 00:00:00 2001
2 From: Md Sadre Alam <quic_mdalam@quicinc.com>
3 Date: Mon, 6 Jan 2025 18:45:58 +0530
4 Subject: [PATCH] mtd: rawnand: qcom: Fix build issue on x86 architecture
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Fix a buffer overflow issue in qcom_clear_bam_transaction by using
10 struct_group to group related fields and avoid FORTIFY_SOURCE warnings.
12 On x86 architecture, the following error occurs due to warnings being
15 In function ‘fortify_memset_chk’,
16 inlined from ‘qcom_clear_bam_transaction’ at
17 drivers/mtd/nand/qpic_common.c:88:2:
18 ./include/linux/fortify-string.h:480:25: error: call to ‘__write_overflow_field’
19 declared with attribute warning: detected write beyond size of field
20 (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
21 480 | __write_overflow_field(p_size_field, size);
22 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 LD [M] drivers/mtd/nand/nandcore.o
24 CC [M] drivers/w1/masters/mxc_w1.o
25 cc1: all warnings being treated as errors
27 This patch addresses the issue by grouping the related fields in
28 struct bam_transaction using struct_group and updating the memset call
31 Fixes: 8c52932da5e6 ("mtd: rawnand: qcom: cleanup qcom_nandc driver")
32 Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
33 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
35 drivers/mtd/nand/qpic_common.c | 2 +-
36 include/linux/mtd/nand-qpic-common.h | 19 +++++++++++--------
37 2 files changed, 12 insertions(+), 9 deletions(-)
39 --- a/drivers/mtd/nand/qpic_common.c
40 +++ b/drivers/mtd/nand/qpic_common.c
41 @@ -85,7 +85,7 @@ void qcom_clear_bam_transaction(struct q
42 if (!nandc->props->supports_bam)
45 - memset(&bam_txn->bam_ce_pos, 0, sizeof(u32) * 8);
46 + memset(&bam_txn->bam_positions, 0, sizeof(bam_txn->bam_positions));
47 bam_txn->last_data_desc = NULL;
49 sg_init_table(bam_txn->cmd_sgl, nandc->max_cwperpage *
50 --- a/include/linux/mtd/nand-qpic-common.h
51 +++ b/include/linux/mtd/nand-qpic-common.h
52 @@ -254,14 +254,17 @@ struct bam_transaction {
53 struct dma_async_tx_descriptor *last_data_desc;
54 struct dma_async_tx_descriptor *last_cmd_desc;
55 struct completion txn_done;
64 + struct_group(bam_positions,