linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] MIPS-kernel: Adjustments for some function implementations
@ 2017-05-23 20:50 SF Markus Elfring
  2017-05-23 20:51 ` [PATCH 1/5] MIPS: pm-cps: Delete an error message for a failed memory allocation in cps_pm_online_cpu() SF Markus Elfring
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: SF Markus Elfring @ 2017-05-23 20:50 UTC (permalink / raw)
  To: linux-mips, Ingo Molnar, James Hogan, Kees Cook,
	Marcin Nowakowski, Masahiro Yamada, Matt Redfearn, Paul Burton,
	Ralf Bächle, Thomas Gleixner
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 23 May 2017 22:40:04 +0200

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (5):
  Delete an error message for a failed memory allocation in cps_pm_online_cpu()
  Delete error messages for failed memory allocations in cps_prepare_cpus()
  Delete an error message for a failed memory allocation in vpe_open()
  Improve a size determination in two functions
  Adjust 13 checks for null pointers

 arch/mips/kernel/pm-cps.c  |  5 ++---
 arch/mips/kernel/smp-cps.c |  9 ++-------
 arch/mips/kernel/vpe.c     | 37 +++++++++++++++++--------------------
 3 files changed, 21 insertions(+), 30 deletions(-)

-- 
2.13.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] MIPS: pm-cps: Delete an error message for a failed memory allocation in cps_pm_online_cpu()
  2017-05-23 20:50 [PATCH 0/5] MIPS-kernel: Adjustments for some function implementations SF Markus Elfring
@ 2017-05-23 20:51 ` SF Markus Elfring
  2017-05-23 20:52 ` [PATCH 2/5] MIPS: smp-cps: Delete error messages for failed memory allocations in cps_prepare_cpus() SF Markus Elfring
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2017-05-23 20:51 UTC (permalink / raw)
  To: linux-mips, Ingo Molnar, James Hogan, Kees Cook,
	Marcin Nowakowski, Masahiro Yamada, Matt Redfearn, Paul Burton,
	Ralf Bächle, Thomas Gleixner
  Cc: LKML, kernel-janitors

>From c7eaa7be6235b37023b23b40b36737f72e5b4b3f Mon Sep 17 00:00:00 2001
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 23 May 2017 21:30:11 +0200
Subject: [PATCH 1/5] MIPS: pm-cps: Delete an error message for a failed memory allocation in cps_pm_online_cpu()

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/mips/kernel/pm-cps.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
index 5f928c34c148..d662838e418f 100644
--- a/arch/mips/kernel/pm-cps.c
+++ b/arch/mips/kernel/pm-cps.c
@@ -666,7 +666,6 @@ static int cps_pm_online_cpu(unsigned int cpu)
-		if (!core_rc) {
-			pr_err("Failed allocate core %u ready_count\n", core);
+		if (!core_rc)
 			return -ENOMEM;
-		}
+
 		per_cpu(ready_count_alloc, core) = core_rc;
 
 		/* Ensure ready_count is aligned to a cacheline boundary */
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/5] MIPS: smp-cps: Delete error messages for failed memory allocations in cps_prepare_cpus()
  2017-05-23 20:50 [PATCH 0/5] MIPS-kernel: Adjustments for some function implementations SF Markus Elfring
  2017-05-23 20:51 ` [PATCH 1/5] MIPS: pm-cps: Delete an error message for a failed memory allocation in cps_pm_online_cpu() SF Markus Elfring
@ 2017-05-23 20:52 ` SF Markus Elfring
  2017-05-23 20:53 ` [PATCH 3/5] MIPS: VPE: Delete an error message for a failed memory allocation in vpe_open() SF Markus Elfring
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2017-05-23 20:52 UTC (permalink / raw)
  To: linux-mips, Ingo Molnar, James Hogan, Kees Cook,
	Marcin Nowakowski, Masahiro Yamada, Matt Redfearn, Paul Burton,
	Ralf Bächle, Thomas Gleixner
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 23 May 2017 21:41:32 +0200

Omit two extra messages for memory allocation failures in this function.

