OSDN Git Service

media: drivers: improve a size determination
authorMarkus Elfring <elfring@users.sourceforge.net>
Mon, 28 Aug 2017 09:55:16 +0000 (05:55 -0400)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Sat, 23 Sep 2017 12:20:57 +0000 (08:20 -0400)
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>
17 files changed:
drivers/media/common/cypress_firmware.c
drivers/media/common/siano/smscoreapi.c
drivers/media/dvb-frontends/as102_fe.c
drivers/media/dvb-frontends/cx24113.c
drivers/media/dvb-frontends/cx24116.c
drivers/media/dvb-frontends/ds3000.c
drivers/media/dvb-frontends/mb86a20s.c
drivers/media/dvb-frontends/sp2.c
drivers/media/i2c/adv7842.c
drivers/media/pci/cx18/cx18-driver.c
drivers/media/pci/mantis/hopper_cards.c
drivers/media/pci/mantis/mantis_cards.c
drivers/media/pci/saa7146/hexium_gemini.c
drivers/media/pci/saa7146/hexium_orion.c
drivers/media/pci/saa7164/saa7164-buffer.c
drivers/media/platform/atmel/atmel-isc.c
drivers/media/usb/zr364xx/zr364xx.c

index bfe47bc..8895158 100644 (file)
@@ -74,7 +74,7 @@ int cypress_load_firmware(struct usb_device *udev,
        struct hexline *hx;
        int ret, pos = 0;
 
-       hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
+       hx = kmalloc(sizeof(*hx), GFP_KERNEL);
        if (!hx)
                return -ENOMEM;
 
index 889b486..ad1c41f 100644 (file)
@@ -447,7 +447,7 @@ static struct smscore_registry_entry_t *smscore_find_registry(char *devpath)
                        return entry;
                }
        }
-       entry = kmalloc(sizeof(struct smscore_registry_entry_t), GFP_KERNEL);
+       entry = kmalloc(sizeof(*entry), GFP_KERNEL);
        if (entry) {
                entry->mode = default_mode;
                strcpy(entry->devpath, devpath);
@@ -536,9 +536,7 @@ int smscore_register_hotplug(hotplug_t hotplug)
        int rc = 0;
 
        kmutex_lock(&g_smscore_deviceslock);
-
-       notifyee = kmalloc(sizeof(struct smscore_device_notifyee_t),
-                          GFP_KERNEL);
+       notifyee = kmalloc(sizeof(*notifyee), GFP_KERNEL);
        if (notifyee) {
                /* now notify callback about existing devices */
                first = &g_smscore_devices;
@@ -627,7 +625,7 @@ smscore_buffer_t *smscore_createbuffer(u8 *buffer, void *common_buffer,
 {
        struct smscore_buffer_t *cb;
 
-       cb = kzalloc(sizeof(struct smscore_buffer_t), GFP_KERNEL);
+       cb = kzalloc(sizeof(*cb), GFP_KERNEL);
        if (!cb)
                return NULL;
 
@@ -655,7 +653,7 @@ int smscore_register_device(struct smsdevice_params_t *params,
        struct smscore_device_t *dev;
        u8 *buffer;
 
-       dev = kzalloc(sizeof(struct smscore_device_t), GFP_KERNEL);
+       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
        if (!dev)
                return -ENOMEM;
 
@@ -1684,7 +1682,7 @@ static int smscore_validate_client(struct smscore_device_t *coredev,
                pr_err("The msg ID already registered to another client.\n");
                return -EEXIST;
        }
-       listentry = kzalloc(sizeof(struct smscore_idlist_t), GFP_KERNEL);
+       listentry = kzalloc(sizeof(*listentry), GFP_KERNEL);
        if (!listentry)
                return -ENOMEM;
 
@@ -1721,7 +1719,7 @@ int smscore_register_client(struct smscore_device_t *coredev,
                return -EEXIST;
        }
 
-       newclient = kzalloc(sizeof(struct smscore_client_t), GFP_KERNEL);
+       newclient = kzalloc(sizeof(*newclient), GFP_KERNEL);
        if (!newclient)
                return -ENOMEM;
 
index 1fb4ab2..b1c84ee 100644 (file)
@@ -455,7 +455,7 @@ struct dvb_frontend *as102_attach(const char *name,
        struct as102_state *state;
        struct dvb_frontend *fe;
 
-       state = kzalloc(sizeof(struct as102_state), GFP_KERNEL);
+       state = kzalloc(sizeof(*state), GFP_KERNEL);
        if (!state)
                return NULL;
 
index 8fc7333..2c5502c 100644 (file)
@@ -552,8 +552,7 @@ struct dvb_frontend *cx24113_attach(struct dvb_frontend *fe,
                const struct cx24113_config *config, struct i2c_adapter *i2c)
 {
        /* allocate memory for the internal state */
-       struct cx24113_state *state =
-               kzalloc(sizeof(struct cx24113_state), GFP_KERNEL);
+       struct cx24113_state *state = kzalloc(sizeof(*state), GFP_KERNEL);
        int rc;
 
        if (!state)
index e5135fb..531c586 100644 (file)
@@ -1126,7 +1126,7 @@ struct dvb_frontend *cx24116_attach(const struct cx24116_config *config,
        dprintk("%s\n", __func__);
 
        /* allocate memory for the internal state */
-       state = kzalloc(sizeof(struct cx24116_state), GFP_KERNEL);
+       state = kzalloc(sizeof(*state), GFP_KERNEL);
        if (state == NULL)
                goto error1;
 
index 293c410..3e347d0 100644 (file)
@@ -839,7 +839,7 @@ struct dvb_frontend *ds3000_attach(const struct ds3000_config *config,
        dprintk("%s\n", __func__);
 
        /* allocate memory for the internal state */
-       state = kzalloc(sizeof(struct ds3000_state), GFP_KERNEL);
+       state = kzalloc(sizeof(*state), GFP_KERNEL);
        if (!state)
                goto error2;
 
index 3409841..ba7a433 100644 (file)
@@ -2071,7 +2071,7 @@ struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config,
        dev_dbg(&i2c->dev, "%s called.\n", __func__);
 
        /* allocate memory for the internal state */
-       state = kzalloc(sizeof(struct mb86a20s_state), GFP_KERNEL);
+       state = kzalloc(sizeof(*state), GFP_KERNEL);
        if (!state)
                goto error;
 
index d3b4f88..dd55601 100644 (file)
@@ -381,7 +381,7 @@ static int sp2_probe(struct i2c_client *client,
 
        dev_dbg(&client->dev, "\n");
 
-       s = kzalloc(sizeof(struct sp2), GFP_KERNEL);
+       s = kzalloc(sizeof(*s), GFP_KERNEL);
        if (!s) {
                ret = -ENOMEM;
                goto err;
index c582bcb..136aa80 100644 (file)
@@ -3467,7 +3467,7 @@ static int adv7842_probe(struct i2c_client *client,
                return -ENODEV;
        }
 
-       state = devm_kzalloc(&client->dev, sizeof(struct adv7842_state), GFP_KERNEL);
+       state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
        if (!state)
                return -ENOMEM;
 
index 9e99c6e..6efa931 100644 (file)
@@ -909,7 +909,7 @@ static int cx18_probe(struct pci_dev *pci_dev,
                return -ENOMEM;
        }
 
-       cx = kzalloc(sizeof(struct cx18), GFP_ATOMIC);
+       cx = kzalloc(sizeof(*cx), GFP_ATOMIC);
        if (!cx)
                return -ENOMEM;
 
index a96ac01..ecb97dc 100644 (file)
@@ -163,7 +163,7 @@ static int hopper_pci_probe(struct pci_dev *pdev,
        struct mantis_hwconfig *config;
        int err;
 
-       mantis = kzalloc(sizeof(struct mantis_pci), GFP_KERNEL);
+       mantis = kzalloc(sizeof(*mantis), GFP_KERNEL);
        if (mantis == NULL) {
                err = -ENOMEM;
                goto fail0;
index 9958b6f..4ce8a90 100644 (file)
@@ -173,7 +173,7 @@ static int mantis_pci_probe(struct pci_dev *pdev,
        struct mantis_hwconfig *config;
        int err;
 
-       mantis = kzalloc(sizeof(struct mantis_pci), GFP_KERNEL);
+       mantis = kzalloc(sizeof(*mantis), GFP_KERNEL);
        if (!mantis)
                return -ENOMEM;
 
index 32c19ba..d31a2d4 100644 (file)
@@ -260,7 +260,7 @@ static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_d
 
        DEB_EE("\n");
 
-       hexium = kzalloc(sizeof(struct hexium), GFP_KERNEL);
+       hexium = kzalloc(sizeof(*hexium), GFP_KERNEL);
        if (!hexium)
                return -ENOMEM;
 
index 8d1dc8e..7dc1822 100644 (file)
@@ -219,7 +219,7 @@ static int hexium_probe(struct saa7146_dev *dev)
                return -EFAULT;
        }
 
-       hexium = kzalloc(sizeof(struct hexium), GFP_KERNEL);
+       hexium = kzalloc(sizeof(*hexium), GFP_KERNEL);
        if (!hexium)
                return -ENOMEM;
 
index 6bd665e..c83b2e9 100644 (file)
@@ -98,7 +98,7 @@ struct saa7164_buffer *saa7164_buffer_alloc(struct saa7164_port *port,
                goto ret;
        }
 
-       buf = kzalloc(sizeof(struct saa7164_buffer), GFP_KERNEL);
+       buf = kzalloc(sizeof(*buf), GFP_KERNEL);
        if (!buf)
                goto ret;
 
@@ -281,7 +281,7 @@ struct saa7164_user_buffer *saa7164_buffer_alloc_user(struct saa7164_dev *dev,
 {
        struct saa7164_user_buffer *buf;
 
-       buf = kzalloc(sizeof(struct saa7164_user_buffer), GFP_KERNEL);
+       buf = kzalloc(sizeof(*buf), GFP_KERNEL);
        if (!buf)
                return NULL;
 
index db410c5..755d2d4 100644 (file)
@@ -1505,7 +1505,7 @@ static int isc_formats_init(struct isc_device *isc)
 
        isc->num_user_formats = num_fmts;
        isc->user_formats = devm_kcalloc(isc->dev,
-                                        num_fmts, sizeof(struct isc_format *),
+                                        num_fmts, sizeof(*isc->user_formats),
                                         GFP_KERNEL);
        if (!isc->user_formats)
                return -ENOMEM;
index b50cff4..b3d0502 100644 (file)
@@ -1421,7 +1421,7 @@ static int zr364xx_probe(struct usb_interface *intf,
                 le16_to_cpu(udev->descriptor.idVendor),
                 le16_to_cpu(udev->descriptor.idProduct));
 
-       cam = kzalloc(sizeof(struct zr364xx_camera), GFP_KERNEL);
+       cam = kzalloc(sizeof(*cam), GFP_KERNEL);
        if (!cam)
                return -ENOMEM;