DriverDev-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2 6/6] staging: exfat: replace kmalloc with kmalloc_array
@ 2019-10-31 12:31 Roi Martin
  2019-10-31 13:25 ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Roi Martin @ 2019-10-31 12:31 UTC (permalink / raw)
  To: valdis.kletnieks; +Cc: devel, gregkh, linux-kernel, Roi Martin

Replace expressions of the form:
	kmalloc(count * size, GFP_KERNEL);
With:
	kmalloc_array(count, size, GFP_KERNEL);

Signed-off-by: Roi Martin <jroi.martin@gmail.com>
---
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(-)

diff --git a/drivers/staging/exfat/exfat_core.c b/drivers/staging/exfat/exfat_core.c
index f71235c6a338..f4f82aecc05d 100644
--- a/drivers/staging/exfat/exfat_core.c
+++ b/drivers/staging/exfat/exfat_core.c
@@ -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 *));
-- 
2.20.1

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH v2 6/6] staging: exfat: replace kmalloc with kmalloc_array
  2019-10-31 12:31 [PATCH v2 6/6] staging: exfat: replace kmalloc with kmalloc_array Roi Martin
@ 2019-10-31 13:25 ` Dan Carpenter
  2019-10-31 16:03   ` Roi Martin
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2019-10-31 13:25 UTC (permalink / raw)
  To: Roi Martin; +Cc: devel, gregkh, valdis.kletnieks, linux-kernel

On Thu, Oct 31, 2019 at 01:31:39PM +0100, Roi Martin wrote:
> diff --git a/drivers/staging/exfat/exfat_core.c b/drivers/staging/exfat/exfat_core.c
> index f71235c6a338..f4f82aecc05d 100644
> --- a/drivers/staging/exfat/exfat_core.c
> +++ b/drivers/staging/exfat/exfat_core.c
> @@ -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.

>  	if (!upcase_table)
>  		return -ENOMEM;

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH v2 6/6] staging: exfat: replace kmalloc with kmalloc_array
  2019-10-31 13:25 ` Dan Carpenter
@ 2019-10-31 16:03   ` Roi Martin
  2019-11-01  9:34     ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Roi Martin @ 2019-10-31 16:03 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: devel, gregkh, valdis.kletnieks, linux-kernel

> > diff --git a/drivers/staging/exfat/exfat_core.c b/drivers/staging/exfat/exfat_core.c
> > index f71235c6a338..f4f82aecc05d 100644
> > --- a/drivers/staging/exfat/exfat_core.c
> > +++ b/drivers/staging/exfat/exfat_core.c
> > @@ -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.

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
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

* Re: [PATCH v2 6/6] staging: exfat: replace kmalloc with kmalloc_array
  2019-10-31 16:03   ` Roi Martin
@ 2019-11-01  9:34     ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2019-11-01  9:34 UTC (permalink / raw)
  To: Roi Martin; +Cc: devel, gregkh, valdis.kletnieks, linux-kernel

On Thu, Oct 31, 2019 at 05:03:56PM +0100, Roi Martin wrote:
> > > diff --git a/drivers/staging/exfat/exfat_core.c b/drivers/staging/exfat/exfat_core.c
> > > index f71235c6a338..f4f82aecc05d 100644
> > > --- a/drivers/staging/exfat/exfat_core.c
> > > +++ b/drivers/staging/exfat/exfat_core.c
> > > @@ -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.
> 
> 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?

No don't modify the patch.  The patch is fine.

> 
> 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;

This line isn't very complex.  It's fine.


> 
> 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

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-31 12:31 [PATCH v2 6/6] staging: exfat: replace kmalloc with kmalloc_array Roi Martin
2019-10-31 13:25 ` Dan Carpenter
2019-10-31 16:03   ` Roi Martin
2019-11-01  9:34     ` Dan Carpenter

DriverDev-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/driverdev-devel/0 driverdev-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 driverdev-devel driverdev-devel/ https://lore.kernel.org/driverdev-devel \
		driverdev-devel@linuxdriverproject.org devel@driverdev.osuosl.org
	public-inbox-index driverdev-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.linuxdriverproject.driverdev-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git