From: SF Markus Elfring <hidden> Date: 2016-09-27 16:44:33
From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 18:29:08 +0200
Several update suggestions were taken into account
from static source code analysis.
Markus Elfring (16):
Use kmalloc_array() in bitmap_storage_alloc()
Move an assignment for the variable "offset" in bitmap_storage_alloc()
Delete an unnecessary variable initialisation in bitmap_storage_alloc()
Improve another size determination in bitmap_storage_alloc()
Return directly after a failed bitmap_storage_alloc() in bitmap_resize()
Return directly after a failed kzalloc() in bitmap_resize()
Replace a kzalloc() call by kcalloc() in bitmap_resize()
Rename a jump label in location_store()
Rename a jump label in bitmap_copy_from_slot()
Rename a jump label in bitmap_create()
Rename a jump label in bitmap_init_from_disk()
One check less in read_page() at the end
Adjust checks for null pointers in 11 functions
Delete unnecessary braces in bitmap_resize()
Add spaces around three comparison operators
Delete an unwanted space in read_sb_page()
drivers/md/bitmap.c | 110 +++++++++++++++++++++++++---------------------------
1 file changed, 52 insertions(+), 58 deletions(-)
--
2.10.0
From: SF Markus Elfring <hidden> Date: 2016-09-27 16:46:09
From: Markus Elfring <redacted>
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 <redacted>
---
drivers/md/bitmap.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
From: SF Markus Elfring <hidden> Date: 2016-09-27 16:48:35
From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 13:10:05 +0200
Move the assignment for the local variable "offset" behind
the source code for memory allocations by this function.
Signed-off-by: Markus Elfring <redacted>
---
drivers/md/bitmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: SF Markus Elfring <hidden> Date: 2016-09-27 16:49:25
From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 13:20:23 +0200
The local variable "offset" will be set to an appropriate value a bit later.
Thus omit the explicit initialisation at the beginning.
Signed-off-by: Markus Elfring <redacted>
---
drivers/md/bitmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: SF Markus Elfring <hidden> Date: 2016-09-27 16:50:22
From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 14:19:00 +0200
Replace the specification of a data type by a pointer dereference
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.
Signed-off-by: Markus Elfring <redacted>
---
drivers/md/bitmap.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
@@ -791,9 +791,9 @@ static int bitmap_storage_alloc(struct bitmap_storage *store,/* We need 4 bits per page, rounded up to a multiple*ofsizeof(unsignedlong)*/-store->filemap_attr=kzalloc(-roundup(DIV_ROUND_UP(num_pages*4,8),sizeof(unsignedlong)),-GFP_KERNEL);+store->filemap_attr=kzalloc(roundup(DIV_ROUND_UP(num_pages*4,8),+sizeof(*store->filemap_attr)),+GFP_KERNEL);if(!store->filemap_attr)return-ENOMEM;
From: SF Markus Elfring <hidden> Date: 2016-09-27 16:51:29
From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 14:47:29 +0200
Return directly after a memory allocation failed in this function
at the beginning.
Signed-off-by: Markus Elfring <redacted>
---
drivers/md/bitmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: SF Markus Elfring <hidden> Date: 2016-09-27 16:53:33
From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 15:21:23 +0200
* Return directly after a call of the function "kzalloc" failed here.
* Delete two assignments for the local variable "ret" and the jump
target "err" which became unnecessary with this refactoring.
Signed-off-by: Markus Elfring <redacted>
---
drivers/md/bitmap.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
From: SF Markus Elfring <hidden> Date: 2016-09-27 16:55:13
From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 15:26:51 +0200
The script "checkpatch.pl" can point information out like the following.
WARNING: Prefer kcalloc over kzalloc with multiply
Thus fix the affected source code place.
Signed-off-by: Markus Elfring <redacted>
---
drivers/md/bitmap.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
From: SF Markus Elfring <hidden> Date: 2016-09-27 16:57:08
From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 15:55:01 +0200
Adjust a jump label according to the current Linux coding style convention.
Signed-off-by: Markus Elfring <redacted>
---
drivers/md/bitmap.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@@ -1910,7 +1910,7 @@ int bitmap_copy_from_slot(struct mddev *mddev, int slot,rv=bitmap_init_from_disk(bitmap,0);if(rv)-gotoerr;+gotofree_bitmap;counts=&bitmap->counts;for(j=0;j<counts->chunks;j++){
@@ -1937,7 +1937,7 @@ int bitmap_copy_from_slot(struct mddev *mddev, int slot,bitmap_unplug(mddev->bitmap);*low=lo;*high=hi;-err:+free_bitmap:bitmap_free(bitmap);returnrv;}
@@ -367,7 +367,7 @@ static int read_page(struct file *file, unsigned long index,bh=alloc_page_buffers(page,1<<inode->i_blkbits,0);if(!bh){ret=-ENOMEM;-gotoout;+gotoreport_failure;}attach_page_buffers(page,bh);block=index<<(PAGE_SHIFT-inode->i_blkbits);
@@ -379,7 +379,7 @@ static int read_page(struct file *file, unsigned long index,if(bh->b_blocknr==0){/* Cannot use this file! */ret=-EINVAL;-gotoout;+gotoreport_failure;}bh->b_bdev=inode->i_sb->s_bdev;if(count<(1<<inode->i_blkbits))
@@ -401,14 +401,14 @@ static int read_page(struct file *file, unsigned long index,wait_event(bitmap->write_wait,atomic_read(&bitmap->pending_writes)==0);-if(test_bit(BITMAP_WRITE_ERROR,&bitmap->flags))+if(test_bit(BITMAP_WRITE_ERROR,&bitmap->flags)){ret=-EIO;-out:-if(ret)+report_failure:printk(KERN_ALERT"md: bitmap read error: (%dB @ %llu): %d\n",(int)PAGE_SIZE,(unsignedlonglong)index<<PAGE_SHIFT,ret);+}returnret;}
From: SF Markus Elfring <hidden> Date: 2016-09-27 17:01:15
From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 17:40:12 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script "checkpatch.pl" can point information out like the following.
Comparison to NULL could be written !…
Thus fix the affected source code places.
Signed-off-by: Markus Elfring <redacted>
---
drivers/md/bitmap.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
@@ -1481,7 +1481,7 @@ static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t{bitmap_counter_t*bmc;intrv;-if(bitmap==NULL){/* FIXME or bitmap set as 'failed' */+if(!bitmap){/* FIXME or bitmap set as 'failed' */*blocks=1024;return1;/* always resync if no bitmap */}
From: SF Markus Elfring <hidden> Date: 2016-09-27 17:02:34
From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 17:53:07 +0200
Do not use curly brackets at one source code place
where a single statement should be sufficient.
Signed-off-by: Markus Elfring <redacted>
---
drivers/md/bitmap.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
From: SF Markus Elfring <hidden> Date: 2016-09-27 17:03:33
From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 18:08:04 +0200
The script "checkpatch.pl" can point information out like the following.
ERROR: spaces required around that '==' (ctx:VxV)
Thus fix the affected source code places.
Signed-off-by: Markus Elfring <redacted>
---
drivers/md/bitmap.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
From: SF Markus Elfring <hidden> Date: 2016-09-27 17:04:30
From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 18:18:16 +0200
The script "checkpatch.pl" can point information out like the following.
ERROR: space prohibited after that '!' (ctx:BxW)
Thus fix the affected source code place.
Signed-off-by: Markus Elfring <redacted>
---
drivers/md/bitmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)