From: Rosen Penev <rosenp@gmail.com>
To: dmaengine@vger.kernel.org
Cc: Peter Ujfalusi <peter.ujfalusi@gmail.com>,
Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Haotian Zhang <vulab@iscas.ac.cn>,
Tony Lindgren <tony@atomide.com>,
Russell King <rmk+kernel@arm.linux.org.uk>,
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|_ptr)?\b)
Subject: [PATCHv3 8/8] dmaengine: ti: omap-dma: turn lch_map into a flexible array
Date: Tue, 2 Jun 2026 20:07:54 -0700 [thread overview]
Message-ID: <20260603030754.288757-9-rosenp@gmail.com> (raw)
In-Reply-To: <20260603030754.288757-1-rosenp@gmail.com>
Convert the separately-allocated lch_map pointer array to a C99
flexible array member at the end of struct omap_dmadev and annotate it
with __counted_by(lch_count). The probe is reordered so platform_data
lookup and the lch_count determination happen before the parent
allocation, letting struct_size() size the FAM and the dedicated
devm_kcalloc() for lch_map go away.
Two allocations collapse into one and the runtime bounds checks from
__counted_by now apply to every lch_map[] access.
Assisted-by: Opencode:BigPickle
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/dma/ti/omap-dma.c | 72 +++++++++++++++++++--------------------
1 file changed, 36 insertions(+), 36 deletions(-)
diff --git a/drivers/dma/ti/omap-dma.c b/drivers/dma/ti/omap-dma.c
index 7343325ce2b1..dab600604572 100644
--- a/drivers/dma/ti/omap-dma.c
+++ b/drivers/dma/ti/omap-dma.c
@@ -49,7 +49,7 @@ struct omap_dmadev {
const struct omap_dma_config *cfg;
struct notifier_block nb;
struct omap_dma_context context;
- int lch_count;
+ u32 lch_count;
DECLARE_BITMAP(lch_bitmap, OMAP_SDMA_CHANNELS);
struct mutex lch_lock; /* for assigning logical channels */
bool legacy;
@@ -58,7 +58,7 @@ struct omap_dmadev {
unsigned dma_requests;
spinlock_t irq_lock;
uint32_t irq_enable_mask;
- struct omap_chan **lch_map;
+ struct omap_chan *lch_map[] __counted_by(lch_count);
};
struct omap_chan {
@@ -1661,36 +1661,55 @@ static const struct omap_dma_config default_cfg;
static int omap_dma_probe(struct platform_device *pdev)
{
const struct omap_dma_config *conf;
+ struct omap_system_dma_plat_info *plat;
struct omap_dmadev *od;
+ u32 lch_count;
int rc, i, irq;
u32 val;
- od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
- if (!od)
- return -ENOMEM;
-
- od->base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(od->base))
- return PTR_ERR(od->base);
-
conf = of_device_get_match_data(&pdev->dev);
if (conf) {
- od->cfg = conf;
- od->plat = dev_get_platdata(&pdev->dev);
- if (!od->plat) {
+ plat = dev_get_platdata(&pdev->dev);
+ if (!plat) {
dev_err(&pdev->dev, "omap_system_dma_plat_info is missing");
return -ENODEV;
}
} else if (IS_ENABLED(CONFIG_ARCH_OMAP1)) {
- od->cfg = &default_cfg;
-
- od->plat = omap_get_plat_info();
- if (!od->plat)
+ plat = omap_get_plat_info();
+ if (!plat)
return -EPROBE_DEFER;
} else {
return -ENODEV;
}
+ /* Number of available logical channels */
+ if (!pdev->dev.of_node) {
+ lch_count = plat->dma_attr->lch_count;
+ if (unlikely(!lch_count))
+ lch_count = OMAP_SDMA_CHANNELS;
+ } else if (of_property_read_u32(pdev->dev.of_node, "dma-channels", &lch_count)) {
+ dev_info(&pdev->dev, "Missing dma-channels property, using %u.\n",
+ OMAP_SDMA_CHANNELS);
+ lch_count = OMAP_SDMA_CHANNELS;
+ }
+
+ if (lch_count > OMAP_SDMA_CHANNELS) {
+ dev_err(&pdev->dev, "invalid dma-channels value %u\n", lch_count);
+ return -EINVAL;
+ }
+
+ od = devm_kzalloc(&pdev->dev, struct_size(od, lch_map, lch_count), GFP_KERNEL);
+ if (!od)
+ return -ENOMEM;
+
+ od->lch_count = lch_count;
+ od->plat = plat;
+ od->cfg = conf ? conf : &default_cfg;
+
+ od->base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(od->base))
+ return PTR_ERR(od->base);
+
od->reg_map = od->plat->reg_map;
dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
@@ -1735,19 +1754,6 @@ static int omap_dma_probe(struct platform_device *pdev)
OMAP_SDMA_REQUESTS);
}
- /* Number of available logical channels */
- if (!pdev->dev.of_node) {
- od->lch_count = od->plat->dma_attr->lch_count;
- if (unlikely(!od->lch_count))
- od->lch_count = OMAP_SDMA_CHANNELS;
- } else if (of_property_read_u32(pdev->dev.of_node, "dma-channels",
- &od->lch_count)) {
- dev_info(&pdev->dev,
- "Missing dma-channels property, using %u.\n",
- OMAP_SDMA_CHANNELS);
- od->lch_count = OMAP_SDMA_CHANNELS;
- }
-
/* Mask of allowed logical channels */
if (pdev->dev.of_node && !of_property_read_u32(pdev->dev.of_node,
"dma-channel-mask",
@@ -1759,12 +1765,6 @@ static int omap_dma_probe(struct platform_device *pdev)
if (od->plat->dma_attr->dev_caps & HS_CHANNELS_RESERVED)
bitmap_set(od->lch_bitmap, 0, 2);
- od->lch_map = devm_kcalloc(&pdev->dev, od->lch_count,
- sizeof(*od->lch_map),
- GFP_KERNEL);
- if (!od->lch_map)
- return -ENOMEM;
-
for (i = 0; i < od->dma_requests; i++) {
rc = omap_dma_chan_init(od);
if (rc) {
--
2.54.0
next prev parent reply other threads:[~2026-06-03 3:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 3:07 [PATCH v3 0/8] dmaengine: ti: omap-dma: probe/remove bug fixes and cleanup Rosen Penev
2026-06-03 3:07 ` [PATCHv3 1/8] dmaengine: ti: omap-dma: fix missing return in probe error path Rosen Penev
2026-06-03 3:18 ` sashiko-bot
2026-06-03 3:07 ` [PATCHv3 2/8] dmaengine: ti: omap-dma: synchronize CPU PM notifier removal Rosen Penev
2026-06-03 3:18 ` sashiko-bot
2026-06-03 3:07 ` [PATCHv3 3/8] dmaengine: ti: omap-dma: fix CPU PM notifier leak Rosen Penev
2026-06-03 3:07 ` [PATCHv3 4/8] dmaengine: ti: omap-dma: stop channels during teardown Rosen Penev
2026-06-03 3:25 ` sashiko-bot
2026-06-03 3:07 ` [PATCHv3 5/8] dmaengine: ti: omap-dma: disable IRQs on probe failure Rosen Penev
2026-06-03 3:21 ` sashiko-bot
2026-06-03 3:07 ` [PATCHv3 6/8] dmaengine: ti: omap-dma: destroy descriptor pool last Rosen Penev
2026-06-03 3:07 ` [PATCHv3 7/8] dmaengine: ti: omap-dma: fix interrupt handling in remove Rosen Penev
2026-06-03 3:07 ` Rosen Penev [this message]
2026-06-03 3:23 ` [PATCHv3 8/8] dmaengine: ti: omap-dma: turn lch_map into a flexible array sashiko-bot
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=20260603030754.288757-9-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peter.ujfalusi@gmail.com \
--cc=rmk+kernel@arm.linux.org.uk \
--cc=tony@atomide.com \
--cc=vkoul@kernel.org \
--cc=vulab@iscas.ac.cn \
/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.