All of lore.kernel.org
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-btrfs@vger.kernel.org, Chris Mason <clm@fb.com>,
	David Sterba <dsterba@suse.com>, Josef Bacik <jbacik@fb.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 3/4] btrfs: Improve eight size determinations
Date: Sun, 20 Aug 2017 20:19:49 +0000	[thread overview]
Message-ID: <eea2ad68-7f8d-bbe4-1cdf-6439a46fb04e@users.sourceforge.net> (raw)
In-Reply-To: <360126ba-e45b-0a8d-57b6-83764c4c2bce@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 20 Aug 2017 21:55:56 +0200

Replace the specification of data types by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 fs/btrfs/ctree.c         | 10 ++++------
 fs/btrfs/delayed-inode.c |  4 ++--
 fs/btrfs/raid56.c        |  2 +-
 fs/btrfs/super.c         |  2 +-
 4 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index b89c101ef45e..3b49f39eaaf6 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -578,7 +578,7 @@ tree_mod_log_insert_move(struct btrfs_fs_info *fs_info,
 	if (!tree_mod_need_log(fs_info, eb))
 		return 0;
 
-	tm_list = kcalloc(nr_items, sizeof(struct tree_mod_elem *), GFP_NOFS);
+	tm_list = kcalloc(nr_items, sizeof(*tm_list), GFP_NOFS);
 	if (!tm_list)
 		return -ENOMEM;
 
@@ -677,8 +677,7 @@ tree_mod_log_insert_root(struct btrfs_fs_info *fs_info,
 
 	if (log_removal && btrfs_header_level(old_root) > 0) {
 		nritems = btrfs_header_nritems(old_root);
-		tm_list = kcalloc(nritems, sizeof(struct tree_mod_elem *),
-				  GFP_NOFS);
+		tm_list = kcalloc(nritems, sizeof(*tm_list), GFP_NOFS);
 		if (!tm_list) {
 			ret = -ENOMEM;
 			goto free_tms;
@@ -813,8 +812,7 @@ tree_mod_log_eb_copy(struct btrfs_fs_info *fs_info, struct extent_buffer *dst,
 	if (btrfs_header_level(dst) = 0 && btrfs_header_level(src) = 0)
 		return 0;
 
-	tm_list = kcalloc(nr_items * 2, sizeof(struct tree_mod_elem *),
-			  GFP_NOFS);
+	tm_list = kcalloc(nr_items * 2, sizeof(*tm_list), GFP_NOFS);
 	if (!tm_list)
 		return -ENOMEM;
 
@@ -904,7 +902,7 @@ tree_mod_log_free_eb(struct btrfs_fs_info *fs_info, struct extent_buffer *eb)
 		return 0;
 
 	nritems = btrfs_header_nritems(eb);
-	tm_list = kcalloc(nritems, sizeof(struct tree_mod_elem *), GFP_NOFS);
+	tm_list = kcalloc(nritems, sizeof(*tm_list), GFP_NOFS);
 	if (!tm_list)
 		return -ENOMEM;
 
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 19e4ad2f3f2e..865aaca445b9 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -750,13 +750,13 @@ static int btrfs_batch_insert_items(struct btrfs_root *root,
 	 */
 	btrfs_set_path_blocking(path);
 
-	keys = kmalloc_array(nitems, sizeof(struct btrfs_key), GFP_NOFS);
+	keys = kmalloc_array(nitems, sizeof(*keys), GFP_NOFS);
 	if (!keys) {
 		ret = -ENOMEM;
 		goto out;
 	}
 
-	data_size = kmalloc_array(nitems, sizeof(u32), GFP_NOFS);
+	data_size = kmalloc_array(nitems, sizeof(*data_size), GFP_NOFS);
 	if (!data_size) {
 		ret = -ENOMEM;
 		goto error;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index 208638384cd2..c85f0f534532 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -1798,7 +1798,7 @@ static void __raid_recover_end_io(struct btrfs_raid_bio *rbio)
 	int err;
 	int i;
 
-	pointers = kcalloc(rbio->real_stripes, sizeof(void *), GFP_NOFS);
+	pointers = kcalloc(rbio->real_stripes, sizeof(*pointers), GFP_NOFS);
 	if (!pointers) {
 		err = -ENOMEM;
 		goto cleanup_io;
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 0b7a1d8cd08b..cd2ba5e3b2d0 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1571,7 +1571,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
 	 * it for searching for existing supers, so this lets us do that and
 	 * then open_ctree will properly initialize everything later.
 	 */
-	fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_KERNEL);
+	fs_info = kzalloc(sizeof(*fs_info), GFP_KERNEL);
 	if (!fs_info) {
 		error = -ENOMEM;
 		goto error_sec_opts;
-- 
2.14.0


WARNING: multiple messages have this Message-ID (diff)
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-btrfs@vger.kernel.org, Chris Mason <clm@fb.com>,
	David Sterba <dsterba@suse.com>, Josef Bacik <jbacik@fb.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 3/4] btrfs: Improve eight size determinations
Date: Sun, 20 Aug 2017 22:19:49 +0200	[thread overview]
Message-ID: <eea2ad68-7f8d-bbe4-1cdf-6439a46fb04e@users.sourceforge.net> (raw)
In-Reply-To: <360126ba-e45b-0a8d-57b6-83764c4c2bce@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 20 Aug 2017 21:55:56 +0200

Replace the specification of data types by pointer dereferences
as the parameter for the operator "sizeof" to make the corresponding size
determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 fs/btrfs/ctree.c         | 10 ++++------
 fs/btrfs/delayed-inode.c |  4 ++--
 fs/btrfs/raid56.c        |  2 +-
 fs/btrfs/super.c         |  2 +-
 4 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index b89c101ef45e..3b49f39eaaf6 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -578,7 +578,7 @@ tree_mod_log_insert_move(struct btrfs_fs_info *fs_info,
 	if (!tree_mod_need_log(fs_info, eb))
 		return 0;
 
-	tm_list = kcalloc(nr_items, sizeof(struct tree_mod_elem *), GFP_NOFS);
+	tm_list = kcalloc(nr_items, sizeof(*tm_list), GFP_NOFS);
 	if (!tm_list)
 		return -ENOMEM;
 
@@ -677,8 +677,7 @@ tree_mod_log_insert_root(struct btrfs_fs_info *fs_info,
 
 	if (log_removal && btrfs_header_level(old_root) > 0) {
 		nritems = btrfs_header_nritems(old_root);
-		tm_list = kcalloc(nritems, sizeof(struct tree_mod_elem *),
-				  GFP_NOFS);
+		tm_list = kcalloc(nritems, sizeof(*tm_list), GFP_NOFS);
 		if (!tm_list) {
 			ret = -ENOMEM;
 			goto free_tms;
@@ -813,8 +812,7 @@ tree_mod_log_eb_copy(struct btrfs_fs_info *fs_info, struct extent_buffer *dst,
 	if (btrfs_header_level(dst) == 0 && btrfs_header_level(src) == 0)
 		return 0;
 
-	tm_list = kcalloc(nr_items * 2, sizeof(struct tree_mod_elem *),
-			  GFP_NOFS);
+	tm_list = kcalloc(nr_items * 2, sizeof(*tm_list), GFP_NOFS);
 	if (!tm_list)
 		return -ENOMEM;
 
@@ -904,7 +902,7 @@ tree_mod_log_free_eb(struct btrfs_fs_info *fs_info, struct extent_buffer *eb)
 		return 0;
 
 	nritems = btrfs_header_nritems(eb);
-	tm_list = kcalloc(nritems, sizeof(struct tree_mod_elem *), GFP_NOFS);
+	tm_list = kcalloc(nritems, sizeof(*tm_list), GFP_NOFS);
 	if (!tm_list)
 		return -ENOMEM;
 
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 19e4ad2f3f2e..865aaca445b9 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -750,13 +750,13 @@ static int btrfs_batch_insert_items(struct btrfs_root *root,
 	 */
 	btrfs_set_path_blocking(path);
 
-	keys = kmalloc_array(nitems, sizeof(struct btrfs_key), GFP_NOFS);
+	keys = kmalloc_array(nitems, sizeof(*keys), GFP_NOFS);
 	if (!keys) {
 		ret = -ENOMEM;
 		goto out;
 	}
 
-	data_size = kmalloc_array(nitems, sizeof(u32), GFP_NOFS);
+	data_size = kmalloc_array(nitems, sizeof(*data_size), GFP_NOFS);
 	if (!data_size) {
 		ret = -ENOMEM;
 		goto error;
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index 208638384cd2..c85f0f534532 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -1798,7 +1798,7 @@ static void __raid_recover_end_io(struct btrfs_raid_bio *rbio)
 	int err;
 	int i;
 
-	pointers = kcalloc(rbio->real_stripes, sizeof(void *), GFP_NOFS);
+	pointers = kcalloc(rbio->real_stripes, sizeof(*pointers), GFP_NOFS);
 	if (!pointers) {
 		err = -ENOMEM;
 		goto cleanup_io;
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 0b7a1d8cd08b..cd2ba5e3b2d0 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1571,7 +1571,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
 	 * it for searching for existing supers, so this lets us do that and
 	 * then open_ctree will properly initialize everything later.
 	 */
-	fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_KERNEL);
+	fs_info = kzalloc(sizeof(*fs_info), GFP_KERNEL);
 	if (!fs_info) {
 		error = -ENOMEM;
 		goto error_sec_opts;
-- 
2.14.0


  parent reply	other threads:[~2017-08-20 20:19 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-20 20:16 [PATCH 0/4] BTRFS: Adjustments for several function implementations SF Markus Elfring
2017-08-20 20:16 ` SF Markus Elfring
2017-08-20 20:17 ` [PATCH 1/4] btrfs: Delete an error message for a failed memory allocation in btrfsic_process_superbl SF Markus Elfring
2017-08-20 20:17   ` [PATCH 1/4] btrfs: Delete an error message for a failed memory allocation in btrfsic_process_superblock() SF Markus Elfring
2017-08-20 20:18 ` [PATCH 2/4] btrfs: Adjust 32 checks for null pointers SF Markus Elfring
2017-08-20 20:18   ` SF Markus Elfring
2017-08-21 10:43   ` Timofey Titovets
2017-08-21 10:43     ` Timofey Titovets
2017-08-21 13:27     ` SF Markus Elfring
2017-08-21 13:27       ` SF Markus Elfring
2017-08-21 14:23       ` Timofey Titovets
2017-08-21 14:23         ` Timofey Titovets
2017-08-20 20:19 ` SF Markus Elfring [this message]
2017-08-20 20:19   ` [PATCH 3/4] btrfs: Improve eight size determinations SF Markus Elfring
2017-08-21  9:20   ` Timofey Titovets
2017-08-21  9:20     ` Timofey Titovets
2017-08-20 20:20 ` [PATCH 4/4] btrfs: Delete an unnecessary variable initialisation in tree_mod_log_eb_copy() SF Markus Elfring
2017-08-20 20:20   ` SF Markus Elfring
2017-08-21 10:50   ` Timofey Titovets
2017-08-21 10:50     ` Timofey Titovets
2017-08-21 13:30     ` SF Markus Elfring
2017-08-21 13:30       ` SF Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eea2ad68-7f8d-bbe4-1cdf-6439a46fb04e@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=jbacik@fb.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.