xfs: use struct_size() helper
A message that is not in the archive (sent off-list or not yet received): 20190411233758.GA19031@embeddedor
[fixing linux-xfs cc]
Quoted 10 lines · Gustavo A. R. Silva
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:
Quoted 7 lines
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 <[email protected]>
Has this been run through xfstests?
--D
Quoted 30 lines
fs/xfs/xfs_attr_list.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)fs/xfs/xfs_attr_list.c +1
-4@@ -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 ;Signature · 1 line
2.21.0
Quoted 2 lines · Darrick J. Wong
[fixing linux-xfs cc]
Thanks for this.
Quoted 13 lines · Gustavo A. R. Silva
Quoted 12 lines
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)
Quoted 8 lines
Quoted 5 lines
and remove unnecessary variable arraytop.
This code was detected with the help of Coccinelle.
Signed-off-by Gustavo A. R. Silva <[email protected]>Has this been run through xfstests?
No. Is this a requirement?
Thanks
--
Gustavo
Quoted 32 lines
--D
Quoted 30 lines
fs/xfs/xfs_attr_list.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)fs/xfs/xfs_attr_list.c +1
-4@@ -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 ;Signature · 1 line
2.21.0
Quoted 23 lines · Gustavo A. R. Silva
Quoted 2 lines · Darrick J. Wong
[fixing linux-xfs cc]
Thanks for this.
Quoted 15 lines · Gustavo A. R. Silva
Quoted 14 lines
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.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
This code was detected with the help of Coccinelle.
Signed-off-by Gustavo A. R. Silva <[email protected]>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
Quoted 36 lines
Thanks
--
GustavoQuoted 32 lines
--D
Quoted 30 lines
fs/xfs/xfs_attr_list.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)fs/xfs/xfs_attr_list.c +1
-4@@ -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 ;Signature · 1 line
2.21.0