Skip to content

Commit

Permalink
ptp: use kcalloc when allocating arrays
Browse files Browse the repository at this point in the history
kcalloc is more semantically correct when allocating arrays of objects, and
overflow-safe.

Signed-off-by: Dmitry Torokhov <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
dtor authored and davem330 committed Feb 17, 2017
1 parent 882f312 commit 6f7aa56
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/ptp/ptp_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 6f7aa56

Please sign in to comment.