fs/ntfs3: Fix various styling issues
cover fs/ntfs3: Fix various styling issues
Many new checkpatch warnings have been introduce to ntfs3. These could have been prevent if checkpatch is used. One thing that worrys me is that Konstantin puts new code without code reviewing process to ntfs3. Patch commit message says one thing, but one huge patch address that and lot of just refactoring code. Also with review process we can prevent these kind of silly checkpatch mistakes.
Kmalloc_array was my fault for some reason checkpatch did not show those. I have no idea how, but I just fix it now and be very ashamed. You should also Konstantin use checkpatch always before push so you can spot these things before hand. I will try to get CI going for patches.
Kari Argillander (5):
fs/ntfs3: Use kmalloc_array over kmalloc with multiply fs/ntfs3: Use consistent spacing around '+' fs/ntfs3: Place Comparisons constant right side of the test fs/ntfs3: Remove braces from single statment block fs/ntfs3: Remove tabs before spaces from comment
fs/ntfs3/bitmap.c | 2 +- fs/ntfs3/frecord.c | 8 ++++---- fs/ntfs3/index.c | 4 ++-- fs/ntfs3/lznt.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-)
base-commit: d3624466b56dd5b1886c1dff500525b544c19c83
Signature · 1 line
2.25.1
PATCH 1/5 fs/ntfs3: Use kmalloc_array over kmalloc with multiply
If we do not use kmalloc_array we get checkpatch warning. It is also little safer if something goes wrong with coding.
--- fs/ntfs3/bitmap.c | 2 +- fs/ntfs3/index.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
fs/ntfs3/bitmap.c +1 -1
@@ -1331,7 +1331,7 @@ int wnd_extend(struct wnd_bitmap *wnd, size_t new_bits) new_last = wbits;if (new_wnd != wnd->nwnd) { - new_free =kmalloc (new_wnd *sizeof (u16),GFP_NOFS ); + new_free =kmalloc_array (new_wnd,sizeof (u16),GFP_NOFS );if (!new_free)return -ENOMEM ;
fs/ntfs3/index.c +2 -2
@@ -685,7 +685,7 @@ static struct NTFS_DE *hdr_find_e(const struct ntfs_index *indx,if (end >0x10000 ) goto next; - offs =kmalloc (sizeof (u16) * nslots,GFP_NOFS ); + offs =kmalloc_array (nslots,sizeof (u16),GFP_NOFS );if (!offs) goto next;
@@ -707,7 +707,7 @@ static struct NTFS_DE *hdr_find_e(const struct ntfs_index *indx,u16 *ptr;int new_slots =ALIGN (2 * nslots,8 ); - ptr =kmalloc (sizeof (u16) * new_slots,GFP_NOFS ); + ptr =kmalloc_array (new_slots,sizeof (u16),GFP_NOFS );if (ptr)memcpy (ptr, offs,sizeof (u16) * max_idx);kfree (offs);
Signature · 1 line
2.25.1
Re: [PATCH 1/5] fs/ntfs3: Use kmalloc_array over kmalloc with multiply
Quoted 2 lines · Kari Argillander
If we do not use
kmalloc_arraywe get checkpatch warning. It is also little safer if something goes wrong with coding.
[]
fs/ntfs3/index.c
Quoted 1 line
fs/ntfs3/index.c +0
-0
[]
Quoted 9 lines
fs/ntfs3/index.c +0
-0@@ -707,7 +707,7 @@ static struct NTFS_DE *hdr_find_e(const struct ntfs_index *indx, u16 *ptr; int new_slots = ALIGN(2 * nslots, 8);fs/ntfs3/index.c +1
-1- ptr =kmalloc (sizeof (u16) * new_slots,GFP_NOFS ); + ptr =kmalloc_array (new_slots,sizeof (u16),GFP_NOFS );if (ptr)
memcpy(ptr, offs, sizeof(u16) * max_idx);
This multiplication could also overflow.
Maybe use krealloc?
Re: [PATCH 1/5] fs/ntfs3: Use kmalloc_array over kmalloc with multiply
Quoted 11 lines · Joe Perches
Quoted 2 lines · Kari Argillander
If we do not use
kmalloc_arraywe get checkpatch warning. It is also little safer if something goes wrong with coding.[]
fs/ntfs3/index.c
Quoted 1 line
fs/ntfs3/index.c +0
-0[]
Quoted 5 lines
fs/ntfs3/index.c +0
-0@@ -707,7 +707,7 @@ static struct NTFS_DE *hdr_find_e(const struct ntfs_index *indx, u16 *ptr; int new_slots = ALIGN(2 * nslots, 8);
Quoted 8 lines
Quoted 4 lines
fs/ntfs3/index.c +1
-1- ptr =kmalloc (sizeof (u16) * new_slots,GFP_NOFS ); + ptr =kmalloc_array (new_slots,sizeof (u16),GFP_NOFS );if (ptr)
memcpy(ptr, offs, sizeof(u16) * max_idx);This multiplication could also overflow.
Maybe use krealloc?
Seems to fit lot better here. But as I was watching this it seems that we do not even need to resize this array. It is quite costly operation compared to what entry compare cost.
We just need to compare it and if entry diff > 0 then we start entry table again from zero without need resize array. It may be that we do not even need to allocate memory. We can probably survive with stack, but let's think that later.
This can also speed up search a lot. It is quite odd that we always fill whole table and will not never check if we are over. Worst case is very very bad. With this change this will be more like jump search but I think it will be good in this case because we won't need memory allocation.
Thanks Joe.
RE: [PATCH 1/5] fs/ntfs3: Use kmalloc_array over kmalloc with multiply
In reply to Joe PerchesFrom: Joe Perches
Quoted 13 lines
Sent: 01 September 2021 03:41
Quoted 2 lines · Kari Argillander
If we do not use
kmalloc_arraywe get checkpatch warning. It is also little safer if something goes wrong with coding.[]
fs/ntfs3/index.c
Quoted 1 line
fs/ntfs3/index.c +0
-0[]
Quoted 5 lines
fs/ntfs3/index.c +0
-0@@ -707,7 +707,7 @@ static struct NTFS_DE *hdr_find_e(const struct ntfs_index *indx, u16 *ptr; int new_slots = ALIGN(2 * nslots, 8);
Quoted 6 lines
fs/ntfs3/index.c static struct NTFS_DE *hdr_find_e(const struct ntfs_index *indx, · line 712
Quoted 4 lines
fs/ntfs3/index.c +1
-1- ptr =kmalloc (sizeof (u16) * new_slots,GFP_NOFS ); + ptr =kmalloc_array (new_slots,sizeof (u16),GFP_NOFS ); if (ptr) memcpy(ptr, offs, sizeof(u16) * max_idx);This multiplication could also overflow.
Not if kmalloc_array() has suceeded.
OTOH the ALIGN(2 * nslots, 8) can also go wrong.
(But probably not if the previous kmalloc() for 1/2 the size worked.)
But there really ought to be some kind of bound check earlier.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
PATCH 2/5 fs/ntfs3: Use consistent spacing around '+'
In reply to Kari ArgillanderUse consistent spacing around '+' for better code reading. Checkpatch will also be happy.
--- fs/ntfs3/frecord.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/frecord.c +1 -1
@@ -1451,7 +1451,7 @@ int ni_insert_resident(struct ntfs_inode *ni, u32 data_size, attr->res.flags =RESIDENT_FLAG_INDEXED ;/* is_attr_indexed(attr)) == true */ -le16_add_cpu (&ni->mi.mrec->hard_links,+1 ); +le16_add_cpu (&ni->mi.mrec->hard_links, +1 ); ni->mi.dirty = true; } attr->res.res =0 ;
Signature · 1 line
2.25.1
Re: [PATCH 2/5] fs/ntfs3: Use consistent spacing around '+'
Quoted 2 lines · Kari Argillander
Use consistent spacing around '+' for better code reading. Checkpatch will also be happy.
I think you should remove the + instead
fs/ntfs3/frecord.c
Quoted 1 line
fs/ntfs3/frecord.c +0
-0
[]
fs/ntfs3/frecord.c int ni_insert_resident(struct ntfs_inode *ni, u32 data_size, · line 1454
Quoted 7 lines
fs/ntfs3/frecord.c +0
-0@@ -1451,7 +1451,7 @@ int ni_insert_resident(struct ntfs_inode *ni, u32 data_size, attr->res.flags = RESIDENT_FLAG_INDEXED;/*
is_attr_indexed(attr)) == true */fs/ntfs3/frecord.c +1
-1-le16_add_cpu (&ni->mi.mrec->hard_links,+1 ); +le16_add_cpu (&ni->mi.mrec->hard_links, +1 );
le16_add_cpu(&ni->mi.mrec->hard_links, 1);
Re: [PATCH 2/5] fs/ntfs3: Use consistent spacing around '+'
Quoted 5 lines · Joe Perches
Quoted 2 lines · Kari Argillander
Use consistent spacing around '+' for better code reading. Checkpatch will also be happy.
I think you should remove the + instead
Konstantin can you look this as this was introduce by you just couple days ago?
Quoted 14 lines
fs/ntfs3/frecord.c
Quoted 2 lines
fs/ntfs3/frecord.c +0
-0[]
fs/ntfs3/frecord.c int ni_insert_resident(struct ntfs_inode *ni, u32 data_size, · line 1454
Quoted 7 lines
fs/ntfs3/frecord.c +0
-0@@ -1451,7 +1451,7 @@ int ni_insert_resident(struct ntfs_inode *ni, u32 data_size, attr->res.flags = RESIDENT_FLAG_INDEXED;/*
is_attr_indexed(attr)) == true */fs/ntfs3/frecord.c +1
-1-le16_add_cpu (&ni->mi.mrec->hard_links,+1 ); +le16_add_cpu (&ni->mi.mrec->hard_links, +1 );le16_add_cpu(&ni->mi.mrec->hard_links, 1);
Konstantin Komarov
maintainerRe: [PATCH 2/5] fs/ntfs3: Use consistent spacing around '+'
Quoted 24 lines · Kari Argillander
Quoted 5 lines · Joe Perches
Quoted 2 lines · Kari Argillander
Use consistent spacing around '+' for better code reading. Checkpatch will also be happy.
I think you should remove the + instead
Konstantin can you look this as this was introduce by you just couple days ago?
Quoted 14 lines
fs/ntfs3/frecord.c
Quoted 2 lines
fs/ntfs3/frecord.c +0
-0[]
fs/ntfs3/frecord.c int ni_insert_resident(struct ntfs_inode *ni, u32 data_size, · line 1454
Quoted 7 lines
fs/ntfs3/frecord.c +0
-0@@ -1451,7 +1451,7 @@ int ni_insert_resident(struct ntfs_inode *ni, u32 data_size, attr->res.flags = RESIDENT_FLAG_INDEXED;/*
is_attr_indexed(attr)) == true */fs/ntfs3/frecord.c +1
-1-le16_add_cpu (&ni->mi.mrec->hard_links,+1 ); +le16_add_cpu (&ni->mi.mrec->hard_links, +1 );le16_add_cpu(&ni->mi.mrec->hard_links, 1);
Hi, Kari, Joe!
Yes, '+' can be removed, it was added for better visibility, but it's subjective.
After checking code - it's the only place with '+1', so let's remove it.
Re: [PATCH 2/5] fs/ntfs3: Use consistent spacing around '+'
Quoted 28 lines · Konstantin Komarov
Quoted 24 lines · Kari Argillander
Quoted 5 lines · Joe Perches
Quoted 2 lines · Kari Argillander
Use consistent spacing around '+' for better code reading. Checkpatch will also be happy.
I think you should remove the + instead
Konstantin can you look this as this was introduce by you just couple days ago?
Quoted 14 lines
fs/ntfs3/frecord.c
Quoted 2 lines
fs/ntfs3/frecord.c +0
-0[]
fs/ntfs3/frecord.c int ni_insert_resident(struct ntfs_inode *ni, u32 data_size, · line 1454
Quoted 7 lines
fs/ntfs3/frecord.c +0
-0@@ -1451,7 +1451,7 @@ int ni_insert_resident(struct ntfs_inode *ni, u32 data_size, attr->res.flags = RESIDENT_FLAG_INDEXED;/*
is_attr_indexed(attr)) == true */fs/ntfs3/frecord.c +1
-1-le16_add_cpu (&ni->mi.mrec->hard_links,+1 ); +le16_add_cpu (&ni->mi.mrec->hard_links, +1 );le16_add_cpu(&ni->mi.mrec->hard_links, 1);
Quoted 4 lines
Hi, Kari, Joe!
Yes, '+' can be removed, it was added for better visibility, but it's subjective.
After checking code - it's the only place with '+1', so let's remove it.
Already done in v2 [1].
[1]: lore.kernel.org/ntfs3/[email protected]
PATCH 3/5 fs/ntfs3: Place Comparisons constant right side of the test
In reply to Kari ArgillanderFor better code readability place constant always right side of the test. This will also address checkpatch warning.
--- fs/ntfs3/frecord.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/frecord.c +1 -1
@@ -1606,7 +1606,7 @@ struct ATTR_FILE_NAME *ni_fname_type(struct ntfs_inode *ni, u8 name_type, *le =NULL ; -if (FILE_NAME_POSIX == name_type) +if (name_type ==FILE_NAME_POSIX )return NULL ;/* Enumerate all names. */
Signature · 1 line
2.25.1
PATCH 4/5 fs/ntfs3: Remove braces from single statment block
In reply to Kari ArgillanderRemove braces from single statment block as they are not needed. Also Linux kernel coding style guide recommend this and checkpatch warn about this.
--- fs/ntfs3/frecord.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ntfs3/frecord.c +2 -2
@@ -2906,9 +2906,9 @@ bool ni_remove_name_undo(struct ntfs_inode *dir_ni, struct ntfs_inode *ni,memcpy (Add2Ptr (attr,SIZEOF_RESIDENT ), de +1 , de_key_size);mi_get_ref (&ni->mi, &de->ref); -if (indx_insert_entry (&dir_ni->dir, dir_ni, de, sbi,NULL ,1 )) { +if (indx_insert_entry (&dir_ni->dir, dir_ni, de, sbi,NULL ,1 ))return false; - } + }return true;
Signature · 1 line
2.25.1