public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ARM: omap2: simplify allocation for omap_device
@ 2026-03-26  2:34 Rosen Penev
  2026-03-27  8:30 ` kernel test robot
  0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-03-26  2:34 UTC (permalink / raw)
  To: linux-omap
  Cc: Aaro Koskinen, Andreas Kemnade, Kevin Hilman, Roger Quadros,
	Tony Lindgren, Russell King, Kees Cook, Gustavo A. R. Silva,
	moderated list:ARM SUB-ARCHITECTURES, open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b

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.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 arch/arm/mach-omap2/omap_device.c | 21 ++++++---------------
 arch/arm/mach-omap2/omap_device.h |  2 +-
 2 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
index 79db4c49ffc9..55f2a9d5f4df 100644
--- a/arch/arm/mach-omap2/omap_device.c
+++ b/arch/arm/mach-omap2/omap_device.c
@@ -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)
diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
index aa8096ecb23c..9283c15c2403 100644
--- a/arch/arm/mach-omap2/omap_device.h
+++ b/arch/arm/mach-omap2/omap_device.h
@@ -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) */
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ARM: omap2: simplify allocation for omap_device
  2026-03-26  2:34 [PATCH] ARM: omap2: simplify allocation for omap_device Rosen Penev
@ 2026-03-27  8:30 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2026-03-27  8:30 UTC (permalink / raw)
  To: Rosen Penev, linux-omap

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/202603271603.kDc2a9Vh-lkp@intel.com/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/202603271603.kDc2a9Vh-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603271603.kDc2a9Vh-lkp@intel.com/

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;
         |                                   ^
         |                                    = NULL
   1 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  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-27  8:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-26  2:34 [PATCH] ARM: omap2: simplify allocation for omap_device Rosen Penev
2026-03-27  8:30 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox