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 diff --git a/drivers/mtd/nand/qpic_common.c b/drivers/mtd/nand/qpic_common.c
40 index 8abbb960a7ce..e0ed25b5afea 100644
41 --- a/drivers/mtd/nand/qpic_common.c
42 +++ b/drivers/mtd/nand/qpic_common.c
43 @@ -85,7 +85,7 @@ void qcom_clear_bam_transaction(struct qcom_nand_controller *nandc)
44 if (!nandc->props->supports_bam)
47 - memset(&bam_txn->bam_ce_pos, 0, sizeof(u32) * 8);
48 + memset(&bam_txn->bam_positions, 0, sizeof(bam_txn->bam_positions));
49 bam_txn->last_data_desc = NULL;
51 sg_init_table(bam_txn->cmd_sgl, nandc->max_cwperpage *
52 diff --git a/include/linux/mtd/nand-qpic-common.h b/include/linux/mtd/nand-qpic-common.h
53 index e79c79775eb8..4d9b736ff8b7 100644
54 --- a/include/linux/mtd/nand-qpic-common.h
55 +++ b/include/linux/mtd/nand-qpic-common.h
56 @@ -254,14 +254,17 @@ struct bam_transaction {
57 struct dma_async_tx_descriptor *last_data_desc;
58 struct dma_async_tx_descriptor *last_cmd_desc;
59 struct completion txn_done;
68 + struct_group(bam_positions,