This issue was detected by using the Coccinelle software.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/mips/kernel/smp-cps.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/arch/mips/kernel/smp-cps.c b/arch/mips/kernel/smp-cps.c
index 36954ddd0b9f..bc8d7f6a62c2 100644
--- a/arch/mips/kernel/smp-cps.c
+++ b/arch/mips/kernel/smp-cps.c
@@ -171,7 +171,5 @@ static void __init cps_prepare_cpus(unsigned int max_cpus)
-	if (!mips_cps_core_bootcfg) {
-		pr_err("Failed to allocate boot config for %u cores\n", ncores);
+	if (!mips_cps_core_bootcfg)
 		goto err_out;
-	}
 
 	/* Allocate VPE boot configuration structs */
 	for (c = 0; c < ncores; c++) {
@@ -182,8 +180,5 @@ static void __init cps_prepare_cpus(unsigned int max_cpus)
-		if (!mips_cps_core_bootcfg[c].vpe_config) {
-			pr_err("Failed to allocate %u VPE boot configs\n",
-			       core_vpes);
+		if (!mips_cps_core_bootcfg[c].vpe_config)
 			goto err_out;
-		}
 	}
 
 	/* Mark this CPU as booted */
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/5] MIPS: VPE: Delete an error message for a failed memory allocation in vpe_open()
  2017-05-23 20:50 [PATCH 0/5] MIPS-kernel: Adjustments for some function implementations SF Markus Elfring
  2017-05-23 20:51 ` [PATCH 1/5] MIPS: pm-cps: Delete an error message for a failed memory allocation in cps_pm_online_cpu() SF Markus Elfring
  2017-05-23 20:52 ` [PATCH 2/5] MIPS: smp-cps: Delete error messages for failed memory allocations in cps_prepare_cpus() SF Markus Elfring
@ 2017-05-23 20:53 ` SF Markus Elfring
  2017-05-23 20:54 ` [PATCH 4/5] MIPS: VPE: Improve a size determination in two functions SF Markus Elfring
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2017-05-23 20:53 UTC (permalink / raw)
  To: linux-mips, Ingo Molnar, James Hogan, Kees Cook,
	Marcin Nowakowski, Masahiro Yamada, Matt Redfearn, Paul Burton,
	Ralf Bächle, Thomas Gleixner
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 23 May 2017 21:54:42 +0200

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Link: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/mips/kernel/vpe.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/mips/kernel/vpe.c b/arch/mips/kernel/vpe.c
index 544ea21bfef9..721b1523b740 100644
--- a/arch/mips/kernel/vpe.c
+++ b/arch/mips/kernel/vpe.c
@@ -799,7 +799,6 @@ static int vpe_open(struct inode *inode, struct file *filp)
-	if (!v->pbuffer) {
-		pr_warn("VPE loader: unable to allocate memory\n");
+	if (!v->pbuffer)
 		return -ENOMEM;
-	}
+
 	v->plen = P_SIZE;
 	v->load_addr = NULL;
 	v->len = 0;
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/5] MIPS: VPE: Improve a size determination in two functions
  2017-05-23 20:50 [PATCH 0/5] MIPS-kernel: Adjustments for some function implementations SF Markus Elfring
                   ` (2 preceding siblings ...)
  2017-05-23 20:53 ` [PATCH 3/5] MIPS: VPE: Delete an error message for a failed memory allocation in vpe_open() SF Markus Elfring
@ 2017-05-23 20:54 ` SF Markus Elfring
  2017-05-23 20:55 ` [PATCH 5/5] MIPS: VPE: Adjust 13 checks for null pointers SF Markus Elfring
  2017-05-23 21:11 ` [PATCH 0/5] MIPS-kernel: Adjustments for some function implementations Joe Perches
  5 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2017-05-23 20:54 UTC (permalink / raw)
  To: linux-mips, Ingo Molnar, James Hogan, Kees Cook,
	Marcin Nowakowski, Masahiro Yamada, Matt Redfearn, Paul Burton,
	Ralf Bächle, Thomas Gleixner
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 23 May 2017 22:04:17 +0200

Replace the specification of two data structures by pointer dereferences
as the parameter for the operator "sizeof" 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/mips/kernel/vpe.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/kernel/vpe.c b/arch/mips/kernel/vpe.c
index 721b1523b740..ed019218496b 100644
--- a/arch/mips/kernel/vpe.c
+++ b/arch/mips/kernel/vpe.c
@@ -93,7 +93,7 @@ struct vpe *alloc_vpe(int minor)
 {
 	struct vpe *v;
 
-	v = kzalloc(sizeof(struct vpe), GFP_KERNEL);
+	v = kzalloc(sizeof(*v), GFP_KERNEL);
 	if (v == NULL)
 		goto out;
 
@@ -114,7 +114,7 @@ struct tc *alloc_tc(int index)
 {
 	struct tc *tc;
 
-	tc = kzalloc(sizeof(struct tc), GFP_KERNEL);
+	tc = kzalloc(sizeof(*tc), GFP_KERNEL);
 	if (tc == NULL)
 		goto out;
 
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/5] MIPS: VPE: Adjust 13 checks for null pointers
  2017-05-23 20:50 [PATCH 0/5] MIPS-kernel: Adjustments for some function implementations SF Markus Elfring
                   ` (3 preceding siblings ...)
  2017-05-23 20:54 ` [PATCH 4/5] MIPS: VPE: Improve a size determination in two functions SF Markus Elfring
@ 2017-05-23 20:55 ` SF Markus Elfring
  2017-05-23 21:11 ` [PATCH 0/5] MIPS-kernel: Adjustments for some function implementations Joe Perches
  5 siblings, 0 replies; 7+ messages in thread
From: SF Markus Elfring @ 2017-05-23 20:55 UTC (permalink / raw)
  To: linux-mips, Ingo Molnar, James Hogan, Kees Cook,
	Marcin Nowakowski, Masahiro Yamada, Matt Redfearn, Paul Burton,
	Ralf Bächle, Thomas Gleixner
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 23 May 2017 22:16:24 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script “checkpatch.pl” pointed information out like the following.

Comparison to NULL could be written …

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/mips/kernel/vpe.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/arch/mips/kernel/vpe.c b/arch/mips/kernel/vpe.c
index ed019218496b..0ef7654e67e4 100644
--- a/arch/mips/kernel/vpe.c
+++ b/arch/mips/kernel/vpe.c
@@ -97,4 +97,4 @@ struct vpe *alloc_vpe(int minor)
-	if (v == NULL)
+	if (!v)
 		goto out;
 
 	INIT_LIST_HEAD(&v->tc);
@@ -118,4 +118,4 @@ struct tc *alloc_tc(int index)
-	if (tc == NULL)
+	if (!tc)
 		goto out;
 
 	INIT_LIST_HEAD(&tc->tc);
@@ -340,10 +340,9 @@ static int apply_r_mips_lo16(struct module *me, uint32_t *location,
 	/* Sign extend the addend we extract from the lo insn.	*/
 	vallo = ((insnlo & 0xffff) ^ 0x8000) - 0x8000;
 
-	if (mips_hi16_list != NULL) {
-
+	if (mips_hi16_list) {
 		l = mips_hi16_list;
-		while (l != NULL) {
+		while (l) {
 			unsigned long insn;
 
 			/*
@@ -391,7 +390,7 @@ static int apply_r_mips_lo16(struct module *me, uint32_t *location,
 	return 0;
 
 out_free:
-	while (l != NULL) {
+	while (l) {
 		next = l->next;
 		kfree(l);
 		l = next;
@@ -562,7 +561,7 @@ static int find_vpe_symbols(struct vpe *v, Elf_Shdr *sechdrs,
 			v->shared_ptr = (void *)sym[i].st_value;
 	}
 
-	if ((v->__start == 0) || (v->shared_ptr == NULL))
+	if ((v->__start == 0) || !v->shared_ptr)
 		return -1;
 
 	return 0;
@@ -737,7 +736,7 @@ static int vpe_elfload(struct vpe *v)
 			return -ENOEXEC;
 		}
 
-		if (v->shared_ptr == NULL)
+		if (!v->shared_ptr)
 			pr_warn("VPE loader: program does not contain vpe_shared symbol.\n"
 				" Unable to use AMVP (AP/SP) facilities.\n");
 	}
@@ -777,7 +776,7 @@ static int vpe_open(struct inode *inode, struct file *filp)
 	}
 
 	v = get_vpe(aprp_cpu_index());
-	if (v == NULL) {
+	if (!v) {
 		pr_warn("VPE loader: unable to get vpe\n");
 
 		return -ENODEV;
@@ -822,7 +821,7 @@ static int vpe_release(struct inode *inode, struct file *filp)
 	int ret = 0;
 
 	v = get_vpe(aprp_cpu_index());
-	if (v == NULL)
+	if (!v)
 		return -ENODEV;
 
 	hdr = (Elf_Ehdr *) v->pbuffer;
@@ -866,8 +865,7 @@ static ssize_t vpe_write(struct file *file, const char __user *buffer,
 		return -ENODEV;
 
 	v = get_vpe(aprp_cpu_index());
-
-	if (v == NULL)
+	if (!v)
 		return -ENODEV;
 
 	if ((count + v->len) > v->plen) {
@@ -895,7 +893,7 @@ void *vpe_get_shared(int index)
 {
 	struct vpe *v = get_vpe(index);
 
-	if (v == NULL)
+	if (!v)
 		return NULL;
 
 	return v->shared_ptr;
@@ -906,7 +904,7 @@ int vpe_notify(int index, struct vpe_notifications *notify)
 {
 	struct vpe *v = get_vpe(index);
 
-	if (v == NULL)
+	if (!v)
 		return -1;
 
 	list_add(&notify->list, &v->notify);
@@ -918,7 +916,7 @@ char *vpe_getcwd(int index)
 {
 	struct vpe *v = get_vpe(index);
 
-	if (v == NULL)
+	if (!v)
 		return NULL;
 
 	return v->cwd;
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/5] MIPS-kernel: Adjustments for some function implementations
  2017-05-23 20:50 [PATCH 0/5] MIPS-kernel: Adjustments for some function implementations SF Markus Elfring
                   ` (4 preceding siblings ...)
  2017-05-23 20:55 ` [PATCH 5/5] MIPS: VPE: Adjust 13 checks for null pointers SF Markus Elfring
@ 2017-05-23 21:11 ` Joe Perches
  5 siblings, 0 replies; 7+ messages in thread
From: Joe Perches @ 2017-05-23 21:11 UTC (permalink / raw)
  To: SF Markus Elfring, linux-mips, Ingo Molnar, James Hogan,
	Kees Cook, Marcin Nowakowski, Masahiro Yamada, Matt Redfearn,
	Paul Burton, Ralf Bächle, Thomas Gleixner
  Cc: LKML, kernel-janitors

On Tue, 2017-05-23 at 22:50 +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 23 May 2017 22:40:04 +0200
> 
> A few update suggestions were taken into account
> from static source code analysis.

Stop sending new patches until you handle the
feedback you receive on old patches.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-05-23 21:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-23 20:50 [PATCH 0/5] MIPS-kernel: Adjustments for some function implementations SF Markus Elfring
2017-05-23 20:51 ` [PATCH 1/5] MIPS: pm-cps: Delete an error message for a failed memory allocation in cps_pm_online_cpu() SF Markus Elfring
2017-05-23 20:52 ` [PATCH 2/5] MIPS: smp-cps: Delete error messages for failed memory allocations in cps_prepare_cpus() SF Markus Elfring
2017-05-23 20:53 ` [PATCH 3/5] MIPS: VPE: Delete an error message for a failed memory allocation in vpe_open() SF Markus Elfring
2017-05-23 20:54 ` [PATCH 4/5] MIPS: VPE: Improve a size determination in two functions SF Markus Elfring
2017-05-23 20:55 ` [PATCH 5/5] MIPS: VPE: Adjust 13 checks for null pointers SF Markus Elfring
2017-05-23 21:11 ` [PATCH 0/5] MIPS-kernel: Adjustments for some function implementations Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).