Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1471679 > unrolled thread
| Started by | Paolo Bonzini <pbonzini@redhat.com> |
|---|---|
| First post | 2016-08-29 11:50 +0200 |
| Last post | 2016-08-29 18:50 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions Paolo Bonzini <pbonzini@redhat.com> - 2016-08-29 11:50 +0200
Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-29 12:40 +0200
Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions walter harms <wharms@bfs.de> - 2016-08-29 14:00 +0200
Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions Paolo Bonzini <pbonzini@redhat.com> - 2016-08-29 18:50 +0200
| From | Paolo Bonzini <pbonzini@redhat.com> |
|---|---|
| Date | 2016-08-29 11:50 +0200 |
| Subject | Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions |
| Message-ID | <sbrmx-5BR-7@gated-at.bofh.it> |
On 25/08/2016 10:22, SF Markus Elfring wrote: > --- a/arch/sparc/kernel/led.c > +++ b/arch/sparc/kernel/led.c > @@ -69,7 +69,7 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer, > if (count > LED_MAX_LENGTH) > count = LED_MAX_LENGTH; > > - buf = kmalloc(sizeof(char) * (count + 1), GFP_KERNEL); > + buf = kmalloc_array(count + 1, sizeof(*buf), GFP_KERNEL); > if (!buf) > return -ENOMEM; > Here it's probably best to just remove sizeof(char) completely, as it's 1 by definition. Paolo
[toc] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2016-08-29 12:40 +0200 |
| Message-ID | <sbs8W-69R-15@gated-at.bofh.it> |
| In reply to | #1471679 |
>> @@ -69,7 +69,7 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer, >> if (count > LED_MAX_LENGTH) >> count = LED_MAX_LENGTH; >> >> - buf = kmalloc(sizeof(char) * (count + 1), GFP_KERNEL); >> + buf = kmalloc_array(count + 1, sizeof(*buf), GFP_KERNEL); >> if (!buf) >> return -ENOMEM; >> > > Here it's probably best to just remove sizeof(char) completely, > as it's 1 by definition. Would you like to be prepared anyhow that the shown buffer variable could eventually store other data than ordinary single byte characters? Regards, Markus
[toc] | [prev] | [next] | [standalone]
| From | walter harms <wharms@bfs.de> |
|---|---|
| Date | 2016-08-29 14:00 +0200 |
| Message-ID | <sbtol-6P8-1@gated-at.bofh.it> |
| In reply to | #1471679 |
Am 29.08.2016 11:47, schrieb Paolo Bonzini: > > > On 25/08/2016 10:22, SF Markus Elfring wrote: >> --- a/arch/sparc/kernel/led.c >> +++ b/arch/sparc/kernel/led.c >> @@ -69,7 +69,7 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer, >> if (count > LED_MAX_LENGTH) >> count = LED_MAX_LENGTH; >> >> - buf = kmalloc(sizeof(char) * (count + 1), GFP_KERNEL); >> + buf = kmalloc_array(count + 1, sizeof(*buf), GFP_KERNEL); >> if (!buf) >> return -ENOMEM; >> > > Here it's probably best to just remove sizeof(char) completely, as it's > 1 by definition. > > Paolo I would not do so, if you ever change buf to something else it would break, having a sizeof(*buf) here is harmless and a known pattern. re, wh
[toc] | [prev] | [next] | [standalone]
| From | Paolo Bonzini <pbonzini@redhat.com> |
|---|---|
| Date | 2016-08-29 18:50 +0200 |
| Message-ID | <sbxV0-1fP-29@gated-at.bofh.it> |
| In reply to | #1471750 |
On 29/08/2016 13:57, walter harms wrote: > > > - buf = kmalloc(sizeof(char) * (count + 1), GFP_KERNEL); > > > + buf = kmalloc_array(count + 1, sizeof(*buf), GFP_KERNEL); > > > if (!buf) > > > return -ENOMEM; > > > > > > > Here it's probably best to just remove sizeof(char) completely, as it's > > 1 by definition. > > I would not do so, if you ever change buf to something else it would break, > having a sizeof(*buf) here is harmless and a known pattern. Fair enough, it's not code I maintain. Paolo
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web