linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] dm ioctl: Use struct_size() helper
       [not found] <20190828183825.GA4216@embeddedor>
@ 2020-06-16 22:06 ` Gustavo A. R. Silva
  2020-06-17 16:30   ` Mike Snitzer
  0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2020-06-16 22:06 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, dm-devel, linux-kernel, Kees Cook

Hi all,

Friendly ping: who can take this?

It's been almost a year... and I just noticed there was a problem
with the email addresses back then...

I just fixed the issue and this patch should now appear on
dm-devel@redhat.com and LKML.

Thanks
--
Gustavo

On 8/28/19 13:38, Gustavo A. R. Silva wrote:
> One of the more common cases of allocation size calculations is finding
> the size of a structure that has a zero-sized array at the end, along
> with memory for some number of elements for that array. For example:
> 
> struct dm_target_deps {
> 	...
>         __u64 dev[0];   /* out */
> };
> 
> Make use of the struct_size() helper instead of an open-coded version
> in order to avoid any potential type mistakes.
> 
> So, replace the following form:
> 
> sizeof(*deps) + (sizeof(*deps->dev) * count)
> 
> with:
> 
> struct_size(deps, dev, count)
> 
> This code was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  drivers/md/dm-ioctl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
> index fb6f8fb1f13d..b2d52cec70d4 100644
> --- a/drivers/md/dm-ioctl.c
> +++ b/drivers/md/dm-ioctl.c
> @@ -1446,7 +1446,7 @@ static void retrieve_deps(struct dm_table *table,
>  	/*
>  	 * Check we have enough space.
>  	 */
> -	needed = sizeof(*deps) + (sizeof(*deps->dev) * count);
> +	needed = struct_size(deps, dev, count);
>  	if (len < needed) {
>  		param->flags |= DM_BUFFER_FULL_FLAG;
>  		return;
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: dm ioctl: Use struct_size() helper
  2020-06-16 22:06 ` [PATCH] dm ioctl: Use struct_size() helper Gustavo A. R. Silva
@ 2020-06-17 16:30   ` Mike Snitzer
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Snitzer @ 2020-06-17 16:30 UTC (permalink / raw)
  To: Gustavo A. R. Silva; +Cc: Alasdair Kergon, dm-devel, linux-kernel, Kees Cook

On Tue, Jun 16 2020 at  6:06pm -0400,
Gustavo A. R. Silva <gustavo@embeddedor.com> wrote:

> Hi all,
> 
> Friendly ping: who can take this?
> 
> It's been almost a year... and I just noticed there was a problem
> with the email addresses back then...
> 
> I just fixed the issue and this patch should now appear on
> dm-devel@redhat.com and LKML.

I don't see any resubmit from you on either list.  But I've applied the
fix by hand and attributed it to you.

Thanks,
Mike


> On 8/28/19 13:38, Gustavo A. R. Silva wrote:
> > One of the more common cases of allocation size calculations is finding
> > the size of a structure that has a zero-sized array at the end, along
> > with memory for some number of elements for that array. For example:
> > 
> > struct dm_target_deps {
> > 	...
> >         __u64 dev[0];   /* out */
> > };
> > 
> > Make use of the struct_size() helper instead of an open-coded version
> > in order to avoid any potential type mistakes.
> > 
> > So, replace the following form:
> > 
> > sizeof(*deps) + (sizeof(*deps->dev) * count)
> > 
> > with:
> > 
> > struct_size(deps, dev, count)
> > 
> > This code was detected with the help of Coccinelle.
> > 
> > Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> > ---
> >  drivers/md/dm-ioctl.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
> > index fb6f8fb1f13d..b2d52cec70d4 100644
> > --- a/drivers/md/dm-ioctl.c
> > +++ b/drivers/md/dm-ioctl.c
> > @@ -1446,7 +1446,7 @@ static void retrieve_deps(struct dm_table *table,
> >  	/*
> >  	 * Check we have enough space.
> >  	 */
> > -	needed = sizeof(*deps) + (sizeof(*deps->dev) * count);
> > +	needed = struct_size(deps, dev, count);
> >  	if (len < needed) {
> >  		param->flags |= DM_BUFFER_FULL_FLAG;
> >  		return;
> > 
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-17 16:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20190828183825.GA4216@embeddedor>
2020-06-16 22:06 ` [PATCH] dm ioctl: Use struct_size() helper Gustavo A. R. Silva
2020-06-17 16:30   ` Mike Snitzer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).