* [PATCH] dmaengine: lpc18xx-dmamux: simplify allocation
@ 2026-04-07 3:51 Rosen Penev
2026-04-07 13:46 ` Vladimir Zapolskiy
2026-04-08 7:48 ` Frank Li
0 siblings, 2 replies; 3+ messages in thread
From: Rosen Penev @ 2026-04-07 3:51 UTC (permalink / raw)
To: dmaengine
Cc: Vinod Koul, Frank Li, Vladimir Zapolskiy, Kees Cook,
Gustavo A. R. Silva, moderated list:ARM/LPC18XX ARCHITECTURE,
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. Requires
preparation, aka reshuffling before the actual allocation to get the
proper size.
Add __counted_by for extra runtime analysis.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/dma/lpc18xx-dmamux.c | 42 +++++++++++++++++-------------------
1 file changed, 20 insertions(+), 22 deletions(-)
diff --git a/drivers/dma/lpc18xx-dmamux.c b/drivers/dma/lpc18xx-dmamux.c
index d3ff521951b8..5dfefbc496da 100644
--- a/drivers/dma/lpc18xx-dmamux.c
+++ b/drivers/dma/lpc18xx-dmamux.c
@@ -32,11 +32,11 @@ struct lpc18xx_dmamux {
struct lpc18xx_dmamux_data {
struct dma_router dmarouter;
- struct lpc18xx_dmamux *muxes;
u32 dma_master_requests;
u32 dma_mux_requests;
struct regmap *reg;
spinlock_t lock;
+ struct lpc18xx_dmamux muxes[] __counted_by(dma_master_requests);
};
static void lpc18xx_dmamux_free(struct device *dev, void *route_data)
@@ -122,12 +122,30 @@ static int lpc18xx_dmamux_probe(struct platform_device *pdev)
{
struct device_node *dma_np, *np = pdev->dev.of_node;
struct lpc18xx_dmamux_data *dmamux;
+ u32 dma_master_requests;
int ret;
- dmamux = devm_kzalloc(&pdev->dev, sizeof(*dmamux), GFP_KERNEL);
+ dma_np = of_parse_phandle(np, "dma-masters", 0);
+ if (!dma_np) {
+ dev_err(&pdev->dev, "can't get dma master\n");
+ return -ENODEV;
+ }
+
+ ret = of_property_read_u32(dma_np, "dma-requests",
+ &dma_master_requests);
+ of_node_put(dma_np);
+ if (ret) {
+ dev_err(&pdev->dev, "missing master dma-requests property\n");
+ return ret;
+ }
+
+ dmamux = devm_kzalloc(&pdev->dev, struct_size(dmamux, muxes, dma_master_requests),
+ GFP_KERNEL);
if (!dmamux)
return -ENOMEM;
+ dmamux->dma_master_requests = dma_master_requests;
+
dmamux->reg = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg");
if (IS_ERR(dmamux->reg)) {
dev_err(&pdev->dev, "syscon lookup failed\n");
@@ -141,26 +159,6 @@ static int lpc18xx_dmamux_probe(struct platform_device *pdev)
return ret;
}
- dma_np = of_parse_phandle(np, "dma-masters", 0);
- if (!dma_np) {
- dev_err(&pdev->dev, "can't get dma master\n");
- return -ENODEV;
- }
-
- ret = of_property_read_u32(dma_np, "dma-requests",
- &dmamux->dma_master_requests);
- of_node_put(dma_np);
- if (ret) {
- dev_err(&pdev->dev, "missing master dma-requests property\n");
- return ret;
- }
-
- dmamux->muxes = devm_kcalloc(&pdev->dev, dmamux->dma_master_requests,
- sizeof(struct lpc18xx_dmamux),
- GFP_KERNEL);
- if (!dmamux->muxes)
- return -ENOMEM;
-
spin_lock_init(&dmamux->lock);
platform_set_drvdata(pdev, dmamux);
dmamux->dmarouter.dev = &pdev->dev;
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] dmaengine: lpc18xx-dmamux: simplify allocation
2026-04-07 3:51 [PATCH] dmaengine: lpc18xx-dmamux: simplify allocation Rosen Penev
@ 2026-04-07 13:46 ` Vladimir Zapolskiy
2026-04-08 7:48 ` Frank Li
1 sibling, 0 replies; 3+ messages in thread
From: Vladimir Zapolskiy @ 2026-04-07 13:46 UTC (permalink / raw)
To: Rosen Penev, dmaengine
Cc: Vinod Koul, Frank Li, Kees Cook, Gustavo A. R. Silva,
moderated list:ARM/LPC18XX ARCHITECTURE, open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
On 4/7/26 06:51, Rosen Penev wrote:
> Use a flexible array member to combine allocations. Requires
> preparation, aka reshuffling before the actual allocation to get the
> proper size.
>
> Add __counted_by for extra runtime analysis.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> drivers/dma/lpc18xx-dmamux.c | 42 +++++++++++++++++-------------------
> 1 file changed, 20 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/dma/lpc18xx-dmamux.c b/drivers/dma/lpc18xx-dmamux.c
> index d3ff521951b8..5dfefbc496da 100644
> --- a/drivers/dma/lpc18xx-dmamux.c
> +++ b/drivers/dma/lpc18xx-dmamux.c
> @@ -32,11 +32,11 @@ struct lpc18xx_dmamux {
>
> struct lpc18xx_dmamux_data {
> struct dma_router dmarouter;
> - struct lpc18xx_dmamux *muxes;
> u32 dma_master_requests;
> u32 dma_mux_requests;
> struct regmap *reg;
> spinlock_t lock;
> + struct lpc18xx_dmamux muxes[] __counted_by(dma_master_requests);
> };
>
> static void lpc18xx_dmamux_free(struct device *dev, void *route_data)
> @@ -122,12 +122,30 @@ static int lpc18xx_dmamux_probe(struct platform_device *pdev)
> {
> struct device_node *dma_np, *np = pdev->dev.of_node;
> struct lpc18xx_dmamux_data *dmamux;
> + u32 dma_master_requests;
> int ret;
>
> - dmamux = devm_kzalloc(&pdev->dev, sizeof(*dmamux), GFP_KERNEL);
> + dma_np = of_parse_phandle(np, "dma-masters", 0);
> + if (!dma_np) {
> + dev_err(&pdev->dev, "can't get dma master\n");
> + return -ENODEV;
> + }
> +
> + ret = of_property_read_u32(dma_np, "dma-requests",
> + &dma_master_requests);
> + of_node_put(dma_np);
> + if (ret) {
> + dev_err(&pdev->dev, "missing master dma-requests property\n");
> + return ret;
> + }
> +
> + dmamux = devm_kzalloc(&pdev->dev, struct_size(dmamux, muxes, dma_master_requests),
> + GFP_KERNEL);
> if (!dmamux)
> return -ENOMEM;
>
> + dmamux->dma_master_requests = dma_master_requests;
> +
> dmamux->reg = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg");
> if (IS_ERR(dmamux->reg)) {
> dev_err(&pdev->dev, "syscon lookup failed\n");
> @@ -141,26 +159,6 @@ static int lpc18xx_dmamux_probe(struct platform_device *pdev)
> return ret;
> }
>
> - dma_np = of_parse_phandle(np, "dma-masters", 0);
> - if (!dma_np) {
> - dev_err(&pdev->dev, "can't get dma master\n");
> - return -ENODEV;
> - }
> -
> - ret = of_property_read_u32(dma_np, "dma-requests",
> - &dmamux->dma_master_requests);
> - of_node_put(dma_np);
> - if (ret) {
> - dev_err(&pdev->dev, "missing master dma-requests property\n");
> - return ret;
> - }
> -
> - dmamux->muxes = devm_kcalloc(&pdev->dev, dmamux->dma_master_requests,
> - sizeof(struct lpc18xx_dmamux),
> - GFP_KERNEL);
> - if (!dmamux->muxes)
> - return -ENOMEM;
> -
> spin_lock_init(&dmamux->lock);
> platform_set_drvdata(pdev, dmamux);
> dmamux->dmarouter.dev = &pdev->dev;
Reviewed-by: Vladimir Zapolskiy <vz@mleia.com>
--
Best wishes,
Vladimir
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] dmaengine: lpc18xx-dmamux: simplify allocation
2026-04-07 3:51 [PATCH] dmaengine: lpc18xx-dmamux: simplify allocation Rosen Penev
2026-04-07 13:46 ` Vladimir Zapolskiy
@ 2026-04-08 7:48 ` Frank Li
1 sibling, 0 replies; 3+ messages in thread
From: Frank Li @ 2026-04-08 7:48 UTC (permalink / raw)
To: Rosen Penev
Cc: dmaengine, Vinod Koul, Frank Li, Vladimir Zapolskiy, Kees Cook,
Gustavo A. R. Silva, moderated list:ARM/LPC18XX ARCHITECTURE,
open list,
open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b
On Mon, Apr 06, 2026 at 08:51:32PM -0700, Rosen Penev wrote:
Subject need descript summary.
dmaengine: lpc18xx-dmamux: use flexible array to simplify allocation
Frank
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-08 7:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07 3:51 [PATCH] dmaengine: lpc18xx-dmamux: simplify allocation Rosen Penev
2026-04-07 13:46 ` Vladimir Zapolskiy
2026-04-08 7:48 ` Frank Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox