ptp: use kcalloc when allocating arrays
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Tue, 14 Feb 2017 18:23:32 +0000 (10:23 -0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 17 Feb 2017 16:03:06 +0000 (11:03 -0500)
kcalloc is more semantically correct when allocating arrays of objects, and
overflow-safe.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/ptp/ptp_sysfs.c

index 53d43954a9740a5520229a1e8798516805a73c19..27cd46ab5e32edc4c8b24829942e35805ce927f5 100644 (file)
@@ -269,13 +269,12 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
        struct ptp_clock_info *info = ptp->info;
        int err = -ENOMEM, i, n_pins = info->n_pins;
 
-       ptp->pin_dev_attr = kzalloc(n_pins * sizeof(*ptp->pin_dev_attr),
+       ptp->pin_dev_attr = kcalloc(n_pins, sizeof(*ptp->pin_dev_attr),
                                    GFP_KERNEL);
        if (!ptp->pin_dev_attr)
                goto no_dev_attr;
 
-       ptp->pin_attr = kzalloc((1 + n_pins) * sizeof(struct attribute *),
-                               GFP_KERNEL);
+       ptp->pin_attr = kcalloc(1 + n_pins, sizeof(*ptp->pin_attr), GFP_KERNEL);
        if (!ptp->pin_attr)
                goto no_pin_attr;