Skip to content

Commit 7acd119

Browse files
elfringehristev
authored andcommitted
media: drivers: improve a size determination
Replace the specification of a data structure 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. This issue was detected by using the Coccinelle software. [mchehab@s-opensoure.com: merge similar patches into one] Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> Signed-off-by: Hans Verkuil <hansverk@cisco.com>
1 parent 9011bc6 commit 7acd119

17 files changed

Lines changed: 23 additions & 26 deletions

File tree

drivers/media/common/cypress_firmware.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ int cypress_load_firmware(struct usb_device *udev,
7474
struct hexline *hx;
7575
int ret, pos = 0;
7676

77-
hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
77+
hx = kmalloc(sizeof(*hx), GFP_KERNEL);
7878
if (!hx)
7979
return -ENOMEM;
8080

drivers/media/common/siano/smscoreapi.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static struct smscore_registry_entry_t *smscore_find_registry(char *devpath)
447447
return entry;
448448
}
449449
}
450-
entry = kmalloc(sizeof(struct smscore_registry_entry_t), GFP_KERNEL);
450+
entry = kmalloc(sizeof(*entry), GFP_KERNEL);
451451
if (entry) {
452452
entry->mode = default_mode;
453453
strcpy(entry->devpath, devpath);
@@ -536,9 +536,7 @@ int smscore_register_hotplug(hotplug_t hotplug)
536536
int rc = 0;
537537

538538
kmutex_lock(&g_smscore_deviceslock);
539-
540-
notifyee = kmalloc(sizeof(struct smscore_device_notifyee_t),
541-
GFP_KERNEL);
539+
notifyee = kmalloc(sizeof(*notifyee), GFP_KERNEL);
542540
if (notifyee) {
543541
/* now notify callback about existing devices */
544542
first = &g_smscore_devices;
@@ -627,7 +625,7 @@ smscore_buffer_t *smscore_createbuffer(u8 *buffer, void *common_buffer,
627625
{
628626
struct smscore_buffer_t *cb;
629627

630-
cb = kzalloc(sizeof(struct smscore_buffer_t), GFP_KERNEL);
628+
cb = kzalloc(sizeof(*cb), GFP_KERNEL);
631629
if (!cb)
632630
return NULL;
633631

@@ -655,7 +653,7 @@ int smscore_register_device(struct smsdevice_params_t *params,
655653
struct smscore_device_t *dev;
656654
u8 *buffer;
657655

658-
dev = kzalloc(sizeof(struct smscore_device_t), GFP_KERNEL);
656+
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
659657
if (!dev)
660658
return -ENOMEM;
661659

@@ -1684,7 +1682,7 @@ static int smscore_validate_client(struct smscore_device_t *coredev,
16841682
pr_err("The msg ID already registered to another client.\n");
16851683
return -EEXIST;
16861684
}
1687-
listentry = kzalloc(sizeof(struct smscore_idlist_t), GFP_KERNEL);
1685+
listentry = kzalloc(sizeof(*listentry), GFP_KERNEL);
16881686
if (!listentry)
16891687
return -ENOMEM;
16901688

@@ -1721,7 +1719,7 @@ int smscore_register_client(struct smscore_device_t *coredev,
17211719
return -EEXIST;
17221720
}
17231721

1724-
newclient = kzalloc(sizeof(struct smscore_client_t), GFP_KERNEL);
1722+
newclient = kzalloc(sizeof(*newclient), GFP_KERNEL);
17251723
if (!newclient)
17261724
return -ENOMEM;
17271725

drivers/media/dvb-frontends/as102_fe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ struct dvb_frontend *as102_attach(const char *name,
455455
struct as102_state *state;
456456
struct dvb_frontend *fe;
457457

458-
state = kzalloc(sizeof(struct as102_state), GFP_KERNEL);
458+
state = kzalloc(sizeof(*state), GFP_KERNEL);
459459
if (!state)
460460
return NULL;
461461

drivers/media/dvb-frontends/cx24113.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,7 @@ struct dvb_frontend *cx24113_attach(struct dvb_frontend *fe,
552552
const struct cx24113_config *config, struct i2c_adapter *i2c)
553553
{
554554
/* allocate memory for the internal state */
555-
struct cx24113_state *state =
556-
kzalloc(sizeof(struct cx24113_state), GFP_KERNEL);
555+
struct cx24113_state *state = kzalloc(sizeof(*state), GFP_KERNEL);
557556
int rc;
558557

559558
if (!state)

drivers/media/dvb-frontends/cx24116.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ struct dvb_frontend *cx24116_attach(const struct cx24116_config *config,
11261126
dprintk("%s\n", __func__);
11271127

11281128
/* allocate memory for the internal state */
1129-
state = kzalloc(sizeof(struct cx24116_state), GFP_KERNEL);
1129+
state = kzalloc(sizeof(*state), GFP_KERNEL);
11301130
if (state == NULL)
11311131
goto error1;
11321132

drivers/media/dvb-frontends/ds3000.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ struct dvb_frontend *ds3000_attach(const struct ds3000_config *config,
839839
dprintk("%s\n", __func__);
840840

841841
/* allocate memory for the internal state */
842-
state = kzalloc(sizeof(struct ds3000_state), GFP_KERNEL);
842+
state = kzalloc(sizeof(*state), GFP_KERNEL);
843843
if (!state)
844844
goto error2;
845845

drivers/media/dvb-frontends/mb86a20s.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2071,7 +2071,7 @@ struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config,
20712071
dev_dbg(&i2c->dev, "%s called.\n", __func__);
20722072

20732073
/* allocate memory for the internal state */
2074-
state = kzalloc(sizeof(struct mb86a20s_state), GFP_KERNEL);
2074+
state = kzalloc(sizeof(*state), GFP_KERNEL);
20752075
if (!state)
20762076
goto error;
20772077

drivers/media/dvb-frontends/sp2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ static int sp2_probe(struct i2c_client *client,
381381

382382
dev_dbg(&client->dev, "\n");
383383

384-
s = kzalloc(sizeof(struct sp2), GFP_KERNEL);
384+
s = kzalloc(sizeof(*s), GFP_KERNEL);
385385
if (!s) {
386386
ret = -ENOMEM;
387387
goto err;

drivers/media/i2c/adv7842.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3467,7 +3467,7 @@ static int adv7842_probe(struct i2c_client *client,
34673467
return -ENODEV;
34683468
}
34693469

3470-
state = devm_kzalloc(&client->dev, sizeof(struct adv7842_state), GFP_KERNEL);
3470+
state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
34713471
if (!state)
34723472
return -ENOMEM;
34733473

drivers/media/pci/cx18/cx18-driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ static int cx18_probe(struct pci_dev *pci_dev,
909909
return -ENOMEM;
910910
}
911911

912-
cx = kzalloc(sizeof(struct cx18), GFP_ATOMIC);
912+
cx = kzalloc(sizeof(*cx), GFP_ATOMIC);
913913
if (!cx)
914914
return -ENOMEM;
915915

0 commit comments

Comments
 (0)