[PATCH 3/4] char/snsc: Improve a size determination in two functions

From: SF Markus Elfring
Date: Mon Oct 16 2017 - 11:06:37 EST


From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 16 Oct 2017 16:26:09 +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@xxxxxxxxxxxxxxxxxxxxx>
---
drivers/char/snsc.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/char/snsc.c b/drivers/char/snsc.c
index eefc306033ab..bec3bd966b1f 100644
--- a/drivers/char/snsc.c
+++ b/drivers/char/snsc.c
@@ -79,7 +79,7 @@ scdrv_open(struct inode *inode, struct file *file)
scd = container_of(inode->i_cdev, struct sysctl_data_s, scd_cdev);

/* allocate memory for subchannel data */
- sd = kzalloc(sizeof (struct subch_data_s), GFP_KERNEL);
+ sd = kzalloc(sizeof(*sd), GFP_KERNEL);
if (!sd)
return -ENOMEM;

@@ -405,8 +405,7 @@ scdrv_init(void)
geo_slab(geoid));

/* allocate sysctl device data */
- scd = kzalloc(sizeof (struct sysctl_data_s),
- GFP_KERNEL);
+ scd = kzalloc(sizeof(*scd), GFP_KERNEL);
if (!scd)
continue;

--
2.14.2