public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Rosen Penev <rosenp@gmail.com>, dmaengine@vger.kernel.org
Cc: Patrice Chotard <patrice.chotard@foss.st.com>,
	Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
	Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	"moderated list:ARM/STI ARCHITECTURE"
	<linux-arm-kernel@lists.infradead.org>,
	open list <linux-kernel@vger.kernel.org>,
	open "list:KERNEL" HARDENING "(not" covered by other
	"areas):Keyword:b__counted_by(_le|_be)?b"
	<linux-hardening@vger.kernel.org>
Subject: Re: [PATCH] dmaengine: st_fdma: simplify allocation
Date: Tue, 31 Mar 2026 09:33:13 -0600	[thread overview]
Message-ID: <5977a259-a7ae-43be-ad09-d09115268854@embeddedor.com> (raw)
In-Reply-To: <20260330211555.13974-1-rosenp@gmail.com>



On 3/30/26 15:15, Rosen Penev wrote:
> Use a flexible array member to combine kzalloc and kcalloc to a single
> allocation.
> 
> Add __counted_by for extra runtime analysis. 

Assign counting variable
> after allocation as required by __counted_by.

This is misinformation and should be phrased differently[1]

-Gustavo

[1] https://lore.kernel.org/linux-hardening/37378f49-437f-438b-ad6c-d60480feb306@embeddedor.com/

> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>   drivers/dma/st_fdma.c | 27 ++++++++-------------------
>   drivers/dma/st_fdma.h |  4 ++--
>   2 files changed, 10 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/dma/st_fdma.c b/drivers/dma/st_fdma.c
> index d9547017f3bd..3ec0d6731b8d 100644
> --- a/drivers/dma/st_fdma.c
> +++ b/drivers/dma/st_fdma.c
> @@ -710,16 +710,6 @@ static const struct of_device_id st_fdma_match[] = {
>   };
>   MODULE_DEVICE_TABLE(of, st_fdma_match);
>   
> -static int st_fdma_parse_dt(struct platform_device *pdev,
> -			const struct st_fdma_driverdata *drvdata,
> -			struct st_fdma_dev *fdev)
> -{
> -	snprintf(fdev->fw_name, FW_NAME_SIZE, "fdma_%s_%d.elf",
> -		drvdata->name, drvdata->id);
> -
> -	return of_property_read_u32(pdev->dev.of_node, "dma-channels",
> -				    &fdev->nr_channels);
> -}
>   #define FDMA_DMA_BUSWIDTHS	(BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \
>   				 BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \
>   				 BIT(DMA_SLAVE_BUSWIDTH_3_BYTES) | \
> @@ -742,27 +732,26 @@ static int st_fdma_probe(struct platform_device *pdev)
>   	struct st_fdma_dev *fdev;
>   	struct device_node *np = pdev->dev.of_node;
>   	const struct st_fdma_driverdata *drvdata;
> +	u32 nr_channels;
>   	int ret, i;
>   
>   	drvdata = device_get_match_data(&pdev->dev);
>   
> -	fdev = devm_kzalloc(&pdev->dev, sizeof(*fdev), GFP_KERNEL);
> -	if (!fdev)
> -		return -ENOMEM;
> -
> -	ret = st_fdma_parse_dt(pdev, drvdata, fdev);
> +	ret = of_property_read_u32(pdev->dev.of_node, "dma-channels", &nr_channels);
>   	if (ret) {
>   		dev_err(&pdev->dev, "unable to find platform data\n");
> -		goto err;
> +		return ret;
>   	}
>   
> -	fdev->chans = devm_kcalloc(&pdev->dev, fdev->nr_channels,
> -				   sizeof(struct st_fdma_chan), GFP_KERNEL);
> -	if (!fdev->chans)
> +	fdev = devm_kzalloc(&pdev->dev, struct_size(fdev, chans, nr_channels), GFP_KERNEL);
> +	if (!fdev)
>   		return -ENOMEM;
>   
> +	fdev->nr_channels = nr_channels;
>   	fdev->dev = &pdev->dev;
>   	fdev->drvdata = drvdata;
> +	snprintf(fdev->fw_name, FW_NAME_SIZE, "fdma_%s_%d.elf", drvdata->name, drvdata->id);
> +
>   	platform_set_drvdata(pdev, fdev);
>   
>   	fdev->irq = platform_get_irq(pdev, 0);
> diff --git a/drivers/dma/st_fdma.h b/drivers/dma/st_fdma.h
> index f1e746f7bc7d..27ded555879f 100644
> --- a/drivers/dma/st_fdma.h
> +++ b/drivers/dma/st_fdma.h
> @@ -136,13 +136,13 @@ struct st_fdma_dev {
>   
>   	int irq;
>   
> -	struct st_fdma_chan *chans;
> -
>   	spinlock_t dreq_lock;
>   	unsigned long dreq_mask;
>   
>   	u32 nr_channels;
>   	char fw_name[FW_NAME_SIZE];
> +
> +	struct st_fdma_chan chans[] __counted_by(nr_channels);
>   };
>   
>   /* Peripheral Registers*/



      reply	other threads:[~2026-03-31 15:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-30 21:15 [PATCH] dmaengine: st_fdma: simplify allocation Rosen Penev
2026-03-31 15:33 ` Gustavo A. R. Silva [this message]

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=5977a259-a7ae-43be-ad09-d09115268854@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=gustavoars@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patrice.chotard@foss.st.com \
    --cc=rosenp@gmail.com \
    --cc=vkoul@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox