From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Rosen Penev <rosenp@gmail.com>
Cc: dmaengine@vger.kernel.org, Andy Shevchenko <andy@kernel.org>,
Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
"open list:INTEL MID (Mobile Internet Device) PLATFORM"
<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: hsu: use kzalloc_flex
Date: Fri, 27 Mar 2026 12:03:11 +0200 [thread overview]
Message-ID: <acZV35Q80GfDKkkd@ashevche-desk.local> (raw)
In-Reply-To: <20260327025943.8178-1-rosenp@gmail.com>
On Thu, Mar 26, 2026 at 07:59:43PM -0700, Rosen Penev wrote:
> Simplifies allocations by using a flexible array member in this struct.
>
> Remove hsu_dma_alloc_desc. It now offers no readability advantages in
> this single usage.
>
> Add __counted_by to get extra runtime analysis.
>
> Apply the exact same treatment to struct hsu_dma and devm_kzalloc.
We refer to the functions in the comments and commit messages as func().
Please, update this patch accordingly.
...
> static void hsu_dma_desc_free(struct virt_dma_desc *vdesc)
> {
> struct hsu_dma_desc *desc = to_hsu_dma_desc(vdesc);
>
> - kfree(desc->sg);
> kfree(desc);
It can be collapsed to a single line, but for the sake of clarity the above is
okay.
> }
...
> - desc = hsu_dma_alloc_desc(sg_len);
> + desc = kzalloc_flex(*desc, sg, sg_len, GFP_NOWAIT);
> if (!desc)
> return NULL;
>
> + desc->nents = sg_len;
> +
> - desc->nents = sg_len;
> desc->direction = direction;
> /* desc->active = 0 by kzalloc */
> desc->status = DMA_IN_PROGRESS;
This nents move makes disruption is the field assignment block.
Please, move them all up.
...
> void __iomem *addr = chip->regs + chip->offset;
> unsigned short i;
> int ret;
> + unsigned short nr_channels;
Preserve reversed xmas tree order.
...
> - hsu = devm_kzalloc(chip->dev, sizeof(*hsu), GFP_KERNEL);
> + /* Calculate nr_channels from the IO space length */
> + nr_channels = (chip->length - chip->offset) / HSU_DMA_CHAN_LENGTH;
> + hsu = devm_kzalloc(chip->dev, struct_size(hsu, chan, nr_channels), GFP_KERNEL);
> if (!hsu)
> return -ENOMEM;
>
> + hsu->nr_channels = nr_channels;
+ blank line.
> chip->hsu = hsu;
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2026-03-27 10:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-27 2:59 Rosen Penev
2026-03-27 10:03 ` Andy Shevchenko [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=acZV35Q80GfDKkkd@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=Frank.Li@kernel.org \
--cc=andy@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=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
all inboxes | Powered by JetHome®