Skip to content

Commit d8dfa59

Browse files
committed
bus: imx-weim: Remove VLA usage
In the quest to remove all stack VLA usage from the kernel[1], this switches to using a maximum size and adds a sanity check. [1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com Cc: Shawn Guo <shawnguo@kernel.org> Cc: Sascha Hauer <s.hauer@pengutronix.de> Cc: Pengutronix Kernel Team <kernel@pengutronix.de> Cc: Fabio Estevam <fabio.estevam@nxp.com> Cc: NXP Linux Team <linux-imx@nxp.com> Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Shawn Guo <shawnguo@kernel.org>
1 parent 699112f commit d8dfa59

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎drivers/bus/imx-weim.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ static const struct imx_weim_devtype imx51_weim_devtype = {
4545
.cs_stride = 0x18,
4646
};
4747

48+
#define MAX_CS_REGS_COUNT 6
49+
4850
static const struct of_device_id weim_id_table[] = {
4951
/* i.MX1/21 */
5052
{ .compatible = "fsl,imx1-weim", .data = &imx1_weim_devtype, },
@@ -112,9 +114,12 @@ static int __init imx_weim_gpr_setup(struct platform_device *pdev)
112114
static int __init weim_timing_setup(struct device_node *np, void __iomem *base,
113115
const struct imx_weim_devtype *devtype)
114116
{
115-
u32 cs_idx, value[devtype->cs_regs_count];
117+
u32 cs_idx, value[MAX_CS_REGS_COUNT];
116118
int i, ret;
117119

120+
if (WARN_ON(devtype->cs_regs_count > MAX_CS_REGS_COUNT))
121+
return -EINVAL;
122+
118123
/* get the CS index from this child node's "reg" property. */
119124
ret = of_property_read_u32(np, "reg", &cs_idx);
120125
if (ret)

0 commit comments

Comments
 (0)