Message ID | fbdf6d83-08ac-a6b2-1674-53bc86c69ae8@users.sourceforge.net |
---|---|
State | Deferred |
Delegated to: | David Miller |
Headers | show |
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 -- To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
>> @@ -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 -- To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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 -- To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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 -- To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/arch/sparc/kernel/led.c b/arch/sparc/kernel/led.c index 3ae36f3..7444e4a 100644 --- 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; diff --git a/arch/sparc/kernel/nmi.c b/arch/sparc/kernel/nmi.c index a9973bb..b88e97b 100644 --- a/arch/sparc/kernel/nmi.c +++ b/arch/sparc/kernel/nmi.c @@ -166,7 +166,9 @@ static int __init check_nmi_watchdog(void) if (!atomic_read(&nmi_active)) return 0; - prev_nmi_count = kmalloc(nr_cpu_ids * sizeof(unsigned int), GFP_KERNEL); + prev_nmi_count = kmalloc_array(nr_cpu_ids, + sizeof(*prev_nmi_count), + GFP_KERNEL); if (!prev_nmi_count) { err = -ENOMEM; goto error; diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c index fe8b8ee..25b7a14 100644 --- a/arch/sparc/kernel/sys_sparc_64.c +++ b/arch/sparc/kernel/sys_sparc_64.c @@ -580,8 +580,10 @@ SYSCALL_DEFINE5(utrap_install, utrap_entry_t, type, unsigned long *p = current_thread_info()->utraps; current_thread_info()->utraps = - kmalloc((UT_TRAP_INSTRUCTION_31+1)*sizeof(long), - GFP_KERNEL); + kmalloc_array(UT_TRAP_INSTRUCTION_31 + 1, + sizeof(*current_thread_info() + ->utraps), + GFP_KERNEL); if (!current_thread_info()->utraps) { current_thread_info()->utraps = p; return -ENOMEM;