5c3fcc43c8f476dc8cfa8d2ff872fd45e435019c
[openwrt/staging/wigyori.git] /
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
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
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.
11
12 On x86 architecture, the following error occurs due to warnings being
13 treated as errors:
14
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
26
27 This patch addresses the issue by grouping the related fields in
28 struct bam_transaction using struct_group and updating the memset call
29 accordingly.
30
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>
34 ---
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(-)
38
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)
45 return;
46
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;
50
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;
60 - u32 bam_ce_pos;
61 - u32 bam_ce_start;
62 - u32 cmd_sgl_pos;
63 - u32 cmd_sgl_start;
64 - u32 tx_sgl_pos;
65 - u32 tx_sgl_start;
66 - u32 rx_sgl_pos;
67 - u32 rx_sgl_start;
68 + struct_group(bam_positions,
69 + u32 bam_ce_pos;
70 + u32 bam_ce_start;
71 + u32 cmd_sgl_pos;
72 + u32 cmd_sgl_start;
73 + u32 tx_sgl_pos;
74 + u32 tx_sgl_start;
75 + u32 rx_sgl_pos;
76 + u32 rx_sgl_start;
77 +
78 + );
79 };
80
81 /*
82 --
83 2.47.1
84