[PATCH 00/16] md/bitmap: Fine-tuning for several function implementations

STALE939d

18 messages, 2 authors, 2016-09-28 · open the first message on its own page

[PATCH 00/16] md/bitmap: Fine-tuning for several function implementations

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

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

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(-)
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 (!store->filemap)
 		return -ENOMEM;
 
-- 
2.10.0

[PATCH 02/16] md/bitmap: Move an assignment for the variable "offset" in bitmap_storage_alloc()

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(-)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 8cfb02c..78512c6 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -759,7 +759,6 @@ static int bitmap_storage_alloc(struct bitmap_storage *store,
 		bytes += sizeof(bitmap_super_t);
 
 	num_pages = DIV_ROUND_UP(bytes, PAGE_SIZE);
-	offset = slot_number * num_pages;
 	store->filemap = kmalloc_array(num_pages,
 				       sizeof(*store->filemap),
 				       GFP_KERNEL);
@@ -772,6 +771,7 @@ static int bitmap_storage_alloc(struct bitmap_storage *store,
 			return -ENOMEM;
 	}
 
+	offset = slot_number * num_pages;
 	pnum = 0;
 	if (store->sb_page) {
 		store->filemap[0] = store->sb_page;
-- 
2.10.0

[PATCH 03/16] md/bitmap: Delete an unnecessary variable initialisation in bitmap_storage_alloc()

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(-)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 78512c6..9b3f723 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -750,7 +750,7 @@ static int bitmap_storage_alloc(struct bitmap_storage *store,
 				unsigned long chunks, int with_super,
 				int slot_number)
 {
-	int pnum, offset = 0;
+	int pnum, offset;
 	unsigned long num_pages;
 	unsigned long bytes;
 
-- 
2.10.0

[PATCH 04/16] md/bitmap: Improve another size determination in bitmap_storage_alloc()

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(-)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 9b3f723..c278865 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -791,9 +791,9 @@ static int bitmap_storage_alloc(struct bitmap_storage *store,
 
 	/* We need 4 bits per page, rounded up to a multiple
 	 * of sizeof(unsigned long) */
-	store->filemap_attr = kzalloc(
-		roundup(DIV_ROUND_UP(num_pages*4, 8), sizeof(unsigned long)),
-		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;
 
-- 
2.10.0

[PATCH 05/16] md/bitmap: Return directly after a failed bitmap_storage_alloc() in bitmap_resize()

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(-)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index c278865..5092bc0 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -2032,7 +2032,7 @@ int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
 					   mddev_is_clustered(bitmap->mddev)
 					   ? bitmap->cluster_slot : 0);
 	if (ret)
-		goto err;
+		return ret;
 
 	pages = DIV_ROUND_UP(chunks, PAGE_COUNTER_RATIO);
 
-- 
2.10.0

[PATCH 06/16] md/bitmap: Return directly after a failed kzalloc() in bitmap_resize()

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(-)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 5092bc0..2d30c83 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -2037,10 +2037,9 @@ int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
 	pages = DIV_ROUND_UP(chunks, PAGE_COUNTER_RATIO);
 
 	new_bp = kzalloc(pages * sizeof(*new_bp), GFP_KERNEL);
-	ret = -ENOMEM;
 	if (!new_bp) {
 		bitmap_file_unmap(&store);
-		goto err;
+		return -ENOMEM;
 	}
 
 	if (!init)
@@ -2160,8 +2159,6 @@ int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
 		bitmap_unplug(bitmap);
 		bitmap->mddev->pers->quiesce(bitmap->mddev, 0);
 	}
-	ret = 0;
-err:
 	return ret;
 }
 EXPORT_SYMBOL_GPL(bitmap_resize);
-- 
2.10.0

[PATCH 07/16] md/bitmap: Replace a kzalloc() call by kcalloc() in bitmap_resize()

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(-)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 2d30c83..41d99fd 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -2035,8 +2035,7 @@ int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
 		return ret;
 
 	pages = DIV_ROUND_UP(chunks, PAGE_COUNTER_RATIO);
-
-	new_bp = kzalloc(pages * sizeof(*new_bp), GFP_KERNEL);
+	new_bp = kcalloc(pages, sizeof(*new_bp), GFP_KERNEL);
 	if (!new_bp) {
 		bitmap_file_unmap(&store);
 		return -ENOMEM;
-- 
2.10.0

[PATCH 08/16] md/bitmap: Rename a jump label in location_store()

From: SF Markus Elfring <hidden>
Date: 2016-09-27 16:55:57

From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 15:46:22 +0200

Adjust jump labels according to the current Linux coding style convention.

Signed-off-by: Markus Elfring <redacted>
---
 drivers/md/bitmap.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 41d99fd..22fa09a 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -2187,11 +2187,11 @@ location_store(struct mddev *mddev, const char *buf, size_t len)
 	if (mddev->pers) {
 		if (!mddev->pers->quiesce) {
 			rv = -EBUSY;
-			goto out;
+			goto unlock;
 		}
 		if (mddev->recovery || mddev->sync_thread) {
 			rv = -EBUSY;
-			goto out;
+			goto unlock;
 		}
 	}
 
@@ -2200,7 +2200,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len)
 		/* bitmap already configured.  Only option is to clear it */
 		if (strncmp(buf, "none", 4) != 0) {
 			rv = -EBUSY;
-			goto out;
+			goto unlock;
 		}
 		if (mddev->pers) {
 			mddev->pers->quiesce(mddev, 1);
@@ -2221,23 +2221,23 @@ location_store(struct mddev *mddev, const char *buf, size_t len)
 		else if (strncmp(buf, "file:", 5) == 0) {
 			/* Not supported yet */
 			rv = -EINVAL;
-			goto out;
+			goto unlock;
 		} else {
 			if (buf[0] == '+')
 				rv = kstrtoll(buf+1, 10, &offset);
 			else
 				rv = kstrtoll(buf, 10, &offset);
 			if (rv)
-				goto out;
+				goto unlock;
 			if (offset == 0) {
 				rv = -EINVAL;
-				goto out;
+				goto unlock;
 			}
 			if (mddev->bitmap_info.external == 0 &&
 			    mddev->major_version == 0 &&
 			    offset != mddev->bitmap_info.default_offset) {
 				rv = -EINVAL;
-				goto out;
+				goto unlock;
 			}
 			mddev->bitmap_info.offset = offset;
 			if (mddev->pers) {
@@ -2255,7 +2255,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len)
 				mddev->pers->quiesce(mddev, 0);
 				if (rv) {
 					bitmap_destroy(mddev);
-					goto out;
+					goto unlock;
 				}
 			}
 		}
@@ -2268,7 +2268,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len)
 		md_wakeup_thread(mddev->thread);
 	}
 	rv = 0;
