* Re: [PATCH] xfs: use struct_size() helper [not found] <20190411233758.GA19031@embeddedor> @ 2019-04-12 0:19 ` Darrick J. Wong 2019-04-12 1:57 ` Gustavo A. R. Silva 0 siblings, 1 reply; 3+ messages in thread From: Darrick J. Wong @ 2019-04-12 0:19 UTC (permalink / raw) To: Gustavo A. R. Silva; +Cc: linux-xfs, linux-kernel [fixing linux-xfs cc] On Thu, Apr 11, 2019 at 06:37:58PM -0500, Gustavo A. R. Silva wrote: > Make use of the struct_size() helper instead of an open-coded version > in order to avoid any potential type mistakes, in particular in the > context in which this code is being used. > > So, replace code of the following form: > > sizeof(*alist) + context->count * sizeof(alist->al_offset[0] > > with: > > struct_size(alist, al_offset, context->count) > > and remove unnecessary variable arraytop. > > This code was detected with the help of Coccinelle. > > Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Has this been run through xfstests? --D > fs/xfs/xfs_attr_list.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/fs/xfs/xfs_attr_list.c b/fs/xfs/xfs_attr_list.c > index 3d213a7394c5..05e03348553e 100644 > --- a/fs/xfs/xfs_attr_list.c > +++ b/fs/xfs/xfs_attr_list.c > @@ -553,7 +553,6 @@ xfs_attr_put_listent( > { > struct attrlist *alist = (struct attrlist *)context->alist; > attrlist_ent_t *aep; > - int arraytop; > > ASSERT(!context->seen_enough); > ASSERT(!(context->flags & ATTR_KERNOVAL)); > @@ -572,10 +571,8 @@ xfs_attr_put_listent( > ((flags & XFS_ATTR_ROOT) == 0)) > return; > > - arraytop = sizeof(*alist) + > - context->count * sizeof(alist->al_offset[0]); > context->firstu -= ATTR_ENTSIZE(namelen); > - if (context->firstu < arraytop) { > + if (context->firstu < struct_size(alist, al_offset, context->count)) { > trace_xfs_attr_list_full(context); > alist->al_more = 1; > context->seen_enough = 1; > -- > 2.21.0 > ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] xfs: use struct_size() helper 2019-04-12 0:19 ` [PATCH] xfs: use struct_size() helper Darrick J. Wong @ 2019-04-12 1:57 ` Gustavo A. R. Silva 2019-04-12 6:30 ` Darrick J. Wong 0 siblings, 1 reply; 3+ messages in thread From: Gustavo A. R. Silva @ 2019-04-12 1:57 UTC (permalink / raw) To: Darrick J. Wong; +Cc: linux-xfs, linux-kernel On 4/11/19 7:19 PM, Darrick J. Wong wrote: > [fixing linux-xfs cc] > Thanks for this. > On Thu, Apr 11, 2019 at 06:37:58PM -0500, Gustavo A. R. Silva wrote: >> Make use of the struct_size() helper instead of an open-coded version >> in order to avoid any potential type mistakes, in particular in the >> context in which this code is being used. >> >> So, replace code of the following form: >> >> sizeof(*alist) + context->count * sizeof(alist->al_offset[0] >> >> with: >> >> struct_size(alist, al_offset, context->count) >> >> and remove unnecessary variable arraytop. >> >> This code was detected with the help of Coccinelle. >> >> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> > > Has this been run through xfstests? > No. Is this a requirement? Thanks -- Gustavo > --D > >> fs/xfs/xfs_attr_list.c | 5 +---- >> 1 file changed, 1 insertion(+), 4 deletions(-) >> >> diff --git a/fs/xfs/xfs_attr_list.c b/fs/xfs/xfs_attr_list.c >> index 3d213a7394c5..05e03348553e 100644 >> --- a/fs/xfs/xfs_attr_list.c >> +++ b/fs/xfs/xfs_attr_list.c >> @@ -553,7 +553,6 @@ xfs_attr_put_listent( >> { >> struct attrlist *alist = (struct attrlist *)context->alist; >> attrlist_ent_t *aep; >> - int arraytop; >> >> ASSERT(!context->seen_enough); >> ASSERT(!(context->flags & ATTR_KERNOVAL)); >> @@ -572,10 +571,8 @@ xfs_attr_put_listent( >> ((flags & XFS_ATTR_ROOT) == 0)) >> return; >> >> - arraytop = sizeof(*alist) + >> - context->count * sizeof(alist->al_offset[0]); >> context->firstu -= ATTR_ENTSIZE(namelen); >> - if (context->firstu < arraytop) { >> + if (context->firstu < struct_size(alist, al_offset, context->count)) { >> trace_xfs_attr_list_full(context); >> alist->al_more = 1; >> context->seen_enough = 1; >> -- >> 2.21.0 >> ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] xfs: use struct_size() helper 2019-04-12 1:57 ` Gustavo A. R. Silva @ 2019-04-12 6:30 ` Darrick J. Wong 0 siblings, 0 replies; 3+ messages in thread From: Darrick J. Wong @ 2019-04-12 6:30 UTC (permalink / raw) To: Gustavo A. R. Silva; +Cc: linux-xfs, linux-kernel On Thu, Apr 11, 2019 at 08:57:14PM -0500, Gustavo A. R. Silva wrote: > > > On 4/11/19 7:19 PM, Darrick J. Wong wrote: > > [fixing linux-xfs cc] > > > > Thanks for this. > > > On Thu, Apr 11, 2019 at 06:37:58PM -0500, Gustavo A. R. Silva wrote: > >> Make use of the struct_size() helper instead of an open-coded version > >> in order to avoid any potential type mistakes, in particular in the > >> context in which this code is being used. > >> > >> So, replace code of the following form: > >> > >> sizeof(*alist) + context->count * sizeof(alist->al_offset[0] > >> > >> with: > >> > >> struct_size(alist, al_offset, context->count) > >> > >> and remove unnecessary variable arraytop. > >> > >> This code was detected with the help of Coccinelle. > >> > >> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> > > > > Has this been run through xfstests? > > > > No. Is this a requirement? Yes, since this is a change to core functionality (and my eyes aren't so good at digging through preprocessor macros...) --D > Thanks > -- > Gustavo > > > --D > > > >> fs/xfs/xfs_attr_list.c | 5 +---- > >> 1 file changed, 1 insertion(+), 4 deletions(-) > >> > >> diff --git a/fs/xfs/xfs_attr_list.c b/fs/xfs/xfs_attr_list.c > >> index 3d213a7394c5..05e03348553e 100644 > >> --- a/fs/xfs/xfs_attr_list.c > >> +++ b/fs/xfs/xfs_attr_list.c > >> @@ -553,7 +553,6 @@ xfs_attr_put_listent( > >> { > >> struct attrlist *alist = (struct attrlist *)context->alist; > >> attrlist_ent_t *aep; > >> - int arraytop; > >> > >> ASSERT(!context->seen_enough); > >> ASSERT(!(context->flags & ATTR_KERNOVAL)); > >> @@ -572,10 +571,8 @@ xfs_attr_put_listent( > >> ((flags & XFS_ATTR_ROOT) == 0)) > >> return; > >> > >> - arraytop = sizeof(*alist) + > >> - context->count * sizeof(alist->al_offset[0]); > >> context->firstu -= ATTR_ENTSIZE(namelen); > >> - if (context->firstu < arraytop) { > >> + if (context->firstu < struct_size(alist, al_offset, context->count)) { > >> trace_xfs_attr_list_full(context); > >> alist->al_more = 1; > >> context->seen_enough = 1; > >> -- > >> 2.21.0 > >> ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-12 6:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20190411233758.GA19031@embeddedor>
2019-04-12 0:19 ` [PATCH] xfs: use struct_size() helper Darrick J. Wong
2019-04-12 1:57 ` Gustavo A. R. Silva
2019-04-12 6:30 ` Darrick J. Wong
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox