[PATCH 3/5] mtd/rfd_ftl: Improve a size determination in two functions

From: SF Markus Elfring
Date: Sat Jan 06 2018 - 10:10:26 EST


From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 6 Jan 2018 15:03:29 +0100

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@xxxxxxxxxxxxxxxxxxxxx>
---
drivers/mtd/rfd_ftl.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index 19e14f909dc6..dcf1b88e1193 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -323,10 +323,9 @@ static void erase_callback(struct erase_info *erase)

static int erase_block(struct partition *part, int block)
{
- struct erase_info *erase;
int rc = -ENOMEM;
+ struct erase_info *erase = kmalloc(sizeof(*erase), GFP_KERNEL);

- erase = kmalloc(sizeof(struct erase_info), GFP_KERNEL);
if (!erase)
goto err;

@@ -759,7 +758,7 @@ static void rfd_ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
if (mtd->type != MTD_NORFLASH || mtd->size > UINT_MAX)
return;

- part = kzalloc(sizeof(struct partition), GFP_KERNEL);
+ part = kzalloc(sizeof(*part), GFP_KERNEL);
if (!part)
return;

--
2.15.1