-out:
+unlock:
 	mddev_unlock(mddev);
 	if (rv)
 		return rv;
-- 
2.10.0

[PATCH 09/16] md/bitmap: Rename a jump label in bitmap_copy_from_slot()

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(-)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 22fa09a..5125186 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -1910,7 +1910,7 @@ int bitmap_copy_from_slot(struct mddev *mddev, int slot,
 
 	rv = bitmap_init_from_disk(bitmap, 0);
 	if (rv)
-		goto err;
+		goto free_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);
 	return rv;
 }
-- 
2.10.0

[PATCH 10/16] md/bitmap: Rename a jump label in bitmap_create()

From: SF Markus Elfring <hidden>
Date: 2016-09-27 16:58:05

From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 16:06:35 +0200

Adjust jump labels according to the current Linux coding style convention.

Signed-off-by: Markus Elfring <redacted>
---
 drivers/md/bitmap.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 5125186..1f7f1e1 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -1818,22 +1818,22 @@ struct bitmap *bitmap_create(struct mddev *mddev, int slot)
 			err = -EINVAL;
 	}
 	if (err)
-		goto error;
+		goto free_bitmap;
 
 	bitmap->daemon_lastrun = jiffies;
 	err = bitmap_resize(bitmap, blocks, mddev->bitmap_info.chunksize, 1);
 	if (err)
-		goto error;
+		goto free_bitmap;
 
 	printk(KERN_INFO "created bitmap (%lu pages) for device %s\n",
 	       bitmap->counts.pages, bmname(bitmap));
 
 	err = test_bit(BITMAP_WRITE_ERROR, &bitmap->flags) ? -EIO : 0;
 	if (err)
-		goto error;
+		goto free_bitmap;
 
 	return bitmap;
- error:
+free_bitmap:
 	bitmap_free(bitmap);
 	return ERR_PTR(err);
 }
-- 
2.10.0

[PATCH 11/16] md/bitmap: Rename a jump label in bitmap_init_from_disk()

From: SF Markus Elfring <hidden>
Date: 2016-09-27 16:58:55

From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 16:12:47 +0200

Adjust jump labels according to the current Linux coding style convention.

Signed-off-by: Markus Elfring <redacted>
---
 drivers/md/bitmap.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 1f7f1e1..c186e5d 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -1064,7 +1064,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
 		       bmname(bitmap),
 		       (unsigned long) i_size_read(file->f_mapping->host),
 		       store->bytes);
-		goto err;
+		goto report_failure;
 	}
 
 	oldindex = ~0L;
@@ -1098,7 +1098,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
 					index + node_offset, count);
 
 			if (ret)
-				goto err;
+				goto report_failure;
 
 			oldindex = index;
 
@@ -1116,7 +1116,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
 				ret = -EIO;
 				if (test_bit(BITMAP_WRITE_ERROR,
 					     &bitmap->flags))
-					goto err;
+					goto report_failure;
 			}
 		}
 		paddr = kmap_atomic(page);
@@ -1143,8 +1143,7 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
 	       bit_cnt, chunks);
 
 	return 0;
-
- err:
+report_failure:
 	printk(KERN_INFO "%s: bitmap initialisation failed: %d\n",
 	       bmname(bitmap), ret);
 	return ret;
-- 
2.10.0

[PATCH 12/16] md/bitmap: One check less in read_page() at the end

From: SF Markus Elfring <hidden>
Date: 2016-09-27 17:00:06

From: Markus Elfring <redacted>
Date: Tue, 27 Sep 2016 16:30:25 +0200

* Adjust a jump target.

* Delete a repeated check which became unnecessary with this refactoring.

Signed-off-by: Markus Elfring <redacted>
---
 drivers/md/bitmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index c186e5d..e7a7fc8 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -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;
-		goto out;
+		goto report_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;
-				goto out;
+				goto report_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,
 			(unsigned long long)index << PAGE_SHIFT,
 			ret);
+	}
 	return ret;
 }
 
-- 
2.10.0

Re: [PATCH 12/16] md/bitmap: One check less in read_page() at the end

From: Dan Carpenter <hidden>
Date: 2016-09-28 07:34:04

This makes the code ugly.

regards,
dan carpenter

[PATCH 13/16] md/bitmap: Adjust checks for null pointers in 11 functions

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(-)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index e7a7fc8..f8900cc 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -88,7 +88,7 @@ __acquires(bitmap->lock)
 	mappage = kzalloc(PAGE_SIZE, GFP_NOIO);
 	spin_lock_irq(&bitmap->lock);
 
-	if (mappage == NULL) {
+	if (!mappage) {
 		pr_debug("md/bitmap: map page allocation failed, hijacking\n");
 		/* We don't support hijack for cluster raid */
 		if (no_hijack)
@@ -186,7 +186,7 @@ static struct md_rdev *next_active_rdev(struct md_rdev *rdev, struct mddev *mdde
 	 * list_for_each_entry_continue_rcu() to find the first entry.
 	 */
 	rcu_read_lock();
-	if (rdev == NULL)
+	if (!rdev)
 		/* start at the beginning */
 		rdev = list_entry(&mddev->disks, struct md_rdev, same_set);
 	else {
@@ -284,7 +284,7 @@ static void write_page(struct bitmap *bitmap, struct page *page, int wait)
 {
 	struct buffer_head *bh;
 
-	if (bitmap->storage.file == NULL) {
+	if (!bitmap->storage.file) {
 		switch (write_sb_page(bitmap, page, wait)) {
 		case -EINVAL:
 			set_bit(BITMAP_WRITE_ERROR, &bitmap->flags);
@@ -493,7 +493,7 @@ static int bitmap_new_disk_sb(struct bitmap *bitmap)
 	unsigned long chunksize, daemon_sleep, write_behind;
 
 	bitmap->storage.sb_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
-	if (bitmap->storage.sb_page == NULL)
+	if (!bitmap->storage.sb_page)
 		return -ENOMEM;
 	bitmap->storage.sb_page->index = 0;
 
@@ -767,7 +767,7 @@ static int bitmap_storage_alloc(struct bitmap_storage *store,
 
 	if (with_super && !store->sb_page) {
 		store->sb_page = alloc_page(GFP_KERNEL|__GFP_ZERO);
-		if (store->sb_page == NULL)
+		if (!store->sb_page)
 			return -ENOMEM;
 	}
 
@@ -1209,7 +1209,7 @@ void bitmap_daemon_work(struct mddev *mddev)
 	 */
 	mutex_lock(&mddev->bitmap_info.mutex);
 	bitmap = mddev->bitmap;
-	if (bitmap == NULL) {
+	if (!bitmap) {
 		mutex_unlock(&mddev->bitmap_info.mutex);
 		return;
 	}
@@ -1336,7 +1336,7 @@ __acquires(bitmap->lock)
 	err = bitmap_checkpage(bitmap, page, create, 0);
 
 	if (bitmap->bp[page].hijacked ||
-	    bitmap->bp[page].map == NULL)
+	    !bitmap->bp[page].map)
 		csize = ((sector_t)1) << (bitmap->chunkshift +
 					  PAGE_COUNTER_SHIFT - 1);
 	else
@@ -1481,7 +1481,7 @@ static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t
 {
 	bitmap_counter_t *bmc;
 	int rv;
-	if (bitmap == NULL) {/* FIXME or bitmap set as 'failed' */
+	if (!bitmap) {/* FIXME or bitmap set as 'failed' */
 		*blocks = 1024;
 		return 1; /* always resync if no bitmap */
 	}
@@ -1533,13 +1533,13 @@ void bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, i
 	bitmap_counter_t *bmc;
 	unsigned long flags;
 
-	if (bitmap == NULL) {
+	if (!bitmap) {
 		*blocks = 1024;
 		return;
 	}
 	spin_lock_irqsave(&bitmap->counts.lock, flags);
 	bmc = bitmap_get_counter(&bitmap->counts, offset, blocks, 0);
-	if (bmc == NULL)
+	if (!bmc)
 		goto unlock;
 	/* locked */
 	if (RESYNC(*bmc)) {
@@ -2455,7 +2455,7 @@ static ssize_t can_clear_show(struct mddev *mddev, char *page)
 
 static ssize_t can_clear_store(struct mddev *mddev, const char *buf, size_t len)
 {
-	if (mddev->bitmap == NULL)
+	if (!mddev->bitmap)
 		return -ENOENT;
 	if (strncmp(buf, "false", 5) == 0)
 		mddev->bitmap->need_sync = 1;
@@ -2476,7 +2476,7 @@ behind_writes_used_show(struct mddev *mddev, char *page)
 {
 	ssize_t ret;
 	spin_lock(&mddev->lock);
-	if (mddev->bitmap == NULL)
+	if (!mddev->bitmap)
 		ret = sprintf(page, "0\n");
 	else
 		ret = sprintf(page, "%lu\n",
-- 
2.10.0

[PATCH 14/16] md/bitmap: Delete unnecessary braces in bitmap_resize()

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(-)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index f8900cc..9d77f16 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -2075,9 +2075,8 @@ int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
 				unsigned long k;
 
 				/* deallocate the page memory */
-				for (k = 0; k < page; k++) {
+				for (k = 0; k < page; k++)
 					kfree(new_bp[k].map);
-				}
 
 				/* restore some fields from old_counts */
 				bitmap->counts.bp = old_counts.bp;
-- 
2.10.0

[PATCH 15/16] md/bitmap: Add spaces around three comparison operators

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(-)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 9d77f16..d029576 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -303,7 +303,7 @@ static void write_page(struct bitmap *bitmap, struct page *page, int wait)
 
 		if (wait)
 			wait_event(bitmap->write_wait,
-				   atomic_read(&bitmap->pending_writes)==0);
+				   atomic_read(&bitmap->pending_writes) == 0);
 	}
 	if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags))
 		bitmap_file_kick(bitmap);
@@ -400,7 +400,7 @@ static int read_page(struct file *file, unsigned long index,
 	page->index = index;
 
 	wait_event(bitmap->write_wait,
-		   atomic_read(&bitmap->pending_writes)==0);
+		   atomic_read(&bitmap->pending_writes) == 0);
 	if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags)) {
 		ret = -EIO;
 report_failure:
@@ -1003,7 +1003,7 @@ void bitmap_unplug(struct bitmap *bitmap)
 	}
 	if (bitmap->storage.file)
 		wait_event(bitmap->write_wait,
-			   atomic_read(&bitmap->pending_writes)==0);
+			   atomic_read(&bitmap->pending_writes) == 0);
 	else
 		md_super_wait(bitmap->mddev);
 
-- 
2.10.0

[PATCH 16/16] md/bitmap: Delete an unwanted space in read_sb_page()

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(-)
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index d029576..c6a6d59 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -154,7 +154,7 @@ static int read_sb_page(struct mddev *mddev, loff_t offset,
 	sector_t target;
 
 	rdev_for_each(rdev, mddev) {
-		if (! test_bit(In_sync, &rdev->flags)
+		if (!test_bit(In_sync, &rdev->flags)
 		    || test_bit(Faulty, &rdev->flags))
 			continue;
 
-- 
2.10.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help