ARM: omap2: simplify allocation for omap_device
Subsystems (3)
PATCH 1/1 ARM: omap2: simplify allocation for omap_device
Use a flexible array member to combine allocations.
Add __counted_by for extra runtime analysis.
Remove goto paths as they are not really needed anymore.
--- arch/arm/mach-omap2/omap_device.c | 21 ++++++--------------- arch/arm/mach-omap2/omap_device.h | 2 +- 2 files changed, 7 insertions(+), 16 deletions(-)
arch/arm/mach-omap2/omap_device.c +6 -15
@@ -309,17 +309,15 @@ static struct omap_device *omap_device_alloc(struct platform_device *pdev,int i;struct omap_hwmod **hwmods; - od = kzalloc_obj(struct omap_device); -if (!od) - goto oda_exit1; + od =kzalloc_flex (*od, hwmods, oh_cnt); +if (!od) { +dev_err (&pdev->dev,"omap_device: build failed (%d)\n" , ret); +return ERR_PTR (ret); + } od->hwmods_cnt = oh_cnt; +memcpy (od->hwmods, ohs, oh_cnt *sizeof (*od->hwmods)); - hwmods =kmemdup_array (ohs, oh_cnt,sizeof (*hwmods),GFP_KERNEL ); -if (!hwmods) - goto oda_exit2; - - od->hwmods = hwmods; od->pdev = pdev; pdev->archdata.od = od;
@@ -329,13 +327,6 @@ static struct omap_device *omap_device_alloc(struct platform_device *pdev, }return od; - -oda_exit2: -kfree (od); -oda_exit1: -dev_err (&pdev->dev,"omap_device: build failed (%d)\n" , ret); - -return ERR_PTR (ret); }static void omap_device_delete (struct omap_device *od)
arch/arm/mach-omap2/omap_device.h +1 -1
@@ -51,11 +51,11 @@*/ struct omap_device {struct platform_device *pdev; -struct omap_hwmod **hwmods;unsigned long _driver_status;u8 hwmods_cnt;u8 _state;u8 flags; + struct omap_hwmod *hwmods[] __counted_by(hwmods_cnt); };/* Device driver interface (call via platform_data fn ptrs) */
Signature · 1 line
2.53.0
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Rosen,
kernel test robot noticed the following build warnings:
[auto build test WARNING on v7.0-rc5]
[also build test WARNING on linus/master next-20260326]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Rosen-Penev/ARM-omap2-simplify-allocation-for-omap_device/20260327-022104 base: v7.0-rc5 patch link: https://lore.kernel.org/r/20260326023432.54127-1-rosenp%40gmail.com patch subject: [PATCH] ARM: omap2: simplify allocation for omap_device config: arm-randconfig-003-20260327 (https://download.01.org/0day-ci/archive/20260327/[email protected]/config) compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260327/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> arch/arm/mach-omap2/omap_device.c:325:3: warning: variable 'hwmods' is uninitialized when used here [-Wuninitialized]
325 | hwmods[i]->od = od;
| ^~~~~~
arch/arm/mach-omap2/omap_device.c:310:28: note: initialize the variable 'hwmods' to silence this warning
310 | struct omap_hwmod **hwmods;
| ^
| = NULL1 warning generated.
vim +/hwmods +325 arch/arm/mach-omap2/omap_device.c
b04b65ab5b4fc8 arch/arm/plat-omap/omap_device.c Paul Walmsley 2009-09-03 292
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 293 /**
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 294 * omap_device_alloc - allocate an omap_device
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 295 * @pdev: platform_device that will be included in this omap_device
7b6560b4bc623d arch/arm/mach-omap2/omap_device.c Ben Dooks (Codethink 2019-11-06 296) * @ohs: ptr to the omap_hwmod for this omap_device
7b6560b4bc623d arch/arm/mach-omap2/omap_device.c Ben Dooks (Codethink 2019-11-06 297) * @oh_cnt: the size of the ohs list
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 298 *
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 299 * Convenience function for allocating an omap_device structure and filling
c1d1cd597fc77a arch/arm/mach-omap2/omap_device.c Paul Walmsley 2013-01-26 300 * hwmods, and resources.
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 301 *
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 302 * Returns an struct omap_device pointer or ERR_PTR() on error;
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 303 */
6aeb51c1035c1c arch/arm/mach-omap2/omap_device.c Arnd Bergmann 2022-09-28 304 static struct omap_device *omap_device_alloc(struct platform_device *pdev,
c1d1cd597fc77a arch/arm/mach-omap2/omap_device.c Paul Walmsley 2013-01-26 305 struct omap_hwmod **ohs, int oh_cnt)
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 306 {
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 307 int ret = -ENOMEM;
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 308 struct omap_device *od;
c2b84a9bb3414c arch/arm/mach-omap2/omap_device.c Tony Lindgren 2017-10-10 309 int i;
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 310 struct omap_hwmod **hwmods;
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 311
d2740219a804bc arch/arm/mach-omap2/omap_device.c Rosen Penev 2026-03-25 312 od = kzalloc_flex(*od, hwmods, oh_cnt);
d2740219a804bc arch/arm/mach-omap2/omap_device.c Rosen Penev 2026-03-25 313 if (!od) {
d2740219a804bc arch/arm/mach-omap2/omap_device.c Rosen Penev 2026-03-25 314 dev_err(&pdev->dev, "omap_device: build failed (%d)\n", ret);
d2740219a804bc arch/arm/mach-omap2/omap_device.c Rosen Penev 2026-03-25 315 return ERR_PTR(ret);
d2740219a804bc arch/arm/mach-omap2/omap_device.c Rosen Penev 2026-03-25 316 }
6d9be9376b0e29 arch/arm/mach-omap2/omap_device.c Jing Xiangfeng 2020-09-19 317
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 318 od->hwmods_cnt = oh_cnt;
d2740219a804bc arch/arm/mach-omap2/omap_device.c Rosen Penev 2026-03-25 319 memcpy(od->hwmods, ohs, oh_cnt * sizeof(*od->hwmods));
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 320
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 321 od->pdev = pdev;
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 322 pdev->archdata.od = od;
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 323
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 324 for (i = 0; i < oh_cnt; i++) {
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 @325 hwmods[i]->od = od;
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 326 _add_hwmod_clocks_clkdev(od, hwmods[i]);
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 327 }
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 328
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 329 return od;
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 330 }
a4f6cdb0672fe9 arch/arm/plat-omap/omap_device.c Benoit Cousson 2011-08-09 331 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki