From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-mtd@lists.infradead.org,
Adrian Hunter <adrian.hunter@intel.com>,
Artem Bityutskiy <dedekind1@gmail.com>,
Richard Weinberger <richard@nod.at>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 2/2] UBIFS: Improve 19 size determinations
Date: Wed, 16 Aug 2017 15:30:06 +0200 [thread overview]
Message-ID: <f4d6422e-96a5-e53f-76af-7997a4d528f8@users.sourceforge.net> (raw)
In-Reply-To: <bd8107ce-fc62-db39-8134-59dca314da7c@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 16 Aug 2017 14:14:28 +0200
Replace the specification of data structures 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/ubifs/log.c | 2 +-
fs/ubifs/lpt.c | 12 ++++++------
fs/ubifs/orphan.c | 6 +++---
fs/ubifs/recovery.c | 2 +-
fs/ubifs/replay.c | 8 ++++----
fs/ubifs/scan.c | 4 ++--
fs/ubifs/super.c | 2 +-
fs/ubifs/tnc.c | 2 +-
8 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/fs/ubifs/log.c b/fs/ubifs/log.c
index 8c795e6392b1..cd19f2c28b3d 100644
--- a/fs/ubifs/log.c
+++ b/fs/ubifs/log.c
@@ -179,7 +179,7 @@ int ubifs_add_bud_to_log(struct ubifs_info *c, int jhead, int lnum, int offs)
struct ubifs_bud *bud;
struct ubifs_ref_node *ref;
- bud = kmalloc(sizeof(struct ubifs_bud), GFP_NOFS);
+ bud = kmalloc(sizeof(*bud), GFP_NOFS);
if (!bud)
return -ENOMEM;
ref = kzalloc(c->ref_node_alsz, GFP_NOFS);
diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c
index 9a517109da0f..014614a62522 100644
--- a/fs/ubifs/lpt.c
+++ b/fs/ubifs/lpt.c
@@ -629,8 +629,8 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
c->main_first = c->leb_cnt - *main_lebs;
lsave = kmalloc(sizeof(int) * c->lsave_cnt, GFP_KERNEL);
- pnode = kzalloc(sizeof(struct ubifs_pnode), GFP_KERNEL);
- nnode = kzalloc(sizeof(struct ubifs_nnode), GFP_KERNEL);
+ pnode = kzalloc(sizeof(*pnode), GFP_KERNEL);
+ nnode = kzalloc(sizeof(*nnode), GFP_KERNEL);
buf = vmalloc(c->leb_size);
ltab = vmalloc(sizeof(struct ubifs_lpt_lprops) * c->lpt_lebs);
if (!pnode || !nnode || !buf || !ltab || !lsave) {
@@ -1205,7 +1205,7 @@ int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip)
lnum = c->lpt_lnum;
offs = c->lpt_offs;
}
- nnode = kzalloc(sizeof(struct ubifs_nnode), GFP_NOFS);
+ nnode = kzalloc(sizeof(*nnode), GFP_NOFS);
if (!nnode) {
err = -ENOMEM;
goto out;
@@ -1268,7 +1268,7 @@ static int read_pnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip)
branch = &parent->nbranch[iip];
lnum = branch->lnum;
offs = branch->offs;
- pnode = kzalloc(sizeof(struct ubifs_pnode), GFP_NOFS);
+ pnode = kzalloc(sizeof(*pnode), GFP_NOFS);
if (!pnode)
return -ENOMEM;
@@ -1498,7 +1498,7 @@ static struct ubifs_nnode *dirty_cow_nnode(struct ubifs_info *c,
}
/* nnode is being committed, so copy it */
- n = kmemdup(nnode, sizeof(struct ubifs_nnode), GFP_NOFS);
+ n = kmemdup(nnode, sizeof(*n), GFP_NOFS);
if (unlikely(!n))
return ERR_PTR(-ENOMEM);
@@ -1548,7 +1548,7 @@ static struct ubifs_pnode *dirty_cow_pnode(struct ubifs_info *c,
}
/* pnode is being committed, so copy it */
- p = kmemdup(pnode, sizeof(struct ubifs_pnode), GFP_NOFS);
+ p = kmemdup(pnode, sizeof(*p), GFP_NOFS);
if (unlikely(!p))
return ERR_PTR(-ENOMEM);
diff --git a/fs/ubifs/orphan.c b/fs/ubifs/orphan.c
index f5b01f9f9985..05e4136fa090 100644
--- a/fs/ubifs/orphan.c
+++ b/fs/ubifs/orphan.c
@@ -67,7 +67,7 @@ int ubifs_add_orphan(struct ubifs_info *c, ino_t inum)
struct ubifs_orphan *orphan, *o;
struct rb_node **p, *parent = NULL;
- orphan = kzalloc(sizeof(struct ubifs_orphan), GFP_NOFS);
+ orphan = kzalloc(sizeof(*orphan), GFP_NOFS);
if (!orphan)
return -ENOMEM;
orphan->inum = inum;
@@ -514,7 +514,7 @@ static int insert_dead_orphan(struct ubifs_info *c, ino_t inum)
struct ubifs_orphan *orphan, *o;
struct rb_node **p, *parent = NULL;
- orphan = kzalloc(sizeof(struct ubifs_orphan), GFP_KERNEL);
+ orphan = kzalloc(sizeof(*orphan), GFP_KERNEL);
if (!orphan)
return -ENOMEM;
orphan->inum = inum;
@@ -771,7 +771,7 @@ static int dbg_ins_check_orphan(struct rb_root *root, ino_t inum)
struct check_orphan *orphan, *o;
struct rb_node **p, *parent = NULL;
- orphan = kzalloc(sizeof(struct check_orphan), GFP_NOFS);
+ orphan = kzalloc(sizeof(*orphan), GFP_NOFS);
if (!orphan)
return -ENOMEM;
orphan->inum = inum;
diff --git a/fs/ubifs/recovery.c b/fs/ubifs/recovery.c
index 3af4472061cc..e9821820b260 100644
--- a/fs/ubifs/recovery.c
+++ b/fs/ubifs/recovery.c
@@ -1269,7 +1269,7 @@ static int add_ino(struct ubifs_info *c, ino_t inum, loff_t i_size,
p = &(*p)->rb_right;
}
- e = kzalloc(sizeof(struct size_entry), GFP_KERNEL);
+ e = kzalloc(sizeof(*e), GFP_KERNEL);
if (!e)
return -ENOMEM;
diff --git a/fs/ubifs/replay.c b/fs/ubifs/replay.c
index ae5c02f22f3e..479d871a8573 100644
--- a/fs/ubifs/replay.c
+++ b/fs/ubifs/replay.c
@@ -365,7 +365,7 @@ static int insert_node(struct ubifs_info *c, int lnum, int offs, int len,
if (key_inum(c, key) >= c->highest_inum)
c->highest_inum = key_inum(c, key);
- r = kzalloc(sizeof(struct replay_entry), GFP_KERNEL);
+ r = kzalloc(sizeof(*r), GFP_KERNEL);
if (!r)
return -ENOMEM;
@@ -412,7 +412,7 @@ static int insert_dent(struct ubifs_info *c, int lnum, int offs, int len,
if (key_inum(c, key) >= c->highest_inum)
c->highest_inum = key_inum(c, key);
- r = kzalloc(sizeof(struct replay_entry), GFP_KERNEL);
+ r = kzalloc(sizeof(*r), GFP_KERNEL);
if (!r)
return -ENOMEM;
@@ -750,11 +750,11 @@ static int add_replay_bud(struct ubifs_info *c, int lnum, int offs, int jhead,
dbg_mnt("add replay bud LEB %d:%d, head %d", lnum, offs, jhead);
- bud = kmalloc(sizeof(struct ubifs_bud), GFP_KERNEL);
+ bud = kmalloc(sizeof(*bud), GFP_KERNEL);
if (!bud)
return -ENOMEM;
- b = kmalloc(sizeof(struct bud_entry), GFP_KERNEL);
+ b = kmalloc(sizeof(*b), GFP_KERNEL);
if (!b) {
kfree(bud);
return -ENOMEM;
diff --git a/fs/ubifs/scan.c b/fs/ubifs/scan.c
index aab87340d3de..1a0c98ac410c 100644
--- a/fs/ubifs/scan.c
+++ b/fs/ubifs/scan.c
@@ -142,7 +142,7 @@ struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum,
dbg_scan("scan LEB %d:%d", lnum, offs);
- sleb = kzalloc(sizeof(struct ubifs_scan_leb), GFP_NOFS);
+ sleb = kzalloc(sizeof(*sleb), GFP_NOFS);
if (!sleb)
return ERR_PTR(-ENOMEM);
@@ -198,7 +198,7 @@ int ubifs_add_snod(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
struct ubifs_ino_node *ino = buf;
struct ubifs_scan_node *snod;
- snod = kmalloc(sizeof(struct ubifs_scan_node), GFP_NOFS);
+ snod = kmalloc(sizeof(*snod), GFP_NOFS);
if (!snod)
return -ENOMEM;
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index bffadbb67e47..9723c08fcbd1 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -1965,7 +1965,7 @@ static struct ubifs_info *alloc_ubifs_info(struct ubi_volume_desc *ubi)
{
struct ubifs_info *c;
- c = kzalloc(sizeof(struct ubifs_info), GFP_KERNEL);
+ c = kzalloc(sizeof(*c), GFP_KERNEL);
if (c) {
spin_lock_init(&c->cnt_lock);
spin_lock_init(&c->cs_lock);
diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c
index 0a213dcba2a1..276233dff9bf 100644
--- a/fs/ubifs/tnc.c
+++ b/fs/ubifs/tnc.c
@@ -84,7 +84,7 @@ static int insert_old_idx(struct ubifs_info *c, int lnum, int offs)
struct ubifs_old_idx *old_idx, *o;
struct rb_node **p, *parent = NULL;
- old_idx = kmalloc(sizeof(struct ubifs_old_idx), GFP_NOFS);
+ old_idx = kmalloc(sizeof(*old_idx), GFP_NOFS);
if (unlikely(!old_idx))
return -ENOMEM;
old_idx->lnum = lnum;
--
2.14.0
prev parent reply other threads:[~2017-08-16 13:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-16 13:26 [PATCH 0/2] UBIFS: Adjustments for some function implementations SF Markus Elfring
2017-08-16 13:27 ` [PATCH 1/2] UBIFS: Delete an error message for a failed memory allocation in dbg_check_orphans() SF Markus Elfring
2017-08-16 13:30 ` SF Markus Elfring [this message]
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=f4d6422e-96a5-e53f-76af-7997a4d528f8@users.sourceforge.net \
--to=elfring@users.sourceforge.net \
--cc=adrian.hunter@intel.com \
--cc=dedekind1@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome