* [PATCH 0/2] sparc: Fine-tuning for three function implementations @ 2016-08-25 8:20 ` SF Markus Elfring 0 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2016-08-25 8:20 UTC (permalink / raw) To: sparclinux, David S. Miller Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 25 Aug 2016 10:05:45 +0200 A few update suggestions were taken into account from static source code analysis. Markus Elfring (2): Use kmalloc_array() Delete an unnecessary initialisation in led_proc_write() arch/sparc/kernel/led.c | 4 ++-- arch/sparc/kernel/nmi.c | 4 +++- arch/sparc/kernel/sys_sparc_64.c | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) -- 2.9.3 ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 0/2] sparc: Fine-tuning for three function implementations @ 2016-08-25 8:20 ` SF Markus Elfring 0 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2016-08-25 8:20 UTC (permalink / raw) To: sparclinux, David S. Miller Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 25 Aug 2016 10:05:45 +0200 A few update suggestions were taken into account from static source code analysis. Markus Elfring (2): Use kmalloc_array() Delete an unnecessary initialisation in led_proc_write() arch/sparc/kernel/led.c | 4 ++-- arch/sparc/kernel/nmi.c | 4 +++- arch/sparc/kernel/sys_sparc_64.c | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) -- 2.9.3 ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/2] sparc: Use kmalloc_array() in three functions 2016-08-25 8:20 ` SF Markus Elfring @ 2016-08-25 8:22 ` SF Markus Elfring -1 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2016-08-25 8:22 UTC (permalink / raw) To: sparclinux, David S. Miller Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 25 Aug 2016 09:52:44 +0200 * Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus reuse the corresponding function "kmalloc_array". This issue was detected by using the Coccinelle software. * Replace the specifications of data types by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- arch/sparc/kernel/led.c | 2 +- arch/sparc/kernel/nmi.c | 4 +++- arch/sparc/kernel/sys_sparc_64.c | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) 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; -- 2.9.3 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 1/2] sparc: Use kmalloc_array() in three functions @ 2016-08-25 8:22 ` SF Markus Elfring 0 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2016-08-25 8:22 UTC (permalink / raw) To: sparclinux, David S. Miller Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 25 Aug 2016 09:52:44 +0200 * Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus reuse the corresponding function "kmalloc_array". This issue was detected by using the Coccinelle software. * Replace the specifications of data types by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- arch/sparc/kernel/led.c | 2 +- arch/sparc/kernel/nmi.c | 4 +++- arch/sparc/kernel/sys_sparc_64.c | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) 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; -- 2.9.3 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions 2016-08-25 8:22 ` SF Markus Elfring @ 2016-08-29 9:47 ` Paolo Bonzini -1 siblings, 0 replies; 14+ messages in thread From: Paolo Bonzini @ 2016-08-29 9:47 UTC (permalink / raw) To: SF Markus Elfring, sparclinux, David S. Miller Cc: LKML, kernel-janitors, Julia Lawall 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions @ 2016-08-29 9:47 ` Paolo Bonzini 0 siblings, 0 replies; 14+ messages in thread From: Paolo Bonzini @ 2016-08-29 9:47 UTC (permalink / raw) To: SF Markus Elfring, sparclinux, David S. Miller Cc: LKML, kernel-janitors, Julia Lawall 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions 2016-08-29 9:47 ` Paolo Bonzini @ 2016-08-29 10:36 ` SF Markus Elfring -1 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2016-08-29 10:36 UTC (permalink / raw) To: Paolo Bonzini Cc: sparclinux, David S. Miller, LKML, kernel-janitors, Julia Lawall >> @@ -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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions @ 2016-08-29 10:36 ` SF Markus Elfring 0 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2016-08-29 10:36 UTC (permalink / raw) To: Paolo Bonzini Cc: sparclinux, David S. Miller, LKML, kernel-janitors, Julia Lawall >> @@ -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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions 2016-08-29 9:47 ` Paolo Bonzini @ 2016-08-29 11:57 ` walter harms -1 siblings, 0 replies; 14+ messages in thread From: walter harms @ 2016-08-29 11:57 UTC (permalink / raw) To: Paolo Bonzini Cc: SF Markus Elfring, sparclinux, David S. Miller, LKML, kernel-janitors, Julia Lawall 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions @ 2016-08-29 11:57 ` walter harms 0 siblings, 0 replies; 14+ messages in thread From: walter harms @ 2016-08-29 11:57 UTC (permalink / raw) To: Paolo Bonzini Cc: SF Markus Elfring, sparclinux, David S. Miller, LKML, kernel-janitors, Julia Lawall 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions 2016-08-29 11:57 ` walter harms @ 2016-08-29 16:38 ` Paolo Bonzini -1 siblings, 0 replies; 14+ messages in thread From: Paolo Bonzini @ 2016-08-29 16:38 UTC (permalink / raw) To: wharms Cc: SF Markus Elfring, sparclinux, David S. Miller, LKML, kernel-janitors, Julia Lawall 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions @ 2016-08-29 16:38 ` Paolo Bonzini 0 siblings, 0 replies; 14+ messages in thread From: Paolo Bonzini @ 2016-08-29 16:38 UTC (permalink / raw) To: wharms Cc: SF Markus Elfring, sparclinux, David S. Miller, LKML, kernel-janitors, Julia Lawall 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 ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 2/2] sparc: Delete an unnecessary initialisation in led_proc_write() 2016-08-25 8:20 ` SF Markus Elfring @ 2016-08-25 8:24 ` SF Markus Elfring -1 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2016-08-25 8:24 UTC (permalink / raw) To: sparclinux, David S. Miller Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 25 Aug 2016 09:55:22 +0200 The local variable "buf" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- arch/sparc/kernel/led.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/sparc/kernel/led.c b/arch/sparc/kernel/led.c index 7444e4a..d6671af 100644 --- a/arch/sparc/kernel/led.c +++ b/arch/sparc/kernel/led.c @@ -64,7 +64,7 @@ static int led_proc_open(struct inode *inode, struct file *file) static ssize_t led_proc_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) { - char *buf = NULL; + char *buf; if (count > LED_MAX_LENGTH) count = LED_MAX_LENGTH; -- 2.9.3 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/2] sparc: Delete an unnecessary initialisation in led_proc_write() @ 2016-08-25 8:24 ` SF Markus Elfring 0 siblings, 0 replies; 14+ messages in thread From: SF Markus Elfring @ 2016-08-25 8:24 UTC (permalink / raw) To: sparclinux, David S. Miller Cc: LKML, kernel-janitors, Julia Lawall, Paolo Bonzini From: Markus Elfring <elfring@users.sourceforge.net> Date: Thu, 25 Aug 2016 09:55:22 +0200 The local variable "buf" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning. Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> --- arch/sparc/kernel/led.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/sparc/kernel/led.c b/arch/sparc/kernel/led.c index 7444e4a..d6671af 100644 --- a/arch/sparc/kernel/led.c +++ b/arch/sparc/kernel/led.c @@ -64,7 +64,7 @@ static int led_proc_open(struct inode *inode, struct file *file) static ssize_t led_proc_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) { - char *buf = NULL; + char *buf; if (count > LED_MAX_LENGTH) count = LED_MAX_LENGTH; -- 2.9.3 ^ permalink raw reply related [flat|nested] 14+ messages in thread
end of thread, other threads:[~2016-08-29 16:47 UTC | newest] Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-08-25 8:20 [PATCH 0/2] sparc: Fine-tuning for three function implementations SF Markus Elfring 2016-08-25 8:20 ` SF Markus Elfring 2016-08-25 8:22 ` [PATCH 1/2] sparc: Use kmalloc_array() in three functions SF Markus Elfring 2016-08-25 8:22 ` SF Markus Elfring 2016-08-29 9:47 ` Paolo Bonzini 2016-08-29 9:47 ` Paolo Bonzini 2016-08-29 10:36 ` SF Markus Elfring 2016-08-29 10:36 ` SF Markus Elfring 2016-08-29 11:57 ` walter harms 2016-08-29 11:57 ` walter harms 2016-08-29 16:38 ` Paolo Bonzini 2016-08-29 16:38 ` Paolo Bonzini 2016-08-25 8:24 ` [PATCH 2/2] sparc: Delete an unnecessary initialisation in led_proc_write() SF Markus Elfring 2016-08-25 8:24 ` SF Markus Elfring
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.