Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1492939

Re: [PATCH 01/16] md/bitmap: Use kmalloc_array() in bitmap_storage_alloc()

From Jes Sorensen <Jes.Sorensen@redhat.com>
Newsgroups linux.kernel
Subject Re: [PATCH 01/16] md/bitmap: Use kmalloc_array() in bitmap_storage_alloc()
Date 2016-09-28 22:00 +0200
Message-ID <smtbj-2Ad-7@gated-at.bofh.it> (permalink)
References <qEuGl-43C-5@gated-at.bofh.it> <sm3JT-3si-3@gated-at.bofh.it> <sm3JU-3si-41@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


SF Markus Elfring <elfring@users.sourceforge.net> writes:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 27 Sep 2016 13:01:07 +0200
>
> * A multiplication for the size determination of a memory allocation
>   indicated that an array data structure should be processed.
>   Thus use the corresponding function "kmalloc_array".
>
>   This issue was detected by using the Coccinelle software.
>
> * Replace the specification of a data type by a pointer dereference
>   to make the corresponding size determination a bit safer according to
>   the Linux coding style convention.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  drivers/md/bitmap.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
> index 13041ee..8cfb02c 100644
> --- a/drivers/md/bitmap.c
> +++ b/drivers/md/bitmap.c
> @@ -760,9 +760,9 @@ static int bitmap_storage_alloc(struct bitmap_storage *store,
>  
>  	num_pages = DIV_ROUND_UP(bytes, PAGE_SIZE);
>  	offset = slot_number * num_pages;
> -
> -	store->filemap = kmalloc(sizeof(struct page *)
> -				 * num_pages, GFP_KERNEL);
> +	store->filemap = kmalloc_array(num_pages,
> +				       sizeof(*store->filemap),
> +				       GFP_KERNEL);

If you have to make cosmetic changes for the sake of it, then at least
use the 80 characters per line that you have available.

This one makes the code uglier.

Jes

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/16] md/bitmap: Fine-tuning for several function  implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 18:50 +0200
  [PATCH 03/16] md/bitmap: Delete an unnecessary variable  initialisation in bitmap_storage_alloc() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 18:50 +0200
  [PATCH 02/16] md/bitmap: Move an assignment for the variable "offset"  in bitmap_storage_alloc() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 18:50 +0200
  [PATCH 01/16] md/bitmap: Use kmalloc_array() in  bitmap_storage_alloc() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 18:50 +0200
    Re: [PATCH 01/16] md/bitmap: Use kmalloc_array() in bitmap_storage_alloc() Jes Sorensen <Jes.Sorensen@redhat.com> - 2016-09-28 22:00 +0200
  [PATCH 09/16] md/bitmap: Rename a jump label in  bitmap_copy_from_slot() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 19:00 +0200
  [PATCH 08/16] md/bitmap: Rename a jump label in location_store() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 19:00 +0200
    Re: [PATCH 08/16] md/bitmap: Rename a jump label in location_store() Jes Sorensen <Jes.Sorensen@redhat.com> - 2016-09-28 22:00 +0200
      Re: [PATCH 08/16] md/bitmap: Rename a jump label in location_store() Guoqing Jiang <gqjiang@suse.com> - 2016-09-29 05:20 +0200
  [PATCH 06/16] md/bitmap: Return directly after a failed kzalloc() in  bitmap_resize() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 19:00 +0200
  [PATCH 11/16] md/bitmap: Rename a jump label in  bitmap_init_from_disk() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 19:00 +0200
  [PATCH 04/16] md/bitmap: Improve another size determination in  bitmap_storage_alloc() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 19:00 +0200
  [PATCH 05/16] md/bitmap: Return directly after a failed  bitmap_storage_alloc() in bitmap_resize() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 19:00 +0200
  [PATCH 07/16] md/bitmap: Replace a kzalloc() call by kcalloc() in  bitmap_resize() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 19:00 +0200
  [PATCH 10/16] md/bitmap: Rename a jump label in bitmap_create() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 19:00 +0200
  [PATCH 15/16] md/bitmap: Add spaces around three comparison operators SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 19:10 +0200
  [PATCH 12/16] md/bitmap: One check less in read_page() at the end SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 19:10 +0200
    Re: [PATCH 12/16] md/bitmap: One check less in read_page() at the end Dan Carpenter <dan.carpenter@oracle.com> - 2016-09-28 09:40 +0200
  [PATCH 16/16] md/bitmap: Delete an unwanted space in read_sb_page() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 19:10 +0200
  [PATCH 14/16] md/bitmap: Delete unnecessary braces in bitmap_resize() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 19:10 +0200
  [PATCH 13/16] md/bitmap: Adjust checks for null pointers in 11  functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-27 19:10 +0200

csiph-web