Skip to contentSkip to conversation

irqchip: Use struct_size() helper in devm_kzalloc()

PATCH Applied Gustavo A. R. Silva 2 participants 2 messages Jun 16, 2020 – Jun 27, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 irqchip: Use struct_size() helper in devm_kzalloc()

Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes.

This code was detected with the help of Coccinelle and, audited and fixed manually.

---
 drivers/irqchip/irq-imx-intmux.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/irqchip/irq-imx-intmux.c +1 -2
index c27577c81126..54d8bb4fc5a1 100644
@@ -210,8 +210,7 @@ static int imx_intmux_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	data = devm_kzalloc(&pdev->dev, sizeof(*data) +
-			    channum * sizeof(data->irqchip_data[0]), GFP_KERNEL);
+	data = devm_kzalloc(&pdev->dev, struct_size(data, irqchip_data, channum), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
Signature · 1 line
2.27.0
Applied
#1 lore raw
Quoted 5 lines · Gustavo A. R. Silva

Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes.

This code was detected with the help of Coccinelle and, audited and fixed manually.

Applied to irq/irqchip-5.9:

[1/1] irqchip/imx-intmux: Use struct_size() helper in devm_kzalloc()

      commit: 2f7a9bda42f74e1169fcd9ef55c8ade989ef8bba

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.