Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

gpio: dwapb: reduce allocation to single kzalloc

Instead of kzalloc + kcalloc, Combine the two using a flexible array
member.

Allows using __counted_by for extra runtime analysis. Move counting
variable to right after allocation as required by __counted_by.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Link: https://patch.msgid.link/20260320005338.30355-1-rosenp@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

authored by

Rosen Penev and committed by
Bartosz Golaszewski
9a5bf2f5 a6e53d05

+5 -14
+5 -14
drivers/gpio/gpio-dwapb.c
··· 75 75 }; 76 76 77 77 struct dwapb_platform_data { 78 - struct dwapb_port_property *properties; 79 78 unsigned int nports; 79 + struct dwapb_port_property properties[] __counted_by(nports); 80 80 }; 81 81 82 82 /* Store GPIO context across system-wide suspend/resume transitions */ ··· 114 114 struct dwapb_gpio { 115 115 struct device *dev; 116 116 void __iomem *regs; 117 - struct dwapb_gpio_port *ports; 118 117 unsigned int nr_ports; 119 118 unsigned int flags; 120 119 struct reset_control *rst; 121 120 struct clk_bulk_data clks[DWAPB_NR_CLOCKS]; 121 + struct dwapb_gpio_port ports[] __counted_by(nr_ports); 122 122 }; 123 123 124 124 static inline u32 gpio_reg_v2_convert(unsigned int offset) ··· 585 585 if (nports == 0) 586 586 return ERR_PTR(-ENODEV); 587 587 588 - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 588 + pdata = devm_kzalloc(dev, struct_size(pdata, properties, nports), GFP_KERNEL); 589 589 if (!pdata) 590 - return ERR_PTR(-ENOMEM); 591 - 592 - pdata->properties = devm_kcalloc(dev, nports, sizeof(*pp), GFP_KERNEL); 593 - if (!pdata->properties) 594 590 return ERR_PTR(-ENOMEM); 595 591 596 592 pdata->nports = nports; ··· 710 714 if (IS_ERR(pdata)) 711 715 return PTR_ERR(pdata); 712 716 713 - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); 717 + gpio = devm_kzalloc(&pdev->dev, struct_size(gpio, ports, pdata->nports), GFP_KERNEL); 714 718 if (!gpio) 715 719 return -ENOMEM; 716 720 717 - gpio->dev = &pdev->dev; 718 721 gpio->nr_ports = pdata->nports; 722 + gpio->dev = &pdev->dev; 719 723 720 724 err = dwapb_get_reset(gpio); 721 725 if (err) 722 726 return err; 723 - 724 - gpio->ports = devm_kcalloc(&pdev->dev, gpio->nr_ports, 725 - sizeof(*gpio->ports), GFP_KERNEL); 726 - if (!gpio->ports) 727 - return -ENOMEM; 728 727 729 728 gpio->regs = devm_platform_ioremap_resource(pdev, 0); 730 729 if (IS_ERR(gpio->regs))