dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: christian.koenig@amd.com
Cc: dri-devel <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH] dma-buf: use struct_size macro
Date: Thu, 8 Oct 2020 08:18:24 -0500	[thread overview]
Message-ID: <20201008131824.GA6588@embeddedor> (raw)
In-Reply-To: <5d1b3405-64d4-0e69-7337-caa456abcb78@gmail.com>

On Thu, Oct 08, 2020 at 10:40:10AM +0200, Christian König wrote:
> Am 08.10.20 um 10:17 schrieb Daniel Vetter:
> > On Thu, Oct 8, 2020 at 10:10 AM Christian König
> > <ckoenig.leichtzumerken@gmail.com> wrote:
> > > Instead of manually calculating the structure size.
> > > 
> > > Signed-off-by: Christian König <christian.koenig@amd.com>
> > Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

> 
> Thanks, could anybody (not me) come up with a cocci script for this?
> 
> I'm pretty sure we have used this pattern more than once in the kernel.
> 

Sure thing. I'll take care of that. I saw this same pattern, recently[1]:

"
> +       size = offsetof(struct pmt_crashlog_priv, entry[pdev->num_resources]);
> +       priv = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
> +       if (!priv)
> +               return -ENOMEM;

struct_size()
"

[1] https://lore.kernel.org/lkml/CAHp75VcP58Ub=gmbRVy0TPJtntKvnQZoi3tOakxE0qsEqzGPVA@mail.gmail.com/

Thanks
--
Gustavo

> 
> > 
> > > ---
> > >   drivers/dma-buf/dma-resv.c | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
> > > index 1c8f2581cb09..bb5a42b10c29 100644
> > > --- a/drivers/dma-buf/dma-resv.c
> > > +++ b/drivers/dma-buf/dma-resv.c
> > > @@ -63,7 +63,7 @@ static struct dma_resv_list *dma_resv_list_alloc(unsigned int shared_max)
> > >   {
> > >          struct dma_resv_list *list;
> > > 
> > > -       list = kmalloc(offsetof(typeof(*list), shared[shared_max]), GFP_KERNEL);
> > > +       list = kmalloc(struct_size(list, shared, shared_max), GFP_KERNEL);
> > >          if (!list)
> > >                  return NULL;
> > > 
> > > --
> > > 2.17.1
> > > 
> > > _______________________________________________
> > > dri-devel mailing list
> > > dri-devel@lists.freedesktop.org
> > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> > 
> > 
> 
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

      reply	other threads:[~2020-10-08 13:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-08  8:10 [PATCH] dma-buf: use struct_size macro Christian König
2020-10-08  8:17 ` Daniel Vetter
2020-10-08  8:40   ` Christian König
2020-10-08 13:18     ` 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=20201008131824.GA6588@embeddedor \
    --to=gustavoars@kernel.org \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.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