Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1580391
| From | Richard Cochran <richardcochran@gmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 2/4] ptp: use kcalloc/kmallco_array when allocating arrays |
| Date | 2017-02-14 09:40 +0100 |
| Message-ID | <taGOt-7QG-5@gated-at.bofh.it> (permalink) |
| References | <taCrw-4Mc-13@gated-at.bofh.it> <taCrw-4Mc-17@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Mon, Feb 13, 2017 at 07:51:06PM -0800, Dmitry Torokhov wrote: > @@ -269,13 +269,13 @@ 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 = kmalloc_array(1 + n_pins, sizeof(*ptp->pin_attr), > + GFP_KERNEL); I prefer kcalloc here as well, even if it isn't strictly necessary according to the current usage of pin_attr. That way, any future changes to the pin handling code won't have to worry about uninitialized memory. After all, this is hardly a performance path. > if (!ptp->pin_attr) > goto no_pin_attr; > > @@ -289,6 +289,9 @@ static int ptp_populate_pins(struct ptp_clock *ptp) > ptp->pin_attr[i] = &da->attr; > } > > + /* NULL terminator */ > + ptp->pin_attr[n_pins] = NULL; And drop this then, please. Thanks, Richard
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 1/4] ptp: do not explicitly set drvdata in ptp_clock_register() Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-02-14 05:00 +0100
[PATCH 2/4] ptp: use kcalloc/kmallco_array when allocating arrays Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-02-14 05:00 +0100
Re: [PATCH 2/4] ptp: use kcalloc/kmallco_array when allocating arrays Richard Cochran <richardcochran@gmail.com> - 2017-02-14 09:40 +0100
[PATCH 3/4] ptp: use is_visible method to hide unused attributes Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-02-14 05:00 +0100
Re: [PATCH 3/4] ptp: use is_visible method to hide unused attributes Richard Cochran <richardcochran@gmail.com> - 2017-02-14 09:50 +0100
Re: [PATCH 3/4] ptp: use is_visible method to hide unused attributes Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-02-14 19:10 +0100
Re: [PATCH 3/4] ptp: use is_visible method to hide unused attributes Richard Cochran <richardcochran@gmail.com> - 2017-02-14 19:20 +0100
[PATCH 4/4] ptp: create "pins" together with the rest of attributes Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-02-14 05:00 +0100
Re: [PATCH 1/4] ptp: do not explicitly set drvdata in ptp_clock_register() Richard Cochran <richardcochran@gmail.com> - 2017-02-14 09:40 +0100
csiph-web