staging: exfat: replace kmalloc with kmalloc_array
PATCH v2 6/6 staging: exfat: replace kmalloc with kmalloc_array
Replace expressions of the form:
kmalloc(count * size, GFP_KERNEL); With: kmalloc_array(count, size, GFP_KERNEL);
---
v2 changes:
This patch has been rebased against the branch "staging-testing" of the tree:
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git
drivers/staging/exfat/exfat_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/exfat/exfat_core.c +4 -4
@@ -713,8 +713,8 @@ static s32 __load_upcase_table(struct super_block *sb, sector_t sector,u32 checksum =0 ; - upcase_table = p_fs->vol_utbl =kmalloc (UTBL_COL_COUNT *sizeof (u16 *), -GFP_KERNEL ); + upcase_table =kmalloc_array (UTBL_COL_COUNT ,sizeof (u16 *),GFP_KERNEL ); + p_fs->vol_utbl = upcase_table;if (!upcase_table)return -ENOMEM ;memset (upcase_table,0 ,UTBL_COL_COUNT *sizeof (u16 *));
@@ -793,8 +793,8 @@ static s32 __load_default_upcase_table(struct super_block *sb)u16 uni =0 ;u16 **upcase_table; - upcase_table = p_fs->vol_utbl =kmalloc (UTBL_COL_COUNT *sizeof (u16 *), -GFP_KERNEL ); + upcase_table =kmalloc_array (UTBL_COL_COUNT ,sizeof (u16 *),GFP_KERNEL ); + p_fs->vol_utbl = upcase_table;if (!upcase_table)return -ENOMEM ;memset (upcase_table,0 ,UTBL_COL_COUNT *sizeof (u16 *));
Signature · 1 line
2.20.1
drivers/staging/exfat/exfat_core.c static s32 __load_upcase_table(struct super_block *sb, sector_t sector, · line 717
Quoted 12 lines · Roi Martin
drivers/staging/exfat/exfat_core.c +2
-2@@ -713,8 +713,8 @@ static s32 __load_upcase_table(struct super_block *sb, sector_t sector,u32 checksum =0 ; - upcase_table = p_fs->vol_utbl =kmalloc (UTBL_COL_COUNT *sizeof (u16 *), -GFP_KERNEL ); + upcase_table =kmalloc_array (UTBL_COL_COUNT ,sizeof (u16 *),GFP_KERNEL ); + p_fs->vol_utbl = upcase_table;
This patch is fine, but one idea for future patches is that you could remove the "upcase_table" variable and use "p_fs->vol_utbl" everywhere instead.
drivers/staging/exfat/exfat_core.c static s32 __load_upcase_table(struct super_block *sb, sector_t sector, · line 719
Quoted 2 lines
drivers/staging/exfat/exfat_core.c +0
-0if (!upcase_table)return -ENOMEM ;
regards,
dan carpenter
Quoted 8 lines
Quoted 8 lines
drivers/staging/exfat/exfat_core.c +0
-0@@ -713,8 +713,8 @@ static s32 __load_upcase_table(struct super_block *sb, sector_t sector,u32 checksum =0 ;
Quoted 8 lines
drivers/staging/exfat/exfat_core.c static s32 __load_upcase_table(struct super_block *sb, sector_t sector, · line 717
Quoted 4 lines
drivers/staging/exfat/exfat_core.c +2
-2- upcase_table = p_fs->vol_utbl =kmalloc (UTBL_COL_COUNT *sizeof (u16 *), -GFP_KERNEL ); + upcase_table =kmalloc_array (UTBL_COL_COUNT ,sizeof (u16 *),GFP_KERNEL ); + p_fs->vol_utbl = upcase_table;This patch is fine, but one idea for future patches is that you could remove the "
upcase_table" variable and use "p_fs->vol_utbl" everywhere instead.
Thanks for the suggestion.
This is my first contribution and I tried to introduce the minimum number of changes necessary to fix the issues reported by checkpatch.pl. Also, I'm still immersed in getting familiar with the contribution process and the code.
Do you think it makes sense to include this change in a future patch series along with other refactoring? Or, should I modify this patch?
By the way, upcase_table is sometimes accessed in quite complex ways. For instance:
upcase_table[col_index][get_row_index(index)] = uni;
Where having an intermediate variable instead of using the struct field directly seems to improve readability a bit. Otherwise:
p_fs->vol_utbl[col_index][get_row_index(index)] = uni;
I assume, in cases like this, from a coding style perspective, the following approach is preferred:
row_index = get_row_index(index); p_fs->vol_utbl[col_index][row_index] = uni;
Is that correct?
Regards,
Roi Martin
Quoted 19 lines · Roi Martin
Quoted 8 lines
Quoted 8 lines
drivers/staging/exfat/exfat_core.c +0
-0@@ -713,8 +713,8 @@ static s32 __load_upcase_table(struct super_block *sb, sector_t sector,u32 checksum =0 ;Quoted 8 lines
drivers/staging/exfat/exfat_core.c static s32 __load_upcase_table(struct super_block *sb, sector_t sector, · line 717
Quoted 4 lines
drivers/staging/exfat/exfat_core.c +2
-2- upcase_table = p_fs->vol_utbl =kmalloc (UTBL_COL_COUNT *sizeof (u16 *), -GFP_KERNEL ); + upcase_table =kmalloc_array (UTBL_COL_COUNT ,sizeof (u16 *),GFP_KERNEL ); + p_fs->vol_utbl = upcase_table;This patch is fine, but one idea for future patches is that you could remove the "
upcase_table" variable and use "p_fs->vol_utbl" everywhere instead.Thanks for the suggestion.
Quoted 7 lines
This is my first contribution and I tried to introduce the minimum number of changes necessary to fix the issues reported by checkpatch.pl. Also, I'm still immersed in getting familiar with the contribution process and the code.
Do you think it makes sense to include this change in a future patch series along with other refactoring? Or, should I modify this patch?
No don't modify the patch. The patch is fine.
Quoted 10 lines
By the way,
upcase_tableis sometimes accessed in quite complex ways. For instance:upcase_table[col_index][get_row_index(index)] = uni;Where having an intermediate variable instead of using the struct field directly seems to improve readability a bit. Otherwise:
p_fs->vol_utbl[col_index][get_row_index(index)] = uni;
This line isn't very complex. It's fine.
Quoted 6 lines
I assume, in cases like this, from a coding style perspective, the following approach is preferred:
row_index = get_row_index(index); p_fs->vol_utbl[col_index][row_index] = uni;
But this is better, yes.
regards,
dan carpenter