From: Rosen Penev <rosenp@gmail.com>
To: linux-omap@vger.kernel.org
Cc: Aaro Koskinen <aaro.koskinen@iki.fi>,
Andreas Kemnade <andreas@kemnade.info>,
Kevin Hilman <khilman@baylibre.com>,
Roger Quadros <rogerq@kernel.org>,
Tony Lindgren <tony@atomide.com>,
Russell King <linux@armlinux.org.uk>, Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-arm-kernel@lists.infradead.org (moderated list:ARM
SUB-ARCHITECTURES), linux-kernel@vger.kernel.org (open list),
linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not
covered by other areas):Keyword:\b__counted_by(_le|_be)?\b)
Subject: [PATCHv2] ARM: omap2: simplify allocation for omap_device
Date: Fri, 27 Mar 2026 12:11:04 -0700 [thread overview]
Message-ID: <20260327191104.206512-1-rosenp@gmail.com> (raw)
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>
---
v2: remove kfree and fix compilation.
arch/arm/mach-omap2/omap_device.c | 29 ++++++++++-------------------
arch/arm/mach-omap2/omap_device.h | 4 ++--
2 files changed, 12 insertions(+), 21 deletions(-)
diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
index 79db4c49ffc9..77a75b0b9ae6 100644
--- a/arch/arm/mach-omap2/omap_device.c
+++ b/arch/arm/mach-omap2/omap_device.c
@@ -307,35 +307,27 @@ static struct omap_device *omap_device_alloc(struct platform_device *pdev,
int ret = -ENOMEM;
struct omap_device *od;
int i;
- struct omap_hwmod **hwmods;
+ struct omap_hwmod *hwmod;
- 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;
for (i = 0; i < oh_cnt; i++) {
- hwmods[i]->od = od;
- _add_hwmod_clocks_clkdev(od, hwmods[i]);
+ hwmod = od->hwmods[i];
+ hwmod->od = od;
+ _add_hwmod_clocks_clkdev(od, hwmod);
}
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)
@@ -344,7 +336,6 @@ static void omap_device_delete(struct omap_device *od)
return;
od->pdev->archdata.od = NULL;
- kfree(od->hwmods);
kfree(od);
}
diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
index aa8096ecb23c..fae09cfce137 100644
--- a/arch/arm/mach-omap2/omap_device.h
+++ b/arch/arm/mach-omap2/omap_device.h
@@ -37,11 +37,11 @@
/**
* struct omap_device - omap_device wrapper for platform_devices
* @pdev: platform_device
- * @hwmods: (one .. many per omap_device)
* @hwmods_cnt: ARRAY_SIZE() of @hwmods
* @_state: one of OMAP_DEVICE_STATE_* (see above)
* @flags: device flags
* @_driver_status: one of BUS_NOTIFY_*_DRIVER from <linux/device.h>
+ * @hwmods: (one .. many per omap_device)
*
* Integrates omap_hwmod data into Linux platform_device.
*
@@ -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
next reply other threads:[~2026-03-27 19:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-27 19:11 Rosen Penev [this message]
2026-03-30 21:20 ` [PATCHv2] ARM: omap2: simplify allocation for omap_device Kevin Hilman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260327191104.206512-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=aaro.koskinen@iki.fi \
--cc=andreas@kemnade.info \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=khilman@baylibre.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=rogerq@kernel.org \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.