Skip to contentSkip to conversation

Remove unnecessary null pointer checks?

Cocci Applied SF Markus Elfring 178 participants 1,551 messages Feb 21, 2014 – Apr 12, 2017 3 messages not in the archive Page 3 of 7

Subsystems (270)
lore
Share & tools
lore
#182 lore raw

[Cocci] while compiling coccci 1.0.0-rc22

In reply to Julia Lawall

Hi,

Anyone got this?

/home/berenger/.opam/4.01.0/bin/ocamlopt.opt -unsafe -I /home/berenger/.opam/4.01.0/lib/menhirLib -I /home/berenger/.opam/4.01.0/lib/ocaml -I /home/berenger/.opam/4.01.0/lib/pcre -I /home/berenger/src/coccinelle-1.0.0-rc22/bundles/pycaml/ -I commons -I commons/ocamlextra -I ctl -I engine -I extra -I globals -I ocaml -I
parsing_c -I parsing_cocci -I popl09 -I python -cclib -lpycaml_stubs
-cclib -lpython2.7 -ccopt -lpcre -cclib -lpcre_stubs -o spatch.opt str.cmxa unix.cmxa bigarray.cmxa nums.cmxa /home/berenger/.opam/4.01.0/lib/ocaml/dynlink.cmxa /home/berenger/src/coccinelle-1.0.0-rc22/bundles/pycaml//pycaml.cmxa /home/berenger/.opam/4.01.0/lib/pcre/pcre.cmxa commons/commons.cmxa globals/globals.cmxa ctl/ctl.cmxa parsing_cocci/cocci_parser.cmxa parsing_c/parsing_c.cmxa engine/cocciengine.cmxa popl09/popl.cmxa extra/extra.cmxa python/coccipython.cmxa ocaml/cocciocaml.cmxa flag_cocci.cmx cocci.cmx testing.cmx test.cmx main.cmx
File "_none_", line 1:
Error: No implementations provided for the following modules:
Bytes referenced from
/home/berenger/.opam/4.01.0/lib/pcre/pcre.cmxa(Pcre)

Regards,
F.

#183 lore raw

[Cocci] while compiling coccci 1.0.0-rc22

There is exactly the same problem with 1.0.0-rc21. So the coccinelle opam package just got broken recently.

The only change I could see is that the package pcre-ocaml was renamed to pcre.

I will dig a little ...

Quoted 31 lines · Francois Berenger

Hi,

Anyone got this?

/home/berenger/.opam/4.01.0/bin/ocamlopt.opt -unsafe -I /home/berenger/.opam/4.01.0/lib/menhirLib -I /home/berenger/.opam/4.01.0/lib/ocaml -I /home/berenger/.opam/4.01.0/lib/pcre -I /home/berenger/src/coccinelle-1.0.0-rc22/bundles/pycaml/ -I commons -I commons/ocamlextra -I ctl -I engine -I extra -I globals -I ocaml -I
parsing_c -I parsing_cocci -I popl09 -I python -cclib -lpycaml_stubs
-cclib -lpython2.7 -ccopt -lpcre -cclib -lpcre_stubs -o spatch.opt str.cmxa unix.cmxa bigarray.cmxa nums.cmxa /home/berenger/.opam/4.01.0/lib/ocaml/dynlink.cmxa /home/berenger/src/coccinelle-1.0.0-rc22/bundles/pycaml//pycaml.cmxa /home/berenger/.opam/4.01.0/lib/pcre/pcre.cmxa commons/commons.cmxa globals/globals.cmxa ctl/ctl.cmxa parsing_cocci/cocci_parser.cmxa parsing_c/parsing_c.cmxa engine/cocciengine.cmxa popl09/popl.cmxa extra/extra.cmxa python/coccipython.cmxa ocaml/cocciocaml.cmxa flag_cocci.cmx cocci.cmx testing.cmx test.cmx main.cmx
File "_none_", line 1:
Error: No implementations provided for the following modules:
Bytes referenced from
/home/berenger/.opam/4.01.0/lib/pcre/pcre.cmxa(Pcre)

Regards,
F.
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

Signature · 2 lines
Regards,
Francois.
#184 lore raw

[Cocci] while compiling coccci 1.0.0-rc22

Quoted 5 lines · Francois Berenger

There is exactly the same problem with 1.0.0-rc21. So the coccinelle opam package just got broken recently.

The only change I could see is that the package pcre-ocaml was renamed to pcre.

OK, on my computer, pcre has to be downgraded from 7.1.3 to 7.1.1 in order for cocci rc21 and rc22 to compile.

I think I will send in the opam repository a request to fix dependency version of pcre to 7.1.1 for coccinelle.

If anybody doesn't agree with that, please shout now. :)

Quoted 35 lines

I will dig a little ...

Quoted 31 lines · Francois Berenger

Hi,

Anyone got this?

/home/berenger/.opam/4.01.0/bin/ocamlopt.opt -unsafe -I /home/berenger/.opam/4.01.0/lib/menhirLib -I /home/berenger/.opam/4.01.0/lib/ocaml -I /home/berenger/.opam/4.01.0/lib/pcre -I /home/berenger/src/coccinelle-1.0.0-rc22/bundles/pycaml/ -I commons -I commons/ocamlextra -I ctl -I engine -I extra -I globals -I ocaml -I
parsing_c -I parsing_cocci -I popl09 -I python -cclib -lpycaml_stubs
-cclib -lpython2.7 -ccopt -lpcre -cclib -lpcre_stubs -o spatch.opt str.cmxa unix.cmxa bigarray.cmxa nums.cmxa /home/berenger/.opam/4.01.0/lib/ocaml/dynlink.cmxa /home/berenger/src/coccinelle-1.0.0-rc22/bundles/pycaml//pycaml.cmxa /home/berenger/.opam/4.01.0/lib/pcre/pcre.cmxa commons/commons.cmxa globals/globals.cmxa ctl/ctl.cmxa parsing_cocci/cocci_parser.cmxa parsing_c/parsing_c.cmxa engine/cocciengine.cmxa popl09/popl.cmxa extra/extra.cmxa python/coccipython.cmxa ocaml/cocciocaml.cmxa flag_cocci.cmx cocci.cmx testing.cmx test.cmx main.cmx
File "_none_", line 1:
Error: No implementations provided for the following modules:
Bytes referenced from
/home/berenger/.opam/4.01.0/lib/pcre/pcre.cmxa(Pcre)

Regards,
F.
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

Signature · 2 lines
Regards,
Francois.
#191 lore raw

Re: [patch] CodingStyle: add some more error handling guidelines

In reply to Arend van Spriel
Quoted 5 lines
Quoted 2 lines

Which name pattern do you find more appropriate in such an use case?

I think Dan wants the label to be descriptive about the tasks needed in the exception handling itself.

I would usually prefer also such a target-oriented labelling for the affected identifiers.
How are the chances to express an expectation in this direction unambiguously for the proposed coding style update?

Quoted 2 lines

This makes sense as the exception handling steps may be reused for different failures in the code.

I would stress a different reason from my point of view.

Regards,
Markus

#185 lore raw

[Cocci] while compiling coccci 1.0.0-rc22

In reply to Francois Berenger
Quoted 7 lines · Francois Berenger
Quoted 5 lines · Francois Berenger

There is exactly the same problem with 1.0.0-rc21. So the coccinelle opam package just got broken recently.

The only change I could see is that the package pcre-ocaml was renamed to pcre.

Quoted 7 lines

OK, on my computer, pcre has to be downgraded from 7.1.3 to 7.1.1 in order for cocci rc21 and rc22 to compile.

I think I will send in the opam repository a request to fix dependency version of pcre to 7.1.1 for coccinelle.

If anybody doesn't agree with that, please shout now. :)

Since no one shouted yet, plus the fix I propose allows to compile cocci with ocaml 4.00.0 and 4.01.0 (instead of just with ocaml 4.02.0, the current status with OPAM).

I will send my pull request shortly into the OPAM repository.

Quoted 36 lines
Quoted 35 lines

I will dig a little ...

Quoted 31 lines · Francois Berenger

Hi,

Anyone got this?

/home/berenger/.opam/4.01.0/bin/ocamlopt.opt -unsafe -I /home/berenger/.opam/4.01.0/lib/menhirLib -I /home/berenger/.opam/4.01.0/lib/ocaml -I /home/berenger/.opam/4.01.0/lib/pcre -I /home/berenger/src/coccinelle-1.0.0-rc22/bundles/pycaml/ -I commons -I commons/ocamlextra -I ctl -I engine -I extra -I globals -I ocaml -I
parsing_c -I parsing_cocci -I popl09 -I python -cclib -lpycaml_stubs
-cclib -lpython2.7 -ccopt -lpcre -cclib -lpcre_stubs -o spatch.opt str.cmxa unix.cmxa bigarray.cmxa nums.cmxa /home/berenger/.opam/4.01.0/lib/ocaml/dynlink.cmxa /home/berenger/src/coccinelle-1.0.0-rc22/bundles/pycaml//pycaml.cmxa /home/berenger/.opam/4.01.0/lib/pcre/pcre.cmxa commons/commons.cmxa globals/globals.cmxa ctl/ctl.cmxa parsing_cocci/cocci_parser.cmxa parsing_c/parsing_c.cmxa engine/cocciengine.cmxa popl09/popl.cmxa extra/extra.cmxa python/coccipython.cmxa ocaml/cocciocaml.cmxa flag_cocci.cmx cocci.cmx testing.cmx test.cmx main.cmx
File "_none_", line 1:
Error: No implementations provided for the following modules:
Bytes referenced from
/home/berenger/.opam/4.01.0/lib/pcre/pcre.cmxa(Pcre)

Regards,
F.
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

Signature · 2 lines
Regards,
Francois.
Applied
#648 lore raw

Re: [PATCH 1/1] of-unittest: Deletion of an unnecessary check before the function call "of_node_put"

In reply to SF Markus Elfring
Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 2 Dec 2014 13:54:00 +0100

The of_node_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Applied, thanks.

g.

Quoted 21 lines
---
 drivers/of/unittest.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/of/unittest.c +1 -2
index cc0c5ec..06ebe9d 100644
@@ -486,8 +486,7 @@ static void __init of_selftest_changeset(void)
 	/* Make sure node names are constructed correctly */
 	selftest((np = of_find_node_by_path("/testcase-data/changeset/n2/n21")),
 		 "'%s' not added\n", n21->full_name);
-	if (np)
-		of_node_put(np);
+	of_node_put(np);
 
 	mutex_lock(&of_mutex);
 	selftest(!of_changeset_revert(&chgset), "revert failed\n");
Signature · 1 line
2.1.3
#667 lore raw

Re: ALSA: ctxfi: Delete an unnecessary check before kfree()

In reply to Takashi Iwai
Quoted 6 lines · Takashi Iwai

At Wed, 03 Dec 2014 12:38:51 +0100,

Quoted 4 lines · SF Markus Elfring
Quoted 4 lines
Quoted 3 lines

Deletion of an unnecessary check before the function call "kfree" One function call less in get_daio_rsc() after error detection

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

In these cases, the changes aren't so straightforward, and they don't improve the readability.

How do you prefer to improve the affected source code here?

Don't touch then. There are no bugs to fix there.

Takashi, what did you think of this?
https://lkml.org/lkml/2014/12/2/771

Just unnecessary?

#186 lore raw

[Cocci] while compiling coccci 1.0.0-rc22

In reply to Francois Berenger
Quoted 14 lines · Francois Berenger

Hi,

Anyone got this?

/home/berenger/.opam/4.01.0/bin/ocamlopt.opt -unsafe -I /home/berenger/.opam/4.01.0/lib/menhirLib -I /home/berenger/.opam/4.01.0/lib/ocaml -I /home/berenger/.opam/4.01.0/lib/pcre -I /home/berenger/src/coccinelle-1.0.0-rc22/bundles/pycaml/ -I commons -I commons/ocamlextra -I ctl -I engine -I extra -I globals -I ocaml -I parsing_c

(quoted diff) +0 -2
-I parsing_cocci -I popl09 -I python    -cclib -lpycaml_stubs -cclib
-lpython2.7 -ccopt -lpcre -cclib -lpcre_stubs -o spatch.opt str.cmxa unix.cmxa

bigarray.cmxa nums.cmxa /home/berenger/.opam/4.01.0/lib/ocaml/dynlink.cmxa /home/berenger/src/coccinelle-1.0.0-rc22/bundles/pycaml//pycaml.cmxa /home/berenger/.opam/4.01.0/lib/pcre/pcre.cmxa commons/commons.cmxa

Quoted 8 lines

globals/globals.cmxa ctl/ctl.cmxa parsing_cocci/cocci_parser.cmxa parsing_c/parsing_c.cmxa engine/cocciengine.cmxa popl09/popl.cmxa extra/extra.cmxa python/coccipython.cmxa ocaml/cocciocaml.cmxa flag_cocci.cmx cocci.cmx testing.cmx test.cmx main.cmx
File "_none_", line 1:
Error: No implementations provided for the following modules:
Bytes referenced from
/home/berenger/.opam/4.01.0/lib/pcre/pcre.cmxa(Pcre)

My OCaml is not so up to date...

julia

#668 lore raw

Re: ALSA: ctxfi: Delete an unnecessary check before kfree()

In reply to Joe Perches

At Wed, 03 Dec 2014 09:14:48 -0800,

Quoted 11 lines · Joe Perches
Quoted 9 lines · Takashi Iwai

At Wed, 03 Dec 2014 12:38:51 +0100,

Quoted 7 lines · SF Markus Elfring
Quoted 6 lines
Quoted 3 lines

Deletion of an unnecessary check before the function call "kfree" One function call less in get_daio_rsc() after error detection

In these cases, the changes aren't so straightforward, and they don't improve the readability.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

How do you prefer to improve the affected source code here?

Don't touch then. There are no bugs to fix there.

Takashi, what did you think of this?
https://lkml.org/lkml/2014/12/2/771

Just unnecessary?

Well, this one looks more consistent. But honestly speaking, it's rather a matter of taste. So I'm not so much inclined to merge the stuff, too, sorry. If it's proven to reduce the compiled size, etc, I'll happily apply it, though.

FWIW, what wasn't good in the original patch was to break the balance. It removed only the check for dai, and not for dao. One would wonder why there is a check only for one.

It could be two simple kfree() calls instead. But then this won't be an improvement, as it gets one more function call, which is more expensive than a conditional.

Takashi

#669 lore raw

PATCH 1/1 ALSA: ctxfi: Neaten get_daio_rsc

Move the pointer declarations into the blocks that use them. Neaten the kfree calls when the _init functions fail.

Trivially reduces object size (defconfig x86-64)

$ size sound/pci/ctxfi/ctdaio.o.*
   text	   data	    bss	    dec	    hex	filename
   5287	    224	      0	   5511	   1587	sound/pci/ctxfi/ctdaio.o.new
   5319	    224	      0	   5543	   15a7	sound/pci/ctxfi/ctdaio.o.old

---

Quoted 11 lines · Takashi Iwai
Quoted 5 lines · Joe Perches

On Wed, 2014-12-03 at 13:41 +0100, Takashi Iwai wrote:
Takashi, what did you think of this?
https://lkml.org/lkml/2014/12/2/771

Just unnecessary?

Well, this one looks more consistent. But honestly speaking, it's rather a matter of taste. So I'm not so much inclined to merge the stuff, too, sorry. If it's proven to reduce the compiled size, etc, I'll happily apply it, though.

 sound/pci/ctxfi/ctdaio.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)
sound/pci/ctxfi/ctdaio.c +13 -17
index c1c3f88..9b87dd2 100644
@@ -528,8 +528,6 @@ static int get_daio_rsc(struct daio_mgr *mgr,
 			struct daio **rdaio)
 {
 	int err;
-	struct dai *dai = NULL;
-	struct dao *dao = NULL;
 	unsigned long flags;
 
 	*rdaio = NULL;
@@ -544,27 +542,30 @@ static int get_daio_rsc(struct daio_mgr *mgr,
 		return err;
 	}
 
+	err = -ENOMEM;
 	/* Allocate mem for daio resource */
 	if (desc->type <= DAIO_OUT_MAX) {
-		dao = kzalloc(sizeof(*dao), GFP_KERNEL);
-		if (!dao) {
-			err = -ENOMEM;
+		struct dao *dao = kzalloc(sizeof(*dao), GFP_KERNEL);
+		if (!dao)
 			goto error;
-		}
+
 		err = dao_rsc_init(dao, desc, mgr);
-		if (err)
+		if (err) {
+			kfree(dao);
 			goto error;
+		}
 
 		*rdaio = &dao->daio;
 	} else {
-		dai = kzalloc(sizeof(*dai), GFP_KERNEL);
-		if (!dai) {
-			err = -ENOMEM;
+		struct dai *dai = kzalloc(sizeof(*dai), GFP_KERNEL);
+		if (!dai)
 			goto error;
-		}
+
 		err = dai_rsc_init(dai, desc, mgr);
-		if (err)
+		if (err) {
+			kfree(dai);
 			goto error;
+		}
 
 		*rdaio = &dai->daio;
 	}
@@ -575,11 +576,6 @@ static int get_daio_rsc(struct daio_mgr *mgr,
 	return 0;
 
 error:
-	if (dao)
-		kfree(dao);
-	else if (dai)
-		kfree(dai);
-
 	spin_lock_irqsave(&mgr->mgr_lock, flags);
 	daio_mgr_put_rsc(&mgr->mgr, desc->type);
 	spin_unlock_irqrestore(&mgr->mgr_lock, flags);
maintainer Applied
#650 lore raw

Re: [PATCH 1/1] ASoC: fsi: Deletion of unnecessary checks before the function call "clk_disable"

In reply to SF Markus Elfring
Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 2 Dec 2014 14:34:30 +0100

The clk_disable() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

Applied, thanks.

maintainer
#652 lore raw

Re: [PATCH 1/1] ASoC: mop500: Deletion of unnecessary checks before the function call "of_node_put"

In reply to SF Markus Elfring
Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 2 Dec 2014 17:15:11 +0100

The of_node_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This doesn't apply against current code, please check and resend.

maintainer
#653 lore raw

Re: [PATCH 1/1] ASoC: mop500: Deletion of unnecessary checks before the function call "of_node_put"

In reply to SF Markus Elfring
Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 2 Dec 2014 17:15:11 +0100

The of_node_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

Sorry, realised what the dependency was - applied, thanks.

#192 lore raw

Re: [patch] CodingStyle: add some more error handling guidelines

In reply to SF Markus Elfring
Quoted 12 lines · SF Markus Elfring
Quoted 5 lines
Quoted 2 lines

Which name pattern do you find more appropriate in such an use case?

I think Dan wants the label to be descriptive about the tasks needed in the exception handling itself.

I would usually prefer also such a target-oriented labelling for the affected identifiers.
How are the chances to express an expectation in this direction unambiguously for the proposed coding style update?

Quoted 4 lines
Quoted 2 lines

This makes sense as the exception handling steps may be reused for different failures in the code.

I would stress a different reason from my point of view.

I meant as apposed to using a goto-/source-oriented labelling. Please provide your point of view. That way the explanations given in this email exchange might be incorporated in the next round of the proposed update or at least be used as input.

Regards,
Arend

Applied
#670 lore raw

Re: [PATCH] ALSA: ctxfi: Neaten get_daio_rsc

In reply to Joe Perches

At Wed, 03 Dec 2014 09:59:31 -0800,

Quoted 11 lines · Joe Perches

Move the pointer declarations into the blocks that use them. Neaten the kfree calls when the _init functions fail.

Trivially reduces object size (defconfig x86-64)

$ size sound/pci/ctxfi/ctdaio.o.*
   text	   data	    bss	    dec	    hex	filename
   5287	    224	      0	   5511	   1587	sound/pci/ctxfi/ctdaio.o.new
   5319	    224	      0	   5543	   15a7	sound/pci/ctxfi/ctdaio.o.old
Quoted 15 lines

---

Quoted 11 lines · Takashi Iwai
Quoted 5 lines · Joe Perches

On Wed, 2014-12-03 at 13:41 +0100, Takashi Iwai wrote:
Takashi, what did you think of this?
https://lkml.org/lkml/2014/12/2/771

Just unnecessary?

Well, this one looks more consistent. But honestly speaking, it's rather a matter of taste. So I'm not so much inclined to merge the stuff, too, sorry. If it's proven to reduce the compiled size, etc, I'll happily apply it, though.

Thanks, applied now.

Takashi

Quoted 72 lines
 sound/pci/ctxfi/ctdaio.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)
sound/pci/ctxfi/ctdaio.c +13 -17
index c1c3f88..9b87dd2 100644
@@ -528,8 +528,6 @@ static int get_daio_rsc(struct daio_mgr *mgr,
 			struct daio **rdaio)
 {
 	int err;
-	struct dai *dai = NULL;
-	struct dao *dao = NULL;
 	unsigned long flags;
 
 	*rdaio = NULL;
@@ -544,27 +542,30 @@ static int get_daio_rsc(struct daio_mgr *mgr,
 		return err;
 	}
 
+	err = -ENOMEM;
 	/* Allocate mem for daio resource */
 	if (desc->type <= DAIO_OUT_MAX) {
-		dao = kzalloc(sizeof(*dao), GFP_KERNEL);
-		if (!dao) {
-			err = -ENOMEM;
+		struct dao *dao = kzalloc(sizeof(*dao), GFP_KERNEL);
+		if (!dao)
 			goto error;
-		}
+
 		err = dao_rsc_init(dao, desc, mgr);
-		if (err)
+		if (err) {
+			kfree(dao);
 			goto error;
+		}
 
 		*rdaio = &dao->daio;
 	} else {
-		dai = kzalloc(sizeof(*dai), GFP_KERNEL);
-		if (!dai) {
-			err = -ENOMEM;
+		struct dai *dai = kzalloc(sizeof(*dai), GFP_KERNEL);
+		if (!dai)
 			goto error;
-		}
+
 		err = dai_rsc_init(dai, desc, mgr);
-		if (err)
+		if (err) {
+			kfree(dai);
 			goto error;
+		}
 
 		*rdaio = &dai->daio;
 	}
@@ -575,11 +576,6 @@ static int get_daio_rsc(struct daio_mgr *mgr,
 	return 0;
 
 error:
-	if (dao)
-		kfree(dao);
-	else if (dai)
-		kfree(dai);
-
 	spin_lock_irqsave(&mgr->mgr_lock, flags);
 	daio_mgr_put_rsc(&mgr->mgr, desc->type);
 	spin_unlock_irqrestore(&mgr->mgr_lock, flags);
#193 lore raw

Re: [patch] CodingStyle: add some more error handling guidelines

In reply to Arend van Spriel
Quoted 1 line

Please provide your point of view.

I would like to interpret the key word "goto" from the C programming language a bit more here so that a better common understanding can eventually be achieved.

Strong opinions might be floating around for the consistent naming of jump labels. My reasoning works like the following.

This key word could also be interpreted as two items "go" and "to", couldn't it?
How much does this variation stress its meaning in a specific direction?

Some software developers would like to express the reason about an unexpected event at the jump source. But I guess that this approach increases the risk for a popular story like "goto fail;", doesn't it? I would prefer not to specify "go to failure".

So I find that there are more variants possible to stress the jump target. Examples:
* Failure_exit
* out_memory_release
* unregister_item

Regards,
Markus

#480 lore raw

Re: [PATCH 1/1] video: fbdev-LCDC: Deletion of an unnecessary check before the function call "vfree"

In reply to SF Markus Elfring

Hi,

Quoted 18 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 22 Nov 2014 16:51:31 +0100

The vfree() function performs also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/video/fbdev/sh_mobile_lcdcfb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/fbdev/sh_mobile_lcdcfb.c +0 -0
index 2bcc84a..cfde21d 100644

drivers/video/fbdev/sh_mobile_lcdcfb.c sh_mobile_lcdc_channel_fb_cleanup(struct sh_mobile_lcdc_chan *ch) · line 2187

Quoted 9 lines
drivers/video/fbdev/sh_mobile_lcdcfb.c +1 -2
@@ -2181,8 +2181,7 @@ sh_mobile_lcdc_channel_fb_cleanup(struct sh_mobile_lcdc_chan *ch)
 	if (!info || !info->device)
 		return;
 
-	if (ch->sglist)
-		vfree(ch->sglist);
+	vfree(ch->sglist);
 
 	fb_dealloc_cmap(&info->cmap);
 	framebuffer_release(info);

Thanks, I've applied the fbdev patches. Next time, please use git-format-patch and git-send-email to send a proper patch series.

Tomi

#571 lore raw

v2 cover net-PPP: Deletion of a few unnecessary checks

In reply to Sergei Shtylyov

From: Markus Elfring <[email protected]>
Date: Thu, 4 Dec 2014 22:50:28 +0100

Further update suggestions were taken into account before and after a patch was applied from static source code analysis.

Markus Elfring (6):
Replacement of a printk() call by pr_warn() in mppe_rekey() Fix indentation
Deletion of unnecessary checks before the function call "kfree" Less function calls in mppe_alloc() after error detection Delete an unnecessary assignment in mppe_alloc() Delete another unnecessary assignment in mppe_alloc()

 drivers/net/ppp/ppp_mppe.c | 49 +++++++++++++++++++---------------------------
 1 file changed, 20 insertions(+), 29 deletions(-)
Signature · 1 line
2.1.3
#572 lore raw

PATCH v2 1/6 net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

From: Markus Elfring <[email protected]>
Date: Thu, 4 Dec 2014 18:28:52 +0100

The mppe_rekey() function contained a few update candidates.
* Curly brackets were still used around a single function call "printk".
* Unwanted space characters

Let us improve these implementation details according to the current Linux coding style convention.

---
 drivers/net/ppp/ppp_mppe.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ppp/ppp_mppe.c +2 -3
index 911b216..84b7bce 100644
@@ -172,9 +172,8 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
 		setup_sg(sg_in, state->sha1_digest, state->keylen);
 		setup_sg(sg_out, state->session_key, state->keylen);
 		if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
-					     state->keylen) != 0) {
-    		    printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n");
-		}
+					     state->keylen) != 0)
+			pr_warn("mppe_rekey: cipher_encrypt failed\n");
 	} else {
 		memcpy(state->session_key, state->sha1_digest, state->keylen);
 	}
Signature · 1 line
2.1.3
#589 lore raw

PATCH v2 2/6 net-PPP: Fix indentation

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 4 Dec 2014 22:15:20 +0100

The implementations of the functions "mppe_alloc" and "mppe_free" contained unwanted space characters.

Let us improve the indentation according to the Linux coding style convention.

---
 drivers/net/ppp/ppp_mppe.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/net/ppp/ppp_mppe.c +13 -13
index 84b7bce..b80af29 100644
@@ -236,15 +236,15 @@ static void *mppe_alloc(unsigned char *options, int optlen)
 
 	return (void *)state;
 
-	out_free:
-	    if (state->sha1_digest)
+out_free:
+	if (state->sha1_digest)
 		kfree(state->sha1_digest);
-	    if (state->sha1)
+	if (state->sha1)
 		crypto_free_hash(state->sha1);
-	    if (state->arc4)
+	if (state->arc4)
 		crypto_free_blkcipher(state->arc4);
-	    kfree(state);
-	out:
+	kfree(state);
+out:
 	return NULL;
 }
 
@@ -255,13 +255,13 @@ static void mppe_free(void *arg)
 {
 	struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
 	if (state) {
-	    if (state->sha1_digest)
-		kfree(state->sha1_digest);
-	    if (state->sha1)
-		crypto_free_hash(state->sha1);
-	    if (state->arc4)
-		crypto_free_blkcipher(state->arc4);
-	    kfree(state);
+		if (state->sha1_digest)
+			kfree(state->sha1_digest);
+		if (state->sha1)
+			crypto_free_hash(state->sha1);
+		if (state->arc4)
+			crypto_free_blkcipher(state->arc4);
+		kfree(state);
 	}
 }
 
Signature · 1 line
2.1.3
#590 lore raw

PATCH v2 3/6 net-PPP: Deletion of unnecessary checks before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 4 Dec 2014 22:22:23 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/ppp/ppp_mppe.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ppp/ppp_mppe.c +2 -4
index b80af29..94ff216 100644
@@ -237,8 +237,7 @@ static void *mppe_alloc(unsigned char *options, int optlen)
 	return (void *)state;
 
 out_free:
-	if (state->sha1_digest)
-		kfree(state->sha1_digest);
+	kfree(state->sha1_digest);
 	if (state->sha1)
 		crypto_free_hash(state->sha1);
 	if (state->arc4)
@@ -255,8 +254,7 @@ static void mppe_free(void *arg)
 {
 	struct ppp_mppe_state *state = (struct ppp_mppe_state *) arg;
 	if (state) {
-		if (state->sha1_digest)
-			kfree(state->sha1_digest);
+		kfree(state->sha1_digest);
 		if (state->sha1)
 			crypto_free_hash(state->sha1);
 		if (state->arc4)
Signature · 1 line
2.1.3
#591 lore raw

PATCH v2 4/6 net-PPP: Less function calls in mppe_alloc() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 4 Dec 2014 22:30:20 +0100

The functions crypto_free_blkcipher((), crypto_free_hash() and kfree() could be called in some cases by the mppe_alloc() function during error handling even if the passed data structure element contained still a null pointer.

This implementation detail could be improved by adjustments for jump labels.

---
 drivers/net/ppp/ppp_mppe.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
drivers/net/ppp/ppp_mppe.c +9 -11
index 94ff216..c82198f 100644
@@ -196,11 +196,11 @@ static void *mppe_alloc(unsigned char *options, int optlen)
 
 	if (optlen != CILEN_MPPE + sizeof(state->master_key) ||
 	    options[0] != CI_MPPE || options[1] != CILEN_MPPE)
-		goto out;
+		return NULL;
 
 	state = kzalloc(sizeof(*state), GFP_KERNEL);
 	if (state = NULL)
-		goto out;
+		return NULL;
 
 
 	state->arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
@@ -212,16 +212,16 @@ static void *mppe_alloc(unsigned char *options, int optlen)
 	state->sha1 = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC);
 	if (IS_ERR(state->sha1)) {
 		state->sha1 = NULL;
-		goto out_free;
+		goto out_free_blkcipher;
 	}
 
 	digestsize = crypto_hash_digestsize(state->sha1);
 	if (digestsize < MPPE_MAX_KEY_LEN)
-		goto out_free;
+		goto out_free_hash;
 
 	state->sha1_digest = kmalloc(digestsize, GFP_KERNEL);
 	if (!state->sha1_digest)
-		goto out_free;
+		goto out_free_hash;
 
 	/* Save keys. */
 	memcpy(state->master_key, &options[CILEN_MPPE],
@@ -236,14 +236,12 @@ static void *mppe_alloc(unsigned char *options, int optlen)
 
 	return (void *)state;
 
+out_free_hash:
+	crypto_free_hash(state->sha1);
+out_free_blkcipher:
+	crypto_free_blkcipher(state->arc4);
 out_free:
-	kfree(state->sha1_digest);
-	if (state->sha1)
-		crypto_free_hash(state->sha1);
-	if (state->arc4)
-		crypto_free_blkcipher(state->arc4);
 	kfree(state);
-out:
 	return NULL;
 }
 
Signature · 1 line
2.1.3
#592 lore raw

PATCH v2 5/6 net-PPP: Delete an unnecessary assignment in mppe_alloc()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 4 Dec 2014 22:33:34 +0100

The data structure element "arc4" was assigned a null pointer by the mppe_alloc() function if a previous function call "crypto_alloc_blkcipher" failed. This assignment became unnecessary with previous source code adjustments.

Let us delete it from the affected implementation because the element "arc4" will not be accessible outside the function after the detected allocation failure.

---
 drivers/net/ppp/ppp_mppe.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ppp/ppp_mppe.c +1 -3
index c82198f..b7db4b1 100644
@@ -204,10 +204,8 @@ static void *mppe_alloc(unsigned char *options, int optlen)
 
 
 	state->arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
-	if (IS_ERR(state->arc4)) {
-		state->arc4 = NULL;
+	if (IS_ERR(state->arc4))
 		goto out_free;
-	}
 
 	state->sha1 = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC);
 	if (IS_ERR(state->sha1)) {
Signature · 1 line
2.1.3
#597 lore raw

PATCH v2 6/6 net-PPP: Delete another unnecessary assignment in mppe_alloc()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 4 Dec 2014 22:42:30 +0100

The data structure element "sha1" was assigned a null pointer by the mppe_alloc() after a function call "crypto_alloc_hash" failed. It was determined that this element was not accessed by the implementation of the crypto_free_blkcipher() function.

Let us delete it from the affected implementation because the element "sha1" will not be accessible outside the function after the detected allocation failure.

---
 drivers/net/ppp/ppp_mppe.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ppp/ppp_mppe.c +1 -3
index b7db4b1..32cb054 100644
@@ -208,10 +208,8 @@ static void *mppe_alloc(unsigned char *options, int optlen)
 		goto out_free;
 
 	state->sha1 = crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC);
-	if (IS_ERR(state->sha1)) {
-		state->sha1 = NULL;
+	if (IS_ERR(state->sha1))
 		goto out_free_blkcipher;
-	}
 
 	digestsize = crypto_hash_digestsize(state->sha1);
 	if (digestsize < MPPE_MAX_KEY_LEN)
Signature · 1 line
2.1.3
#573 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

In reply to SF Markus Elfring
Quoted 6 lines · SF Markus Elfring

The mppe_rekey() function contained a few update candidates.
* Curly brackets were still used around a single function call "printk".
* Unwanted space characters

Let us improve these implementation details according to the current Linux coding style convention.

trivia:

drivers/net/ppp/ppp_mppe.c

Quoted 1 line
drivers/net/ppp/ppp_mppe.c +0 -0

[]

drivers/net/ppp/ppp_mppe.c static void mppe_rekey(struct ppp_mppe_state * state, int initial_key) · line 176

Quoted 9 lines
drivers/net/ppp/ppp_mppe.c +2 -3
@@ -172,9 +172,8 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
 		setup_sg(sg_in, state->sha1_digest, state->keylen);
 		setup_sg(sg_out, state->session_key, state->keylen);
 		if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
-					     state->keylen) != 0) {
-    		    printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n");
-		}
+					     state->keylen) != 0)
+			pr_warn("mppe_rekey: cipher_encrypt failed\n");

It's generally nicer to replace embedded function names with "%s: ", __func__

			pr_warn("%s: cipher_encrypt failed\n", __func__);
#574 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

Quoted 15 lines

drivers/net/ppp/ppp_mppe.c

Quoted 1 line
drivers/net/ppp/ppp_mppe.c +0 -0

[]

drivers/net/ppp/ppp_mppe.c static void mppe_rekey(struct ppp_mppe_state * state, int initial_key) · line 176

Quoted 9 lines
drivers/net/ppp/ppp_mppe.c +2 -3
@@ -172,9 +172,8 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
 		setup_sg(sg_in, state->sha1_digest, state->keylen);
 		setup_sg(sg_out, state->session_key, state->keylen);
 		if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
-					     state->keylen) != 0) {
-    		    printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n");
-		}
+					     state->keylen) != 0)
+			pr_warn("mppe_rekey: cipher_encrypt failed\n");

It's generally nicer to replace embedded function names with "%s: ", __func__

Quoted 1 line
			pr_warn("%s: cipher_encrypt failed\n", __func__);

Do you want that I send a third patch series for the fine-tuning of these parameters?

Regards,
Martkus

#575 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

Quoted 15 lines · SF Markus Elfring
Quoted 15 lines

drivers/net/ppp/ppp_mppe.c

Quoted 1 line
drivers/net/ppp/ppp_mppe.c +0 -0

[]

drivers/net/ppp/ppp_mppe.c static void mppe_rekey(struct ppp_mppe_state * state, int initial_key) · line 176

Quoted 9 lines
drivers/net/ppp/ppp_mppe.c +2 -3
@@ -172,9 +172,8 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
 		setup_sg(sg_in, state->sha1_digest, state->keylen);
 		setup_sg(sg_out, state->session_key, state->keylen);
 		if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
-					     state->keylen) != 0) {
-    		    printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n");
-		}
+					     state->keylen) != 0)
+			pr_warn("mppe_rekey: cipher_encrypt failed\n");

It's generally nicer to replace embedded function names with "%s: ", __func__

Quoted 3 lines
Quoted 1 line
			pr_warn("%s: cipher_encrypt failed\n", __func__);

Do you want that I send a third patch series for the fine-tuning of these parameters?

If you want.

I just wanted you to be aware of it for future patches.

#576 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

Quoted 16 lines · Joe Perches
Quoted 15 lines · SF Markus Elfring
Quoted 15 lines

drivers/net/ppp/ppp_mppe.c

Quoted 1 line
drivers/net/ppp/ppp_mppe.c +0 -0

[]

drivers/net/ppp/ppp_mppe.c static void mppe_rekey(struct ppp_mppe_state * state, int initial_key) · line 176

Quoted 9 lines
drivers/net/ppp/ppp_mppe.c +2 -3
@@ -172,9 +172,8 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
 		setup_sg(sg_in, state->sha1_digest, state->keylen);
 		setup_sg(sg_out, state->session_key, state->keylen);
 		if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
-					     state->keylen) != 0) {
-    		    printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n");
-		}
+					     state->keylen) != 0)
+			pr_warn("mppe_rekey: cipher_encrypt failed\n");

It's generally nicer to replace embedded function names with "%s: ", __func__

Quoted 7 lines
Quoted 3 lines
Quoted 1 line
			pr_warn("%s: cipher_encrypt failed\n", __func__);

Do you want that I send a third patch series for the fine-tuning of these parameters?

If you want.

I just wanted you to be aware of it for future patches.

Markus, are you sure that you cannot use netdev_warn in this case?

julia

#579 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

In reply to Joe Perches
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

It's generally nicer to replace embedded function names with "%s: ", __func__

			pr_warn("%s: cipher_encrypt failed\n", __func__);

Do you want that I send a third patch series for the fine-tuning of these parameters?

If you want.

Would "a committer" fix such a small source code adjustment also without a resend of a patch series?

Quoted 1 line

I just wanted you to be aware of it for future patches.

Thanks for your tip.

Does it make sense to express such implementation details in the Linux coding style documentation more explicitly (besides the fact that this update suggestion was also triggered by a warning from the script "checkpatch.pl").

Regards,
Markus

#583 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

In reply to Joe Perches
Quoted 25 lines · Joe Perches
Quoted 6 lines · SF Markus Elfring

The mppe_rekey() function contained a few update candidates.
* Curly brackets were still used around a single function call "printk".
* Unwanted space characters

Let us improve these implementation details according to the current Linux coding style convention.

trivia:

drivers/net/ppp/ppp_mppe.c

Quoted 1 line
drivers/net/ppp/ppp_mppe.c +0 -0

[]

drivers/net/ppp/ppp_mppe.c static void mppe_rekey(struct ppp_mppe_state * state, int initial_key) · line 176

Quoted 9 lines
drivers/net/ppp/ppp_mppe.c +2 -3
@@ -172,9 +172,8 @@ static void mppe_rekey(struct ppp_mppe_state * state, int initial_key)
 		setup_sg(sg_in, state->sha1_digest, state->keylen);
 		setup_sg(sg_out, state->session_key, state->keylen);
 		if (crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
-					     state->keylen) != 0) {
-    		    printk(KERN_WARNING "mppe_rekey: cipher_encrypt failed\n");
-		}
+					     state->keylen) != 0)
+			pr_warn("mppe_rekey: cipher_encrypt failed\n");

It's generally nicer to replace embedded function names with "%s: ", __func__

Quoted 1 line
			pr_warn("%s: cipher_encrypt failed\n", __func__);

Doing so may potentially allow some strings to be shared, thus saving a little space. Perhaps not in this case, though.

julia

#584 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

Quoted 8 lines · Julia Lawall
Quoted 4 lines · Joe Perches

It's generally nicer to replace embedded function names with "%s: ", __func__

			pr_warn("%s: cipher_encrypt failed\n", __func__);

Doing so may potentially allow some strings to be shared, thus saving a little space. Perhaps not in this case, though.

It's not necessarily a code size savings in any case.

It can be, but the real benefits are stylistic consistency and lack of mismatch between function name and message.

If the code is refactored or copy/pasted into another function, a moderately common defect is not modifying the embedded function name in the message.

There may be some smallish savings if ever these __func__ uses were converted to use %pf via some internal standardized mechanism.

A negative to that approach is inlined functions would take the function name of the parent not keep the inlined function name.

#580 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

In reply to SF Markus Elfring
Quoted 11 lines · SF Markus Elfring
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

It's generally nicer to replace embedded function names with "%s: ", __func__

			pr_warn("%s: cipher_encrypt failed\n", __func__);

Do you want that I send a third patch series for the fine-tuning of these parameters?

If you want.

Would "a committer" fix such a small source code adjustment also without a resend of a patch series?

Depends on the committer. Some might, most wouldn't.

drivers/net/ppp doesn't have a specific maintainer.

The networking maintainer generally asks for resends of patches that don't suit his taste, but lots of non-perfect patches still get applied there.

It's a process, and it's not immediate. Wait to see if these get applied as-is. If the embedded function name use, which is trivial, bothers you, send another patch later on that changes it.

Quoted 3 lines

Does it make sense to express such implementation details in the Linux coding style documentation more explicitly (besides the fact that this update suggestion was also triggered by a warning from the script "checkpatch.pl").

Probably not.

Overly formalized coding style rules are perhaps more of a barrier to entry than most want.

#577 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

In reply to Julia Lawall
Quoted 1 line

Markus, are you sure that you cannot use netdev_warn in this case?

No. - I did not become familiar enough with the software infrastructure around the mppe_rekey() function.

I do not see so far how I could determine a pointer for the first parameter there. The data structure "ppp_mppe_state" (which is referenced by the input variable "state") does not contain corresponding context information, does it?

Regards,
Markus

#578 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

Quoted 8 lines · SF Markus Elfring
Quoted 1 line

Markus, are you sure that you cannot use netdev_warn in this case?

No. - I did not become familiar enough with the software infrastructure around the mppe_rekey() function.

I do not see so far how I could determine a pointer for the first parameter there. The data structure "ppp_mppe_state" (which is referenced by the input variable "state") does not contain corresponding context information, does it?

Indeed, I also don't see anything promising.

julia

#581 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

In reply to Joe Perches
Quoted 2 lines

It's a process, and it's not immediate. Wait to see if these get applied as-is.

Thanks for your constructive feedback.

Quoted 2 lines

If the embedded function name use, which is trivial, bothers you, send another patch later on that changes it.

Not really at the moment ...

I guess that I would prefer a general development of another semantic patch approach according to your request with the topic "Finding embedded function names?" a moment ago.
https://systeme.lip6.fr/pipermail/cocci/2014-December/001517.html
http://article.gmane.org/gmane.comp.version-control.coccinelle/4399

Regards,
Markus

#593 lore raw

Re: [PATCH v2 5/6] net-PPP: Delete an unnecessary assignment in mppe_alloc()

In reply to SF Markus Elfring
Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 4 Dec 2014 22:33:34 +0100

The data structure element "arc4" was assigned a null pointer by the mppe_alloc() function if a previous function call "crypto_alloc_blkcipher" failed.

No. crypto_alloc_blkcipher() returns error pointers and not NULL.

This patch creates a bug.

regards,
dan carpenter

#598 lore raw

Re: [PATCH v2 6/6] net-PPP: Delete another unnecessary assignment in mppe_alloc()

In reply to SF Markus Elfring
Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 4 Dec 2014 22:42:30 +0100

The data structure element "sha1" was assigned a null pointer by the mppe_alloc() after a function call "crypto_alloc_hash" failed.

This patch is also buggy.

regards,
dan carpenter

#594 lore raw

Re: [PATCH v2 5/6] net-PPP: Delete an unnecessary assignment in mppe_alloc()

In reply to Dan Carpenter
Quoted 5 lines
Quoted 3 lines

The data structure element "arc4" was assigned a null pointer by the mppe_alloc() function if a previous function call "crypto_alloc_blkcipher" failed.

crypto_alloc_blkcipher() returns error pointers and not NULL.

That is true.

Quoted 1 line

This patch creates a bug.

Please explain: How?

Did you notice that the data structure element "arc4" was reset to a null pointer if a failure was detected for the function call "crypto_alloc_blkcipher"?

Do you find this specific assignment still necessary for exception handling in the implementation of mppe_alloc() function?

Regards,
Markus

#599 lore raw

Re: [PATCH v2 6/6] net-PPP: Delete another unnecessary assignment in mppe_alloc()

In reply to Dan Carpenter
Quoted 4 lines
Quoted 2 lines

The data structure element "sha1" was assigned a null pointer by the mppe_alloc() after a function call "crypto_alloc_hash" failed.

This patch is also buggy.

Do you really want to keep a variable reset after a detected failure?

Regards,
Markus

#595 lore raw

Re: [PATCH v2 5/6] net-PPP: Delete an unnecessary assignment in mppe_alloc()

In reply to SF Markus Elfring
Quoted 8 lines · SF Markus Elfring
Quoted 5 lines
Quoted 3 lines

The data structure element "arc4" was assigned a null pointer by the mppe_alloc() function if a previous function call "crypto_alloc_blkcipher" failed.

crypto_alloc_blkcipher() returns error pointers and not NULL.

That is true.

Oh. In that case, I misunderstood what you wrote. Looking at it now, this patch is actually ok.

regards,
dan carpenter

#600 lore raw

Re: [PATCH v2 6/6] net-PPP: Delete another unnecessary assignment in mppe_alloc()

In reply to Dan Carpenter
Quoted 8 lines · Dan Carpenter
Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 4 Dec 2014 22:42:30 +0100

The data structure element "sha1" was assigned a null pointer by the mppe_alloc() after a function call "crypto_alloc_hash" failed.

This patch is also buggy.

Actually it's ok. I was just confused by the changelog.

Sorry about that, Markus.

regards,
dan carpenter

#596 lore raw

Re: [PATCH v2 5/6] net-PPP: Delete an unnecessary assignment in mppe_alloc()

In reply to Dan Carpenter
Quoted 3 lines
Quoted 1 line

That is true.

In that case, I misunderstood what you wrote.

I find it a bit interesting how this misunderstanding could happen here somehow.

Quoted 1 line

Looking at it now, this patch is actually ok.

Does that mean that you would like to add any tag like "Acked-by" or "Reviewed-by" to any of the proposed six update steps?

Regards,
Markus

#582 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

In reply to Joe Perches

... ciao:

: on "12-4-2014" "Joe Perches" writ:
: > Does it make sense to express such implementation details in the Linux : > coding style documentation more explicitly (besides the fact that this : > update suggestion was also triggered by a warning from the script : > "checkpatch.pl".
:
: Probably not.
:
: Overly formalized coding style rules are perhaps
: more of a barrier to entry than most want.

funny you should mention that. as nothing more than a casual observer,
i'm noticing a "TIRED" sensation reading this thread. i have "0" confidence a "SERIOUS" participant's enthusiasm would remain untested.

however, the "checkpatch.pl" warning suggests an assumed 'custom'. i
can't tell if this a 'serious' issue, or "pickin' fly shit out of pepper".

but from my reading of it, the "CODE" , and the "logic" driving it, is
not the problem.

season's best ...

Signature · 2 lines
... it's not what you see ,
    but in stead , notice ...
maintainer Applied
#530 lore raw

Re: [PATCH 1/1] net: cassini: Deletion of an unnecessary check before the function call "vfree"

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Sat, 29 Nov 2014 15:05:33 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Sat, 29 Nov 2014 14:34:59 +0100

The vfree() function performs also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Applied.

maintainer Applied
#536 lore raw

Re: [PATCH 1/1] net-ipvlan: Deletion of an unnecessary check before the function call "free_percpu"

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Sat, 29 Nov 2014 16:30:27 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Sat, 29 Nov 2014 16:23:20 +0100

The free_percpu() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Applied.

maintainer Applied
#564 lore raw

Re: [PATCH 1/1] net-PA Semi: Deletion of unnecessary checks before the function call "pci_dev_put"

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Sat, 29 Nov 2014 19:00:17 +0100

Quoted 10 lines

From: Markus Elfring <[email protected]>
Date: Sat, 29 Nov 2014 18:55:40 +0100

The pci_dev_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Applied.

#585 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

In reply to Joe Perches
Quoted 3 lines

A negative to that approach is inlined functions would take the function name of the parent not keep the inlined function name.

I tried the following:

#include <stdio.h>

inline int foo() {
printf("%s %x\n",__func__,0x12345);
}

int main () {
foo();
}

The assembly code generated for main is:

0000000000400470 <main>:

  400470:       b9 45 23 01 00          mov    $0x12345,%ecx
  400475:       ba 4b 06 40 00          mov    $0x40064b,%edx
  40047a:       be 44 06 40 00          mov    $0x400644,%esi
  40047f:       bf 01 00 00 00          mov    $0x1,%edi
  400484:       31 c0                   xor    %eax,%eax
  400486:       e9 d5 ff ff ff          jmpq   400460 <__printf_chk@plt>

That is, the call to foo seems tom be inlined.

But the output is:

foo 12345

So it seems that __func__ is determined before inlining.

julia

#586 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

Quoted 26 lines · Julia Lawall
Quoted 3 lines

A negative to that approach is inlined functions would take the function name of the parent not keep the inlined function name.

I tried the following:

#include <stdio.h>

inline int foo() {
printf("%s %x\n",__func__,0x12345);
}

int main () {
foo();
}

The assembly code generated for main is:

0000000000400470 <main>:

  400470:       b9 45 23 01 00          mov    $0x12345,%ecx
  400475:       ba 4b 06 40 00          mov    $0x40064b,%edx
  40047a:       be 44 06 40 00          mov    $0x400644,%esi
  40047f:       bf 01 00 00 00          mov    $0x1,%edi
  400484:       31 c0                   xor    %eax,%eax
  400486:       e9 d5 ff ff ff          jmpq   400460 <__printf_chk@plt>
Quoted 7 lines

That is, the call to foo seems tom be inlined.

But the output is:

foo 12345

So it seems that __func__ is determined before inlining.

True, and that's what I intended to describe.

If you did that with a kernel module and replaced "%s, __func__" with "%pf, __builtin_return_address(0)" when built with kallsyms you should get:

"modname 12345" when most would expect "foo 12345"

when built without kallsyms, that output should be "<address> 12345"

but the object code should be smaller.

#587 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

Quoted 41 lines · Joe Perches
Quoted 26 lines · Julia Lawall
Quoted 3 lines

A negative to that approach is inlined functions would take the function name of the parent not keep the inlined function name.

I tried the following:

#include <stdio.h>

inline int foo() {
printf("%s %x\n",__func__,0x12345);
}

int main () {
foo();
}

The assembly code generated for main is:

0000000000400470 <main>:

  400470:       b9 45 23 01 00          mov    $0x12345,%ecx
  400475:       ba 4b 06 40 00          mov    $0x40064b,%edx
  40047a:       be 44 06 40 00          mov    $0x400644,%esi
  40047f:       bf 01 00 00 00          mov    $0x1,%edi
  400484:       31 c0                   xor    %eax,%eax
  400486:       e9 d5 ff ff ff          jmpq   400460 <__printf_chk@plt>
Quoted 7 lines

That is, the call to foo seems tom be inlined.

But the output is:

foo 12345

So it seems that __func__ is determined before inlining.

True, and that's what I intended to describe.

If you did that with a kernel module and replaced "%s, __func__" with "%pf, __builtin_return_address(0)" when built with kallsyms you should get:

Quoted 6 lines

"modname 12345" when most would expect "foo 12345"

when built without kallsyms, that output should be "<address> 12345"

but the object code should be smaller.

OK. But the semantic patch is only using __func__ and only in cases where the string wanted is similar to the name of the current function, so I think it should be OK?

julia

#588 lore raw

Re: [PATCH v2 1/6] net-PPP: Replacement of a printk() call by pr_warn() in mppe_rekey()

Quoted 3 lines · Julia Lawall

the semantic patch is only using __func__ and only in cases where the string wanted is similar to the name of the current function, so I think it should be OK?

Yes, it'd be a good thing.

reviewer Applied
#633 lore raw

Re: [PATCH 1/1] thermal: int3403: Delete a check before thermal_zone_device_unregister()

In reply to SF Markus Elfring
Quoted 10 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 1 Dec 2014 05:45:42 +0100

The thermal_zone_device_unregister() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

applied.

thanks,
rui

Quoted 18 lines
---
 drivers/thermal/int340x_thermal/int3403_thermal.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/thermal/int340x_thermal/int3403_thermal.c +1 -2
index 6e9fb62..790b8f6 100644
@@ -293,8 +293,7 @@ static int int3403_sensor_add(struct int3403_priv *priv)
 	return 0;
 
  err_free_obj:
-	if (obj->tzone)
-		thermal_zone_device_unregister(obj->tzone);
+	thermal_zone_device_unregister(obj->tzone);
 	return result;
 }
 
Applied
#635 lore raw

Re: [PATCH 1/1] DMA: Delete a check before free_percpu()

In reply to SF Markus Elfring
Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 1 Dec 2014 06:06:57 +0100

The free_percpu() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Please make sure you use the right subsystem name

Applied, thanks

Signature · 1 line
~Vinod
maintainer
#601 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Thu, 04 Dec 2014 23:03:30 +0100

Quoted 5 lines

From: Markus Elfring <[email protected]>
Date: Thu, 4 Dec 2014 22:50:28 +0100

Further update suggestions were taken into account before and after a patch was applied from static source code analysis.

Generally speaking, it is advisable to not leave error pointers in data structures, even if they are about to be free'd up in an error path anyways.

Therefore I do not like some of the patches in this series.

Sorry.

maintainer Applied
#400 lore raw

Re: [PATCH 1/1] PCI: hotplug: Deletion of an unnecessary check before the function call "pci_dev_put"

In reply to SF Markus Elfring
Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 17:42:23 +0100

The pci_dev_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Applied to next-pci/misc for v3.19, thanks. This branch will be rebased when v3.19-rc1 is released.

Bjorn

Quoted 21 lines
---
 drivers/pci/hotplug/cpci_hotplug_core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/pci/hotplug/cpci_hotplug_core.c +1 -2
index e09cf78..82c969b 100644
@@ -211,8 +211,7 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
 
 	kfree(slot->hotplug_slot->info);
 	kfree(slot->hotplug_slot);
-	if (slot->dev)
-		pci_dev_put(slot->dev);
+	pci_dev_put(slot->dev);
 	kfree(slot);
 }
 
Signature · 1 line
2.1.3
#602 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

In reply to David Miller
Quoted 4 lines

Generally speaking, it is advisable to not leave error pointers in data structures, even if they are about to be free'd up in an error path anyways.

Therefore I do not like some of the patches in this series.

Can you give any more concrete feedback here?

Regards,
Markus

maintainer
#603 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

From: SF Markus Elfring <[email protected]>
Date: Fri, 12 Dec 2014 08:01:54 +0100

Quoted 6 lines
Quoted 4 lines

Generally speaking, it is advisable to not leave error pointers in data structures, even if they are about to be free'd up in an error path anyways.

Therefore I do not like some of the patches in this series.

Can you give any more concrete feedback here?

I gave you very concrete feedback, I said exactly that I don't want error pointers left in data structure members.

I cannot describe my requirements any more precisely than that.

#604 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

Quoted 2 lines

I gave you very concrete feedback, I said exactly that I don't want error pointers left in data structure members.

I find that your critique affects the proposed update steps four to six, doesn't it?
Are the other steps acceptable in principle?

Quoted 1 line

I cannot describe my requirements any more precisely than that.

I hope that a bit more constructive suggestions will be contributed by involved
software developers around the affected source code. Now it seems that a small code clean-up becomes a more challenging development task.

How do you prefer to redesign corresponding data structures eventually?

Regards,
Markus

maintainer
#605 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

You are asking me to invest a lot of time for a very trivial set of changes.

Why don't you just integrate the feedback you were given and resubmit your patch series, just like any other developer would?

#606 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

Quoted 3 lines

You are asking me to invest a lot of time for a very trivial set of changes.

I find the proposed six update steps also trivial so far.

Quoted 2 lines

Why don't you just integrate the feedback you were given and resubmit your patch series, just like any other developer would?

I find the requested redesign and reorganisation of involved data structures not so easy and therefore more challenging at the moment.
Where should "the error pointers" be stored instead?
Is such a software improvement even a kind of add-on to my patch series?

Regards,
Markus

maintainer
#607 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

From: SF Markus Elfring <[email protected]>
Date: Fri, 12 Dec 2014 17:56:36 +0100

Quoted 1 line

Where should "the error pointers" be stored instead?

A local variable, before you assign it into the datastructure.

#608 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

Quoted 2 lines
Quoted 1 line

Where should "the error pointers" be stored instead?

A local variable, before you assign it into the datastructure.

Will it be acceptable for you that anyone (or even me) will introduce such a change with a seventh (and eventually eighth) update step here? Do you want any other sequence for source code preparation of the requested software improvement?

Regards,
Markus

#620 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

In reply to SF Markus Elfring
Quoted 4 lines

I hope that a bit more constructive suggestions will be contributed by involved
software developers around the affected source code. Now it seems that a small code clean-up becomes a more challenging development task.

This is often the case. Doing something half way is not useful.

julia

#609 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

In reply to SF Markus Elfring
Quoted 4 lines · SF Markus Elfring

Will it be acceptable for you that anyone (or even me) will introduce such a change with a seventh (and eventually eighth) update step here? Do you want any other sequence for source code preparation of the requested software improvement?

The thing is : We are in the merge window, tracking bugs added in latest dev cycle.

Having to deal with patches like yours is adding pressure on the maintainer (and other developers) at the wrong time.

maintainer
#611 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Fri, 12 Dec 2014 18:22:48 +0100

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

Where should "the error pointers" be stored instead?

A local variable, before you assign it into the datastructure.

Will it be acceptable for you that anyone (or even me) will introduce such a change with a seventh (and eventually eighth) update step here? Do you want any other sequence for source code preparation of the requested software improvement?

I'd like to honestly ask why you are being so difficult?

Everyone gets their code reviewed, everyone has to modify their changes to adhere to the subsystem maintainer's wishes. You are not being treated specially, and quite frankly nobody is asking anything unreasonable of you.

maintainer Applied
#459 lore raw

Re: [PATCH 1/1] IDE: Deletion of an unnecessary check before the function call "module_put"

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 20:26:29 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 20:22:32 +0100

The module_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Applied.

#610 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

In reply to Eric Dumazet
Quoted 1 line

We are in the merge window, tracking bugs added in latest dev cycle.

I am also curious on the software evolution about how many improvements will arrive in the next Linux versions.

Quoted 2 lines

Having to deal with patches like yours is adding pressure on the maintainer (and other developers) at the wrong time.

You can relax a bit eventually. More merge windows will follow, won't they?

It will be nice if a bunch of recent code clean-ups which were also triggered
by static source code analysis will be integrated into Linux 3.19 already. More update suggestions will be considered later again as usual.

Regards,
Markus

#612 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

In reply to David Miller
Quoted 1 line

I'd like to honestly ask why you are being so difficult?

There are several factors which contribute to your perception of difficulty here.

1. I try to extract from every feedback the information about the amount of acceptance or rejection for a specific update suggestion. A terse feedback (like yours for this issue) makes it occasionally
harder to see the next useful steps. So another constructive discussion is evolving around the clarification of some implementation details.

2. I prefer also different communication styles at some points.

3. I reached a point where the desired software updates were not immediately obvious for me while other contributors might have achieved a better understanding for the affected issues already.

4. I am on the way at the moment to get my Linux software development system running again.

https://forums.opensuse.org/showthread.php/503327-System-startup-does-not-continue-after-hard-disk-detection

Quoted 2 lines

Everyone gets their code reviewed, everyone has to modify their changes to adhere to the subsystem maintainer's wishes.

That is fine as usual.

Quoted 2 lines

You are not being treated specially, and quite frankly nobody is asking anything unreasonable of you.

That is also true as the software development process will be continued.

Regards,
Markus

#621 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

... ciao:

: on "12-12-2014" "SF Markus Elfring" writ:

:> I don't want error pointers left in data structure members. :> I cannot describe my requirements any more precisely than that.

to me, "error pointers 'left' in data structure members", seems a
little cavalier. objection to their existence tends to suggest that not a function of the design, or logic involved.

: I hope that a bit more constructive suggestions will be contributed by : involved software developers around the affected source code.

so, this 'error pointers' issue fails to meet your 'constructive'
suggestion threshold. to my mind, what i choose to ignore, imposes a dangerous minimum. what are you willing to ignore.

: Now it seems that a small code clean-up becomes a more challenging : development task.

first, if you've EVER dealt with imperfect code, that should be a
given. but more importantly to me, i never knew "code clean-up", wasn't "REQUIRED" ...

Signature · 2 lines
... it's not what you see ,
    but in stead , notice ...
#613 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

In reply to David Miller
Quoted 3 lines
Quoted 1 line

Where should "the error pointers" be stored instead?

A local variable, before you assign it into the datastructure.

I have looked at the affected software infrastructure once more. Now I find still that your data reorgansisation wish can not be resolved in a simple way.

I imagine that your update suggestion would mean that the corresponding pointers will be passed around by function parameters instead, wouldn't it?

Two pointers were stored as the members "arc4" and "sha1" of the data structure "ppp_mppe_state" for a specific reason. A pointer to this structure is passed to the ppp_register_compressor() function.
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/include/linux/ppp-comp.h?id`7ca46e97a1b6594b29647d98a32d545c24bdff#n32

The data structure "compressor" manages some function pointers. I assume that this interface should not be changed at the moment, should it?

Are further ideas needed here?

Regards,
Markus

maintainer
#614 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

From: SF Markus Elfring <[email protected]>
Date: Thu, 18 Dec 2014 18:23:08 +0100

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Where should "the error pointers" be stored instead?

A local variable, before you assign it into the datastructure.

I have looked at the affected software infrastructure once more. Now I find still that your data reorgansisation wish can not be resolved in a simple way.

I'm saying to leave the code alone.

If it goes:

	var = foo_that_returns_ptr_err()
	if (IS_ERR(var))
		return PTR_ERR(var);

	p->bar = var;

or whatever, simply keep it that way!

I'm not engaging in this conversation any further, you have already consumed way too much of my limited time on this incredibly trivial matter.

#615 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

Quoted 4 lines
Quoted 2 lines

Now I find still that your data reorgansisation wish can not be resolved in a simple way.

I'm saying to leave the code alone.

It seems that there might be a misunderstanding between us.

Quoted 9 lines

If it goes:

	var = foo_that_returns_ptr_err()
	if (IS_ERR(var))
		return PTR_ERR(var);

	p->bar = var;

or whatever, simply keep it that way!

A simple return was not used by the mppe_alloc() function so far because a bit of memory clean-up will also be useful after error detection, won't it?

Quoted 2 lines

I'm not engaging in this conversation any further, you have already consumed way too much of my limited time on this incredibly trivial matter.

It can occasionally happen that a safe clarification of specific implementation details will need more efforts than you would like to invest at the moment.

Regards,
Markus

#616 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

In reply to David Miller
Quoted 1 line

I'm saying to leave the code alone.

Do I need to try another interpretation out for your feedback?

Quoted 9 lines

If it goes:

	var = foo_that_returns_ptr_err()
	if (IS_ERR(var))
		return PTR_ERR(var);

	p->bar = var;

or whatever, simply keep it that way!

Do you want to express here that a data structure member should only be set after a previous function call succeeded?

Quoted 3 lines

I'm not engaging in this conversation any further, you have already consumed way too much of my limited time on this incredibly trivial matter.

I hope that you will find a bit time and patience again to clarify affected implementation details in a safer and unambiguous way.

Regards,
Markus

#617 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

Hi Markus,

Quoted 11 lines · SF Markus Elfring
Quoted 1 line

I'm saying to leave the code alone.

Do I need to try another interpretation out for your feedback?

Quoted 6 lines

If it goes:

	var = foo_that_returns_ptr_err()
	if (IS_ERR(var))
		return PTR_ERR(var);
Quoted 7 lines
Quoted 3 lines
	p->bar = var;

or whatever, simply keep it that way!

Do you want to express here that a data structure member should only be set after a previous function call succeeded?

I think what David said was pretty clear: If you see code like the above there is no need to refactor it. That does not mean that this is the _preferred_ way of error handling. Its just good enough to be left alone.

Regards,
Lino

#618 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

Quoted 2 lines

I think what David said was pretty clear: If you see code like the above there is no need to refactor it.

I can understand this view in principle.

Quoted 1 line

That does not mean that this is the _preferred_ way of error handling.

Can your feedback help in the clarification of suggestions around my update steps one to six for this Linux software module?

Regards,
Markus

maintainer
#619 lore raw

Re: [PATCH v2 0/6] net-PPP: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Sat, 20 Dec 2014 15:45:32 +0100

Quoted 3 lines

I hope that you will find a bit time and patience again to clarify affected implementation details in a safer and unambiguous way.

Sorry, another developer will have to hold your hand, as I said I already invested too much time into this.

#675 lore raw

cover fs/9p: Deletion of some unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Dec 2014 14:50:08 +0100

Further update suggestions were taken into account after a patch was applied from static source code analysis.

Markus Elfring (8):
Deletion of unnecessary checks before the function call "p9_client_clunk" One function call less in v9fs_create() after error detection One function call less in v9fs_vfs_atomic_open() after error detection One function call less in v9fs_fid_xattr_get() after error detection One function call less in v9fs_vfs_atomic_open_dotl() after error detection Less function calls in v9fs_vfs_mkdir_dotl() after error detection One function call less in v9fs_vfs_symlink_dotl() after error detection Less function calls in v9fs_vfs_mknod_dotl() after error detection

 fs/9p/vfs_dir.c        |  3 +--
 fs/9p/vfs_inode.c      | 25 ++++++++++--------------
 fs/9p/vfs_inode_dotl.c | 52 +++++++++++++++++++++-----------------------------
 fs/9p/xattr.c          |  6 ++----
 4 files changed, 35 insertions(+), 51 deletions(-)
Signature · 1 line
2.2.1
#676 lore raw

PATCH 1/8 fs/9p: Deletion of unnecessary checks before the function call "p9_client_clunk"

From: Markus Elfring <[email protected]>
Date: Sat, 27 Dec 2014 09:34:39 +0100

The p9_client_clunk() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 fs/9p/vfs_dir.c        |  3 +--
 fs/9p/vfs_inode.c      | 12 ++++--------
 fs/9p/vfs_inode_dotl.c | 15 +++++----------
 fs/9p/xattr.c          |  3 +--
 4 files changed, 11 insertions(+), 22 deletions(-)
fs/9p/vfs_dir.c +1 -2
index 4f11510..9c13866 100644
@@ -229,8 +229,7 @@ int v9fs_dir_release(struct inode *inode, struct file *filp)
 	fid = filp->private_data;
 	p9_debug(P9_DEBUG_VFS, "inode: %p filp: %p fid: %d\n",
 		 inode, filp, fid ? fid->fid : -1);
-	if (fid)
-		p9_client_clunk(fid);
+	p9_client_clunk(fid);
 	return 0;
 }
 
fs/9p/vfs_inode.c +4 -8
index 9ee5343..a787d4c 100644
@@ -700,11 +700,9 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
 	}
 	return ofid;
 error:
-	if (ofid)
-		p9_client_clunk(ofid);
+	p9_client_clunk(ofid);
 
-	if (fid)
-		p9_client_clunk(fid);
+	p9_client_clunk(fid);
 
 	return ERR_PTR(err);
 }
@@ -768,8 +766,7 @@ static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode
 		v9fs_invalidate_inode_attr(dir);
 	}
 
-	if (fid)
-		p9_client_clunk(fid);
+	p9_client_clunk(fid);
 
 	return err;
 }
@@ -916,8 +913,7 @@ out:
 	return err;
 
 error:
-	if (fid)
-		p9_client_clunk(fid);
+	p9_client_clunk(fid);
 	goto out;
 }
 
fs/9p/vfs_inode_dotl.c +5 -10
index 6054c16b..3611b0f 100644
@@ -363,11 +363,9 @@ out:
 	return err;
 
 error:
-	if (fid)
-		p9_client_clunk(fid);
+	p9_client_clunk(fid);
 err_clunk_old_fid:
-	if (ofid)
-		p9_client_clunk(ofid);
+	p9_client_clunk(ofid);
 	goto out;
 }
 
@@ -464,8 +462,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir,
 	inc_nlink(dir);
 	v9fs_invalidate_inode_attr(dir);
 error:
-	if (fid)
-		p9_client_clunk(fid);
+	p9_client_clunk(fid);
 	v9fs_put_acl(dacl, pacl);
 	return err;
 }
@@ -744,8 +741,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
 	}
 
 error:
-	if (fid)
-		p9_client_clunk(fid);
+	p9_client_clunk(fid);
 
 	return err;
 }
@@ -896,8 +892,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
 		d_instantiate(dentry, inode);
 	}
 error:
-	if (fid)
-		p9_client_clunk(fid);
+	p9_client_clunk(fid);
 	v9fs_put_acl(dacl, pacl);
 	return err;
 }
fs/9p/xattr.c +1 -2
index f95e01e..8e72269 100644
@@ -65,8 +65,7 @@ ssize_t v9fs_fid_xattr_get(struct p9_fid *fid, const char *name,
 	/* Total read xattr bytes */
 	retval = offset;
 error:
-	if (attr_fid)
-		p9_client_clunk(attr_fid);
+	p9_client_clunk(attr_fid);
 	return retval;
 
 }
Signature · 1 line
2.2.1
#689 lore raw

PATCH 2/8 fs/9p: One function call less in v9fs_create() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Dec 2014 08:28:51 +0100

The p9_client_clunk() function was called in two cases by the v9fs_create() function during error handling even if the passed variable "fid" contained a null pointer. This implementation detail could be improved by the introduction of another jump label.

---
 fs/9p/vfs_inode.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
fs/9p/vfs_inode.c +6 -6
index a787d4c..81b945a 100644
@@ -672,7 +672,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
 	err = p9_client_fcreate(ofid, name, perm, mode, extension);
 	if (err < 0) {
 		p9_debug(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err);
-		goto error;
+		goto ofid_clunk;
 	}
 
 	if (!(perm & P9_DMLINK)) {
@@ -682,8 +682,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
 			err = PTR_ERR(fid);
 			p9_debug(P9_DEBUG_VFS,
 				   "p9_client_walk failed %d\n", err);
-			fid = NULL;
-			goto error;
+			goto ofid_clunk;
 		}
 		/*
 		 * instantiate inode and assign the unopened fid to the dentry
@@ -693,16 +692,17 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
 			err = PTR_ERR(inode);
 			p9_debug(P9_DEBUG_VFS,
 				   "inode creation failed %d\n", err);
-			goto error;
+			goto fid_clunk;
 		}
 		v9fs_fid_add(dentry, fid);
 		d_instantiate(dentry, inode);
 	}
 	return ofid;
-error:
-	p9_client_clunk(ofid);
 
+fid_clunk:
 	p9_client_clunk(fid);
+ofid_clunk:
+	p9_client_clunk(ofid);
 
 	return ERR_PTR(err);
 }
Signature · 1 line
2.2.1
#690 lore raw

PATCH 3/8 fs/9p: One function call less in v9fs_vfs_atomic_open() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Dec 2014 08:45:31 +0100

The p9_client_clunk() function was called in one case by the v9fs_vfs_atomic_open() function during error handling even if the passed variable "fid" contained a null pointer.

This implementation detail could be improved by the adjustment of a jump target. Let us delete also an unnecessary variable assignment there.

---
 fs/9p/vfs_inode.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/9p/vfs_inode.c +1 -2
index 81b945a..f568427 100644
@@ -873,8 +873,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
 						v9fs_proto_dotu(v9ses)));
 	if (IS_ERR(fid)) {
 		err = PTR_ERR(fid);
-		fid = NULL;
-		goto error;
+		goto out;
 	}
 
 	v9fs_invalidate_inode_attr(dir);
Signature · 1 line
2.2.1
#691 lore raw

PATCH 4/8 fs/9p: One function call less in v9fs_fid_xattr_get() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Dec 2014 09:05:25 +0100

The p9_client_clunk() function was called in one case by the v9fs_fid_xattr_get() function during error handling even if the passed variable "attr_fid" contained a null pointer.

Let us delete an unnecessary variable assignment there and return from this implementation directly after a failure detection for a p9_client_xattrwalk() call.

---
 fs/9p/xattr.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/9p/xattr.c +1 -2
index 8e72269..05ef790 100644
@@ -34,8 +34,7 @@ ssize_t v9fs_fid_xattr_get(struct p9_fid *fid, const char *name,
 		retval = PTR_ERR(attr_fid);
 		p9_debug(P9_DEBUG_VFS, "p9_client_attrwalk failed %zd\n",
 			 retval);
-		attr_fid = NULL;
-		goto error;
+		return retval;
 	}
 	if (!buffer_size) {
 		/* request to get the attr_size */
Signature · 1 line
2.2.1
#692 lore raw

PATCH 5/8 fs/9p: One function call less in v9fs_vfs_atomic_open_dotl() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Dec 2014 09:29:40 +0100

The p9_client_clunk() function was called in three cases by the v9fs_vfs_atomic_open_dotl() function during error handling even if the passed variable "fid" contained a null pointer.

This implementation detail could be improved by the adjustment of jump targets. Let us delete also an unnecessary variable assignment there.

---
 fs/9p/vfs_inode_dotl.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/9p/vfs_inode_dotl.c +3 -4
index 3611b0f..ce1f5bb 100644
@@ -297,14 +297,14 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
 	if (err) {
 		p9_debug(P9_DEBUG_VFS, "Failed to get acl values in creat %d\n",
 			 err);
-		goto error;
+		goto err_clunk_old_fid;
 	}
 	err = p9_client_create_dotl(ofid, name, v9fs_open_to_dotl_flags(flags),
 				    mode, gid, &qid);
 	if (err < 0) {
 		p9_debug(P9_DEBUG_VFS, "p9_client_open_dotl failed in creat %d\n",
 			 err);
-		goto error;
+		goto err_clunk_old_fid;
 	}
 	v9fs_invalidate_inode_attr(dir);
 
@@ -313,8 +313,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
 	if (IS_ERR(fid)) {
 		err = PTR_ERR(fid);
 		p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
-		fid = NULL;
-		goto error;
+		goto err_clunk_old_fid;
 	}
 	inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->i_sb);
 	if (IS_ERR(inode)) {
Signature · 1 line
2.2.1
#693 lore raw

PATCH 6/8 fs/9p: Less function calls in v9fs_vfs_mkdir_dotl() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Dec 2014 12:44:22 +0100

The p9_client_clunk() function was called in some cases by the v9fs_vfs_mkdir_dotl() function during error handling even if the passed variable "fid" contained a null pointer.

* Corresponding details could be improved by the introduction of another jump label.

* Let us delete also two unnecessary variable assignments there.

* Return from this implementation directly after failure detection for the function calls "v9fs_fid_lookup" and "v9fs_acl_mode".

---
 fs/9p/vfs_inode_dotl.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
fs/9p/vfs_inode_dotl.c +5 -6
index ce1f5bb..672d84f 100644
@@ -403,8 +403,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir,
 	if (IS_ERR(dfid)) {
 		err = PTR_ERR(dfid);
 		p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
-		dfid = NULL;
-		goto error;
+		return err;
 	}
 
 	gid = v9fs_get_fsgid_for_create(dir);
@@ -414,20 +413,19 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir,
 	if (err) {
 		p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mkdir %d\n",
 			 err);
-		goto error;
+		return err;
 	}
 	name = (char *) dentry->d_name.name;
 	err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
 	if (err < 0)
-		goto error;
+		goto put_acl;
 
 	fid = p9_client_walk(dfid, 1, &name, 1);
 	if (IS_ERR(fid)) {
 		err = PTR_ERR(fid);
 		p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
 			 err);
-		fid = NULL;
-		goto error;
+		goto put_acl;
 	}
 
 	/* instantiate inode and assign the unopened fid to the dentry */
@@ -462,6 +460,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir,
 	v9fs_invalidate_inode_attr(dir);
 error:
 	p9_client_clunk(fid);
+put_acl:
 	v9fs_put_acl(dacl, pacl);
 	return err;
 }
Signature · 1 line
2.2.1
#694 lore raw

PATCH 7/8 fs/9p: One function call less in v9fs_vfs_symlink_dotl() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Dec 2014 13:00:54 +0100

The p9_client_clunk() function was called in two cases by the v9fs_vfs_symlink_dotl() function during error handling even if the passed variable "fid" contained a null pointer.

* This implementation detail could be improved by the introduction of another jump label.

* Let us delete also an unnecessary variable assignment there.

---
 fs/9p/vfs_inode_dotl.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/9p/vfs_inode_dotl.c +3 -4
index 672d84f..3b38dda 100644
@@ -701,7 +701,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
 
 	if (err < 0) {
 		p9_debug(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
-		goto error;
+		goto exit;
 	}
 
 	v9fs_invalidate_inode_attr(dir);
@@ -712,8 +712,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
 			err = PTR_ERR(fid);
 			p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
 				 err);
-			fid = NULL;
-			goto error;
+			goto exit;
 		}
 
 		/* instantiate inode and assign the unopened fid to dentry */
@@ -740,7 +739,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
 
 error:
 	p9_client_clunk(fid);
-
+exit:
 	return err;
 }
 
Signature · 1 line
2.2.1
#695 lore raw

PATCH 8/8 fs/9p: Less function calls in v9fs_vfs_mknod_dotl() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Dec 2014 13:36:28 +0100

The p9_client_clunk() function was called in four cases by the v9fs_vfs_mknod_dotl() function during error handling even if the passed variable "fid" contained a null pointer. The v9fs_put_acl() function could also be unnecessarily called with null pointers.

* This implementation detail could be improved by the introduction of two jump labels.

* Let us delete also two unnecessary variable assignments there.

---
 fs/9p/vfs_inode_dotl.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
fs/9p/vfs_inode_dotl.c +6 -6
index 3b38dda..ff3c26a 100644
@@ -832,8 +832,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
 	if (IS_ERR(dfid)) {
 		err = PTR_ERR(dfid);
 		p9_debug(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
-		dfid = NULL;
-		goto error;
+		goto exit;
 	}
 
 	gid = v9fs_get_fsgid_for_create(dir);
@@ -843,13 +842,13 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
 	if (err) {
 		p9_debug(P9_DEBUG_VFS, "Failed to get acl values in mknod %d\n",
 			 err);
-		goto error;
+		goto exit;
 	}
 	name = (char *) dentry->d_name.name;
 
 	err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
 	if (err < 0)
-		goto error;
+		goto put_acl;
 
 	v9fs_invalidate_inode_attr(dir);
 	fid = p9_client_walk(dfid, 1, &name, 1);
@@ -857,8 +856,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
 		err = PTR_ERR(fid);
 		p9_debug(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
 			 err);
-		fid = NULL;
-		goto error;
+		goto put_acl;
 	}
 
 	/* instantiate inode and assign the unopened fid to the dentry */
@@ -890,7 +888,9 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
 	}
 error:
 	p9_client_clunk(fid);
+put_acl:
 	v9fs_put_acl(dacl, pacl);
+exit:
 	return err;
 }
 
Signature · 1 line
2.2.1
#677 lore raw

Re: [PATCH 1/8] fs/9p: Deletion of unnecessary checks before the function call "p9_client_clunk"

In reply to SF Markus Elfring
Quoted 8 lines
fs/9p/vfs_inode.c +0 -0
index 9ee5343..a787d4c 100644
@@ -700,11 +700,9 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
 	}
 	return ofid;
 error:

fs/9p/vfs_inode.c v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir, · line 708

Quoted 10 lines
fs/9p/vfs_inode.c +2 -4
-	if (ofid)
-		p9_client_clunk(ofid);
+	p9_client_clunk(ofid);
 
-	if (fid)
-		p9_client_clunk(fid);
+	p9_client_clunk(fid);
 
 	return ERR_PTR(err);
 }

This code seems rather sloppy. ofid could never be NULL at the point where it was tested. There is a useless definition of ofid to NULL at the top of the function. The error handling code could be rearranged with an extra error label so that p9_client_clunk is never called on fid when it it is not defined. The the two assignments of fid to NULL could also be removed. There is also a useless initialization of err to 0 at the beginning of the function. And the first two calls to ERR_PTR are not needed, as the types of dfid and ofid are the same as the return type of the function.

fs/9p/vfs_inode.c static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode · line 772

Quoted 10 lines
fs/9p/vfs_inode.c +1 -2
@@ -768,8 +766,7 @@ static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode
 		v9fs_invalidate_inode_attr(dir);
 	}
 
-	if (fid)
-		p9_client_clunk(fid);
+	p9_client_clunk(fid);
 
 	return err;
 }

This function is also unnecessarily complex. The if above this one, that detects the error could just return PTR_ERR(fid);. The rest of the function could call inc_nlink, v9fs_invalidate_inode_attr, and p9_client_clunk, and the returnvalue could be 0, removing the need for the err variable.

fs/9p/vfs_inode.c out: · line 918

Quoted 9 lines
fs/9p/vfs_inode.c +1 -2
@@ -916,8 +913,7 @@ out:
 	return err;
 
 error:
-	if (fid)
-		p9_client_clunk(fid);
+	p9_client_clunk(fid);
 	goto out;
 }

In the case where fid is set to NULL, it could just goto out directly, instead of calling p9_client_clunk, testing fid, coming back, and going to out anyway.

julia

Quoted 66 lines
fs/9p/vfs_inode_dotl.c +5 -10
index 6054c16b..3611b0f 100644
@@ -363,11 +363,9 @@ out:
 	return err;
 
 error:
-	if (fid)
-		p9_client_clunk(fid);
+	p9_client_clunk(fid);
 err_clunk_old_fid:
-	if (ofid)
-		p9_client_clunk(ofid);
+	p9_client_clunk(ofid);
 	goto out;
 }
 
@@ -464,8 +462,7 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir,
 	inc_nlink(dir);
 	v9fs_invalidate_inode_attr(dir);
 error:
-	if (fid)
-		p9_client_clunk(fid);
+	p9_client_clunk(fid);
 	v9fs_put_acl(dacl, pacl);
 	return err;
 }
@@ -744,8 +741,7 @@ v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
 	}
 
 error:
-	if (fid)
-		p9_client_clunk(fid);
+	p9_client_clunk(fid);
 
 	return err;
 }
@@ -896,8 +892,7 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
 		d_instantiate(dentry, inode);
 	}
 error:
-	if (fid)
-		p9_client_clunk(fid);
+	p9_client_clunk(fid);
 	v9fs_put_acl(dacl, pacl);
 	return err;
 }
fs/9p/xattr.c +1 -2
index f95e01e..8e72269 100644
@@ -65,8 +65,7 @@ ssize_t v9fs_fid_xattr_get(struct p9_fid *fid, const char *name,
 	/* Total read xattr bytes */
 	retval = offset;
 error:
-	if (attr_fid)
-		p9_client_clunk(attr_fid);
+	p9_client_clunk(attr_fid);
 	return retval;
 
 }
Signature · 1 line
2.2.1
#696 lore raw

cover ALSA: Deletion of some unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 4 Jan 2015 11:50:12 +0100

Further update suggestions were taken into account after several patches were applied from static source code analysis.

Markus Elfring (3):
seq: Deletion of unnecessary checks before the function call "snd_midi_event_free"
oss: Deletion of unnecessary checks before the function call "vfree"
emu10k1: Delete an unnecessary check before the function call "kfree"
oxygen: Delete an unnecessary check before the function call "snd_pcm_suspend"
emux: Delete an unnecessary check before the function call "snd_sf_free"
ASoC: Intel: Delete an unnecessary check before the function call "sst_dma_free"
ASoC: fsi: Deletion of unnecessary checks before the function call "clk_enable"
ASoC: Intel: Delete an unnecessary check before the function call "release_firmware"
i2sbus: Delete an unnecessary check before the function call "snd_pcm_suspend_all"
sb: Delete an unnecessary check before the function call "snd_emux_free" Deletion of checks before the function call "iounmap"
msnd: One function call less in snd_msnd_attach() after error detection
msnd: Fix centralized exiting from snd_msnd_attach()

 sound/aoa/soundbus/i2sbus/core.c | 13 ++++++-------
 sound/arm/aaci.c                 |  4 ++--
 sound/drivers/ml403-ac97cr.c     |  3 +--
 sound/isa/msnd/msnd_pinnacle.c   | 31 ++++++++++++++++---------------
 sound/parisc/harmony.c           |  4 +---
 sound/pci/ad1889.c               |  5 +----
 sound/pci/asihpi/hpioctl.c       |  6 ++----
 sound/pci/atiixp.c               |  3 +--
 sound/pci/atiixp_modem.c         |  3 +--
 sound/pci/aw2/aw2-alsa.c         |  4 +---
 sound/pci/bt87x.c                |  3 +--
 sound/pci/cs4281.c               |  6 ++----
 sound/pci/cs46xx/cs46xx_lib.c    |  4 ++--
 sound/pci/ctxfi/cthw20k1.c       |  5 +----
 sound/pci/ctxfi/cthw20k2.c       |  5 +----
 sound/pci/echoaudio/echoaudio.c  |  6 +-----
 sound/pci/hda/hda_intel.c        |  3 +--
 sound/pci/lola/lola.c            |  6 ++----
 sound/pci/mixart/mixart.c        |  7 +++----
 sound/pci/nm256/nm256.c          |  6 ++----
 sound/pci/rme9652/hdsp.c         |  4 +---
 sound/pci/rme9652/hdspm.c        |  4 +---
 sound/pci/rme9652/rme9652.c      |  3 +--
 sound/pci/sis7019.c              |  5 +----
 sound/pci/ymfpci/ymfpci_main.c   |  3 +--
 sound/ppc/pmac.c                 | 15 +++++----------
 26 files changed, 58 insertions(+), 103 deletions(-)
Signature · 1 line
2.2.1
#697 lore raw

PATCH 1/13 ALSA: seq: Deletion of unnecessary checks before the function call "snd_midi_event_free"

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 14:54:56 +0100

The snd_midi_event_free() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 sound/core/seq/oss/seq_oss_midi.c | 6 ++----
 sound/core/seq/seq_midi.c         | 3 +--
 2 files changed, 3 insertions(+), 6 deletions(-)
sound/core/seq/oss/seq_oss_midi.c +2 -4
index 3a45696..e79cc44 100644
@@ -237,8 +237,7 @@ snd_seq_oss_midi_check_exit_port(int client, int port)
 		spin_unlock_irqrestore(&register_lock, flags);
 		snd_use_lock_free(&mdev->use_lock);
 		snd_use_lock_sync(&mdev->use_lock);
-		if (mdev->coder)
-			snd_midi_event_free(mdev->coder);
+		snd_midi_event_free(mdev->coder);
 		kfree(mdev);
 	}
 	spin_lock_irqsave(&register_lock, flags);
@@ -265,8 +264,7 @@ snd_seq_oss_midi_clear_all(void)
 	spin_lock_irqsave(&register_lock, flags);
 	for (i = 0; i < max_midi_devs; i++) {
 		if ((mdev = midi_devs[i]) != NULL) {
-			if (mdev->coder)
-				snd_midi_event_free(mdev->coder);
+			snd_midi_event_free(mdev->coder);
 			kfree(mdev);
 			midi_devs[i] = NULL;
 		}
sound/core/seq/seq_midi.c +1 -2
index a1fd77a..68fec77 100644
@@ -268,8 +268,7 @@ static void snd_seq_midisynth_delete(struct seq_midisynth *msynth)
 		snd_seq_event_port_detach(msynth->seq_client, msynth->seq_port);
 	}
 
-	if (msynth->parser)
-		snd_midi_event_free(msynth->parser);
+	snd_midi_event_free(msynth->parser);
 }
 
 /* register new midi synth port */
Signature · 1 line
2.2.1
#698 lore raw

PATCH 2/13 ALSA: oss: Deletion of unnecessary checks before the function call "vfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 15:10:52 +0100

The vfree() function performs also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 sound/oss/pss.c  | 2 +-
 sound/oss/trix.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
sound/oss/pss.c +1 -1
index ca0d6e9..81314f9 100644
@@ -1228,7 +1228,7 @@ static void __exit cleanup_pss(void)
 {
 	if(!pss_no_sound)
 	{
-		if(fw_load && pss_synth)
+		if (fw_load)
 			vfree(pss_synth);
 		if(pssmss)
 			unload_pss_mss(&cfg2);
sound/oss/trix.c +1 -1
index 944e0c0..3c494dc 100644
@@ -487,7 +487,7 @@ static int __init init_trix(void)
 
 static void __exit cleanup_trix(void)
 {
-	if (fw_load && trix_boot)
+	if (fw_load)
 		vfree(trix_boot);
 	if (sb)
 		unload_trix_sb(&cfg2);
Signature · 1 line
2.2.1
#699 lore raw

PATCH 3/13 ALSA: emu10k1: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 17:06:04 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 sound/pci/emu10k1/p16v.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
sound/pci/emu10k1/p16v.c +2 -5
index b672755..3c60b43 100644
@@ -166,11 +166,8 @@ static struct snd_pcm_hardware snd_p16v_capture_hw = {
 static void snd_p16v_pcm_free_substream(struct snd_pcm_runtime *runtime)
 {
 	struct snd_emu10k1_pcm *epcm = runtime->private_data;
-  
-	if (epcm) {
-		/* dev_dbg(emu->card->dev, "epcm free: %p\n", epcm); */
-		kfree(epcm);
-	}
+
+	kfree(epcm);
 }
 
 /* open_playback callback */
Signature · 1 line
2.2.1
#700 lore raw

PATCH 4/13 ALSA: oxygen: Delete an unnecessary check before the function call "snd_pcm_suspend"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 17:37:28 +0100

The snd_pcm_suspend() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 sound/pci/oxygen/oxygen_lib.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/pci/oxygen/oxygen_lib.c +1 -2
index b67e306..61a62c0 100644
@@ -736,8 +736,7 @@ static int oxygen_pci_suspend(struct device *dev)
 	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
 
 	for (i = 0; i < PCM_COUNT; ++i)
-		if (chip->streams[i])
-			snd_pcm_suspend(chip->streams[i]);
+		snd_pcm_suspend(chip->streams[i]);
 
 	if (chip->model.suspend)
 		chip->model.suspend(chip);
Signature · 1 line
2.2.1
#701 lore raw

PATCH 5/13 ALSA: emux: Delete an unnecessary check before the function call "snd_sf_free"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 18:28:21 +0100

The snd_sf_free() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 sound/synth/emux/emux.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
sound/synth/emux/emux.c +1 -5
index 9352207..f27a1c8 100644
@@ -160,12 +160,8 @@ int snd_emux_free(struct snd_emux *emu)
 	snd_emux_detach_seq_oss(emu);
 #endif
 	snd_emux_detach_seq(emu);
-
 	snd_emux_delete_hwdep(emu);
-
-	if (emu->sflist)
-		snd_sf_free(emu->sflist);
-
+	snd_sf_free(emu->sflist);
 	kfree(emu->voices);
 	kfree(emu->name);
 	kfree(emu);
Signature · 1 line
2.2.1
#702 lore raw

PATCH 6/13 ASoC: Intel: Delete an unnecessary check before the function call "sst_dma_free"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 19:03:55 +0100

The sst_dma_free() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 sound/soc/intel/sst-dsp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/intel/sst-dsp.c +1 -2
index 86e4108..64e9421 100644
@@ -410,8 +410,7 @@ void sst_dsp_free(struct sst_dsp *sst)
 	if (sst->ops->free)
 		sst->ops->free(sst);
 
-	if (sst->dma)
-		sst_dma_free(sst->dma);
+	sst_dma_free(sst->dma);
 }
 EXPORT_SYMBOL_GPL(sst_dsp_free);
 
Signature · 1 line
2.2.1
#707 lore raw

PATCH 7/13 ASoC: fsi: Deletion of unnecessary checks before the function call "clk_enable"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 19:25:55 +0100

The clk_enable() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 sound/soc/sh/fsi.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
sound/soc/sh/fsi.c +3 -6
index 8869971..d49f25f 100644
@@ -820,12 +820,9 @@ static int fsi_clk_enable(struct device *dev,
 			return ret;
 		}
 
-		if (clock->xck)
-			clk_enable(clock->xck);
-		if (clock->ick)
-			clk_enable(clock->ick);
-		if (clock->div)
-			clk_enable(clock->div);
+		clk_enable(clock->xck);
+		clk_enable(clock->ick);
+		clk_enable(clock->div);
 
 		clock->count++;
 	}
Signature · 1 line
2.2.1
#709 lore raw

PATCH 8/13 ASoC: Intel: Delete an unnecessary check before the function call "release_firmware"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 19:49:37 +0100

The release_firmware() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 sound/soc/intel/sst/sst_loader.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/intel/sst/sst_loader.c +1 -2
index b580f96..7888cd7 100644
@@ -324,8 +324,7 @@ void sst_firmware_load_cb(const struct firmware *fw, void *context)
 
 	if (ctx->sst_state != SST_RESET ||
 			ctx->fw_in_mem != NULL) {
-		if (fw != NULL)
-			release_firmware(fw);
+		release_firmware(fw);
 		mutex_unlock(&ctx->sst_lock);
 		return;
 	}
Signature · 1 line
2.2.1
#711 lore raw

PATCH 9/13 ALSA: i2sbus: Delete an unnecessary check before the function call "snd_pcm_suspend_all"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 20:43:01 +0100

The snd_pcm_suspend_all() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 sound/aoa/soundbus/i2sbus/core.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
sound/aoa/soundbus/i2sbus/core.c +2 -4
index 4e2b4fb..837ba99 100644
@@ -381,10 +381,8 @@ static int i2sbus_suspend(struct macio_dev* dev, pm_message_t state)
 
 	list_for_each_entry(i2sdev, &control->list, item) {
 		/* Notify Alsa */
-		if (i2sdev->sound.pcm) {
-			/* Suspend PCM streams */
-			snd_pcm_suspend_all(i2sdev->sound.pcm);
-		}
+		/* Suspend PCM streams */
+		snd_pcm_suspend_all(i2sdev->sound.pcm);
 
 		/* Notify codecs */
 		list_for_each_entry(cii, &i2sdev->sound.codec_list, list) {
Signature · 1 line
2.2.1
#712 lore raw

PATCH 10/13 ALSA: sb: Delete an unnecessary check before the function call "snd_emux_free"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 21:02:32 +0100

The snd_emux_free() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 sound/isa/sb/emu8000_synth.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/isa/sb/emu8000_synth.c +1 -2
index 95b39be..72332df 100644
@@ -103,8 +103,7 @@ static int snd_emu8000_delete_device(struct snd_seq_device *dev)
 	hw = dev->driver_data;
 	if (hw->pcm)
 		snd_device_free(dev->card, hw->pcm);
-	if (hw->emu)
-		snd_emux_free(hw->emu);
+	snd_emux_free(hw->emu);
 	snd_util_memhdr_free(hw->memhdr);
 	hw->emu = NULL;
 	hw->memhdr = NULL;
Signature · 1 line
2.2.1
#713 lore raw

PATCH 11/13 ALSA: Deletion of checks before the function call "iounmap"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 22:55:54 +0100

The iounmap() function performs also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 sound/aoa/soundbus/i2sbus/core.c | 13 ++++++-------
 sound/arm/aaci.c                 |  4 ++--
 sound/drivers/ml403-ac97cr.c     |  3 +--
 sound/isa/msnd/msnd_pinnacle.c   |  3 +--
 sound/parisc/harmony.c           |  4 +---
 sound/pci/ad1889.c               |  5 +----
 sound/pci/asihpi/hpioctl.c       |  6 ++----
 sound/pci/atiixp.c               |  3 +--
 sound/pci/atiixp_modem.c         |  3 +--
 sound/pci/aw2/aw2-alsa.c         |  4 +---
 sound/pci/bt87x.c                |  3 +--
 sound/pci/cs4281.c               |  6 ++----
 sound/pci/cs46xx/cs46xx_lib.c    |  4 ++--
 sound/pci/ctxfi/cthw20k1.c       |  5 +----
 sound/pci/ctxfi/cthw20k2.c       |  5 +----
 sound/pci/echoaudio/echoaudio.c  |  6 +-----
 sound/pci/hda/hda_intel.c        |  3 +--
 sound/pci/lola/lola.c            |  6 ++----
 sound/pci/mixart/mixart.c        |  7 +++----
 sound/pci/nm256/nm256.c          |  6 ++----
 sound/pci/rme9652/hdsp.c         |  4 +---
 sound/pci/rme9652/hdspm.c        |  4 +---
 sound/pci/rme9652/rme9652.c      |  3 +--
 sound/pci/sis7019.c              |  5 +----
 sound/pci/ymfpci/ymfpci_main.c   |  3 +--
 sound/ppc/pmac.c                 | 15 +++++----------
 26 files changed, 43 insertions(+), 90 deletions(-)
sound/aoa/soundbus/i2sbus/core.c +6 -7
index 4e2b4fb..7835045 100644
@@ -74,10 +74,9 @@ static void i2sbus_release_dev(struct device *dev)
 	int i;
 
 	i2sdev = container_of(dev, struct i2sbus_dev, sound.ofdev.dev);
-
- 	if (i2sdev->intfregs) iounmap(i2sdev->intfregs);
- 	if (i2sdev->out.dbdma) iounmap(i2sdev->out.dbdma);
- 	if (i2sdev->in.dbdma) iounmap(i2sdev->in.dbdma);
+	iounmap(i2sdev->intfregs);
+	iounmap(i2sdev->out.dbdma);
+	iounmap(i2sdev->in.dbdma);
 	for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++)
 		release_and_free_resource(i2sdev->allocated_resource[i]);
 	free_dbdma_descriptor_ring(i2sdev, &i2sdev->out.dbdma_ring);
@@ -318,9 +317,9 @@ static int i2sbus_add_dev(struct macio_dev *macio,
 			free_irq(dev->interrupts[i], dev);
 	free_dbdma_descriptor_ring(dev, &dev->out.dbdma_ring);
 	free_dbdma_descriptor_ring(dev, &dev->in.dbdma_ring);
-	if (dev->intfregs) iounmap(dev->intfregs);
-	if (dev->out.dbdma) iounmap(dev->out.dbdma);
-	if (dev->in.dbdma) iounmap(dev->in.dbdma);
+	iounmap(dev->intfregs);
+	iounmap(dev->out.dbdma);
+	iounmap(dev->in.dbdma);
 	for (i=0;i<3;i++)
 		release_and_free_resource(dev->allocated_resource[i]);
 	mutex_destroy(&dev->lock);
sound/arm/aaci.c +2 -2
index 0e83a73..4140b1b 100644
@@ -889,8 +889,8 @@ static int aaci_probe_ac97(struct aaci *aaci)
 static void aaci_free_card(struct snd_card *card)
 {
 	struct aaci *aaci = card->private_data;
-	if (aaci->base)
-		iounmap(aaci->base);
+
+	iounmap(aaci->base);
 }
 
 static struct aaci *aaci_init_card(struct amba_device *dev)
sound/drivers/ml403-ac97cr.c +1 -2
index ec01de1..bdcb572 100644
@@ -1094,8 +1094,7 @@ static int snd_ml403_ac97cr_free(struct snd_ml403_ac97cr *ml403_ac97cr)
 	if (ml403_ac97cr->capture_irq >= 0)
 		free_irq(ml403_ac97cr->capture_irq, ml403_ac97cr);
 	/* give back "port" */
-	if (ml403_ac97cr->port != NULL)
-		iounmap(ml403_ac97cr->port);
+	iounmap(ml403_ac97cr->port);
 	kfree(ml403_ac97cr);
 	PDEBUG(INIT_INFO, "free(): (done)\n");
 	return 0;
sound/isa/msnd/msnd_pinnacle.c +1 -2
index 65b3682..4c07266 100644
@@ -627,8 +627,7 @@ static int snd_msnd_attach(struct snd_card *card)
 	return 0;
 
 err_release_region:
-	if (chip->mappedbase)
-		iounmap(chip->mappedbase);
+	iounmap(chip->mappedbase);
 	release_mem_region(chip->base, BUFFSIZE);
 	release_region(chip->io, DSP_NUMIO);
 	free_irq(chip->irq, chip);
sound/parisc/harmony.c +1 -3
index 29604a2..f2350c1 100644
@@ -893,9 +893,7 @@ snd_harmony_free(struct snd_harmony *h)
 	if (h->irq >= 0)
 		free_irq(h->irq, h);
 
-	if (h->iobase)
-		iounmap(h->iobase);
-
+	iounmap(h->iobase);
 	kfree(h);
 	return 0;
 }
sound/pci/ad1889.c +1 -4
index 547ee30..0de3129 100644
@@ -853,12 +853,9 @@ snd_ad1889_free(struct snd_ad1889 *chip)
 		free_irq(chip->irq, chip);
 
 skip_hw:
-	if (chip->iobase)
-		iounmap(chip->iobase);
-
+	iounmap(chip->iobase);
 	pci_release_regions(chip->pci);
 	pci_disable_device(chip->pci);
-
 	kfree(chip);
 	return 0;
 }
sound/pci/asihpi/hpioctl.c +2 -4
index 72af66b..67d1133 100644
@@ -541,10 +541,8 @@ void asihpi_adapter_remove(struct pci_dev *pci_dev)
 	hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
 
 	/* unmap PCI memory space, mapped during device init. */
-	for (idx = 0; idx < HPI_MAX_ADAPTER_MEM_SPACES; idx++) {
-		if (pci.ap_mem_base[idx])
-			iounmap(pci.ap_mem_base[idx]);
-	}
+	for (idx = 0; idx < HPI_MAX_ADAPTER_MEM_SPACES; ++idx)
+		iounmap(pci.ap_mem_base[idx]);
 
 	if (pa->irq)
 		free_irq(pa->irq, pa);
sound/pci/atiixp.c +1 -2
index 9c1c445..d24188f 100644
@@ -1585,8 +1585,7 @@ static int snd_atiixp_free(struct atiixp *chip)
       __hw_end:
 	if (chip->irq >= 0)
 		free_irq(chip->irq, chip);
-	if (chip->remap_addr)
-		iounmap(chip->remap_addr);
+	iounmap(chip->remap_addr);
 	pci_release_regions(chip->pci);
 	pci_disable_device(chip->pci);
 	kfree(chip);
sound/pci/atiixp_modem.c +1 -2
index b2f63e0..c321a97 100644
@@ -1211,8 +1211,7 @@ static int snd_atiixp_free(struct atiixp_modem *chip)
       __hw_end:
 	if (chip->irq >= 0)
 		free_irq(chip->irq, chip);
-	if (chip->remap_addr)
-		iounmap(chip->remap_addr);
+	iounmap(chip->remap_addr);
 	pci_release_regions(chip->pci);
 	pci_disable_device(chip->pci);
 	kfree(chip);
sound/pci/aw2/aw2-alsa.c +1 -3
index e1cf019..8d2fee7 100644
@@ -229,9 +229,7 @@ static int snd_aw2_dev_free(struct snd_device *device)
 	if (chip->irq >= 0)
 		free_irq(chip->irq, (void *)chip);
 	/* release the i/o ports & memory */
-	if (chip->iobase_virt)
-		iounmap(chip->iobase_virt);
-
+	iounmap(chip->iobase_virt);
 	pci_release_regions(chip->pci);
 	/* disable the PCI entry */
 	pci_disable_device(chip->pci);
sound/pci/bt87x.c +1 -2
index 058b997..e82ceac 100644
@@ -690,8 +690,7 @@ static int snd_bt87x_free(struct snd_bt87x *chip)
 		snd_bt87x_stop(chip);
 	if (chip->irq >= 0)
 		free_irq(chip->irq, chip);
-	if (chip->mmio)
-		iounmap(chip->mmio);
+	iounmap(chip->mmio);
 	pci_release_regions(chip->pci);
 	pci_disable_device(chip->pci);
 	kfree(chip);
sound/pci/cs4281.c +2 -4
index 05a4337..ea33911 100644
@@ -1316,10 +1316,8 @@ static int snd_cs4281_free(struct cs4281 *chip)
 
 	if (chip->irq >= 0)
 		free_irq(chip->irq, chip);
-	if (chip->ba0)
-		iounmap(chip->ba0);
-	if (chip->ba1)
-		iounmap(chip->ba1);
+	iounmap(chip->ba0);
+	iounmap(chip->ba1);
 	pci_release_regions(chip->pci);
 	pci_disable_device(chip->pci);
 
sound/pci/cs46xx/cs46xx_lib.c +2 -2
index dfec84e..128bbfe 100644
@@ -2949,8 +2949,8 @@ static int snd_cs46xx_free(struct snd_cs46xx *chip)
 
 	for (idx = 0; idx < 5; idx++) {
 		struct snd_cs46xx_region *region = &chip->region.idx[idx];
-		if (region->remap_addr)
-			iounmap(region->remap_addr);
+
+		iounmap(region->remap_addr);
 		release_and_free_resource(region->resource);
 	}
 
sound/pci/ctxfi/cthw20k1.c +1 -4
index b425aa8..b8b0d8e 100644
@@ -1985,10 +1985,7 @@ static int hw_card_shutdown(struct hw *hw)
 		free_irq(hw->irq, hw);
 
 	hw->irq	= -1;
-
-	if (hw->mem_base)
-		iounmap(hw->mem_base);
-
+	iounmap(hw->mem_base);
 	hw->mem_base = NULL;
 
 	if (hw->io_base)
sound/pci/ctxfi/cthw20k2.c +1 -4
index 253899d..4e16b4d 100644
@@ -2110,10 +2110,7 @@ static int hw_card_shutdown(struct hw *hw)
 		free_irq(hw->irq, hw);
 
 	hw->irq	= -1;
-
-	if (hw->mem_base)
-		iounmap(hw->mem_base);
-
+	iounmap(hw->mem_base);
 	hw->mem_base = NULL;
 
 	if (hw->io_base)
sound/pci/echoaudio/echoaudio.c +1 -5
index 21228ad..98d4f35 100644
@@ -1872,12 +1872,8 @@ static int snd_echo_free(struct echoaudio *chip)
 	if (chip->comm_page)
 		snd_dma_free_pages(&chip->commpage_dma_buf);
 
-	if (chip->dsp_registers)
-		iounmap(chip->dsp_registers);
-
+	iounmap(chip->dsp_registers);
 	release_and_free_resource(chip->iores);
-
-
 	pci_disable_device(chip->pci);
 
 	/* release chip data */
sound/pci/hda/hda_intel.c +1 -2
index d426a0b..a971425 100644
@@ -1138,8 +1138,7 @@ static int azx_free(struct azx *chip)
 		free_irq(chip->irq, (void*)chip);
 	if (chip->msi)
 		pci_disable_msi(chip->pci);
-	if (chip->remap_addr)
-		iounmap(chip->remap_addr);
+	iounmap(chip->remap_addr);
 
 	azx_free_stream_pages(chip);
 	if (chip->region_requested)
sound/pci/lola/lola.c +2 -4
index 4cf4be5..9ff60008 100644
@@ -551,10 +551,8 @@ static void lola_free(struct lola *chip)
 	lola_free_mixer(chip);
 	if (chip->irq >= 0)
 		free_irq(chip->irq, (void *)chip);
-	if (chip->bar[0].remap_addr)
-		iounmap(chip->bar[0].remap_addr);
-	if (chip->bar[1].remap_addr)
-		iounmap(chip->bar[1].remap_addr);
+	iounmap(chip->bar[0].remap_addr);
+	iounmap(chip->bar[1].remap_addr);
 	if (chip->rb.area)
 		snd_dma_free_pages(&chip->rb);
 	pci_release_regions(chip->pci);
sound/pci/mixart/mixart.c +3 -4
index 1faf47e..c3a9f39 100644
@@ -1114,10 +1114,9 @@ static int snd_mixart_free(struct mixart_mgr *mgr)
 	}
 
 	/* release the i/o ports */
-	for (i = 0; i < 2; i++) {
-		if (mgr->mem[i].virt)
-			iounmap(mgr->mem[i].virt);
-	}
+	for (i = 0; i < 2; ++i)
+		iounmap(mgr->mem[i].virt);
+
 	pci_release_regions(mgr->pci);
 
 	/* free flowarray */
sound/pci/nm256/nm256.c +2 -4
index 4e41a4e..3f52a44 100644
@@ -1460,10 +1460,8 @@ static int snd_nm256_free(struct nm256 *chip)
 	if (chip->irq >= 0)
 		free_irq(chip->irq, chip);
 
-	if (chip->cport)
-		iounmap(chip->cport);
-	if (chip->buffer)
-		iounmap(chip->buffer);
+	iounmap(chip->cport);
+	iounmap(chip->buffer);
 	release_and_free_resource(chip->res_cport);
 	release_and_free_resource(chip->res_buffer);
 
sound/pci/rme9652/hdsp.c +1 -3
index cf5a6c8..fe66bcb 100644
@@ -5309,9 +5309,7 @@ static int snd_hdsp_free(struct hdsp *hdsp)
 
 	release_firmware(hdsp->firmware);
 	vfree(hdsp->fw_uploaded);
-
-	if (hdsp->iobase)
-		iounmap(hdsp->iobase);
+	iounmap(hdsp->iobase);
 
 	if (hdsp->port)
 		pci_release_regions(hdsp->pci);
sound/pci/rme9652/hdspm.c +1 -3
index 3342705..8109b8e 100644
@@ -6965,9 +6965,7 @@ static int snd_hdspm_free(struct hdspm * hdspm)
 		free_irq(hdspm->irq, (void *) hdspm);
 
 	kfree(hdspm->mixer);
-
-	if (hdspm->iobase)
-		iounmap(hdspm->iobase);
+	iounmap(hdspm->iobase);
 
 	if (hdspm->port)
 		pci_release_regions(hdspm->pci);
sound/pci/rme9652/rme9652.c +1 -2
index 6521521..648911c 100644
@@ -1756,8 +1756,7 @@ static int snd_rme9652_free(struct snd_rme9652 *rme9652)
 
 	if (rme9652->irq >= 0)
 		free_irq(rme9652->irq, (void *)rme9652);
-	if (rme9652->iobase)
-		iounmap(rme9652->iobase);
+	iounmap(rme9652->iobase);
 	if (rme9652->port)
 		pci_release_regions(rme9652->pci);
 
sound/pci/sis7019.c +1 -4
index 7f6a0a0..5e9437b 100644
@@ -1064,12 +1064,9 @@ static int sis_chip_free(struct sis7019 *sis)
 	if (sis->irq >= 0)
 		free_irq(sis->irq, sis);
 
-	if (sis->ioaddr)
-		iounmap(sis->ioaddr);
-
+	iounmap(sis->ioaddr);
 	pci_release_regions(sis->pci);
 	pci_disable_device(sis->pci);
-
 	sis_free_suspend(sis);
 	return 0;
 }
sound/pci/ymfpci/ymfpci_main.c +1 -2
index f5581a9..de7f06f 100644
@@ -2246,8 +2246,7 @@ static int snd_ymfpci_free(struct snd_ymfpci *chip)
 	release_and_free_resource(chip->mpu_res);
 	release_and_free_resource(chip->fm_res);
 	snd_ymfpci_free_gameport(chip);
-	if (chip->reg_area_virt)
-		iounmap(chip->reg_area_virt);
+	iounmap(chip->reg_area_virt);
 	if (chip->work_ptr.area)
 		snd_dma_free_pages(&chip->work_ptr);
 	
sound/ppc/pmac.c +5 -10
index 5a13b22..d399df4 100644
@@ -867,16 +867,11 @@ static int snd_pmac_free(struct snd_pmac *chip)
 	snd_pmac_dbdma_free(chip, &chip->capture.cmd);
 	snd_pmac_dbdma_free(chip, &chip->extra_dma);
 	snd_pmac_dbdma_free(chip, &emergency_dbdma);
-	if (chip->macio_base)
-		iounmap(chip->macio_base);
-	if (chip->latch_base)
-		iounmap(chip->latch_base);
-	if (chip->awacs)
-		iounmap(chip->awacs);
-	if (chip->playback.dma)
-		iounmap(chip->playback.dma);
-	if (chip->capture.dma)
-		iounmap(chip->capture.dma);
+	iounmap(chip->macio_base);
+	iounmap(chip->latch_base);
+	iounmap(chip->awacs);
+	iounmap(chip->playback.dma);
+	iounmap(chip->capture.dma);
 
 	if (chip->node) {
 		int i;
Signature · 1 line
2.2.1
#718 lore raw

PATCH 12/13 ALSA: msnd: One function call less in snd_msnd_attach() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 4 Jan 2015 11:00:11 +0100

The iounmap() function was called in one case by the snd_msnd_attach() function even if a previous call of the ioremap_nocache() function failed.

This implementation detail could be improved by the introduction of another jump label.

---
 sound/isa/msnd/msnd_pinnacle.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
sound/isa/msnd/msnd_pinnacle.c +8 -7
index 4c07266..e2e940d 100644
@@ -575,23 +575,23 @@ static int snd_msnd_attach(struct snd_card *card)
 
 	err = snd_msnd_dsp_full_reset(card);
 	if (err < 0)
-		goto err_release_region;
+		goto io_unmap;
 
 	/* Register device */
 	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
 	if (err < 0)
-		goto err_release_region;
+		goto io_unmap;
 
 	err = snd_msnd_pcm(card, 0);
 	if (err < 0) {
 		printk(KERN_ERR LOGNAME ": error creating new PCM device\n");
-		goto err_release_region;
+		goto io_unmap;
 	}
 
 	err = snd_msndmix_new(card);
 	if (err < 0) {
 		printk(KERN_ERR LOGNAME ": error creating new Mixer device\n");
-		goto err_release_region;
+		goto io_unmap;
 	}
 
 
@@ -607,7 +607,7 @@ static int snd_msnd_attach(struct snd_card *card)
 		if (err < 0) {
 			printk(KERN_ERR LOGNAME
 				": error creating new Midi device\n");
-			goto err_release_region;
+			goto io_unmap;
 		}
 		mpu = chip->rmidi->private_data;
 
@@ -622,12 +622,13 @@ static int snd_msnd_attach(struct snd_card *card)
 
 	err = snd_card_register(card);
 	if (err < 0)
-		goto err_release_region;
+		goto io_unmap;
 
 	return 0;
 
-err_release_region:
+io_unmap:
 	iounmap(chip->mappedbase);
+err_release_region:
 	release_mem_region(chip->base, BUFFSIZE);
 	release_region(chip->io, DSP_NUMIO);
 	free_irq(chip->irq, chip);
Signature · 1 line
2.2.1
#720 lore raw

PATCH 13/13 ALSA: msnd: Fix centralized exiting from snd_msnd_attach()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 4 Jan 2015 11:47:17 +0100

Two return statements were used by the snd_msnd_attach() function at source code places where the Linux coding style recommends an alternative approach.

Let us improve the affected implementation details with adjustments for corresponding jump targets.

---
 sound/isa/msnd/msnd_pinnacle.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
sound/isa/msnd/msnd_pinnacle.c +8 -7
index e2e940d..0e66e5e 100644
@@ -552,17 +552,16 @@ static int snd_msnd_attach(struct snd_card *card)
 		return err;
 	}
 	if (request_region(chip->io, DSP_NUMIO, card->shortname) = NULL) {
-		free_irq(chip->irq, chip);
-		return -EBUSY;
+		err = -EBUSY;
+		goto free_an_irq;
 	}
 
 	if (!request_mem_region(chip->base, BUFFSIZE, card->shortname)) {
 		printk(KERN_ERR LOGNAME
 			": unable to grab memory region 0x%lx-0x%lx\n",
 			chip->base, chip->base + BUFFSIZE - 1);
-		release_region(chip->io, DSP_NUMIO);
-		free_irq(chip->irq, chip);
-		return -EBUSY;
+		err = -EBUSY;
+		goto release_resource_region;
 	}
 	chip->mappedbase = ioremap_nocache(chip->base, 0x8000);
 	if (!chip->mappedbase) {
@@ -570,7 +569,7 @@ static int snd_msnd_attach(struct snd_card *card)
 			": unable to map memory region 0x%lx-0x%lx\n",
 			chip->base, chip->base + BUFFSIZE - 1);
 		err = -EIO;
-		goto err_release_region;
+		goto release_memory_region;
 	}
 
 	err = snd_msnd_dsp_full_reset(card);
@@ -628,9 +627,11 @@ static int snd_msnd_attach(struct snd_card *card)
 
 io_unmap:
 	iounmap(chip->mappedbase);
-err_release_region:
+release_memory_region:
 	release_mem_region(chip->base, BUFFSIZE);
+release_resource_region:
 	release_region(chip->io, DSP_NUMIO);
+free_an_irq:
 	free_irq(chip->irq, chip);
 	return err;
 }
Signature · 1 line
2.2.1
#719 lore raw

Re: [PATCH 12/13] ALSA: msnd: One function call less in snd_msnd_attach() after error detection

In reply to SF Markus Elfring

At Sun, 04 Jan 2015 14:38:38 +0100,

Quoted 11 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 4 Jan 2015 11:00:11 +0100

The iounmap() function was called in one case by the snd_msnd_attach() function even if a previous call of the ioremap_nocache() function failed.

This implementation detail could be improved by the introduction of another jump label.

I didn't apply this and the next one. Using goto label isn't bad for the error paths in general, but using too much nested labels worsens the readability significantly. (Though, it's almost a matter of taste, so I don't want to spend my time for discussing this.)

thanks,

Takashi

Quoted 64 lines
---
 sound/isa/msnd/msnd_pinnacle.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
sound/isa/msnd/msnd_pinnacle.c +8 -7
index 4c07266..e2e940d 100644
@@ -575,23 +575,23 @@ static int snd_msnd_attach(struct snd_card *card)
 
 	err = snd_msnd_dsp_full_reset(card);
 	if (err < 0)
-		goto err_release_region;
+		goto io_unmap;
 
 	/* Register device */
 	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
 	if (err < 0)
-		goto err_release_region;
+		goto io_unmap;
 
 	err = snd_msnd_pcm(card, 0);
 	if (err < 0) {
 		printk(KERN_ERR LOGNAME ": error creating new PCM device\n");
-		goto err_release_region;
+		goto io_unmap;
 	}
 
 	err = snd_msndmix_new(card);
 	if (err < 0) {
 		printk(KERN_ERR LOGNAME ": error creating new Mixer device\n");
-		goto err_release_region;
+		goto io_unmap;
 	}
 
 
@@ -607,7 +607,7 @@ static int snd_msnd_attach(struct snd_card *card)
 		if (err < 0) {
 			printk(KERN_ERR LOGNAME
 				": error creating new Midi device\n");
-			goto err_release_region;
+			goto io_unmap;
 		}
 		mpu = chip->rmidi->private_data;
 
@@ -622,12 +622,13 @@ static int snd_msnd_attach(struct snd_card *card)
 
 	err = snd_card_register(card);
 	if (err < 0)
-		goto err_release_region;
+		goto io_unmap;
 
 	return 0;
 
-err_release_region:
+io_unmap:
 	iounmap(chip->mappedbase);
+err_release_region:
 	release_mem_region(chip->base, BUFFSIZE);
 	release_region(chip->io, DSP_NUMIO);
 	free_irq(chip->irq, chip);
Signature · 1 line
2.2.1
#721 lore raw

Re: [PATCH 0/13] ALSA: Deletion of some unnecessary checks

In reply to SF Markus Elfring

At Sun, 04 Jan 2015 13:43:11 +0100,

Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 4 Jan 2015 11:50:12 +0100

Further update suggestions were taken into account after several patches were applied from static source code analysis.

Quoted 14 lines

Markus Elfring (3):
seq: Deletion of unnecessary checks before the function call "snd_midi_event_free"
oss: Deletion of unnecessary checks before the function call "vfree"
emu10k1: Delete an unnecessary check before the function call "kfree"
oxygen: Delete an unnecessary check before the function call "snd_pcm_suspend"
emux: Delete an unnecessary check before the function call "snd_sf_free"
ASoC: Intel: Delete an unnecessary check before the function call "sst_dma_free"
ASoC: fsi: Deletion of unnecessary checks before the function call "clk_enable"
ASoC: Intel: Delete an unnecessary check before the function call "release_firmware"
i2sbus: Delete an unnecessary check before the function call "snd_pcm_suspend_all"
sb: Delete an unnecessary check before the function call "snd_emux_free" Deletion of checks before the function call "iounmap"
msnd: One function call less in snd_msnd_attach() after error detection
msnd: Fix centralized exiting from snd_msnd_attach()

I applied most of them now but leave patches 6-8 left to Mark applying through his tree. As posted in another mail patches 12 and 13 are dropped.

BTW, when you sending a new patch series, you should drop the old references tags.

thanks,

Takashi

Quoted 32 lines
 sound/aoa/soundbus/i2sbus/core.c | 13 ++++++-------
 sound/arm/aaci.c                 |  4 ++--
 sound/drivers/ml403-ac97cr.c     |  3 +--
 sound/isa/msnd/msnd_pinnacle.c   | 31 ++++++++++++++++---------------
 sound/parisc/harmony.c           |  4 +---
 sound/pci/ad1889.c               |  5 +----
 sound/pci/asihpi/hpioctl.c       |  6 ++----
 sound/pci/atiixp.c               |  3 +--
 sound/pci/atiixp_modem.c         |  3 +--
 sound/pci/aw2/aw2-alsa.c         |  4 +---
 sound/pci/bt87x.c                |  3 +--
 sound/pci/cs4281.c               |  6 ++----
 sound/pci/cs46xx/cs46xx_lib.c    |  4 ++--
 sound/pci/ctxfi/cthw20k1.c       |  5 +----
 sound/pci/ctxfi/cthw20k2.c       |  5 +----
 sound/pci/echoaudio/echoaudio.c  |  6 +-----
 sound/pci/hda/hda_intel.c        |  3 +--
 sound/pci/lola/lola.c            |  6 ++----
 sound/pci/mixart/mixart.c        |  7 +++----
 sound/pci/nm256/nm256.c          |  6 ++----
 sound/pci/rme9652/hdsp.c         |  4 +---
 sound/pci/rme9652/hdspm.c        |  4 +---
 sound/pci/rme9652/rme9652.c      |  3 +--
 sound/pci/sis7019.c              |  5 +----
 sound/pci/ymfpci/ymfpci_main.c   |  3 +--
 sound/ppc/pmac.c                 | 15 +++++----------
 26 files changed, 58 insertions(+), 103 deletions(-)
Signature · 1 line
2.2.1
#678 lore raw

Re: [PATCH 1/8] fs/9p: Deletion of unnecessary checks before the function call "p9_client_clunk"

In reply to SF Markus Elfring
Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 27 Dec 2014 09:34:39 +0100

The p9_client_clunk() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

Not true. You are not allowed to call p9_client_clunk(NULL). I assume this patch adds a bug. You have tried to introduce several of these kinds of bugs. You are not careful enough.

regards,
dan carpenter

#714 lore raw

Re: [PATCH 11/13] ALSA: Deletion of checks before the function call "iounmap"

In reply to SF Markus Elfring

sound/pci/asihpi/hpioctl.c void asihpi_adapter_remove(struct pci_dev *pci_dev) · line 545

Quoted 8 lines · SF Markus Elfring
sound/pci/asihpi/hpioctl.c +2 -4
 	/* unmap PCI memory space, mapped during device init. */
-	for (idx = 0; idx < HPI_MAX_ADAPTER_MEM_SPACES; idx++) {
-		if (pci.ap_mem_base[idx])
-			iounmap(pci.ap_mem_base[idx]);
-	}
+	for (idx = 0; idx < HPI_MAX_ADAPTER_MEM_SPACES; ++idx)
+		iounmap(pci.ap_mem_base[idx]);

Don't do the gratuitous idx++ to ++idx changes. You do it a couple other places as well. It belongs in a separate patch if you really feel it is worth doing. (It is not a clean up and it is not worth doing).

regards,
dan carpenter

maintainer
#703 lore raw

Re: [PATCH 6/13] ASoC: Intel: Delete an unnecessary check before the function call "sst_dma_free"

In reply to SF Markus Elfring
Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 19:03:55 +0100

The sst_dma_free() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

I'm missing aptches 1-5, are there any dependencies?

#704 lore raw

Re: [PATCH 6/13] ASoC: Intel: Delete an unnecessary check before the function call "sst_dma_free"

At Mon, 5 Jan 2015 14:35:51 +0000,

Quoted 9 lines · Mark Brown
Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 19:03:55 +0100

The sst_dma_free() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

I'm missing aptches 1-5, are there any dependencies?

No, all individual fixes.

Takashi

maintainer
#705 lore raw

Re: [PATCH 6/13] ASoC: Intel: Delete an unnecessary check before the function call "sst_dma_free"

Quoted 5 lines · Takashi Iwai
Quoted 1 line · Mark Brown

I'm missing aptches 1-5, are there any dependencies?

No, all individual fixes.

OK. SF, in future please always send at least the cover letter to everyone getting patches in the series so they know what's going on.

maintainer Applied
#706 lore raw

Re: [PATCH 6/13] ASoC: Intel: Delete an unnecessary check before the function call "sst_dma_free"

In reply to SF Markus Elfring
Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 19:03:55 +0100

The sst_dma_free() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

Applied, thanks.

maintainer Applied
#708 lore raw

Re: [PATCH 7/13] ASoC: fsi: Deletion of unnecessary checks before the function call "clk_enable"

In reply to SF Markus Elfring
Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 19:25:55 +0100

The clk_enable() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

Applied, thanks.

maintainer Applied
#710 lore raw

Re: [PATCH 8/13] ASoC: Intel: Delete an unnecessary check before the function call "release_firmware"

In reply to SF Markus Elfring
Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Jan 2015 19:49:37 +0100

The release_firmware() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

Applied, thanks.

#679 lore raw

Re: [PATCH 1/8] fs/9p: Deletion of unnecessary checks before the function call "p9_client_clunk"

In reply to Dan Carpenter
Quoted 5 lines
Quoted 3 lines

The p9_client_clunk() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

Not true. You are not allowed to call p9_client_clunk(NULL).

I find that it will work in principle if we refer to the same function implementation.
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/net/9p/client.c?idØ282ea05ad119247122de23db7d48ad6098cfa2#n1448
http://lxr.free-electrons.com/source/net/9p/client.c#L1448

Quoted 1 line

I assume this patch adds a bug.

It can happen that you will not like a corresponding error message if the callers will still pass null pointers eventually.

... Trying to clunk with NULL ...

Quoted 2 lines

I assume this patch adds a bug. You have tried to introduce several of these kinds of bugs.

Do any other contributors want to reject my update suggestions around software components for "fs/9p"?

Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#680 lore raw

Re: [PATCH 1/8] fs/9p: Deletion of unnecessary checks before the function call "p9_client_clunk"

Quoted 10 lines · SF Markus Elfring
Quoted 5 lines
Quoted 3 lines

The p9_client_clunk() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

Not true. You are not allowed to call p9_client_clunk(NULL).

I find that it will work in principle if we refer to the same function implementation.
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/net/9p/client.c?idØ282ea05ad119247122de23db7d48ad6098cfa2#n1448
http://lxr.free-electrons.com/source/net/9p/client.c#L1448

What do you mean by "work in principle"? One possible issue is the return value - I don't have the original patch so I don't know what is the call site, so I don't know if that is an issue. But you don't want to do a dump_stack for no reason. That would at best be very misleading, and I would imagine be quite expensive.

julia
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#681 lore raw

Re: [PATCH 1/8] fs/9p: Deletion of unnecessary checks before the function call "p9_client_clunk"

Quoted 4 lines
Quoted 2 lines

https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/net/9p/client.c?idØ282ea05ad119247122de23db7d48ad6098cfa2#n1448
http://lxr.free-electrons.com/source/net/9p/client.c#L1448

What do you mean by "work in principle"?

If I do not stumble on an unexpected name space issue from my static source analysis again, then I would see the linked function as relevant here. Its implementation provides a clear input parameter validation.

Quoted 2 lines

But you don't want to do a dump_stack for no reason. That would at best be very misleading, and I would imagine be quite expensive.

The error response is clear. Are any software developments efforts expected to clean-up the call stack for unwanted null pointers even more?

Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#682 lore raw

Re: [PATCH 1/8] fs/9p: Deletion of unnecessary checks before the function call "p9_client_clunk"

Quoted 2 lines

The error response is clear. Are any software developments efforts expected to clean-up the call stack for unwanted null pointers even more?

I found the original patch and looked at the call sites. None of them calls dump_stack. The behavior is thus not the same. With your change, something that was previously treated in an orderly manner will be converted to something that looks like an oops. I assume that the cost of the dump_stack will also be huge.

julia

#688 lore raw

Re: [PATCH 1/8] fs/9p: Deletion of unnecessary checks before the function call "p9_client_clunk"

In reply to SF Markus Elfring
Quoted 5 lines · SF Markus Elfring
Quoted 2 lines

I assume this patch adds a bug. You have tried to introduce several of these kinds of bugs.

Do any other contributors want to reject my update suggestions around software components for "fs/9p"?

Some of the 9p patches actually seem like bug fixes so I like those ones. It would be better if the bug fixes had a correct changelog, of course.

regards,
dan carpenter

#683 lore raw

Re: [V9fs-developer] [PATCH 1/8] fs/9p: Deletion of unnecessary checks before the function call "p9_client_clunk"

In reply to Julia Lawall

Hi,

Julia Lawall wrote on Mon, Jan 05, 2015 at 11:01:55PM +0100:

Quoted 8 lines
Quoted 2 lines

The error response is clear. Are any software developments efforts expected to clean-up the call stack for unwanted null pointers even more?

I found the original patch and looked at the call sites. None of them calls dump_stack. The behavior is thus not the same. With your change, something that was previously treated in an orderly manner will be converted to something that looks like an oops. I assume that the cost of the dump_stack will also be huge.

I definitely agree there, this will create unwanted dump_stack messages.

Simple example, without even looking at the multiple possible interactions with multiple clients hammering the server, can be taken from v9fs_create in fs/9p/vfs_inode.c
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/fs/9p/vfs_inode.c?idØ282ea05ad119247122de23db7d48ad6098cfa2#n652

jumping to label error from a failure in p9_client_fcreate (e.g. EPERM or something perfectly valid) will, with your patch, call clunk with fid = NULL and thus generate a stack trace, while it is a perfectly normal code path that should only return to userspace with EPERM.

(admitedly, the linux vfs will do checks first to ensure that the function is likely to succeed, but some servers can implement their own security model on top)

Other patches in the set look good at first glance, but I'll need a bit to find time to look through implications they may have.

Signature · 6 lines
Dominique Martinet,
CEA
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#684 lore raw

Re: [V9fs-developer] [PATCH 1/8] fs/9p: Deletion of unnecessary checks before the function call "p9_client_clunk"

Dominique Martinet wrote on Tue, Jan 06, 2015 at 09:12:53AM +0100:

Quoted 9 lines

Simple example, without even looking at the multiple possible interactions with multiple clients hammering the server, can be taken from v9fs_create in fs/9p/vfs_inode.c
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/fs/9p/vfs_inode.c?idØ282ea05ad119247122de23db7d48ad6098cfa2#n652

jumping to label error from a failure in p9_client_fcreate (e.g. EPERM or something perfectly valid) will, with your patch, call clunk with fid = NULL and thus generate a stack trace, while it is a perfectly normal code path that should only return to userspace with EPERM.

Actually just seen that this precise example is fixed along with more similar code paths in subsequents (!) patchs of the set.

It could actually be interesting to see if we could get all such paths "fixed".
If so, I believe this way will ultimately lead to cleaner code, but I'd rather see taken all other patches first and keep this one in v9fs-devel branch for a bit longer if this makes sense... Well, I guess there is a test window before the merge to linus tree anyway, but given the number of active 9P users it could be useful.

(All other patches in the set look good to me at second glance, now. To answer Dan's mail, none of these are bug fix as far as I've seen, just avoiding unnecessary checks for null or calls+check/warn depending on whether you apply patch #1 first)

Signature · 6 lines
Dominique Martinet,
CEA
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#685 lore raw

Re: [V9fs-developer] [PATCH 1/8] fs/9p: Deletion of unnecessary checks before the function call "p9_client_clunk"

Quoted 4 lines · Dominique Martinet

(All other patches in the set look good to me at second glance, now. To answer Dan's mail, none of these are bug fix as far as I've seen, just avoiding unnecessary checks for null or calls+check/warn depending on whether you apply patch #1 first)

You're right. The patch set introduces bugs then fixes them later.

regards,
dan carpenter

#686 lore raw

Re: [V9fs-developer] [PATCH 1/8] fs/9p: Deletion of unnecessary checks before the function call "p9_client_clunk"

In reply to Dominique Martinet
Quoted 7 lines
Quoted 4 lines

jumping to label error from a failure in p9_client_fcreate (e.g. EPERM or something perfectly valid) will, with your patch, call clunk with fid = NULL and thus generate a stack trace, while it is a perfectly normal code path that should only return to userspace with EPERM.

Actually just seen that this precise example is fixed along with more similar code paths in subsequents (!) patchs of the set.

Do you refer to my update suggestions with a subject like "One function call less in v9fs_…" here?

Quoted 2 lines

It could actually be interesting to see if we could get all such paths "fixed".

Would you like to see any more specific source code clean-up? Which kind of fine-tuning have you got in mind?

Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#687 lore raw

Re: [V9fs-developer] [PATCH 1/8] fs/9p: Deletion of unnecessary checks before the function call "p9_client_clunk"

SF Markus Elfring wrote on Tue, Jan 06, 2015 at 03:34:08PM +0100:

Quoted 5 lines
Quoted 2 lines

Actually just seen that this precise example is fixed along with more similar code paths in subsequents (!) patchs of the set.

Do you refer to my update suggestions with a subject like "One function call less in v9fs_…" here?

Yes. Looking at the patchset as a whole (and under the assumption that calling p9_client_clunk with NULL is harmful), your patchset first introduces many such calls then proceeds onto fixing them.

Thinking a bit more, I think that instead of just changing the order of patches the cleanest way would be to submit this as "reworking jump labels, making NULL checks useless in the process".
Still only looking at v9fs_create, with your patch#2 reflowing, p9_client_clunk can't be called with NULL unless a bug happened (either p9_client_fcreate or p9_client_walk returning non-error but leaving ofid or fid NULL), so it'd actually make sense to remove the quiet check in favor of the warn/stack dump check at this point.

Is what I'm saying making sense?

Quoted 5 lines
Quoted 2 lines

It could actually be interesting to see if we could get all such paths "fixed".

Would you like to see any more specific source code clean-up? Which kind of fine-tuning have you got in mind?

I was really just thinking that if the code flow is thought out the if's can be removed harmlessly, but that it actually needs to be done the other way around.
I honestly am not involved enough in kernel coding style changes or 9p code as a whole to suggest anything else, sorry :)

Thanks,

Signature · 6 lines
Dominique Martinet,
CEA
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#723 lore raw

Re: [PATCH] IOMMU-Tegra: gart: Delete an unnecessary check before the function call "vfree"

In reply to SF Markus Elfring
Quoted 19 lines

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 17:54:16 +0100

The vfree() function performs also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/iommu/tegra-gart.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iommu/tegra-gart.c +0 -0
index f722a0c..07a795a 100644

drivers/iommu/tegra-gart.c static int tegra_gart_remove(struct platform_device *pdev) · line 410

Quoted 9 lines
drivers/iommu/tegra-gart.c +1 -2
@@ -404,8 +404,7 @@ static int tegra_gart_remove(struct platform_device *pdev)
 	struct gart_device *gart = platform_get_drvdata(pdev);
 
 	writel(0, gart->regs + GART_CONFIG);
-	if (gart->savedata)
-		vfree(gart->savedata);
+	vfree(gart->savedata);
 	gart_handle = NULL;
 	return 0;
 }

Would you like to integrate this update suggestion into another source code repository?

Regards,
Markus

#724 lore raw

cover block: Deletion of checks before three function calls

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 18 Jan 2015 14:50:06 +0100

Functions which release a system resource are occasionally documented in the way that they tolerate the passing of a null pointer for example. I do not see a need because of this fact that a function caller repeats a corresponding check.

Markus Elfring (3):
cciss: Deletion of an unnecessary check before the function call "put_disk"
z2ram: Delete an unnecessary check before the function call "kfree" Deletion of checks before the function call "iounmap"

 drivers/block/cciss.c    | 18 ++++++------------
 drivers/block/mg_disk.c  |  3 +--
 drivers/block/skd_main.c |  6 ++----
 3 files changed, 9 insertions(+), 18 deletions(-)
Signature · 1 line
2.2.2
#725 lore raw

PATCH 1/3 block-cciss: Deletion of an unnecessary check before the function call "put_disk"

From: Markus Elfring <[email protected]>
Date: Sun, 18 Jan 2015 11:14:16 +0100

The put_disk() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/block/cciss.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/block/cciss.c +1 -2
index ff20f19..4be0de0 100644
@@ -4424,8 +4424,7 @@ static void free_hba(ctlr_info_t *h)
 
 	hba[h->ctlr] = NULL;
 	for (i = 0; i < h->highest_lun + 1; i++)
-		if (h->gendisk[i] != NULL)
-			put_disk(h->gendisk[i]);
+		put_disk(h->gendisk[i]);
 	kfree(h);
 }
 
Signature · 1 line
2.2.2
#726 lore raw

PATCH 2/3 block-z2ram: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 18 Jan 2015 12:28:27 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/block/z2ram.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/block/z2ram.c +1 -4
index 968f9e5..c32f248 100644
@@ -404,10 +404,7 @@ static void __exit z2_exit(void)
 	    }
 	}
 
-	if ( z2ram_map != NULL )
-	{
-	    kfree( z2ram_map );
-	}
+	kfree(z2ram_map);
     }
 
     return;
Signature · 1 line
2.2.2
#727 lore raw

PATCH 3/3 block: Deletion of checks before the function call "iounmap"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 18 Jan 2015 13:33:25 +0100

The iounmap() function performs also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/block/cciss.c    | 18 ++++++------------
 drivers/block/mg_disk.c  |  3 +--
 drivers/block/skd_main.c |  6 ++----
 3 files changed, 9 insertions(+), 18 deletions(-)
drivers/block/cciss.c +6 -12
index ff20f19..d13ef0f 100644
@@ -4382,12 +4382,9 @@ err_out_free_res:
 	 * Deliberately omit pci_disable_device(): it does something nasty to
 	 * Smart Array controllers that pci_enable_device does not undo
 	 */
-	if (h->transtable)
-		iounmap(h->transtable);
-	if (h->cfgtable)
-		iounmap(h->cfgtable);
-	if (h->vaddr)
-		iounmap(h->vaddr);
+	iounmap(h->transtable);
+	iounmap(h->cfgtable);
+	iounmap(h->vaddr);
 	pci_release_regions(h->pdev);
 	return err;
 }
@@ -4939,12 +4936,9 @@ static void cciss_undo_allocations_after_kdump_soft_reset(ctlr_info_t *h)
 	if (h->reply_pool)
 		pci_free_consistent(h->pdev, h->max_commands * sizeof(__u64),
 				h->reply_pool, h->reply_pool_dhandle);
-	if (h->transtable)
-		iounmap(h->transtable);
-	if (h->cfgtable)
-		iounmap(h->cfgtable);
-	if (h->vaddr)
-		iounmap(h->vaddr);
+	iounmap(h->transtable);
+	iounmap(h->cfgtable);
+	iounmap(h->vaddr);
 	unregister_blkdev(h->major, h->devname);
 	cciss_destroy_hba_sysfs_entry(h);
 	pci_release_regions(h->pdev);
drivers/block/mg_disk.c +1 -2
index 145ce2a..9f738ee 100644
@@ -1068,8 +1068,7 @@ static int mg_remove(struct platform_device *plat_dev)
 		gpio_free(host->rst);
 
 	/* unmap io */
-	if (host->dev_base)
-		iounmap(host->dev_base);
+	iounmap(host->dev_base);
 
 	/* free mg_host */
 	kfree(host);
drivers/block/skd_main.c +2 -4
index 1e46eb2..d4c7c4b 100644
@@ -4944,8 +4944,7 @@ err_out_timer:
 
 err_out_iounmap:
 	for (i = 0; i < SKD_MAX_BARS; i++)
-		if (skdev->mem_map[i])
-			iounmap(skdev->mem_map[i]);
+		iounmap(skdev->mem_map[i]);
 
 	if (skdev->pcie_error_reporting_is_enabled)
 		pci_disable_pcie_error_reporting(pdev);
@@ -5108,8 +5107,7 @@ err_out_timer:
 
 err_out_iounmap:
 	for (i = 0; i < SKD_MAX_BARS; i++)
-		if (skdev->mem_map[i])
-			iounmap(skdev->mem_map[i]);
+		iounmap(skdev->mem_map[i]);
 
 	if (skdev->pcie_error_reporting_is_enabled)
 		pci_disable_pcie_error_reporting(pdev);
Signature · 1 line
2.2.2
#728 lore raw

PATCH 1/1 MTD: Deletion of checks before the function call "iounmap"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 18 Jan 2015 17:30:23 +0100

The iounmap() function performs also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/mtd/maps/latch-addr-flash.c |  3 +--
 drivers/mtd/maps/pci.c              |  6 ++----
 drivers/mtd/maps/physmap_of.c       |  3 +--
 drivers/mtd/maps/plat-ram.c         |  3 +--
 drivers/mtd/maps/pxa2xx-flash.c     |  6 ++----
 drivers/mtd/maps/sa1100-flash.c     |  3 +--
 drivers/mtd/nand/fsl_elbc_nand.c    |  3 +--
 drivers/mtd/nand/fsl_ifc_nand.c     |  3 +--
 drivers/mtd/nand/mpc5121_nfc.c      |  3 +--
 drivers/mtd/onenand/samsung.c       | 12 ++++--------
 10 files changed, 15 insertions(+), 30 deletions(-)
drivers/mtd/maps/latch-addr-flash.c +1 -2
index cadfbe0..60496cd 100644
@@ -109,8 +109,7 @@ static int latch_addr_flash_remove(struct platform_device *dev)
 		map_destroy(info->mtd);
 	}
 
-	if (info->map.virt != NULL)
-		iounmap(info->map.virt);
+	iounmap(info->map.virt);
 
 	if (info->res != NULL)
 		release_mem_region(info->res->start, resource_size(info->res));
drivers/mtd/maps/pci.c +2 -4
index eb0242e..0006794 100644
@@ -118,8 +118,7 @@ intel_iq80310_init(struct pci_dev *dev, struct map_pci_info *map)
 static void
 intel_iq80310_exit(struct pci_dev *dev, struct map_pci_info *map)
 {
-	if (map->base)
-		iounmap(map->base);
+	iounmap(map->base);
 	pci_write_config_dword(dev, 0x44, map->map.map_priv_2);
 }
 
@@ -202,8 +201,7 @@ intel_dc21285_init(struct pci_dev *dev, struct map_pci_info *map)
 static void
 intel_dc21285_exit(struct pci_dev *dev, struct map_pci_info *map)
 {
-	if (map->base)
-		iounmap(map->base);
+	iounmap(map->base);
 
 	/*
 	 * We need to undo the PCI BAR2/PCI ROM BAR address alteration.
drivers/mtd/maps/physmap_of.c +1 -2
index f35cd20..89f5d42 100644
@@ -57,8 +57,7 @@ static int of_flash_remove(struct platform_device *dev)
 		if (info->list[i].mtd)
 			map_destroy(info->list[i].mtd);
 
-		if (info->list[i].map.virt)
-			iounmap(info->list[i].map.virt);
+		iounmap(info->list[i].map.virt);
 
 		if (info->list[i].res) {
 			release_resource(info->list[i].res);
drivers/mtd/maps/plat-ram.c +1 -2
index 4b65c08..da09274 100644
@@ -104,8 +104,7 @@ static int platram_remove(struct platform_device *pdev)
 		kfree(info->area);
 	}
 
-	if (info->map.virt != NULL)
-		iounmap(info->map.virt);
+	iounmap(info->map.virt);
 
 	kfree(info);
 
drivers/mtd/maps/pxa2xx-flash.c +2 -4
index 12fa75d..a5f27b9 100644
@@ -89,8 +89,7 @@ static int pxa2xx_flash_probe(struct platform_device *pdev)
 
 	if (!info->mtd) {
 		iounmap((void *)info->map.virt);
-		if (info->map.cached)
-			iounmap(info->map.cached);
+		iounmap(info->map.cached);
 		return -EIO;
 	}
 	info->mtd->owner = THIS_MODULE;
@@ -110,8 +109,7 @@ static int pxa2xx_flash_remove(struct platform_device *dev)
 
 	map_destroy(info->mtd);
 	iounmap(info->map.virt);
-	if (info->map.cached)
-		iounmap(info->map.cached);
+	iounmap(info->map.cached);
 	kfree(info);
 	return 0;
 }
drivers/mtd/maps/sa1100-flash.c +1 -2
index ea69720..22e5d7d 100644
@@ -58,8 +58,7 @@ static void sa1100_destroy_subdev(struct sa_subdev_info *subdev)
 {
 	if (subdev->mtd)
 		map_destroy(subdev->mtd);
-	if (subdev->map.virt)
-		iounmap(subdev->map.virt);
+	iounmap(subdev->map.virt);
 	release_mem_region(subdev->map.phys, subdev->map.size);
 }
 
drivers/mtd/nand/fsl_elbc_nand.c +1 -2
index 04b22fd..a0f2a91 100644
@@ -801,8 +801,7 @@ static int fsl_elbc_chip_remove(struct fsl_elbc_mtd *priv)
 
 	kfree(priv->mtd.name);
 
-	if (priv->vbase)
-		iounmap(priv->vbase);
+	iounmap(priv->vbase);
 
 	elbc_fcm_ctrl->chips[priv->bank] = NULL;
 	kfree(priv);
drivers/mtd/nand/fsl_ifc_nand.c +1 -2
index 4c05f4f..360d9a3 100644
@@ -995,8 +995,7 @@ static int fsl_ifc_chip_remove(struct fsl_ifc_mtd *priv)
 
 	kfree(priv->mtd.name);
 
-	if (priv->vbase)
-		iounmap(priv->vbase);
+	iounmap(priv->vbase);
 
 	ifc_nand_ctrl->chips[priv->bank] = NULL;
 
drivers/mtd/nand/mpc5121_nfc.c +1 -2
index 1f12e5b..34fa6db 100644
@@ -621,8 +621,7 @@ static void mpc5121_nfc_free(struct device *dev, struct mtd_info *mtd)
 	if (prv->clk)
 		clk_disable_unprepare(prv->clk);
 
-	if (prv->csreg)
-		iounmap(prv->csreg);
+	iounmap(prv->csreg);
 }
 
 static int mpc5121_nfc_probe(struct platform_device *op)
drivers/mtd/onenand/samsung.c +4 -8
index 19cfb97..24ac4cb 100644
@@ -1001,8 +1001,7 @@ static int s3c_onenand_probe(struct platform_device *pdev)
 	return 0;
 
 scan_failed:
-	if (onenand->dma_addr)
-		iounmap(onenand->dma_addr);
+	iounmap(onenand->dma_addr);
 dma_ioremap_failed:
 	if (onenand->dma_res)
 		release_mem_region(onenand->dma_res->start,
@@ -1011,8 +1010,7 @@ dma_ioremap_failed:
 oob_buf_fail:
 	kfree(onenand->page_buf);
 page_buf_fail:
-	if (onenand->ahb_addr)
-		iounmap(onenand->ahb_addr);
+	iounmap(onenand->ahb_addr);
 ahb_ioremap_failed:
 	if (onenand->ahb_res)
 		release_mem_region(onenand->ahb_res->start,
@@ -1036,13 +1034,11 @@ static int s3c_onenand_remove(struct platform_device *pdev)
 	struct mtd_info *mtd = platform_get_drvdata(pdev);
 
 	onenand_release(mtd);
-	if (onenand->ahb_addr)
-		iounmap(onenand->ahb_addr);
+	iounmap(onenand->ahb_addr);
 	if (onenand->ahb_res)
 		release_mem_region(onenand->ahb_res->start,
 				   resource_size(onenand->ahb_res));
-	if (onenand->dma_addr)
-		iounmap(onenand->dma_addr);
+	iounmap(onenand->dma_addr);
 	if (onenand->dma_res)
 		release_mem_region(onenand->dma_res->start,
 				   resource_size(onenand->dma_res));
Signature · 1 line
2.2.2
#739 lore raw

cover PCMCIA: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 18 Jan 2015 19:49:16 +0100

Another update suggestion was taken into account after a patch was applied from static source code analysis.

Markus Elfring (2):
Deletion of checks before the function call "iounmap"
Less function calls in bcm63xx_drv_pcmcia_probe() after error detection

 drivers/pcmcia/bcm63xx_pcmcia.c | 20 ++++++++++----------
 drivers/pcmcia/cistpl.c         |  3 +--
 drivers/pcmcia/electra_cf.c     |  6 ++----
 drivers/pcmcia/yenta_socket.c   |  3 +--
 4 files changed, 14 insertions(+), 18 deletions(-)
Signature · 1 line
2.2.2
#740 lore raw

PATCH 1/2 PCMCIA: Deletion of checks before the function call "iounmap"

From: Markus Elfring <[email protected]>
Date: Sun, 18 Jan 2015 18:48:09 +0100

The iounmap() function performs also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/pcmcia/bcm63xx_pcmcia.c | 6 ++----
 drivers/pcmcia/cistpl.c         | 3 +--
 drivers/pcmcia/electra_cf.c     | 6 ++----
 drivers/pcmcia/yenta_socket.c   | 3 +--
 4 files changed, 6 insertions(+), 12 deletions(-)
drivers/pcmcia/bcm63xx_pcmcia.c +2 -4
index 0802e0b..9e7ad1b 100644
@@ -426,10 +426,8 @@ static int bcm63xx_drv_pcmcia_probe(struct platform_device *pdev)
 	return 0;
 
 err:
-	if (skt->io_base)
-		iounmap(skt->io_base);
-	if (skt->base)
-		iounmap(skt->base);
+	iounmap(skt->io_base);
+	iounmap(skt->base);
 	if (skt->reg_res)
 		release_mem_region(skt->reg_res->start, regmem_size);
 	kfree(skt);
drivers/pcmcia/cistpl.c +1 -2
index 884a984..662462e 100644
@@ -115,8 +115,7 @@ static void __iomem *set_cis_map(struct pcmcia_socket *s,
 	}
 
 	if (s->features & SS_CAP_STATIC_MAP) {
-		if (s->cis_virt)
-			iounmap(s->cis_virt);
+		iounmap(s->cis_virt);
 		s->cis_virt = ioremap(mem->static_start, s->map_size);
 	}
 
drivers/pcmcia/electra_cf.c +2 -4
index 7f9950d..3fb78d6 100644
@@ -316,10 +316,8 @@ fail1:
 
 	if (cf->io_virt)
 		__iounmap_at(cf->io_virt, cf->io_size);
-	if (cf->mem_base)
-		iounmap(cf->mem_base);
-	if (cf->gpio_base)
-		iounmap(cf->gpio_base);
+	iounmap(cf->mem_base);
+	iounmap(cf->gpio_base);
 	device_init_wakeup(&ofdev->dev, 0);
 	kfree(cf);
 	return status;
drivers/pcmcia/yenta_socket.c +1 -2
index 8a23ccb..5ea1d49 100644
@@ -802,8 +802,7 @@ static void yenta_close(struct pci_dev *dev)
 	else
 		del_timer_sync(&sock->poll_timer);
 
-	if (sock->base)
-		iounmap(sock->base);
+	iounmap(sock->base);
 	yenta_free_resources(sock);
 
 	pci_release_regions(dev);
Signature · 1 line
2.2.2
#741 lore raw

PATCH 2/2 PCMCIA: Less function calls in bcm63xx_drv_pcmcia_probe() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 18 Jan 2015 19:45:45 +0100

The functions "iounmap", "kfree" and "release_mem_region" were called in some cases by the bcm63xx_drv_pcmcia_probe() function during error handling even if the passed variable contained a null pointer.

* Corresponding details could be improved by adjustments for jump labels.

* Let us delete also another unnecessary check for the data structure member "reg_res" there.

---
 drivers/pcmcia/bcm63xx_pcmcia.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/pcmcia/bcm63xx_pcmcia.c +8 -6
index 9e7ad1b..9848d91a2 100644
@@ -346,7 +346,7 @@ static int bcm63xx_drv_pcmcia_probe(struct platform_device *pdev)
 	skt->pd = pdev->dev.platform_data;
 	if (!skt->common_res || !skt->attr_res || !irq_res || !skt->pd) {
 		ret = -EINVAL;
-		goto err;
+		goto free_memory;
 	}
 
 	/* remap pcmcia registers */
@@ -354,14 +354,14 @@ static int bcm63xx_drv_pcmcia_probe(struct platform_device *pdev)
 	regmem_size = resource_size(res);
 	if (!request_mem_region(res->start, regmem_size, "bcm63xx_pcmcia")) {
 		ret = -EINVAL;
-		goto err;
+		goto free_memory;
 	}
 	skt->reg_res = res;
 
 	skt->base = ioremap(res->start, regmem_size);
 	if (!skt->base) {
 		ret = -ENOMEM;
-		goto err;
+		goto release_memory_region;
 	}
 
 	/* remap io registers */
@@ -370,7 +370,7 @@ static int bcm63xx_drv_pcmcia_probe(struct platform_device *pdev)
 	skt->io_base = ioremap(res->start, iomem_size);
 	if (!skt->io_base) {
 		ret = -ENOMEM;
-		goto err;
+		goto io_unmap_base;
 	}
 
 	/* resources are static */
@@ -427,9 +427,11 @@ static int bcm63xx_drv_pcmcia_probe(struct platform_device *pdev)
 
 err:
 	iounmap(skt->io_base);
+io_unmap_base:
 	iounmap(skt->base);
-	if (skt->reg_res)
-		release_mem_region(skt->reg_res->start, regmem_size);
+release_memory_region:
+	release_mem_region(skt->reg_res->start, regmem_size);
+free_memory:
 	kfree(skt);
 	return ret;
 }
Signature · 1 line
2.2.2
#742 lore raw

cover video: fbdev: Deletion of some unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 19 Jan 2015 17:57:25 +0100

Further update suggestions were taken into account after a patch was applied from static source code analysis.

Markus Elfring (9):
fbdev: Deletion of checks before the function call "iounmap" One function call less in tdfxfb_probe() after error detection One function call less in vesafb_probe() after error detection Add check for return value of ioremap() in cirrusfb_pci_register() Less function calls in trident_pci_probe() after error detection One function call less in pvr2fb_common_init() after error detection One function call less in tgafb_register() after error detection Less function calls in valkyriefb_init() after error detection Less function calls in w100fb_probe() after error detection

 drivers/video/fbdev/aty/atyfb_base.c   | 15 +++++--------
 drivers/video/fbdev/cirrusfb.c         | 10 ++++++---
 drivers/video/fbdev/controlfb.c        |  6 ++---
 drivers/video/fbdev/efifb.c            |  3 +--
 drivers/video/fbdev/hgafb.c            |  3 +--
 drivers/video/fbdev/hpfb.c             |  3 +--
 drivers/video/fbdev/i810/i810_main.c   |  6 ++---
 drivers/video/fbdev/macfb.c            | 15 +++++--------
 drivers/video/fbdev/offb.c             |  3 +--
 drivers/video/fbdev/pvr2fb.c           | 15 ++++++-------
 drivers/video/fbdev/s1d13xxxfb.c       |  3 +--
 drivers/video/fbdev/s3fb.c             |  6 ++---
 drivers/video/fbdev/sh_mobile_hdmi.c   |  6 ++---
 drivers/video/fbdev/sh_mobile_lcdcfb.c |  3 +--
 drivers/video/fbdev/simplefb.c         |  3 +--
 drivers/video/fbdev/stifb.c            |  3 +--
 drivers/video/fbdev/tdfxfb.c           | 22 +++++++++----------
 drivers/video/fbdev/tgafb.c            | 20 ++++++++---------
 drivers/video/fbdev/tridentfb.c        | 15 +++++++------
 drivers/video/fbdev/valkyriefb.c       | 37 ++++++++++++++++++-------------
 drivers/video/fbdev/vesafb.c           | 11 +++++-----
 drivers/video/fbdev/w100fb.c           | 40 +++++++++++++++++-----------------
 22 files changed, 116 insertions(+), 132 deletions(-)
Signature · 1 line
2.2.2
#729 lore raw

Re: [PATCH] MTD: Deletion of checks before the function call "iounmap"

In reply to SF Markus Elfring
Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 18 Jan 2015 17:30:23 +0100

The iounmap() function performs also input parameter validation. Thus the test around the call is not needed.

Is this guaranteed for all arch'es? I expect that it would be, but I see that, for instance, ARM allows replaceable iounmap() for subarchitectures. Also, I see checks for various sorts of static mappings in ARM and x86; these likely (always?) cover the NULL case, but they're not always straightforward.

Anyway, I'm essentially saying that I'd like to be 100% sure we have a guarantee before dropping all these.

Quoted 1 line

This issue was detected by using the Coccinelle software.

What script? Hand-rolled I guess?

Brian

#743 lore raw

PATCH 1/9 video: Deletion of checks before the function call "iounmap"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 18 Jan 2015 22:45:39 +0100

The iounmap() function performs also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/video/fbdev/aty/atyfb_base.c   | 15 +++++----------
 drivers/video/fbdev/cirrusfb.c         |  3 +--
 drivers/video/fbdev/controlfb.c        |  6 ++----
 drivers/video/fbdev/efifb.c            |  3 +--
 drivers/video/fbdev/hgafb.c            |  3 +--
 drivers/video/fbdev/hpfb.c             |  3 +--
 drivers/video/fbdev/i810/i810_main.c   |  6 ++----
 drivers/video/fbdev/macfb.c            | 15 +++++----------
 drivers/video/fbdev/offb.c             |  3 +--
 drivers/video/fbdev/pvr2fb.c           |  3 +--
 drivers/video/fbdev/s1d13xxxfb.c       |  3 +--
 drivers/video/fbdev/s3fb.c             |  6 ++----
 drivers/video/fbdev/sh_mobile_hdmi.c   |  6 ++----
 drivers/video/fbdev/sh_mobile_lcdcfb.c |  3 +--
 drivers/video/fbdev/simplefb.c         |  3 +--
 drivers/video/fbdev/stifb.c            |  3 +--
 drivers/video/fbdev/tdfxfb.c           |  6 ++----
 drivers/video/fbdev/tgafb.c            |  3 +--
 drivers/video/fbdev/tridentfb.c        |  6 ++----
 drivers/video/fbdev/valkyriefb.c       |  9 +++------
 drivers/video/fbdev/vesafb.c           |  6 ++----
 drivers/video/fbdev/w100fb.c           |  9 +++------
 22 files changed, 41 insertions(+), 82 deletions(-)
drivers/video/fbdev/aty/atyfb_base.c +5 -10
index 37ec09b..0f4b147 100644
@@ -3605,10 +3605,8 @@ err_release_io:
 #ifdef __sparc__
 	kfree(par->mmap_map);
 #else
-	if (par->ati_regbase)
-		iounmap(par->ati_regbase);
-	if (info->screen_base)
-		iounmap(info->screen_base);
+	iounmap(par->ati_regbase);
+	iounmap(info->screen_base);
 #endif
 err_release_mem:
 	if (par->aux_start)
@@ -3733,13 +3731,10 @@ static void atyfb_remove(struct fb_info *info)
 	}
 #endif
 #ifndef __sparc__
-	if (par->ati_regbase)
-		iounmap(par->ati_regbase);
-	if (info->screen_base)
-		iounmap(info->screen_base);
+	iounmap(par->ati_regbase);
+	iounmap(info->screen_base);
 #ifdef __BIG_ENDIAN
-	if (info->sprite.addr)
-		iounmap(info->sprite.addr);
+	iounmap(info->sprite.addr);
 #endif
 #endif
 #ifdef __sparc__
drivers/video/fbdev/cirrusfb.c +1 -2
index d992aa5..d8b3359 100644
@@ -2164,8 +2164,7 @@ err_release_regions:
 #endif
 	pci_release_regions(pdev);
 err_release_fb:
-	if (cinfo->laguna_mmio != NULL)
-		iounmap(cinfo->laguna_mmio);
+	iounmap(cinfo->laguna_mmio);
 	framebuffer_release(info);
 err_out:
 	return ret;
drivers/video/fbdev/controlfb.c +2 -4
index 080fdd2..d386fed 100644
@@ -1068,10 +1068,8 @@ static void control_cleanup(void)
 	if (!p)
 		return;
 
-	if (p->cmap_regs)
-		iounmap(p->cmap_regs);
-	if (p->control_regs)
-		iounmap(p->control_regs);
+	iounmap(p->cmap_regs);
+	iounmap(p->control_regs);
 	if (p->frame_buffer) {
 		if (p->control_use_bank2)
 			p->frame_buffer -= 0x600000;
drivers/video/fbdev/efifb.c +1 -2
index 4bfff34..a6d08f0 100644
@@ -65,8 +65,7 @@ static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green,
 
 static void efifb_destroy(struct fb_info *info)
 {
-	if (info->screen_base)
-		iounmap(info->screen_base);
+	iounmap(info->screen_base);
 	if (request_mem_succeeded)
 		release_mem_region(info->apertures->ranges[0].base,
 				   info->apertures->ranges[0].size);
drivers/video/fbdev/hgafb.c +1 -2
index 5ff9fe2..76b231e 100644
@@ -552,8 +552,7 @@ static int hgafb_probe(struct platform_device *pdev)
 
 	if (! hga_card_detect()) {
 		printk(KERN_INFO "hgafb: HGA card not detected.\n");
-		if (hga_vram)
-			iounmap(hga_vram);
+		iounmap(hga_vram);
 		return -EINVAL;
 	}
 
drivers/video/fbdev/hpfb.c +1 -2
index a1b7e5f..9b47102 100644
@@ -355,8 +355,7 @@ static void hpfb_remove_one(struct dio_dev *d)
 		iounmap((void *)fb_regs);
 	release_mem_region(d->resource.start, resource_size(&d->resource));
 	fb_dealloc_cmap(&fb_info.cmap);
-	if (fb_info.screen_base)
-		iounmap(fb_info.screen_base);
+	iounmap(fb_info.screen_base);
 }
 
 static struct dio_device_id hpfb_dio_tbl[] = {
drivers/video/fbdev/i810/i810_main.c +2 -4
index bb674e4..ce3a585 100644
@@ -2105,10 +2105,8 @@ static void i810fb_release_resource(struct fb_info *info,
 	if (par->i810_gtt.i810_fb_memory)
 		agp_free_memory(gtt->i810_fb_memory);
 
-	if (par->mmio_start_virtual)
-		iounmap(par->mmio_start_virtual);
-	if (par->aperture.virtual)
-		iounmap(par->aperture.virtual);
+	iounmap(par->mmio_start_virtual);
+	iounmap(par->aperture.virtual);
 	kfree(par->edid);
 	if (par->res_flags & FRAMEBUFFER_REQ)
 		release_mem_region(par->aperture.physical,
drivers/video/fbdev/macfb.c +5 -10
index cda7587..dde0520 100644
@@ -541,16 +541,11 @@ static void __init macfb_setup(char *options)
 
 static void __init iounmap_macfb(void)
 {
-	if (dafb_cmap_regs)
-		iounmap(dafb_cmap_regs);
-	if (v8_brazil_cmap_regs)
-		iounmap(v8_brazil_cmap_regs);
-	if (rbv_cmap_regs)
-		iounmap(rbv_cmap_regs);
-	if (civic_cmap_regs)
-		iounmap(civic_cmap_regs);
-	if (csc_cmap_regs)
-		iounmap(csc_cmap_regs);
+	iounmap(dafb_cmap_regs);
+	iounmap(v8_brazil_cmap_regs);
+	iounmap(rbv_cmap_regs);
+	iounmap(civic_cmap_regs);
+	iounmap(csc_cmap_regs);
 }
 
 static int __init macfb_init(void)
drivers/video/fbdev/offb.c +1 -2
index 43a0a52..5efce99 100644
@@ -281,8 +281,7 @@ static int offb_set_par(struct fb_info *info)
 
 static void offb_destroy(struct fb_info *info)
 {
-	if (info->screen_base)
-		iounmap(info->screen_base);
+	iounmap(info->screen_base);
 	release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size);
 	framebuffer_release(info);
 }
drivers/video/fbdev/pvr2fb.c +1 -2
index 7c74f58..7aa4ef1 100644
@@ -841,8 +841,7 @@ static int pvr2fb_common_init(void)
 	return 0;
 
 out_err:
-	if (fb_info->screen_base)
-		iounmap(fb_info->screen_base);
+	iounmap(fb_info->screen_base);
 	if (par->mmio_base)
 		iounmap((void *)par->mmio_base);
 
drivers/video/fbdev/s1d13xxxfb.c +1 -2
index 83433cb..dff38b7 100644
@@ -750,8 +750,7 @@ s1d13xxxfb_remove(struct platform_device *pdev)
 
 		fb_dealloc_cmap(&info->cmap);
 
-		if (info->screen_base)
-			iounmap(info->screen_base);
+		iounmap(info->screen_base);
 
 		framebuffer_release(info);
 	}
drivers/video/fbdev/s3fb.c +2 -4
index f0ae61a..3d9d45f 100644
@@ -1382,8 +1382,7 @@ err_find_mode:
 #ifdef CONFIG_FB_S3_DDC
 	if (par->ddc_registered)
 		i2c_del_adapter(&par->ddc_adapter);
-	if (par->mmio)
-		iounmap(par->mmio);
+	iounmap(par->mmio);
 #endif
 	pci_iounmap(dev, info->screen_base);
 err_iomap:
@@ -1419,8 +1418,7 @@ static void s3_pci_remove(struct pci_dev *dev)
 #ifdef CONFIG_FB_S3_DDC
 		if (par->ddc_registered)
 			i2c_del_adapter(&par->ddc_adapter);
-		if (par->mmio)
-			iounmap(par->mmio);
+		iounmap(par->mmio);
 #endif
 
 		pci_iounmap(dev, info->screen_base);
drivers/video/fbdev/sh_mobile_hdmi.c +2 -4
index 7c72a3f..2a7187d 100644
@@ -1397,8 +1397,7 @@ static int __init sh_hdmi_probe(struct platform_device *pdev)
 ecodec:
 	free_irq(irq, hdmi);
 ereqirq:
-	if (hdmi->htop1)
-		iounmap(hdmi->htop1);
+	iounmap(hdmi->htop1);
 emap_htop1:
 	pm_runtime_put(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
@@ -1428,8 +1427,7 @@ static int __exit sh_hdmi_remove(struct platform_device *pdev)
 	pm_runtime_disable(&pdev->dev);
 	clk_disable_unprepare(hdmi->hdmi_clk);
 	clk_put(hdmi->hdmi_clk);
-	if (hdmi->htop1)
-		iounmap(hdmi->htop1);
+	iounmap(hdmi->htop1);
 	iounmap(hdmi->base);
 	release_mem_region(res->start, resource_size(res));
 
drivers/video/fbdev/sh_mobile_lcdcfb.c +1 -2
index d3013cd..4f9a25b 100644
@@ -2489,8 +2489,7 @@ static int sh_mobile_lcdc_remove(struct platform_device *pdev)
 		clk_put(priv->dot_clk);
 	}
 
-	if (priv->base)
-		iounmap(priv->base);
+	iounmap(priv->base);
 
 	if (priv->irq)
 		free_irq(priv->irq, priv);
drivers/video/fbdev/simplefb.c +1 -2
index 92cac80..40e6b33 100644
@@ -72,8 +72,7 @@ static int simplefb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
 
 static void simplefb_destroy(struct fb_info *info)
 {
-	if (info->screen_base)
-		iounmap(info->screen_base);
+	iounmap(info->screen_base);
 }
 
 static struct fb_ops simplefb_ops = {
drivers/video/fbdev/stifb.c +1 -2
index 86621fa..ea12305 100644
@@ -1374,8 +1374,7 @@ stifb_cleanup(void)
 			unregister_framebuffer(sti->info);
 			release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
 		        release_mem_region(info->fix.smem_start, info->fix.smem_len);
-				if (info->screen_base)
-					iounmap(info->screen_base);
+				iounmap(info->screen_base);
 		        fb_dealloc_cmap(&info->cmap);
 		        framebuffer_release(info);
 		}
drivers/video/fbdev/tdfxfb.c +2 -4
index f761fe3..69d4062 100644
@@ -1572,15 +1572,13 @@ out_err_iobase:
 	release_region(pci_resource_start(pdev, 2),
 		       pci_resource_len(pdev, 2));
 out_err_screenbase:
-	if (info->screen_base)
-		iounmap(info->screen_base);
+	iounmap(info->screen_base);
 	release_mem_region(info->fix.smem_start, pci_resource_len(pdev, 1));
 out_err_regbase:
 	/*
 	 * Cleanup after anything that was remapped/allocated.
 	 */
-	if (default_par->regbase_virt)
-		iounmap(default_par->regbase_virt);
+	iounmap(default_par->regbase_virt);
 	release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
 out_err:
 	framebuffer_release(info);
drivers/video/fbdev/tgafb.c +1 -2
index 65ba992..b6fb7e8 100644
@@ -1520,8 +1520,7 @@ static int tgafb_register(struct device *dev)
  err2:
 	fb_dealloc_cmap(&info->cmap);
  err1:
-	if (mem_base)
-		iounmap(mem_base);
+	iounmap(mem_base);
 	release_mem_region(bar0_start, bar0_len);
  err0:
 	framebuffer_release(info);
drivers/video/fbdev/tridentfb.c +2 -4
index 7ed9a22..71567401 100644
@@ -1531,13 +1531,11 @@ static int trident_pci_probe(struct pci_dev *dev,
 
 out_unmap2:
 	kfree(info->pixmap.addr);
-	if (info->screen_base)
-		iounmap(info->screen_base);
+	iounmap(info->screen_base);
 	release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
 	disable_mmio(info->par);
 out_unmap1:
-	if (default_par->io_virt)
-		iounmap(default_par->io_virt);
+	iounmap(default_par->io_virt);
 	release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
 	framebuffer_release(info);
 	return err;
drivers/video/fbdev/valkyriefb.c +3 -6
index 275fb98..2a9213b 100644
@@ -400,12 +400,9 @@ int __init valkyriefb_init(void)
  out_cmap_free:
 	fb_dealloc_cmap(&p->info.cmap);
  out_free:
-	if (p->frame_buffer)
-		iounmap(p->frame_buffer);
-	if (p->cmap_regs)
-		iounmap(p->cmap_regs);
-	if (p->valkyrie_regs)
-		iounmap(p->valkyrie_regs);
+	iounmap(p->frame_buffer);
+	iounmap(p->cmap_regs);
+	iounmap(p->valkyrie_regs);
 	kfree(p);
 	return err;
 }
drivers/video/fbdev/vesafb.c +2 -4
index d79a0ac..693d18e 100644
@@ -176,8 +176,7 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
 static void vesafb_destroy(struct fb_info *info)
 {
 	fb_dealloc_cmap(&info->cmap);
-	if (info->screen_base)
-		iounmap(info->screen_base);
+	iounmap(info->screen_base);
 	release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size);
 }
 
@@ -492,8 +491,7 @@ static int vesafb_probe(struct platform_device *dev)
 	fb_info(info, "%s frame buffer device\n", info->fix.id);
 	return 0;
 err:
-	if (info->screen_base)
-		iounmap(info->screen_base);
+	iounmap(info->screen_base);
 	framebuffer_release(info);
 	release_mem_region(vesafb_fix.smem_start, size_total);
 	return err;
drivers/video/fbdev/w100fb.c +3 -6
index 10951c8..aeb53eb 100644
@@ -770,12 +770,9 @@ out:
 		fb_dealloc_cmap(&info->cmap);
 		kfree(info->pseudo_palette);
 	}
-	if (remapped_fbuf != NULL)
-		iounmap(remapped_fbuf);
-	if (remapped_regs != NULL)
-		iounmap(remapped_regs);
-	if (remapped_base != NULL)
-		iounmap(remapped_base);
+	iounmap(remapped_fbuf);
+	iounmap(remapped_regs);
+	iounmap(remapped_base);
 	if (info)
 		framebuffer_release(info);
 	return err;
Signature · 1 line
2.2.2
#730 lore raw

Re: [PATCH] MTD: Deletion of checks before the function call "iounmap"

In reply to Brian Norris
Quoted 2 lines

Anyway, I'm essentially saying that I'd like to be 100% sure we have a guarantee before dropping all these.

You can not be absolutely sure. There are various implementation details which will eventually need further considerations.

I hope that a reasonable confidence can be achieved here.

Quoted 3 lines
Quoted 1 line

This issue was detected by using the Coccinelle software.

What script?

I published scripts for static source code analysis in March 2004.

Quoted 1 line

Hand-rolled I guess?

An extended version found some update candidates in source files for Linux according to the software development status of "next-20141226".

My approach is still incomplete at the moment.

Regards,
Markus

#737 lore raw

Re: [PATCH] MTD: Deletion of checks before the function call "iounmap"

In reply to Brian Norris

The sparc iounmap() implementation in arch/sparc/kernel/ioport.c looks it prints an error message if you pass a NULL pointer.

regards,
dan carpenter

#744 lore raw

video: One function call less in tdfxfb_probe() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 18 Jan 2015 23:30:41 +0100

The iounmap() function could be called in two cases by the tdfxfb_probe() function during error handling even if the passed data structure element contained still a null pointer.

This implementation detail could be improved by adjustments for jump labels.

---
 drivers/video/fbdev/tdfxfb.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/video/fbdev/tdfxfb.c +9 -7
index 69d4062..c280a3b 100644
@@ -1438,20 +1438,20 @@ static int tdfxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (!default_par->regbase_virt) {
 		printk(KERN_ERR "fb: Can't remap %s register area.\n",
 				info->fix.id);
-		goto out_err_regbase;
+		goto release_memory_region_regbase;
 	}
 
 	info->fix.smem_start = pci_resource_start(pdev, 1);
 	info->fix.smem_len = do_lfb_size(default_par, pdev->device);
 	if (!info->fix.smem_len) {
 		printk(KERN_ERR "fb: Can't count %s memory.\n", info->fix.id);
-		goto out_err_regbase;
+		goto io_unmap_regbase;
 	}
 
 	if (!request_mem_region(info->fix.smem_start,
 				pci_resource_len(pdev, 1), "tdfx smem")) {
 		printk(KERN_ERR "tdfxfb: Can't reserve smem\n");
-		goto out_err_regbase;
+		goto io_unmap_regbase;
 	}
 
 	info->screen_base = ioremap_nocache(info->fix.smem_start,
@@ -1459,7 +1459,7 @@ static int tdfxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (!info->screen_base) {
 		printk(KERN_ERR "fb: Can't remap %s framebuffer.\n",
 				info->fix.id);
-		goto out_err_screenbase;
+		goto release_memory_region_screenbase;
 	}
 
 	default_par->iobase = pci_resource_start(pdev, 2);
@@ -1467,7 +1467,7 @@ static int tdfxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (!request_region(pci_resource_start(pdev, 2),
 			    pci_resource_len(pdev, 2), "tdfx iobase")) {
 		printk(KERN_ERR "tdfxfb: Can't reserve iobase\n");
-		goto out_err_screenbase;
+		goto io_unmap_screenbase;
 	}
 
 	printk(KERN_INFO "fb: %s memory = %dK\n", info->fix.id,
@@ -1571,14 +1571,16 @@ out_err_iobase:
 			 info->fix.smem_len);
 	release_region(pci_resource_start(pdev, 2),
 		       pci_resource_len(pdev, 2));
-out_err_screenbase:
+io_unmap_screenbase:
 	iounmap(info->screen_base);
+release_memory_region_screenbase:
 	release_mem_region(info->fix.smem_start, pci_resource_len(pdev, 1));
-out_err_regbase:
+io_unmap_regbase:
 	/*
 	 * Cleanup after anything that was remapped/allocated.
 	 */
 	iounmap(default_par->regbase_virt);
+release_memory_region_regbase:
 	release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
 out_err:
 	framebuffer_release(info);
Signature · 1 line
2.2.2
#745 lore raw

PATCH 3/9 video: One function call less in vesafb_probe() after, error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 19 Jan 2015 11:30:33 +0100

The iounmap() function could be called in two cases by the vesafb_probe() function during error handling even if the passed data structure element contained still a null pointer.

This implementation detail could be improved by adjustments for jump labels.

---
 drivers/video/fbdev/vesafb.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/video/fbdev/vesafb.c +3 -2
index 693d18e..de7cad0 100644
@@ -303,7 +303,7 @@ static int vesafb_probe(struct platform_device *dev)
 	info->apertures = alloc_apertures(1);
 	if (!info->apertures) {
 		err = -ENOMEM;
-		goto err;
+		goto release_framebuffer;
 	}
 	info->apertures->ranges[0].base = screen_info.lfb_base;
 	info->apertures->ranges[0].size = size_total;
@@ -462,7 +462,7 @@ static int vesafb_probe(struct platform_device *dev)
 		       "vesafb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n",
 			vesafb_fix.smem_len, vesafb_fix.smem_start);
 		err = -EIO;
-		goto err;
+		goto release_framebuffer;
 	}
 
 	printk(KERN_INFO "vesafb: framebuffer at 0x%lx, mapped to 0x%p, "
@@ -492,6 +492,7 @@ static int vesafb_probe(struct platform_device *dev)
 	return 0;
 err:
 	iounmap(info->screen_base);
+release_framebuffer:
 	framebuffer_release(info);
 	release_mem_region(vesafb_fix.smem_start, size_total);
 	return err;
Signature · 1 line
2.2.2
#731 lore raw

Re: [PATCH] MTD: Deletion of checks before the function call "iounmap"

In reply to SF Markus Elfring
Quoted 5 lines · SF Markus Elfring
Quoted 2 lines

Anyway, I'm essentially saying that I'd like to be 100% sure we have a guarantee before dropping all these.

You can not be absolutely sure. There are various implementation details which will eventually need further considerations.

Let's consider them first. We don't ship code that is missing the implementation details. (At least, we try not to!)

Quoted 8 lines

I hope that a reasonable confidence can be achieved here.

Quoted 3 lines
Quoted 1 line

This issue was detected by using the Coccinelle software.

What script?

I published scripts for static source code analysis in March 2004.

I didn't ask "when?"; where?

Quoted 6 lines
Quoted 1 line

Hand-rolled I guess?

An extended version found some update candidates in source files for Linux according to the software development status of "next-20141226".

My approach is still incomplete at the moment.

Then please complete it.

Thanks,
Brian

#738 lore raw

Re: [PATCH] MTD: Deletion of checks before the function call "iounmap"

In reply to Dan Carpenter
Quoted 2 lines · Dan Carpenter

The sparc iounmap() implementation in arch/sparc/kernel/ioport.c looks it prints an error message if you pass a NULL pointer.

Seems that way. Thanks.

Nak to the patch then.

Brian

#746 lore raw

PATCH 4/9 video: Add check for return value of ioremap() in cirrusfb_pci_register()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 19 Jan 2015 13:18:50 +0100

The return value from a call of the ioremap() function was not checked by the implementation of the cirrusfb_pci_register() function. Let us complete the corresponding error detection and exception handling at this source code place.

---
 drivers/video/fbdev/cirrusfb.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/video/fbdev/cirrusfb.c +7 -2
index d8b3359..aa4050c 100644
@@ -2111,6 +2111,10 @@ static int cirrusfb_pci_register(struct pci_dev *pdev,
 	/* FIXME: this forces VGA.  alternatives? */
 	cinfo->regbase = NULL;
 	cinfo->laguna_mmio = ioremap(info->fix.mmio_start, 0x1000);
+	if (!cinfo->laguna_mmio) {
+		ret = -EIO;
+		goto err_release_fb;
+	}
 
 	dev_dbg(info->device, "Board address: 0x%lx, register address: 0x%lx\n",
 		board_addr, info->fix.mmio_start);
@@ -2122,7 +2126,7 @@ static int cirrusfb_pci_register(struct pci_dev *pdev,
 	if (ret < 0) {
 		dev_err(info->device, "cannot reserve region 0x%lx, abort\n",
 			board_addr);
-		goto err_release_fb;
+		goto io_unmap_laguna;
 	}
 #if 0 /* if the system didn't claim this region, we would... */
 	if (!request_mem_region(0xA0000, 65535, "cirrusfb")) {
@@ -2163,8 +2167,9 @@ err_release_legacy:
 err_release_regions:
 #endif
 	pci_release_regions(pdev);
-err_release_fb:
+io_unmap_laguna:
 	iounmap(cinfo->laguna_mmio);
+err_release_fb:
 	framebuffer_release(info);
 err_out:
 	return ret;
Signature · 1 line
2.2.2
#747 lore raw

PATCH 5/9 video: Less function calls in trident_pci_probe() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 19 Jan 2015 14:18:47 +0100

The functions "iounmap" and "kfree" could be called in a few cases by the trident_pci_probe() function during error handling even if the passed data structure element contained still a null pointer.

This implementation detail could be improved by adjustments for jump labels.

---
 drivers/video/fbdev/tridentfb.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/video/fbdev/tridentfb.c +6 -3
index 71567401..86d4733 100644
@@ -1436,7 +1436,7 @@ static int trident_pci_probe(struct pci_dev *dev,
 	if (!default_par->io_virt) {
 		debug("ioremap failed\n");
 		err = -1;
-		goto out_unmap1;
+		goto release_memory_region_mmio;
 	}
 
 	enable_mmio(default_par);
@@ -1459,7 +1459,7 @@ static int trident_pci_probe(struct pci_dev *dev,
 	if (!info->screen_base) {
 		debug("ioremap failed\n");
 		err = -1;
-		goto out_unmap2;
+		goto release_memory_region_smem;
 	}
 
 	default_par->flatpanel = is_flatpanel(default_par);
@@ -1485,7 +1485,7 @@ static int trident_pci_probe(struct pci_dev *dev,
 	info->pixmap.addr = kmalloc(4096, GFP_KERNEL);
 	if (!info->pixmap.addr) {
 		err = -ENOMEM;
-		goto out_unmap2;
+		goto io_unmap_screenbase;
 	}
 
 	info->pixmap.size = 4096;
@@ -1531,11 +1531,14 @@ static int trident_pci_probe(struct pci_dev *dev,
 
 out_unmap2:
 	kfree(info->pixmap.addr);
+io_unmap_screenbase:
 	iounmap(info->screen_base);
+release_memory_region_smem:
 	release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
 	disable_mmio(info->par);
 out_unmap1:
 	iounmap(default_par->io_virt);
+release_memory_region_mmio:
 	release_mem_region(tridentfb_fix.mmio_start, tridentfb_fix.mmio_len);
 	framebuffer_release(info);
 	return err;
Signature · 1 line
2.2.2
#748 lore raw

PATCH 6/9 video: One function call less in pvr2fb_common_init() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 19 Jan 2015 14:50:44 +0100

The iounmap() function could be called in two cases by the pvr2fb_common_init() function during error handling even if the passed data structure element contained still a null pointer.

This implementation detail could be improved by adjustments for jump labels.

---
 drivers/video/fbdev/pvr2fb.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/video/fbdev/pvr2fb.c +6 -6
index 7aa4ef1..9fb8bbf 100644
@@ -773,14 +773,14 @@ static int pvr2fb_common_init(void)
 
 	if (!fb_info->screen_base) {
 		printk(KERN_ERR "pvr2fb: Failed to remap smem space\n");
-		goto out_err;
+		return -ENXIO;
 	}
 
 	par->mmio_base = (unsigned long)ioremap_nocache(pvr2_fix.mmio_start,
 							pvr2_fix.mmio_len);
 	if (!par->mmio_base) {
 		printk(KERN_ERR "pvr2fb: Failed to remap mmio space\n");
-		goto out_err;
+		goto io_unmap_screen;
 	}
 
 	fb_memset(fb_info->screen_base, 0, pvr2_fix.smem_len);
@@ -807,7 +807,7 @@ static int pvr2fb_common_init(void)
 	fb_alloc_cmap(&fb_info->cmap, 256, 0);
 
 	if (register_framebuffer(fb_info) < 0)
-		goto out_err;
+		goto io_unmap_mmio;
 	/*Must write PIXDEPTH to register before anything is displayed - so force init */
 	pvr2_init_display(fb_info);
 
@@ -840,10 +840,10 @@ static int pvr2fb_common_init(void)
 
 	return 0;
 
-out_err:
+io_unmap_mmio:
+	iounmap((void *)par->mmio_base);
+io_unmap_screen:
 	iounmap(fb_info->screen_base);
-	if (par->mmio_base)
-		iounmap((void *)par->mmio_base);
 
 	return -ENXIO;
 }
Signature · 1 line
2.2.2
#749 lore raw

PATCH 7/9 video: One function call less in tgafb_register() after, error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 19 Jan 2015 15:30:45 +0100

The iounmap() function could be called in one case by the tgafb_register() function during error handling even if the passed variable "mem_base" contained still a null pointer.

This implementation detail could be improved by adjustments for jump labels (according also to current Linux coding style).

---
 drivers/video/fbdev/tgafb.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/video/fbdev/tgafb.c +9 -8
index b6fb7e8..a3cd0ef 100644
@@ -1436,14 +1436,14 @@ static int tgafb_register(struct device *dev)
 	}
 	if (!request_mem_region (bar0_start, bar0_len, "tgafb")) {
 		printk(KERN_ERR "tgafb: cannot reserve FB region\n");
-		goto err0;
+		goto release_framebuffer;
 	}
 
 	/* Map the framebuffer.  */
 	mem_base = ioremap_nocache(bar0_start, bar0_len);
 	if (!mem_base) {
 		printk(KERN_ERR "tgafb: Cannot map MMIO\n");
-		goto err1;
+		goto release_memory_region;
 	}
 
 	/* Grab info about the card.  */
@@ -1484,13 +1484,13 @@ static int tgafb_register(struct device *dev)
 	if (ret = 0 || ret = 4) {
 		printk(KERN_ERR "tgafb: Could not find valid video mode\n");
 		ret = -EINVAL;
-		goto err1;
+		goto io_unmap;
 	}
 
 	if (fb_alloc_cmap(&info->cmap, 256, 0)) {
 		printk(KERN_ERR "tgafb: Could not allocate color map\n");
 		ret = -ENOMEM;
-		goto err1;
+		goto io_unmap;
 	}
 
 	tgafb_set_par(info);
@@ -1498,7 +1498,7 @@ static int tgafb_register(struct device *dev)
 	if (register_framebuffer(info) < 0) {
 		printk(KERN_ERR "tgafb: Could not register framebuffer\n");
 		ret = -EINVAL;
-		goto err2;
+		goto dealloc_cmap;
 	}
 
 	if (tga_bus_pci) {
@@ -1517,12 +1517,13 @@ static int tgafb_register(struct device *dev)
 
 	return 0;
 
- err2:
+dealloc_cmap:
 	fb_dealloc_cmap(&info->cmap);
- err1:
+io_unmap:
 	iounmap(mem_base);
+release_memory_region:
 	release_mem_region(bar0_start, bar0_len);
- err0:
+release_framebuffer:
 	framebuffer_release(info);
 	return ret;
 }
Signature · 1 line
2.2.2
#750 lore raw

PATCH 8/9 video: Less function calls in valkyriefb_init() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 19 Jan 2015 17:01:25 +0100

The iounmap() function could be called in three cases by the valkyriefb_init() function during error handling even if the passed data structure element contained still a null pointer.

This implementation detail could be improved by adjustments for jump labels (according also to current Linux coding style) and error messages.

---
 drivers/video/fbdev/valkyriefb.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)
drivers/video/fbdev/valkyriefb.c +21 -11
index 2a9213b..a81a0f1 100644
@@ -369,40 +369,50 @@ int __init valkyriefb_init(void)
 	}
 	p->total_vram = 0x100000;
 	p->frame_buffer_phys = frame_buffer_phys;
+	err = -ENOMEM;
 	p->frame_buffer = __ioremap(frame_buffer_phys, p->total_vram, flags);
+	if (p->frame_buffer = NULL) {
+		pr_err("%s: %s failed\n", __func__, "Frame buffer mapping");
+		goto free_memory;
+	}
 	p->cmap_regs_phys = cmap_regs_phys;
 	p->cmap_regs = ioremap(p->cmap_regs_phys, 0x1000);
+	if (p->cmap_regs = NULL) {
+		pr_err("%s: %s failed\n", __func__, "cmap");
+		goto io_unmap_framebuffer;
+	}
 	p->valkyrie_regs_phys = cmap_regs_phys+0x6000;
 	p->valkyrie_regs = ioremap(p->valkyrie_regs_phys, 0x1000);
-	err = -ENOMEM;
-	if (p->frame_buffer = NULL || p->cmap_regs = NULL
-	    || p->valkyrie_regs = NULL) {
-		printk(KERN_ERR "valkyriefb: couldn't map resources\n");
-		goto out_free;
+	if (p->valkyrie_regs = NULL) {
+		pr_err("%s: %s failed\n", __func__, "ioremap");
+		goto io_unmap_cmap;
 	}
 
 	valkyrie_choose_mode(p);
 	mac_vmode_to_var(default_vmode, default_cmode, &p->info.var);
 	err = valkyrie_init_info(&p->info, p);
 	if (err < 0)
-		goto out_free;
+		goto io_unmap_valkyrie;
 	valkyrie_init_fix(&p->info.fix, p);
 	if (valkyriefb_set_par(&p->info))
 		/* "can't happen" */
 		printk(KERN_ERR "valkyriefb: can't set default video mode\n");
 
 	if ((err = register_framebuffer(&p->info)) != 0)
-		goto out_cmap_free;
+		goto dealloc_cmap;
 
 	fb_info(&p->info, "valkyrie frame buffer device\n");
 	return 0;
 
- out_cmap_free:
+dealloc_cmap:
 	fb_dealloc_cmap(&p->info.cmap);
- out_free:
-	iounmap(p->frame_buffer);
-	iounmap(p->cmap_regs);
+io_unmap_valkyrie:
 	iounmap(p->valkyrie_regs);
+io_unmap_cmap:
+	iounmap(p->cmap_regs);
+io_unmap_framebuffer:
+	iounmap(p->frame_buffer);
+free_memory:
 	kfree(p);
 	return err;
 }
Signature · 1 line
2.2.2
#751 lore raw

PATCH 9/9 video: Less function calls in w100fb_probe() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 19 Jan 2015 17:56:11 +0100

The iounmap() function could be called in three cases by the w100fb_probe() function during error handling even if the passed data structure element contained still a null pointer.

* This implementation detail could be improved by adjustments for jump labels.

* Let us also delete two unnecessary null pointer checks for the variable "info".

---
 drivers/video/fbdev/w100fb.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)
drivers/video/fbdev/w100fb.c +17 -14
index aeb53eb..67ddc57 100644
@@ -645,12 +645,12 @@ int w100fb_probe(struct platform_device *pdev)
 	/* Remap the chip base address */
 	remapped_base = ioremap_nocache(mem->start+W100_CFG_BASE, W100_CFG_LEN);
 	if (remapped_base = NULL)
-		goto out;
+		goto exit;
 
 	/* Map the register space */
 	remapped_regs = ioremap_nocache(mem->start+W100_REG_BASE, W100_REG_LEN);
 	if (remapped_regs = NULL)
-		goto out;
+		goto io_unmap_base;
 
 	/* Identify the chip */
 	printk("Found ");
@@ -662,19 +662,19 @@ int w100fb_probe(struct platform_device *pdev)
 		default:
 			printk("Unknown imageon chip ID\n");
 			err = -ENODEV;
-			goto out;
+			goto io_unmap_regs;
 	}
 	printk(" at 0x%08lx.\n", (unsigned long) mem->start+W100_CFG_BASE);
 
 	/* Remap the framebuffer */
 	remapped_fbuf = ioremap_nocache(mem->start+MEM_WINDOW_BASE, MEM_WINDOW_SIZE);
 	if (remapped_fbuf = NULL)
-		goto out;
+		goto io_unmap_regs;
 
 	info=framebuffer_alloc(sizeof(struct w100fb_par), &pdev->dev);
 	if (!info) {
 		err = -ENOMEM;
-		goto out;
+		goto io_unmap_framebuffer;
 	}
 
 	par = info->par;
@@ -690,13 +690,13 @@ int w100fb_probe(struct platform_device *pdev)
 	if (!par->pll_table) {
 		printk(KERN_ERR "No matching Xtal definition found\n");
 		err = -EINVAL;
-		goto out;
+		goto release_framebuffer;
 	}
 
 	info->pseudo_palette = kmalloc(sizeof (u32) * MAX_PALETTES, GFP_KERNEL);
 	if (!info->pseudo_palette) {
 		err = -ENOMEM;
-		goto out;
+		goto release_framebuffer;
 	}
 
 	info->fbops = &w100fb_ops;
@@ -716,7 +716,7 @@ int w100fb_probe(struct platform_device *pdev)
 
 	if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
 		err = -ENOMEM;
-		goto out;
+		goto free_palette;
 	}
 
 	par->mode = &inf->modelist[0];
@@ -766,15 +766,18 @@ int w100fb_probe(struct platform_device *pdev)
 	fb_info(info, "%s frame buffer device\n", info->fix.id);
 	return 0;
 out:
-	if (info) {
-		fb_dealloc_cmap(&info->cmap);
-		kfree(info->pseudo_palette);
-	}
+	fb_dealloc_cmap(&info->cmap);
+free_palette:
+	kfree(info->pseudo_palette);
+release_framebuffer:
+	framebuffer_release(info);
+io_unmap_framebuffer:
 	iounmap(remapped_fbuf);
+io_unmap_regs:
 	iounmap(remapped_regs);
+io_unmap_base:
 	iounmap(remapped_base);
-	if (info)
-		framebuffer_release(info);
+exit:
 	return err;
 }
 
Signature · 1 line
2.2.2
#103 lore raw

Re: [PATCH 1/1] s390/net: Deletion of unnecessary checks before two function calls

In reply to Dan Carpenter

I went digging through some of Markus's old patch history, and noticed this...

Quoted 3 lines · Dan Carpenter

This one is buggy.

I'm sorry, but please stop sending these.

I'm tending to concur.

Quoted 9 lines

For kfree(), at least we all know that kfree() accepts NULL pointer. But for this one:
1) I don't know what the functions do so I have to look at the code.
2) It's in a arch that I don't compile so cscope isn't set up meaning it's hard to find the functions.

You're sending a lot of patches and they are all hard to review and some of them are buggy and none of them really add any value. It's a waste of your time and it's a waste of my time.

And you're still sending buggy patches that exhibit the same qualities. They're still wasting Dan's time, and now they're wasting mine.

I appreciate automated checkers where they provide added value, but I really feel you haven't done your diligence on them.

Regards,
Brian

#732 lore raw

Re: [PATCH] MTD: Deletion of checks before the function call "iounmap"

In reply to Brian Norris
Quoted 3 lines
Quoted 1 line

I published scripts for static source code analysis in March 2004.

I didn't ask "when?"; where?

https://lkml.org/lkml/2014/3/5/356
http://article.gmane.org/gmane.comp.version-control.coccinelle/3513/
https://systeme.lip6.fr/pipermail/cocci/2014-March/000676.html

Do you get further ideas from this software analysis approach?

Regards,
Markus

#733 lore raw

Re: [PATCH] MTD: Deletion of checks before the function call "iounmap"

Quoted 1 line · SF Markus Elfring
Quoted 1 line
Quoted 1 line

I published scripts for static source code analysis in March 2004.

^^ That would be March 2014, not March 2004.

Quoted 7 lines
Quoted 1 line

I didn't ask "when?"; where?

https://lkml.org/lkml/2014/3/5/356
http://article.gmane.org/gmane.comp.version-control.coccinelle/3513/
https://systeme.lip6.fr/pipermail/cocci/2014-March/000676.html

Do you get further ideas from this software analysis approach?

I suppose. I've gotten the idea that I can generate a ton of patches using an automated tool, not test or research them, possibly add bugs to the kernel, and still get a good percentage of my patches merged.

Now, have *you* learned anything from this approach?

Brian

#734 lore raw

Re: [PATCH] MTD: Deletion of checks before the function call "iounmap"

Quoted 1 line

Now, have *you* learned anything from this approach?

Yes, of course. ;-)

How would we like to tackle any corresponding software development challenges?

Regards,
Markus

#735 lore raw

Re: [PATCH] MTD: Deletion of checks before the function call "iounmap"

Replying, against my better judgment...

Quoted 3 lines · SF Markus Elfring
Quoted 1 line

Now, have *you* learned anything from this approach?

Yes, of course. ;-)

Do you have any evidence of this? Details? The only evidence I see is a long thread of similar patches from the last several months, of varying (though not increasing) quality. Prior objections to your approach were met with a distinct lack of self-awareness on your part.

Quoted 1 line

How would we like to tackle any corresponding software development challenges?

I don't really see many challenges here to tackle, except for the social issue of dealing with patch bots like you. Your automated patches are generally not solving real problems, but they are at times introducing bugs. So the most efficient "solution" to this "challenge" may simply be to ignore your patches.

Brian

#736 lore raw

Re: [PATCH] MTD: Deletion of checks before the function call "iounmap"

Quoted 2 lines

The only evidence I see is a long thread of similar patches from the last several months, of varying (though not increasing) quality.

I find it acceptable that some of my update suggestions do not fit to your quality expectations at the moment.

Quoted 2 lines

Prior objections to your approach were met with a distinct lack of self-awareness on your part.

I guess that a bit more clarification of this view will help to resolve some open issues, won't it?

Quoted 2 lines

I don't really see many challenges here to tackle, except for the social issue of dealing with patch bots like you.

I hope that you will like other automatic source code analysis results.

Quoted 1 line

Your automated patches are generally not solving real problems,

I try to clean-up Linux source files a bit. Problem solving with a higher value might follow ...

Quoted 1 line

but they are at times introducing bugs.

There are the usual different opinions and disagreements which might be still waiting for a constructive solution.

Regards,
Markus

#752 lore raw

PATCH 1/1 net: sched: One function call less in em_meta_change() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 17:18:48 +0100

The meta_delete() function could be called in four cases by the em_meta_change() function during error handling even if the passed variable "meta" contained still a null pointer.

* This implementation detail could be improved by adjustments for jump labels.

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Let us delete also unnecessary checks for the variables "err" and "meta" there.

---
 net/sched/em_meta.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
net/sched/em_meta.c +10 -10
index b5294ce..2aa67b1 100644
@@ -866,23 +866,23 @@ static int em_meta_change(struct net *net, void *data, int len,
 
 	err = nla_parse(tb, TCA_EM_META_MAX, data, len, meta_policy);
 	if (err < 0)
-		goto errout;
+		return err;
 
 	err = -EINVAL;
 	if (tb[TCA_EM_META_HDR] = NULL)
-		goto errout;
+		goto exit;
 	hdr = nla_data(tb[TCA_EM_META_HDR]);
 
 	if (TCF_META_TYPE(hdr->left.kind) != TCF_META_TYPE(hdr->right.kind) ||
 	    TCF_META_TYPE(hdr->left.kind) > TCF_META_TYPE_MAX ||
 	    TCF_META_ID(hdr->left.kind) > TCF_META_ID_MAX ||
 	    TCF_META_ID(hdr->right.kind) > TCF_META_ID_MAX)
-		goto errout;
+		goto exit;
 
 	meta = kzalloc(sizeof(*meta), GFP_KERNEL);
 	if (meta = NULL) {
 		err = -ENOMEM;
-		goto errout;
+		goto exit;
 	}
 
 	memcpy(&meta->lvalue.hdr, &hdr->left, sizeof(hdr->left));
@@ -891,20 +891,20 @@ static int em_meta_change(struct net *net, void *data, int len,
 	if (!meta_is_supported(&meta->lvalue) ||
 	    !meta_is_supported(&meta->rvalue)) {
 		err = -EOPNOTSUPP;
-		goto errout;
+		goto delete_meta;
 	}
 
 	if (meta_change_data(&meta->lvalue, tb[TCA_EM_META_LVALUE]) < 0 ||
 	    meta_change_data(&meta->rvalue, tb[TCA_EM_META_RVALUE]) < 0)
-		goto errout;
+		goto delete_meta;
 
 	m->datalen = sizeof(*meta);
 	m->data = (unsigned long) meta;
 
-	err = 0;
-errout:
-	if (err && meta)
-		meta_delete(meta);
+	return 0;
+delete_meta:
+	meta_delete(meta);
+exit:
 	return err;
 }
 
Signature · 1 line
2.2.2
#763 lore raw

PATCH 1/1 net: sctp: Deletion of an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 18:10:03 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 net/sctp/associola.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/sctp/associola.c +1 -2
index f791edd..3c2aefc 100644
@@ -391,8 +391,7 @@ void sctp_association_free(struct sctp_association *asoc)
 	sctp_asconf_queue_teardown(asoc);
 
 	/* Free pending address space being deleted */
-	if (asoc->asconf_addr_del_pending != NULL)
-		kfree(asoc->asconf_addr_del_pending);
+	kfree(asoc->asconf_addr_del_pending);
 
 	/* AUTH - Free the endpoint shared keys */
 	sctp_auth_destroy_keys(&asoc->endpoint_shared_keys);
Signature · 1 line
2.2.2
#753 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

In reply to SF Markus Elfring

Hi,

Quoted 68 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 17:18:48 +0100

The meta_delete() function could be called in four cases by the em_meta_change() function during error handling even if the passed variable "meta" contained still a null pointer.

* This implementation detail could be improved by adjustments for jump labels.

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Let us delete also unnecessary checks for the variables "err" and "meta" there.

---
 net/sched/em_meta.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
net/sched/em_meta.c +6 -6
index b5294ce..2aa67b1 100644
@@ -866,23 +866,23 @@ static int em_meta_change(struct net *net, void *data, int len,
 
 	err = nla_parse(tb, TCA_EM_META_MAX, data, len, meta_policy);
 	if (err < 0)
-		goto errout;
+		return err;
 
 	err = -EINVAL;
 	if (tb[TCA_EM_META_HDR] = NULL)
-		goto errout;
+		goto exit;
 	hdr = nla_data(tb[TCA_EM_META_HDR]);
 
 	if (TCF_META_TYPE(hdr->left.kind) != TCF_META_TYPE(hdr->right.kind) ||
 	    TCF_META_TYPE(hdr->left.kind) > TCF_META_TYPE_MAX ||
 	    TCF_META_ID(hdr->left.kind) > TCF_META_ID_MAX ||
 	    TCF_META_ID(hdr->right.kind) > TCF_META_ID_MAX)
-		goto errout;
+		goto exit;
 
 	meta = kzalloc(sizeof(*meta), GFP_KERNEL);
 	if (meta = NULL) {
 		err = -ENOMEM;
-		goto errout;
+		goto exit;
 	}
 
 	memcpy(&meta->lvalue.hdr, &hdr->left, sizeof(hdr->left));
@@ -891,20 +891,20 @@ static int em_meta_change(struct net *net, void *data, int len,
 	if (!meta_is_supported(&meta->lvalue) ||
 	    !meta_is_supported(&meta->rvalue)) {
 		err = -EOPNOTSUPP;
-		goto errout;
+		goto delete_meta;
 	}
 
 	if (meta_change_data(&meta->lvalue, tb[TCA_EM_META_LVALUE]) < 0 ||
 	    meta_change_data(&meta->rvalue, tb[TCA_EM_META_RVALUE]) < 0)
-		goto errout;
+		goto delete_meta;
 
 	m->datalen = sizeof(*meta);
 	m->data = (unsigned long) meta;
 

net/sched/em_meta.c static int em_meta_change(struct net *net, void *data, int len, · line 909

Quoted 10 lines
net/sched/em_meta.c +4 -4
-	err = 0;
-errout:
-	if (err && meta)
-		meta_delete(meta);
+	return 0;
+delete_meta:
+	meta_delete(meta);
+exit:
 	return err;
 }

Why do you use that exit label if it does nothing more than returning the error value? Also if nla_parse fails you dont use it but return the error directly. While using a label which is used only to return an error may be a matter of taste, its at least inconsistent to do both in a function, use such a label in one case and return immediately in another, isnt it?

Regards,
Lino

#758 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

In reply to SF Markus Elfring

net/sched/em_meta.c static int em_meta_change(struct net *net, void *data, int len, · line 907

Quoted 3 lines · SF Markus Elfring
net/sched/em_meta.c +0 -3
-errout:
-	if (err && meta)
-		meta_delete(meta);

Since this patch seems to be about optimization and cleanup you should probably also remove the now unnecessary initialization of "meta" with NULL at the beginning of the function...

Regards,
Lino

Acked-by on v1 1/1
#764 lore raw

Re: [PATCH] net: sctp: Deletion of an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring
Quoted 31 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 18:10:03 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 net/sctp/associola.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/sctp/associola.c +1 -2
index f791edd..3c2aefc 100644
@@ -391,8 +391,7 @@ void sctp_association_free(struct sctp_association *asoc)
 	sctp_asconf_queue_teardown(asoc);
 
 	/* Free pending address space being deleted */
-	if (asoc->asconf_addr_del_pending != NULL)
-		kfree(asoc->asconf_addr_del_pending);
+	kfree(asoc->asconf_addr_del_pending);
 
 	/* AUTH - Free the endpoint shared keys */
 	sctp_auth_destroy_keys(&asoc->endpoint_shared_keys);
Signature · 1 line
2.2.2

Sure, seems reasonable

#766 lore raw

cover netlabel: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 22:00:14 +0100

Further update suggestions were taken into account after patches were applied from static source code analysis.

Markus Elfring (3):
Deletion of an unnecessary check before the function call "cipso_v4_doi_putdef" Deletion of an unnecessary check before the function call "cipso_v4_doi_free" Less function calls in netlbl_mgmt_add_common() after error detection

 net/netlabel/netlabel_cipso_v4.c |  3 +--
 net/netlabel/netlabel_mgmt.c     | 47 ++++++++++++++++++++--------------------
 2 files changed, 24 insertions(+), 26 deletions(-)
Signature · 1 line
2.2.2
#767 lore raw

PATCH 1/3 netlabel: Deletion of an unnecessary check before the function call "cipso_v4_doi_putdef"

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 19:09:50 +0100

The cipso_v4_doi_putdef() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 net/netlabel/netlabel_mgmt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/netlabel/netlabel_mgmt.c +1 -2
index 8b3b789..f5807f5 100644
@@ -242,8 +242,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 	return 0;
 
 add_failure:
-	if (cipsov4)
-		cipso_v4_doi_putdef(cipsov4);
+	cipso_v4_doi_putdef(cipsov4);
 	if (entry)
 		kfree(entry->domain);
 	kfree(addrmap);
Signature · 1 line
2.2.2
#769 lore raw

PATCH 2/3 netlabel: Deletion of an unnecessary check before the function call "cipso_v4_doi_free"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 19:35:59 +0100

The cipso_v4_doi_free() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 net/netlabel/netlabel_cipso_v4.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/netlabel/netlabel_cipso_v4.c +1 -2
index 1796253..7fd1104 100644
@@ -324,8 +324,7 @@ static int netlbl_cipsov4_add_std(struct genl_info *info,
 	return 0;
 
 add_std_failure:
-	if (doi_def)
-		cipso_v4_doi_free(doi_def);
+	cipso_v4_doi_free(doi_def);
 	return ret_val;
 }
 
Signature · 1 line
2.2.2
#771 lore raw

PATCH 3/3 netlabel: Less function calls in netlbl_mgmt_add_common() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 21:55:48 +0100

The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases by the netlbl_mgmt_add_common() function during error handling even if the passed variables contained still a null pointer.

* This implementation detail could be improved by adjustments for jump labels.

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Let us delete also an unnecessary check for the variable "entry" there.

---
 net/netlabel/netlabel_mgmt.c | 46 ++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)
net/netlabel/netlabel_mgmt.c +23 -23
index f5807f5..17f1ed5 100644
@@ -99,17 +99,15 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 	u32 tmp_val;
 
 	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
-	if (entry = NULL) {
-		ret_val = -ENOMEM;
-		goto add_failure;
-	}
+	if (!entry)
+		return -ENOMEM;
 	entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]);
 	if (info->attrs[NLBL_MGMT_A_DOMAIN]) {
 		size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]);
 		entry->domain = kmalloc(tmp_size, GFP_KERNEL);
 		if (entry->domain = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto free_entry;
 		}
 		nla_strlcpy(entry->domain,
 			    info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size);
@@ -125,16 +123,16 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		break;
 	case NETLBL_NLTYPE_CIPSOV4:
 		if (!info->attrs[NLBL_MGMT_A_CV4DOI])
-			goto add_failure;
+			goto free_domain;
 
 		tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]);
 		cipsov4 = cipso_v4_doi_getdef(tmp_val);
 		if (cipsov4 = NULL)
-			goto add_failure;
+			goto free_domain;
 		entry->def.cipso = cipsov4;
 		break;
 	default:
-		goto add_failure;
+		goto free_domain;
 	}
 
 	if (info->attrs[NLBL_MGMT_A_IPV4ADDR]) {
@@ -145,7 +143,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
 		if (addrmap = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto doi_put_def;
 		}
 		INIT_LIST_HEAD(&addrmap->list4);
 		INIT_LIST_HEAD(&addrmap->list6);
@@ -153,12 +151,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV4ADDR]) ! 		    sizeof(struct in_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto free_address_map;
 		}
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV4MASK]) ! 		    sizeof(struct in_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto free_address_map;
 		}
 		addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]);
 		mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]);
@@ -166,7 +164,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		map = kzalloc(sizeof(*map), GFP_KERNEL);
 		if (map = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto free_address_map;
 		}
 		map->list.addr = addr->s_addr & mask->s_addr;
 		map->list.mask = mask->s_addr;
@@ -178,7 +176,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		ret_val = netlbl_af4list_add(&map->list, &addrmap->list4);
 		if (ret_val != 0) {
 			kfree(map);
-			goto add_failure;
+			goto free_address_map;
 		}
 
 		entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -192,7 +190,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
 		if (addrmap = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto doi_put_def;
 		}
 		INIT_LIST_HEAD(&addrmap->list4);
 		INIT_LIST_HEAD(&addrmap->list6);
@@ -200,12 +198,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV6ADDR]) ! 		    sizeof(struct in6_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto free_address_map;
 		}
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV6MASK]) ! 		    sizeof(struct in6_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto free_address_map;
 		}
 		addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]);
 		mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]);
@@ -213,7 +211,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		map = kzalloc(sizeof(*map), GFP_KERNEL);
 		if (map = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto free_address_map;
 		}
 		map->list.addr = *addr;
 		map->list.addr.s6_addr32[0] &= mask->s6_addr32[0];
@@ -227,7 +225,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		ret_val = netlbl_af6list_add(&map->list, &addrmap->list6);
 		if (ret_val != 0) {
 			kfree(map);
-			goto add_failure;
+			goto free_address_map;
 		}
 
 		entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -237,15 +235,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 
 	ret_val = netlbl_domhsh_add(entry, audit_info);
 	if (ret_val != 0)
-		goto add_failure;
+		goto free_address_map;
 
 	return 0;
 
-add_failure:
-	cipso_v4_doi_putdef(cipsov4);
-	if (entry)
-		kfree(entry->domain);
+free_address_map:
 	kfree(addrmap);
+doi_put_def:
+	cipso_v4_doi_putdef(cipsov4);
+free_domain:
+	kfree(entry->domain);
+free_entry:
 	kfree(entry);
 	return ret_val;
 }
Signature · 1 line
2.2.2
#754 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

In reply to Lino Sanfilippo
Quoted 10 lines

net/sched/em_meta.c static int em_meta_change(struct net *net, void *data, int len, · line 909

Quoted 3 lines
net/sched/em_meta.c +1 -0
+exit:
 	return err;
 }

Why do you use that exit label if it does nothing more than returning the error value? Also if nla_parse fails you dont use it but return the error directly. While using a label which is used only to return an error may be a matter of taste, its at least inconsistent to do both in a function, use such a label in one case and return immediately in another, isnt it?

I find that all these cases correspond to the current Linux coding style documentation, doesn't it?

Regards,
Markus

#759 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

In reply to Lino Sanfilippo
Quoted 7 lines

net/sched/em_meta.c static int em_meta_change(struct net *net, void *data, int len, · line 907

Quoted 3 lines
net/sched/em_meta.c +0 -3
-errout:
-	if (err && meta)
-		meta_delete(meta);

Since this patch seems to be about optimization and cleanup you should probably also remove the now unnecessary initialization of "meta" with NULL at the beginning of the function...

Will the optimiser of the C compiler drop any remaining unnecessary variable initialisations?

Do you want another update step here?

Regards,
Markus

#760 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

Quoted 11 lines · SF Markus Elfring
Quoted 7 lines

net/sched/em_meta.c static int em_meta_change(struct net *net, void *data, int len, · line 907

Quoted 3 lines
net/sched/em_meta.c +0 -3
-errout:
-	if (err && meta)
-		meta_delete(meta);

Since this patch seems to be about optimization and cleanup you should probably also remove the now unnecessary initialization of "meta" with NULL at the beginning of the function...

Will the optimiser of the C compiler drop any remaining unnecessary variable initialisations?

I dont know if that matters, since the code is not only used by compilers but also read by humans.

Quoted 2 lines

Do you want another update step here?

I am not the one who decides if this patch is acceptable or not. But I vote for a removal of that assignment (as a part of the same patch).

Regards,
Lino

#755 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

In reply to SF Markus Elfring
Quoted 4 lines · SF Markus Elfring

I find that all these cases correspond to the current Linux coding style documentation, doesn't it?

Sure, I think it does. But it was not coding style violation what I was reffering to.

Regards,
Lino

#756 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

Quoted 4 lines
Quoted 2 lines

I find that all these cases correspond to the current Linux coding style documentation, doesn't it?

Sure, I think it does.

Thanks for your acknowledgement.

Quoted 1 line

But it was not coding style violation what I was reffering to.

Do you suggest any fine-tuning for the affected documentation so that I would tweak my update suggestion once more?

Regards,
Markus

#757 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

Quoted 5 lines · SF Markus Elfring
Quoted 4 lines
Quoted 2 lines

I find that all these cases correspond to the current Linux coding style documentation, doesn't it?

Sure, I think it does.

Quoted 8 lines

Thanks for your acknowledgement.

Quoted 1 line

But it was not coding style violation what I was reffering to.

Do you suggest any fine-tuning for the affected documentation so that I would tweak my update suggestion once more?

No I dont think that any documentation has to be adjusted. If you agree with me you should adjust the patch accordingly and resend it. Otherwise keep it as it is.

Regards,
Lino

maintainer Acked-by on v1 1/3
#768 lore raw

Re: [PATCH 1/3] netlabel: Deletion of an unnecessary check before the function call "cipso_v4_doi_putdef"

In reply to SF Markus Elfring
Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 19:09:50 +0100

The cipso_v4_doi_putdef() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

Quoted 6 lines

This issue was detected by using the Coccinelle software.

---
 net/netlabel/netlabel_mgmt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 17 lines
net/netlabel/netlabel_mgmt.c +1 -3
index 8b3b789..f5807f5 100644
@@ -242,8 +242,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
        return 0;
 
 add_failure:
-       if (cipsov4)
-               cipso_v4_doi_putdef(cipsov4);
+       cipso_v4_doi_putdef(cipsov4);
        if (entry)
                kfree(entry->domain);
        kfree(addrmap);
--

2.2.2

Signature · 2 lines
paul moore
www.paul-moore.com
maintainer Acked-by on v1 2/3
#770 lore raw

Re: [PATCH 2/3] netlabel: Deletion of an unnecessary check before the function call "cipso_v4_doi_free"

In reply to SF Markus Elfring
Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 19:35:59 +0100

The cipso_v4_doi_free() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

Quoted 6 lines

This issue was detected by using the Coccinelle software.

---
 net/netlabel/netlabel_cipso_v4.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 17 lines
net/netlabel/netlabel_cipso_v4.c +1 -3
index 1796253..7fd1104 100644
@@ -324,8 +324,7 @@ static int netlbl_cipsov4_add_std(struct genl_info *info,
        return 0;
 
 add_std_failure:
-       if (doi_def)
-               cipso_v4_doi_free(doi_def);
+       cipso_v4_doi_free(doi_def);
        return ret_val;
 }
 
--

2.2.2

Signature · 2 lines
paul moore
www.paul-moore.com
maintainer
#772 lore raw

Re: [PATCH 3/3] netlabel: Less function calls in netlbl_mgmt_add_common() after error detection

In reply to SF Markus Elfring
Quoted 23 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 21:55:48 +0100

The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases by the netlbl_mgmt_add_common() function during error handling even if the passed variables contained still a null pointer.

* This implementation detail could be improved by adjustments for jump labels.

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Let us delete also an unnecessary check for the variable "entry" there.

---
 net/netlabel/netlabel_mgmt.c | 46 ++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)
net/netlabel/netlabel_mgmt.c +0 -0
index f5807f5..17f1ed5 100644

...

Quoted 13 lines
net/netlabel/netlabel_mgmt.c +1 -5
@@ -237,15 +235,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 
        ret_val = netlbl_domhsh_add(entry, audit_info);
        if (ret_val != 0)
-               goto add_failure;
+               goto free_address_map;
 
        return 0;
 
-add_failure:
-       cipso_v4_doi_putdef(cipsov4);
-       if (entry)
-               kfree(entry->domain);

net/netlabel/netlabel_mgmt.c static int netlbl_mgmt_add_common(struct genl_info *info, · line 251

Quoted 10 lines
net/netlabel/netlabel_mgmt.c +6 -0
+free_address_map:
        kfree(addrmap);
+doi_put_def:
+       cipso_v4_doi_putdef(cipsov4);
+free_domain:
+       kfree(entry->domain);
+free_entry:
        kfree(entry);
        return ret_val;
 }

It would be nice if you could stick with the goto label naming style in the rest of the file, e.g. "add_free_addrmap"/"add_put_doi_def"/"add_free_domain"/"add_free_entry".

Signature · 2 lines
paul moore
www.paul-moore.com
#773 lore raw

PATCH v2 3/3 netlabel: Less function calls in netlbl_mgmt_add_common() after error detection

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 11:11:29 +0100

The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases by the netlbl_mgmt_add_common() function during error handling even if the passed variables contained still a null pointer.

* This implementation detail could be improved by adjustments for jump labels.

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Let us delete also an unnecessary check for the variable "entry" there.

---
 net/netlabel/netlabel_mgmt.c | 49 ++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 25 deletions(-)
net/netlabel/netlabel_mgmt.c +24 -25
index f5807f5..7044074 100644
@@ -93,23 +93,20 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 				  struct netlbl_audit *audit_info)
 {
 	int ret_val = -EINVAL;
-	struct netlbl_dom_map *entry = NULL;
 	struct netlbl_domaddr_map *addrmap = NULL;
 	struct cipso_v4_doi *cipsov4 = NULL;
 	u32 tmp_val;
+	struct netlbl_dom_map *entry = kzalloc(sizeof(*entry), GFP_KERNEL);
 
-	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
-	if (entry = NULL) {
-		ret_val = -ENOMEM;
-		goto add_failure;
-	}
+	if (!entry)
+		return -ENOMEM;
 	entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]);
 	if (info->attrs[NLBL_MGMT_A_DOMAIN]) {
 		size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]);
 		entry->domain = kmalloc(tmp_size, GFP_KERNEL);
 		if (entry->domain = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_free_entry;
 		}
 		nla_strlcpy(entry->domain,
 			    info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size);
@@ -125,16 +122,16 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		break;
 	case NETLBL_NLTYPE_CIPSOV4:
 		if (!info->attrs[NLBL_MGMT_A_CV4DOI])
-			goto add_failure;
+			goto add_free_domain;
 
 		tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]);
 		cipsov4 = cipso_v4_doi_getdef(tmp_val);
 		if (cipsov4 = NULL)
-			goto add_failure;
+			goto add_free_domain;
 		entry->def.cipso = cipsov4;
 		break;
 	default:
-		goto add_failure;
+		goto add_free_domain;
 	}
 
 	if (info->attrs[NLBL_MGMT_A_IPV4ADDR]) {
@@ -145,7 +142,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
 		if (addrmap = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_doi_put_def;
 		}
 		INIT_LIST_HEAD(&addrmap->list4);
 		INIT_LIST_HEAD(&addrmap->list6);
@@ -153,12 +150,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV4ADDR]) ! 		    sizeof(struct in_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV4MASK]) ! 		    sizeof(struct in_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]);
 		mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]);
@@ -166,7 +163,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		map = kzalloc(sizeof(*map), GFP_KERNEL);
 		if (map = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		map->list.addr = addr->s_addr & mask->s_addr;
 		map->list.mask = mask->s_addr;
@@ -178,7 +175,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		ret_val = netlbl_af4list_add(&map->list, &addrmap->list4);
 		if (ret_val != 0) {
 			kfree(map);
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 
 		entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -192,7 +189,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
 		if (addrmap = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_doi_put_def;
 		}
 		INIT_LIST_HEAD(&addrmap->list4);
 		INIT_LIST_HEAD(&addrmap->list6);
@@ -200,12 +197,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV6ADDR]) ! 		    sizeof(struct in6_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV6MASK]) ! 		    sizeof(struct in6_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]);
 		mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]);
@@ -213,7 +210,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		map = kzalloc(sizeof(*map), GFP_KERNEL);
 		if (map = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		map->list.addr = *addr;
 		map->list.addr.s6_addr32[0] &= mask->s6_addr32[0];
@@ -227,7 +224,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		ret_val = netlbl_af6list_add(&map->list, &addrmap->list6);
 		if (ret_val != 0) {
 			kfree(map);
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 
 		entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -237,15 +234,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 
 	ret_val = netlbl_domhsh_add(entry, audit_info);
 	if (ret_val != 0)
-		goto add_failure;
+		goto add_free_addrmap;
 
 	return 0;
 
-add_failure:
-	cipso_v4_doi_putdef(cipsov4);
-	if (entry)
-		kfree(entry->domain);
+add_free_addrmap:
 	kfree(addrmap);
+add_doi_put_def:
+	cipso_v4_doi_putdef(cipsov4);
+add_free_domain:
+	kfree(entry->domain);
+add_free_entry:
 	kfree(entry);
 	return ret_val;
 }
Signature · 1 line
2.2.2
maintainer Acked-by on v2 3/3
#774 lore raw

Re: [PATCH v2 3/3] netlabel: Less function calls in netlbl_mgmt_add_common() after error detection

Quoted 12 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 11:11:29 +0100

The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases by the netlbl_mgmt_add_common() function during error handling even if the passed variables contained still a null pointer.

* This implementation detail could be improved by adjustments for jump labels.

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

Quoted 6 lines

* Let us delete also an unnecessary check for the variable "entry" there.

---
 net/netlabel/netlabel_mgmt.c | 49 ++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 25 deletions(-)

Thanks for fixing the label names.

Quoted 158 lines
net/netlabel/netlabel_mgmt.c +24 -26
index f5807f5..7044074 100644
@@ -93,23 +93,20 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                                  struct netlbl_audit *audit_info)
 {
        int ret_val = -EINVAL;
-       struct netlbl_dom_map *entry = NULL;
        struct netlbl_domaddr_map *addrmap = NULL;
        struct cipso_v4_doi *cipsov4 = NULL;
        u32 tmp_val;
+       struct netlbl_dom_map *entry = kzalloc(sizeof(*entry), GFP_KERNEL);
 
-       entry = kzalloc(sizeof(*entry), GFP_KERNEL);
-       if (entry = NULL) {
-               ret_val = -ENOMEM;
-               goto add_failure;
-       }
+       if (!entry)
+               return -ENOMEM;
        entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]);
        if (info->attrs[NLBL_MGMT_A_DOMAIN]) {
                size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]);
                entry->domain = kmalloc(tmp_size, GFP_KERNEL);
                if (entry->domain = NULL) {
                        ret_val = -ENOMEM;
-                       goto add_failure;
+                       goto add_free_entry;
                }
                nla_strlcpy(entry->domain,
                            info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size);
@@ -125,16 +122,16 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                break;
        case NETLBL_NLTYPE_CIPSOV4:
                if (!info->attrs[NLBL_MGMT_A_CV4DOI])
-                       goto add_failure;
+                       goto add_free_domain;
 
                tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]);
                cipsov4 = cipso_v4_doi_getdef(tmp_val);
                if (cipsov4 = NULL)
-                       goto add_failure;
+                       goto add_free_domain;
                entry->def.cipso = cipsov4;
                break;
        default:
-               goto add_failure;
+               goto add_free_domain;
        }
 
        if (info->attrs[NLBL_MGMT_A_IPV4ADDR]) {
@@ -145,7 +142,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
                if (addrmap = NULL) {
                        ret_val = -ENOMEM;
-                       goto add_failure;
+                       goto add_doi_put_def;
                }
                INIT_LIST_HEAD(&addrmap->list4);
                INIT_LIST_HEAD(&addrmap->list6);
@@ -153,12 +150,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                if (nla_len(info->attrs[NLBL_MGMT_A_IPV4ADDR]) !>                     sizeof(struct in_addr)) {
                        ret_val = -EINVAL;
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
                if (nla_len(info->attrs[NLBL_MGMT_A_IPV4MASK]) !>                     sizeof(struct in_addr)) {
                        ret_val = -EINVAL;
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
                addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]);
                mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]);
@@ -166,7 +163,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                map = kzalloc(sizeof(*map), GFP_KERNEL);
                if (map = NULL) {
                        ret_val = -ENOMEM;
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
                map->list.addr = addr->s_addr & mask->s_addr;
                map->list.mask = mask->s_addr;
@@ -178,7 +175,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                ret_val = netlbl_af4list_add(&map->list, &addrmap->list4);
                if (ret_val != 0) {
                        kfree(map);
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
 
                entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -192,7 +189,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
                if (addrmap = NULL) {
                        ret_val = -ENOMEM;
-                       goto add_failure;
+                       goto add_doi_put_def;
                }
                INIT_LIST_HEAD(&addrmap->list4);
                INIT_LIST_HEAD(&addrmap->list6);
@@ -200,12 +197,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                if (nla_len(info->attrs[NLBL_MGMT_A_IPV6ADDR]) !>                     sizeof(struct in6_addr)) {
                        ret_val = -EINVAL;
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
                if (nla_len(info->attrs[NLBL_MGMT_A_IPV6MASK]) !>                     sizeof(struct in6_addr)) {
                        ret_val = -EINVAL;
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
                addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]);
                mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]);
@@ -213,7 +210,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                map = kzalloc(sizeof(*map), GFP_KERNEL);
                if (map = NULL) {
                        ret_val = -ENOMEM;
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
                map->list.addr = *addr;
                map->list.addr.s6_addr32[0] &= mask->s6_addr32[0];
@@ -227,7 +224,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                ret_val = netlbl_af6list_add(&map->list, &addrmap->list6);
                if (ret_val != 0) {
                        kfree(map);
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
 
                entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -237,15 +234,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 
        ret_val = netlbl_domhsh_add(entry, audit_info);
        if (ret_val != 0)
-               goto add_failure;
+               goto add_free_addrmap;
 
        return 0;
 
-add_failure:
-       cipso_v4_doi_putdef(cipsov4);
-       if (entry)
-               kfree(entry->domain);
+add_free_addrmap:
        kfree(addrmap);
+add_doi_put_def:
+       cipso_v4_doi_putdef(cipsov4);
+add_free_domain:
+       kfree(entry->domain);
+add_free_entry:
        kfree(entry);
        return ret_val;
 }
--

2.2.2

Signature · 2 lines
paul moore
www.paul-moore.com
#780 lore raw

PATCH 1/1 jfs: Deletion of an unnecessary check before the function call "unload_nls"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 17:00:24 +0100

The unload_nls() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 fs/jfs/super.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/jfs/super.c +1 -2
index 16c3a95..5d30c56 100644
@@ -619,8 +619,7 @@ out_mount_failed:
 	iput(sbi->direct_inode);
 	sbi->direct_inode = NULL;
 out_unload:
-	if (sbi->nls_tab)
-		unload_nls(sbi->nls_tab);
+	unload_nls(sbi->nls_tab);
 out_kfree:
 	kfree(sbi);
 	return ret;
Signature · 1 line
2.2.2
#782 lore raw

PATCH 1/1 staging: gdm72xx: Deletion of an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 18:28:33 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/staging/gdm72xx/gdm_wimax.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gdm72xx/gdm_wimax.c +1 -1
index 9cab54b..ac901e6 100644
@@ -362,7 +362,7 @@ static int gdm_wimax_close(struct net_device *dev)
 
 static void kdelete(void **buf)
 {
-	if (buf && *buf) {
+	if (buf) {
 		kfree(*buf);
 		*buf = NULL;
 	}
Signature · 1 line
2.2.2
#783 lore raw

Re: [PATCH] staging: gdm72xx: Deletion of an unnecessary check before the function call "kfree"

Quoted 18 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 18:28:33 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/staging/gdm72xx/gdm_wimax.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gdm72xx/gdm_wimax.c +0 -0
index 9cab54b..ac901e6 100644

drivers/staging/gdm72xx/gdm_wimax.c static int gdm_wimax_close(struct net_device *dev) · line 368

Quoted 8 lines
drivers/staging/gdm72xx/gdm_wimax.c +1 -1
@@ -362,7 +362,7 @@ static int gdm_wimax_close(struct net_device *dev)
 
 static void kdelete(void **buf)
 {
-	if (buf && *buf) {
+	if (buf) {
 		kfree(*buf);
 		*buf = NULL;
 	}

Instead we should delete this function and have the driver use the "correct" kfree calls instead, right? That extra setting the buffer to NULL is a waste for most of these calls.

thanks,

greg k-h

#784 lore raw

cover mn88472: Delete an unnecessary check

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 20:00:17 +0100

Another update suggestion was taken into account after a patch was applied from static source code analysis.

Markus Elfring (2):
Deletion of an unnecessary check before the function call "release_firmware" One function call less in mn88472_init() after error detection

 drivers/staging/media/mn88472/mn88472.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
Signature · 1 line
2.2.2
#785 lore raw

PATCH 1/2 mn88472: Deletion of an unnecessary check before the function call "release_firmware"

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 19:12:56 +0100

The release_firmware() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/staging/media/mn88472/mn88472.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/media/mn88472/mn88472.c +1 -2
index 52de8f8..e7874ae 100644
@@ -315,8 +315,7 @@ static int mn88472_init(struct dvb_frontend *fe)
 
 	return 0;
 err:
-	if (fw)
-		release_firmware(fw);
+	release_firmware(fw);
 
 	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
Signature · 1 line
2.2.2
#786 lore raw

PATCH 2/2 mn88472: One function call less in mn88472_init() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 19:34:37 +0100

The release_firmware() function was called in three cases by the mn88472_init() function during error handling even if the passed variable "fw" contained still a null pointer.

This implementation detail could be improved by the introduction of another jump label.

---
 drivers/staging/media/mn88472/mn88472.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/staging/media/mn88472/mn88472.c +5 -5
index e7874ae..3975a57 100644
@@ -286,7 +286,7 @@ static int mn88472_init(struct dvb_frontend *fe)
 
 	ret = regmap_write(dev->regmap[0], 0xf5, 0x03);
 	if (ret)
-		goto err;
+		goto firmware_release;
 
 	for (remaining = fw->size; remaining > 0;
 			remaining -= (dev->i2c_wr_max - 1)) {
@@ -299,13 +299,13 @@ static int mn88472_init(struct dvb_frontend *fe)
 		if (ret) {
 			dev_err(&client->dev,
 					"firmware download failed=%d\n", ret);
-			goto err;
+			goto firmware_release;
 		}
 	}
 
 	ret = regmap_write(dev->regmap[0], 0xf5, 0x00);
 	if (ret)
-		goto err;
+		goto firmware_release;
 
 	release_firmware(fw);
 	fw = NULL;
@@ -314,9 +314,9 @@ static int mn88472_init(struct dvb_frontend *fe)
 	dev->warm = true;
 
 	return 0;
-err:
+firmware_release:
 	release_firmware(fw);
-
+err:
 	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
Signature · 1 line
2.2.2
maintainer
#775 lore raw

Re: [PATCH v2 3/3] netlabel: Less function calls in netlbl_mgmt_add_common() after error detection

In reply to SF Markus Elfring

When you post a new version of a patch within a series, you must repost the entire series, not just the patch which is changing.

Thanks.

#776 lore raw

v3 cover netlabel: Deletion of a few unnecessary checks

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 11:15:56 +0100

Further update suggestions were taken into account after patches were applied from static source code analysis.

Markus Elfring (3):
Deletion of an unnecessary check before the function call "cipso_v4_doi_putdef" Deletion of an unnecessary check before the function call "cipso_v4_doi_free" Less function calls in netlbl_mgmt_add_common() after error detection

 net/netlabel/netlabel_cipso_v4.c |  3 +--
 net/netlabel/netlabel_mgmt.c     | 50 +++++++++++++++++++---------------------
 2 files changed, 25 insertions(+), 28 deletions(-)
Signature · 1 line
2.2.2
#777 lore raw

PATCH v3 1/3 netlabel: Deletion of an unnecessary check before the function call "cipso_v4_doi_putdef"

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 10:01:45 +0100

The cipso_v4_doi_putdef() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 net/netlabel/netlabel_mgmt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/netlabel/netlabel_mgmt.c +1 -2
index 8b3b789..f5807f5 100644
@@ -242,8 +242,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 	return 0;
 
 add_failure:
-	if (cipsov4)
-		cipso_v4_doi_putdef(cipsov4);
+	cipso_v4_doi_putdef(cipsov4);
 	if (entry)
 		kfree(entry->domain);
 	kfree(addrmap);
Signature · 1 line
2.2.2
#778 lore raw

PATCH v3 2/3 netlabel: Deletion of an unnecessary check before the function call "cipso_v4_doi_free"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 10:40:30 +0100

The cipso_v4_doi_free() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 net/netlabel/netlabel_cipso_v4.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/netlabel/netlabel_cipso_v4.c +1 -2
index 1796253..7fd1104 100644
@@ -324,8 +324,7 @@ static int netlbl_cipsov4_add_std(struct genl_info *info,
 	return 0;
 
 add_std_failure:
-	if (doi_def)
-		cipso_v4_doi_free(doi_def);
+	cipso_v4_doi_free(doi_def);
 	return ret_val;
 }
 
Signature · 1 line
2.2.2
#779 lore raw

PATCH v3 3/3 netlabel: Less function calls in netlbl_mgmt_add_common() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 11:00:24 +0100

The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases by the netlbl_mgmt_add_common() function during error handling even if the passed variables contained still a null pointer.

* This implementation detail could be improved by adjustments for jump labels.

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Let us delete also an unnecessary check for the variable "entry" there.

---
 net/netlabel/netlabel_mgmt.c | 49 ++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 25 deletions(-)
net/netlabel/netlabel_mgmt.c +24 -25
index f5807f5..7044074 100644
@@ -93,23 +93,20 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 				  struct netlbl_audit *audit_info)
 {
 	int ret_val = -EINVAL;
-	struct netlbl_dom_map *entry = NULL;
 	struct netlbl_domaddr_map *addrmap = NULL;
 	struct cipso_v4_doi *cipsov4 = NULL;
 	u32 tmp_val;
+	struct netlbl_dom_map *entry = kzalloc(sizeof(*entry), GFP_KERNEL);
 
-	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
-	if (entry = NULL) {
-		ret_val = -ENOMEM;
-		goto add_failure;
-	}
+	if (!entry)
+		return -ENOMEM;
 	entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]);
 	if (info->attrs[NLBL_MGMT_A_DOMAIN]) {
 		size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]);
 		entry->domain = kmalloc(tmp_size, GFP_KERNEL);
 		if (entry->domain = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_free_entry;
 		}
 		nla_strlcpy(entry->domain,
 			    info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size);
@@ -125,16 +122,16 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		break;
 	case NETLBL_NLTYPE_CIPSOV4:
 		if (!info->attrs[NLBL_MGMT_A_CV4DOI])
-			goto add_failure;
+			goto add_free_domain;
 
 		tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]);
 		cipsov4 = cipso_v4_doi_getdef(tmp_val);
 		if (cipsov4 = NULL)
-			goto add_failure;
+			goto add_free_domain;
 		entry->def.cipso = cipsov4;
 		break;
 	default:
-		goto add_failure;
+		goto add_free_domain;
 	}
 
 	if (info->attrs[NLBL_MGMT_A_IPV4ADDR]) {
@@ -145,7 +142,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
 		if (addrmap = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_doi_put_def;
 		}
 		INIT_LIST_HEAD(&addrmap->list4);
 		INIT_LIST_HEAD(&addrmap->list6);
@@ -153,12 +150,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV4ADDR]) ! 		    sizeof(struct in_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV4MASK]) ! 		    sizeof(struct in_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]);
 		mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]);
@@ -166,7 +163,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		map = kzalloc(sizeof(*map), GFP_KERNEL);
 		if (map = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		map->list.addr = addr->s_addr & mask->s_addr;
 		map->list.mask = mask->s_addr;
@@ -178,7 +175,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		ret_val = netlbl_af4list_add(&map->list, &addrmap->list4);
 		if (ret_val != 0) {
 			kfree(map);
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 
 		entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -192,7 +189,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
 		if (addrmap = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_doi_put_def;
 		}
 		INIT_LIST_HEAD(&addrmap->list4);
 		INIT_LIST_HEAD(&addrmap->list6);
@@ -200,12 +197,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV6ADDR]) ! 		    sizeof(struct in6_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV6MASK]) ! 		    sizeof(struct in6_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]);
 		mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]);
@@ -213,7 +210,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		map = kzalloc(sizeof(*map), GFP_KERNEL);
 		if (map = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		map->list.addr = *addr;
 		map->list.addr.s6_addr32[0] &= mask->s6_addr32[0];
@@ -227,7 +224,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		ret_val = netlbl_af6list_add(&map->list, &addrmap->list6);
 		if (ret_val != 0) {
 			kfree(map);
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 
 		entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -237,15 +234,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 
 	ret_val = netlbl_domhsh_add(entry, audit_info);
 	if (ret_val != 0)
-		goto add_failure;
+		goto add_free_addrmap;
 
 	return 0;
 
-add_failure:
-	cipso_v4_doi_putdef(cipsov4);
-	if (entry)
-		kfree(entry->domain);
+add_free_addrmap:
 	kfree(addrmap);
+add_doi_put_def:
+	cipso_v4_doi_putdef(cipsov4);
+add_free_domain:
+	kfree(entry->domain);
+add_free_entry:
 	kfree(entry);
 	return ret_val;
 }
Signature · 1 line
2.2.2
#787 lore raw

[media] staging: bcm2048: Delete an unnecessary check before the function call "video_unregister_device"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 13:20:23 +0100

The video_unregister_device() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/staging/media/bcm2048/radio-bcm2048.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/media/bcm2048/radio-bcm2048.c +1 -3
index 60a57b2..f308078 100644
@@ -2684,9 +2684,7 @@ static int __exit bcm2048_i2c_driver_remove(struct i2c_client *client)
 		vd = bdev->videodev;
 
 		bcm2048_sysfs_unregister_properties(bdev, ARRAY_SIZE(attrs));
-
-		if (vd)
-			video_unregister_device(vd);
+		video_unregister_device(vd);
 
 		if (bdev->power_state)
 			bcm2048_set_power_state(bdev, BCM2048_POWER_OFF);
Signature · 1 line
2.2.2
#788 lore raw

cover md: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:51:43 +0100

Further update suggestions were taken into account together with results from static source code analysis.

Markus Elfring (3):
dm snapshot: Deletion of unnecessary checks before the function call "vfree" md/bitmap: Delete an unnecessary check before the function call "kfree" dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy"

 drivers/md/bitmap.c             | 10 +++++-----
 drivers/md/dm-ioctl.c           |  3 +--
 drivers/md/dm-snap-persistent.c | 14 ++++----------
 3 files changed, 10 insertions(+), 17 deletions(-)
Signature · 1 line
2.2.2
#789 lore raw

PATCH 1/3 dm snapshot: Deletion of unnecessary checks before the function call "vfree"

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 14:38:29 +0100

The vfree() function performs also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/md/dm-snap-persistent.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/md/dm-snap-persistent.c +4 -10
index d6e8817..808b841 100644
@@ -200,16 +200,11 @@ err_area:
 
 static void free_area(struct pstore *ps)
 {
-	if (ps->area)
-		vfree(ps->area);
+	vfree(ps->area);
 	ps->area = NULL;
-
-	if (ps->zero_area)
-		vfree(ps->zero_area);
+	vfree(ps->zero_area);
 	ps->zero_area = NULL;
-
-	if (ps->header_area)
-		vfree(ps->header_area);
+	vfree(ps->header_area);
 	ps->header_area = NULL;
 }
 
@@ -605,8 +600,7 @@ static void persistent_dtr(struct dm_exception_store *store)
 	free_area(ps);
 
 	/* Allocated in persistent_read_metadata */
-	if (ps->callbacks)
-		vfree(ps->callbacks);
+	vfree(ps->callbacks);
 
 	kfree(ps);
 }
Signature · 1 line
2.2.2
#790 lore raw

PATCH 2/3 md/bitmap: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:10:57 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

* This issue was detected by using the Coccinelle software.

* Let us also move an assignment for the variable "pages" to the place directly before it is really needed for a loop.

* Let us also move another kfree() call into a block which should belong to a previous check for the variable "bp".

---
 drivers/md/bitmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +5 -5
index da3604e..47d72df 100644
@@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
 	bitmap_file_unmap(&bitmap->storage);
 
 	bp = bitmap->counts.bp;
-	pages = bitmap->counts.pages;
 
 	/* free all allocated memory */
-
-	if (bp) /* deallocate the page memory */
+	if (bp) { /* deallocate the page memory */
+		pages = bitmap->counts.pages;
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
-	kfree(bp);
+		kfree(bp);
+	}
 	kfree(bitmap);
 }
 
Signature · 1 line
2.2.2
#797 lore raw

PATCH 3/3 dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:30:37 +0100

The dm_table_destroy() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/md/dm-ioctl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/dm-ioctl.c +1 -2
index 73f791b..4fac6cf 100644
@@ -1053,8 +1053,7 @@ static int do_resume(struct dm_ioctl *param)
 	 * Since dm_swap_table synchronizes RCU, nobody should be in
 	 * read-side critical section already.
 	 */
-	if (old_map)
-		dm_table_destroy(old_map);
+	dm_table_destroy(old_map);
 
 	if (!r)
 		__dev_status(md, param);
Signature · 1 line
2.2.2
#802 lore raw

PATCH 1/1 EDAC: Deletion of unnecessary checks before the function call "pci_dev_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 18:26:34 +0100

The pci_dev_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/edac/i82443bxgx_edac.c | 4 +---
 drivers/edac/i82860_edac.c     | 9 ++-------
 drivers/edac/i82875p_edac.c    | 4 +---
 drivers/edac/i82975x_edac.c    | 4 +---
 4 files changed, 5 insertions(+), 16 deletions(-)
drivers/edac/i82443bxgx_edac.c +1 -3
index b4705d9..38d6406 100644
@@ -445,9 +445,7 @@ fail1:
 	pci_unregister_driver(&i82443bxgx_edacmc_driver);
 
 fail0:
-	if (mci_pdev != NULL)
-		pci_dev_put(mci_pdev);
-
+	pci_dev_put(mci_pdev);
 	return pci_rc;
 }
 
drivers/edac/i82860_edac.c +2 -7
index 4382343..ee1078c 100644
@@ -343,20 +343,15 @@ fail1:
 	pci_unregister_driver(&i82860_driver);
 
 fail0:
-	if (mci_pdev != NULL)
-		pci_dev_put(mci_pdev);
-
+	pci_dev_put(mci_pdev);
 	return pci_rc;
 }
 
 static void __exit i82860_exit(void)
 {
 	edac_dbg(3, "\n");
-
 	pci_unregister_driver(&i82860_driver);
-
-	if (mci_pdev != NULL)
-		pci_dev_put(mci_pdev);
+	pci_dev_put(mci_pdev);
 }
 
 module_init(i82860_init);
drivers/edac/i82875p_edac.c +1 -3
index 64b6832..c26a513 100644
@@ -576,9 +576,7 @@ fail1:
 	pci_unregister_driver(&i82875p_driver);
 
 fail0:
-	if (mci_pdev != NULL)
-		pci_dev_put(mci_pdev);
-
+	pci_dev_put(mci_pdev);
 	return pci_rc;
 }
 
drivers/edac/i82975x_edac.c +1 -3
index 10b1052..35ab66c 100644
@@ -685,9 +685,7 @@ fail1:
 	pci_unregister_driver(&i82975x_driver);
 
 fail0:
-	if (mci_pdev != NULL)
-		pci_dev_put(mci_pdev);
-
+	pci_dev_put(mci_pdev);
 	return pci_rc;
 }
 
Signature · 1 line
2.2.2
#791 lore raw

Re: [PATCH 2/3] md/bitmap: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring
Quoted 34 lines · On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:10:57 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

* This issue was detected by using the Coccinelle software.

* Let us also move an assignment for the variable "pages" to the place directly before it is really needed for a loop.

* Let us also move another kfree() call into a block which should belong to a previous check for the variable "bp".

---
 drivers/md/bitmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +2 -3
index da3604e..47d72df 100644
@@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
 	bitmap_file_unmap(&bitmap->storage);
 
 	bp = bitmap->counts.bp;
-	pages = bitmap->counts.pages;
 
 	/* free all allocated memory */
-
-	if (bp) /* deallocate the page memory */
+	if (bp) { /* deallocate the page memory */
+		pages = bitmap->counts.pages;

drivers/md/bitmap.c static void bitmap_free(struct bitmap *bitmap) · line 1600

Quoted 10 lines
drivers/md/bitmap.c +3 -2
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
-	kfree(bp);
+		kfree(bp);
+	}
 	kfree(bitmap);
 }
 

Hi,
I'm somewhat amused that you removed a test for one kfree, but imposed a test on another. I realised the second test was already there, but why not just:

drivers/md/bitmap.c +1 -1
index da3604e73e8a..ad13b2e1bf1f 100644
@@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap)
 
 	if (bp) /* deallocate the page memory */
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
 	kfree(bp);
 	kfree(bitmap);

It makes the intention of the patch much clearer.

I'd probably prefer to leave the code as it is. I don't think either patch is really an improvement in readability, and readability trumps performance in places like this.

Thanks,
NeilBrown

#804 lore raw

PATCH 1/1 ata: Delete unnecessary checks before the function call "pci_dev_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 22:08:29 +0100

The pci_dev_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/ata/pata_cs5530.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/ata/pata_cs5530.c +2 -4
index 48ae4b4..f9ca72e 100644
@@ -276,10 +276,8 @@ static int cs5530_init_chip(void)
 	pci_dev_put(cs5530_0);
 	return 0;
 fail_put:
-	if (master_0)
-		pci_dev_put(master_0);
-	if (cs5530_0)
-		pci_dev_put(cs5530_0);
+	pci_dev_put(master_0);
+	pci_dev_put(cs5530_0);
 	return -ENODEV;
 }
 
Signature · 1 line
2.2.2
#781 lore raw

Re: [PATCH] jfs: Deletion of an unnecessary check before the function call "unload_nls"

In reply to SF Markus Elfring
Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 17:00:24 +0100

The unload_nls() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Thanks! I'll push this upstream.

Dave

Quoted 19 lines
---
 fs/jfs/super.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/jfs/super.c +1 -2
index 16c3a95..5d30c56 100644
@@ -619,8 +619,7 @@ out_mount_failed:
 	iput(sbi->direct_inode);
 	sbi->direct_inode = NULL;
 out_unload:
-	if (sbi->nls_tab)
-		unload_nls(sbi->nls_tab);
+	unload_nls(sbi->nls_tab);
 out_kfree:
 	kfree(sbi);
 	return ret;
maintainer Applied
#765 lore raw

Re: [PATCH] net: sctp: Deletion of an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 18:15:59 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 18:10:03 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Applied to net-next, thanks.

#806 lore raw

cover sata_mv: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 09:12:22 +0100

Another update suggestion was taken into account after a patch was applied from static source code analysis.

Markus Elfring (2):
Delete unnecessary checks before the function call "phy_power_off" More error handling for phy_power_off() in mv_platform_remove()

 drivers/ata/sata_mv.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.2.2
#807 lore raw

PATCH 1/2 sata_mv: Delete unnecessary checks before the function call "phy_power_off"

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 22:55:53 +0100

The phy_power_off() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/ata/sata_mv.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/ata/sata_mv.c +2 -4
index f9a0e34..f8c33e3 100644
@@ -4185,8 +4185,7 @@ err:
 			clk_disable_unprepare(hpriv->port_clks[port]);
 			clk_put(hpriv->port_clks[port]);
 		}
-		if (hpriv->port_phys[port])
-			phy_power_off(hpriv->port_phys[port]);
+		phy_power_off(hpriv->port_phys[port]);
 	}
 
 	return rc;
@@ -4216,8 +4215,7 @@ static int mv_platform_remove(struct platform_device *pdev)
 			clk_disable_unprepare(hpriv->port_clks[port]);
 			clk_put(hpriv->port_clks[port]);
 		}
-		if (hpriv->port_phys[port])
-			phy_power_off(hpriv->port_phys[port]);
+		phy_power_off(hpriv->port_phys[port]);
 	}
 	return 0;
 }
Signature · 1 line
2.2.2
#809 lore raw

PATCH 2/2 sata_mv: More error handling for phy_power_off() in mv_platform_remove()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 23:30:34 +0100

The return value from the phy_power_off() function was not used by the mv_platform_remove() function.

Let us improve error detection and eventually return a corresponding failure code.

---
 drivers/ata/sata_mv.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/ata/sata_mv.c +4 -2
index f8c33e3..4f9bc33 100644
@@ -4203,7 +4203,7 @@ static int mv_platform_remove(struct platform_device *pdev)
 {
 	struct ata_host *host = platform_get_drvdata(pdev);
 	struct mv_host_priv *hpriv = host->private_data;
-	int port;
+	int port, rc;
 	ata_host_detach(host);
 
 	if (!IS_ERR(hpriv->clk)) {
@@ -4215,7 +4215,9 @@ static int mv_platform_remove(struct platform_device *pdev)
 			clk_disable_unprepare(hpriv->port_clks[port]);
 			clk_put(hpriv->port_clks[port]);
 		}
-		phy_power_off(hpriv->port_phys[port]);
+		rc = phy_power_off(hpriv->port_phys[port]);
+		if (rc)
+			return rc;
 	}
 	return 0;
 }
Signature · 1 line
2.2.2
#792 lore raw

Re: [PATCH 2/3] md/bitmap: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

Am 02.02.2015 20:46, schrieb NeilBrown:

Quoted 68 lines
Quoted 34 lines · On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:10:57 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

* This issue was detected by using the Coccinelle software.

* Let us also move an assignment for the variable "pages" to the place directly before it is really needed for a loop.

* Let us also move another kfree() call into a block which should belong to a previous check for the variable "bp".

---
 drivers/md/bitmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +2 -3
index da3604e..47d72df 100644
@@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
 	bitmap_file_unmap(&bitmap->storage);
 
 	bp = bitmap->counts.bp;
-	pages = bitmap->counts.pages;
 
 	/* free all allocated memory */
-
-	if (bp) /* deallocate the page memory */
+	if (bp) { /* deallocate the page memory */
+		pages = bitmap->counts.pages;

drivers/md/bitmap.c static void bitmap_free(struct bitmap *bitmap) · line 1600

Quoted 10 lines
drivers/md/bitmap.c +3 -2
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
-	kfree(bp);
+		kfree(bp);
+	}
 	kfree(bitmap);
 }
 

Hi,
I'm somewhat amused that you removed a test for one kfree, but imposed a test on another. I realised the second test was already there, but why not just:

drivers/md/bitmap.c +1 -1
index da3604e73e8a..ad13b2e1bf1f 100644
@@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap)
 
 	if (bp) /* deallocate the page memory */
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
 	kfree(bp);
 	kfree(bitmap);
Quoted 6 lines

It makes the intention of the patch much clearer.

I'd probably prefer to leave the code as it is. I don't think either patch is really an improvement in readability, and readability trumps performance in places like this.

hello Neil,
just for my curiosity.
is it possible that a bp[k] exists but bp[k].hijacked is 0 ? if that case: kfree(bp) would free an object in use. otherwise hijacked seems useless here as it is possible to free everything.

re,
wh

#793 lore raw

Re: [PATCH 2/3] md/bitmap: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring
Quoted 86 lines · On Tue, 03 Feb 2015 09:48:01 +0100 walter harms <[email protected]> wrote:

Am 02.02.2015 20:46, schrieb NeilBrown:

Quoted 68 lines
Quoted 34 lines · On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:10:57 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

* This issue was detected by using the Coccinelle software.

* Let us also move an assignment for the variable "pages" to the place directly before it is really needed for a loop.

* Let us also move another kfree() call into a block which should belong to a previous check for the variable "bp".

---
 drivers/md/bitmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +2 -3
index da3604e..47d72df 100644
@@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
 	bitmap_file_unmap(&bitmap->storage);
 
 	bp = bitmap->counts.bp;
-	pages = bitmap->counts.pages;
 
 	/* free all allocated memory */
-
-	if (bp) /* deallocate the page memory */
+	if (bp) { /* deallocate the page memory */
+		pages = bitmap->counts.pages;

drivers/md/bitmap.c static void bitmap_free(struct bitmap *bitmap) · line 1600

Quoted 10 lines
drivers/md/bitmap.c +3 -2
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
-	kfree(bp);
+		kfree(bp);
+	}
 	kfree(bitmap);
 }
 

Hi,
I'm somewhat amused that you removed a test for one kfree, but imposed a test on another. I realised the second test was already there, but why not just:

drivers/md/bitmap.c +1 -1
index da3604e73e8a..ad13b2e1bf1f 100644
@@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap)
 
 	if (bp) /* deallocate the page memory */
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
 	kfree(bp);
 	kfree(bitmap);
Quoted 6 lines

It makes the intention of the patch much clearer.

I'd probably prefer to leave the code as it is. I don't think either patch is really an improvement in readability, and readability trumps performance in places like this.

hello Neil,
just for my curiosity.
is it possible that a bp[k] exists but bp[k].hijacked is 0 ? if that case: kfree(bp) would free an object in use. otherwise hijacked seems useless here as it is possible to free everything.

Quoted 2 lines

re,
wh

If .hijacked is 0, the .map is a pointer (that would need to be freed) or is NULL.
If .hijacked is 1, then .map has been re-tasked as 2 16-bit counters. They are probably bother zero at this point, but I think it is safer to completely skip the 'free' if 'hijacked' is set as in that case 'map' isn't a pointer.

NeilBrown

#794 lore raw

Re: [PATCH 2/3] md/bitmap: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

Am 03.02.2015 10:07, schrieb NeilBrown:

Quoted 88 lines · On Tue, 03 Feb 2015 09:48:01 +0100 walter harms <[email protected]> wrote:
Quoted 87 lines

Am 02.02.2015 20:46, schrieb NeilBrown:

Quoted 68 lines
Quoted 34 lines · On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:10:57 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

* This issue was detected by using the Coccinelle software.

* Let us also move an assignment for the variable "pages" to the place directly before it is really needed for a loop.

* Let us also move another kfree() call into a block which should belong to a previous check for the variable "bp".

---
 drivers/md/bitmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +2 -3
index da3604e..47d72df 100644
@@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
 	bitmap_file_unmap(&bitmap->storage);
 
 	bp = bitmap->counts.bp;
-	pages = bitmap->counts.pages;
 
 	/* free all allocated memory */
-
-	if (bp) /* deallocate the page memory */
+	if (bp) { /* deallocate the page memory */
+		pages = bitmap->counts.pages;

drivers/md/bitmap.c static void bitmap_free(struct bitmap *bitmap) · line 1600

Quoted 10 lines
drivers/md/bitmap.c +3 -2
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
-	kfree(bp);
+		kfree(bp);
+	}
 	kfree(bitmap);
 }
 

Hi,
I'm somewhat amused that you removed a test for one kfree, but imposed a test on another. I realised the second test was already there, but why not just:

drivers/md/bitmap.c +1 -1
index da3604e73e8a..ad13b2e1bf1f 100644
@@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap)
 
 	if (bp) /* deallocate the page memory */
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
 	kfree(bp);
 	kfree(bitmap);
Quoted 6 lines

It makes the intention of the patch much clearer.

I'd probably prefer to leave the code as it is. I don't think either patch is really an improvement in readability, and readability trumps performance in places like this.

hello Neil,
just for my curiosity.
is it possible that a bp[k] exists but bp[k].hijacked is 0 ? if that case: kfree(bp) would free an object in use. otherwise hijacked seems useless here as it is possible to free everything.

Quoted 9 lines
Quoted 2 lines

re,
wh

If .hijacked is 0, the .map is a pointer (that would need to be freed) or is NULL.
If .hijacked is 1, then .map has been re-tasked as 2 16-bit counters. They are probably bother zero at this point, but I think it is safer to completely skip the 'free' if 'hijacked' is set as in that case 'map' isn't a pointer.

It seems i was not clear enough, sorry about that.

we have a loop to kfree(bp[k].map), thats fine how it is done.

I am wondering about the kfree(bp) after the loop.
if bp[k].map is not freed for what ever reason how can it be freed later after a kfree(bp) ?

what is what i am missing ? Is there a hidden copy ?

re,
wh

#814 lore raw

PATCH 1/1 ti-soc-thermal: Delete an unnecessary check before the function call "cpufreq_cooling_unregister"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 11:15:14 +0100

The cpufreq_cooling_unregister() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +1 -1
index 3fb054a..a38c175 100644
@@ -429,7 +429,7 @@ int ti_thermal_unregister_cpu_cooling(struct ti_bandgap *bgp, int id)
 
 	data = ti_bandgap_get_sensor_data(bgp, id);
 
-	if (data && data->cool_dev)
+	if (data)
 		cpufreq_cooling_unregister(data->cool_dev);
 
 	return 0;
Signature · 1 line
2.2.2
#815 lore raw

PATCH 1/1 pwm: Delete an unnecessary check before the function call "of_node_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 11:54:28 +0100

The of_node_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/pwm/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pwm/core.c +1 -1
index 966497d..810aef3 100644
@@ -192,7 +192,7 @@ static void of_pwmchip_add(struct pwm_chip *chip)
 
 static void of_pwmchip_remove(struct pwm_chip *chip)
 {
-	if (chip->dev && chip->dev->of_node)
+	if (chip->dev)
 		of_node_put(chip->dev->of_node);
 }
 
Signature · 1 line
2.2.2
#817 lore raw

PATCH 1/1 x86: Intel-perf_event: Delete an unnecessary check before the function call "pci_dev_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 12:40:54 +0100

The pci_dev_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c +1 -2
index 21af6149e..12d9548 100644
@@ -1132,8 +1132,7 @@ static int snbep_pci2phy_map_init(int devid)
 		}
 	}
 
-	if (ubox_dev)
-		pci_dev_put(ubox_dev);
+	pci_dev_put(ubox_dev);
 
 	return err ? pcibios_err_to_errno(err) : 0;
 }
Signature · 1 line
2.2.2
#816 lore raw

Re: [PATCH] pwm: Delete an unnecessary check before the function call "of_node_put"

In reply to SF Markus Elfring
Quoted 18 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 11:54:28 +0100

The of_node_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/pwm/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pwm/core.c +0 -0
index 966497d..810aef3 100644

drivers/pwm/core.c static void of_pwmchip_add(struct pwm_chip *chip) · line 198

Quoted 8 lines
drivers/pwm/core.c +1 -1
@@ -192,7 +192,7 @@ static void of_pwmchip_add(struct pwm_chip *chip)
 
 static void of_pwmchip_remove(struct pwm_chip *chip)
 {
-	if (chip->dev && chip->dev->of_node)
+	if (chip->dev)
 		of_node_put(chip->dev->of_node);
 }
 

Applied, thanks.

Thierry

Applied
#805 lore raw

Re: [PATCH] ata: Delete unnecessary checks before the function call "pci_dev_put"

In reply to SF Markus Elfring
Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 22:08:29 +0100

The pci_dev_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Applied to libata/for-3.20.

Thanks.

Signature · 1 line
tejun
Applied
#808 lore raw

Re: [PATCH 1/2] sata_mv: Delete unnecessary checks before the function call "phy_power_off"

In reply to SF Markus Elfring
Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 22:55:53 +0100

The phy_power_off() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Applied to libata/for-3.20.

Thanks.

Signature · 1 line
tejun
#810 lore raw

Re: [PATCH 2/2] sata_mv: More error handling for phy_power_off() in mv_platform_remove()

In reply to SF Markus Elfring

On Tue, Feb 03, 2015 at 09:36:01AM +0100, SF Markus Elfring wrote:
...

drivers/ata/sata_mv.c static int mv_platform_remove(struct platform_device *pdev) · line 4220

Quoted 8 lines
drivers/ata/sata_mv.c +3 -1
@@ -4215,7 +4215,9 @@ static int mv_platform_remove(struct platform_device *pdev)
 			clk_disable_unprepare(hpriv->port_clks[port]);
 			clk_put(hpriv->port_clks[port]);
 		}
-		phy_power_off(hpriv->port_phys[port]);
+		rc = phy_power_off(hpriv->port_phys[port]);
+		if (rc)
+			return rc;

So, this is a removal function which is ignoring failure from turning off phy, which seems like the right thing to do. The same thing with suspend routines. If something auxliary which isn't strictly necessary in reaching suspend state fails, the failure should be ignored.

Running static code analysis to locate trivial irregularities and performing identity transformations is fine, even great, but you're changing the behavior here without actually understanding what's going on. Please don't do these things automatically.

Thanks.

Signature · 1 line
tejun
#811 lore raw

Re: [PATCH 2/2] sata_mv: More error handling for phy_power_off() in mv_platform_remove()

In reply to SF Markus Elfring

Am 03.02.2015 13:10, schrieb Tejun Heo:

Quoted 17 lines · SF Markus Elfring

...

drivers/ata/sata_mv.c static int mv_platform_remove(struct platform_device *pdev) · line 4220

Quoted 8 lines
drivers/ata/sata_mv.c +3 -1
@@ -4215,7 +4215,9 @@ static int mv_platform_remove(struct platform_device *pdev)
 			clk_disable_unprepare(hpriv->port_clks[port]);
 			clk_put(hpriv->port_clks[port]);
 		}
-		phy_power_off(hpriv->port_phys[port]);
+		rc = phy_power_off(hpriv->port_phys[port]);
+		if (rc)
+			return rc;

So, this is a removal function which is ignoring failure from turning off phy, which seems like the right thing to do. The same thing with suspend routines. If something auxliary which isn't strictly necessary in reaching suspend state fails, the failure should be ignored.

Quoted 7 lines

Running static code analysis to locate trivial irregularities and performing identity transformations is fine, even great, but you're changing the behavior here without actually understanding what's going on. Please don't do these things automatically.

Thanks.

maybe this can be changed into
(void) phy_power_off(hpriv->port_phys[port]);

that would tell the compiler and other readers that this is intentional.

#812 lore raw

Re: [PATCH 2/2] sata_mv: More error handling for phy_power_off() in mv_platform_remove()

In reply to SF Markus Elfring
Quoted 4 lines · walter harms

maybe this can be changed into
(void) phy_power_off(hpriv->port_phys[port]);

that would tell the compiler and other readers that this is intentional.

That's too anal to be helpful and too spurious to become even remotely consistent. Things like that are actualy harmful. Note that we have an annotation marking the other way - __must_check. Balance is to be found towards that direction, not this, so please stop.

Thanks.

Signature · 1 line
tejun
#813 lore raw

Re: [PATCH 2/2] sata_mv: More error handling for phy_power_off() in mv_platform_remove()

In reply to SF Markus Elfring
Quoted 1 line · Tejun Heo

That's too anal to be helpful and too spurious to become even remotely

Let me clarify the "too anal" part a bit. Let's say people push this like crazy and we successfully mark all places to either check the return value or have (void) in front. It's not difficult to realize that that would be the exact same situation as right now just with more visual clutter. That's the problem when these things become obsessive - they become indisciminate and thus meaningless. Annotate the exceptionals, not the other way around.

Thanks.

Signature · 1 line
tejun
#819 lore raw

PATCH 1/1 PowerPC-PCI: Delete unnecessary checks before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 13:55:53 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 arch/powerpc/platforms/cell/celleb_pci.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/powerpc/platforms/cell/celleb_pci.c +2 -3
index 3ce70de..9b11b5d 100644
@@ -393,11 +393,10 @@ static int __init celleb_setup_fake_pci_device(struct device_node *node,
 
 error:
 	if (mem_init_done) {
-		if (config && *config)
+		if (config)
 			kfree(*config);
-		if (res && *res)
+		if (res)
 			kfree(*res);
-
 	} else {
 		if (config && *config) {
 			size = 256;
Signature · 1 line
2.2.2
#820 lore raw

PATCH 1/1 PowerPC-rheap: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 14:34:10 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 arch/powerpc/lib/rheap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/lib/rheap.c +1 -1
index a1060a8..69abf84 100644
@@ -284,7 +284,7 @@ EXPORT_SYMBOL_GPL(rh_create);
  */
 void rh_destroy(rh_info_t * info)
 {
-	if ((info->flags & RHIF_STATIC_BLOCK) = 0 && info->block != NULL)
+	if ((info->flags & RHIF_STATIC_BLOCK) = 0)
 		kfree(info->block);
 
 	if ((info->flags & RHIF_STATIC_INFO) = 0)
Signature · 1 line
2.2.2
#821 lore raw

PATCH 1/1 sp2: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 15:05:26 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/media/dvb-frontends/sp2.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/media/dvb-frontends/sp2.c +1 -4
index cc1ef96..8fd4276 100644
@@ -413,11 +413,8 @@ static int sp2_remove(struct i2c_client *client)
 	struct sp2 *s = i2c_get_clientdata(client);
 
 	dev_dbg(&client->dev, "\n");
-
 	sp2_exit(client);
-	if (s != NULL)
-		kfree(s);
-
+	kfree(s);
 	return 0;
 }
 
Signature · 1 line
2.2.2
#822 lore raw

PATCH 1/1 V4L2: Delete an unnecessary check before the function call "media_entity_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 15:27:38 +0100

The media_entity_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/media/v4l2-core/v4l2-subdev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +1 -2
index 543631c..b9ff7fd 100644
@@ -93,8 +93,7 @@ static int subdev_open(struct file *file)
 
 err:
 #if defined(CONFIG_MEDIA_CONTROLLER)
-	if (entity)
-		media_entity_put(entity);
+	media_entity_put(entity);
 #endif
 	v4l2_fh_del(&subdev_fh->vfh);
 	v4l2_fh_exit(&subdev_fh->vfh);
Signature · 1 line
2.2.2
#823 lore raw

cover DVB: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 16:50:07 +0100

Another update suggestion was taken into account after a patch was applied from static source code analysis.

Markus Elfring (2):
Delete an unnecessary check before the function call "dvb_unregister_device" Less function calls in dvb_ca_en50221_init() after error detection

 drivers/media/dvb-core/dvb_ca_en50221.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
Signature · 1 line
2.2.2
#824 lore raw

PATCH 1/2 DVB: Delete an unnecessary check before the function call "dvb_unregister_device"

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 16:01:40 +0100

The dvb_unregister_device() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/media/dvb-core/dvb_ca_en50221.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/dvb-core/dvb_ca_en50221.c +1 -2
index 0aac309..b999689 100644
@@ -1726,8 +1726,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
 
 error:
 	if (ca != NULL) {
-		if (ca->dvbdev != NULL)
-			dvb_unregister_device(ca->dvbdev);
+		dvb_unregister_device(ca->dvbdev);
 		kfree(ca->slot_info);
 		kfree(ca);
 	}
Signature · 1 line
2.2.2
#825 lore raw

PATCH 2/2 DVB: Less function calls in dvb_ca_en50221_init() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 16:47:48 +0100

The functions "dvb_unregister_device" and "kfree" could still be called by the dvb_ca_en50221_init() function in the case that a previous resource allocation failed.

* Corresponding details could be improved by adjustments for jump targets.

* Let us delete also an unnecessary check for the variable "ca" there.

---
 drivers/media/dvb-core/dvb_ca_en50221.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
drivers/media/dvb-core/dvb_ca_en50221.c +12 -11
index b999689..9842fd1 100644
@@ -1676,14 +1676,14 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
 	/* initialise the system data */
 	if ((ca = kzalloc(sizeof(struct dvb_ca_private), GFP_KERNEL)) = NULL) {
 		ret = -ENOMEM;
-		goto error;
+		goto exit;
 	}
 	ca->pub = pubca;
 	ca->flags = flags;
 	ca->slot_count = slot_count;
 	if ((ca->slot_info = kcalloc(slot_count, sizeof(struct dvb_ca_slot), GFP_KERNEL)) = NULL) {
 		ret = -ENOMEM;
-		goto error;
+		goto free_ca;
 	}
 	init_waitqueue_head(&ca->wait_queue);
 	ca->open = 0;
@@ -1694,7 +1694,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
 	/* register the DVB device */
 	ret = dvb_register_device(dvb_adapter, &ca->dvbdev, &dvbdev_ca, ca, DVB_DEVICE_CA);
 	if (ret)
-		goto error;
+		goto free_slot_info;
 
 	/* now initialise each slot */
 	for (i = 0; i < slot_count; i++) {
@@ -1709,7 +1709,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
 
 	if (signal_pending(current)) {
 		ret = -EINTR;
-		goto error;
+		goto unregister_device;
 	}
 	mb();
 
@@ -1720,16 +1720,17 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
 		ret = PTR_ERR(ca->thread);
 		printk("dvb_ca_init: failed to start kernel_thread (%d)\n",
 			ret);
-		goto error;
+		goto unregister_device;
 	}
 	return 0;
 
-error:
-	if (ca != NULL) {
-		dvb_unregister_device(ca->dvbdev);
-		kfree(ca->slot_info);
-		kfree(ca);
-	}
+unregister_device:
+	dvb_unregister_device(ca->dvbdev);
+free_slot_info:
+	kfree(ca->slot_info);
+free_ca:
+	kfree(ca);
+exit:
 	pubca->private = NULL;
 	return ret;
 }
Signature · 1 line
2.2.2
maintainer Applied
#803 lore raw

Re: [PATCH] EDAC: Deletion of unnecessary checks before the function call "pci_dev_put"

In reply to SF Markus Elfring
Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 18:26:34 +0100

The pci_dev_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Queued for 3.21, thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#826 lore raw

PATCH 1/1 stk-webcam: Delete an unnecessary check before the function call "vfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 18:36:35 +0100

The vfree() function performs also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/media/usb/stkwebcam/stk-webcam.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/usb/stkwebcam/stk-webcam.c +2 -4
index 3588dc3..3686c4e 100644
@@ -556,10 +556,8 @@ static int stk_free_sio_buffers(struct stk_camera *dev)
 	nbufs = dev->n_sbufs;
 	dev->n_sbufs = 0;
 	spin_unlock_irqrestore(&dev->spinlock, flags);
-	for (i = 0; i < nbufs; i++) {
-		if (dev->sio_bufs[i].buffer != NULL)
-			vfree(dev->sio_bufs[i].buffer);
-	}
+	for (i = 0; i < nbufs; i++)
+		vfree(dev->sio_bufs[i].buffer);
 	kfree(dev->sio_bufs);
 	dev->sio_bufs = NULL;
 	return 0;
Signature · 1 line
2.2.2
#827 lore raw

PATCH 1/1 au0828: Delete unnecessary checks before the function call "video_unregister_device"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 19:00:25 +0100

The video_unregister_device() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/media/usb/au0828/au0828-video.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/media/usb/au0828/au0828-video.c +2 -6
index 5f337b1..e593fb5 100644
@@ -870,12 +870,8 @@ void au0828_analog_unregister(struct au0828_dev *dev)
 {
 	dprintk(1, "au0828_release_resources called\n");
 	mutex_lock(&au0828_sysfs_lock);
-
-	if (dev->vdev)
-		video_unregister_device(dev->vdev);
-	if (dev->vbi_dev)
-		video_unregister_device(dev->vbi_dev);
-
+	video_unregister_device(dev->vdev);
+	video_unregister_device(dev->vbi_dev);
 	mutex_unlock(&au0828_sysfs_lock);
 }
 
Signature · 1 line
2.2.2
#828 lore raw

PATCH 1/1 cpufreq-dt: Delete an unnecessary check before the function call "cpufreq_cooling_unregister"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 19:21:21 +0100

The cpufreq_cooling_unregister() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/cpufreq/cpufreq-dt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cpufreq/cpufreq-dt.c +1 -2
index fde97d6..bab67db 100644
@@ -320,8 +320,7 @@ static int cpufreq_exit(struct cpufreq_policy *policy)
 {
 	struct private_data *priv = policy->driver_data;
 
-	if (priv->cdev)
-		cpufreq_cooling_unregister(priv->cdev);
+	cpufreq_cooling_unregister(priv->cdev);
 	dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table);
 	of_free_opp_table(priv->cpu_dev);
 	clk_put(policy->clk);
Signature · 1 line
2.2.2
#830 lore raw

PATCH 1/1 IBM-EMAC: Delete an unnecessary check before the function call "of_dev_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 19:47:33 +0100

The of_dev_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/ibm/emac/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/ibm/emac/core.c +1 -1
index 9388a83..162762d 100644
@@ -2367,7 +2367,7 @@ static int emac_wait_deps(struct emac_instance *dev)
 	err = emac_check_deps(dev, deps) ? 0 : -ENODEV;
 	for (i = 0; i < EMAC_DEP_COUNT; i++) {
 		of_node_put(deps[i].node);
-		if (err && deps[i].ofdev)
+		if (err)
 			of_dev_put(deps[i].ofdev);
 	}
 	if (err = 0) {
Signature · 1 line
2.2.2
#832 lore raw

PATCH 1/1 NetCP: Deletion of unnecessary checks before two function calls

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 20:12:25 +0100

The functions cpsw_ale_destroy() and of_dev_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/ti/netcp_ethss.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/ti/netcp_ethss.c +2 -4
index fa1041a..cbd6dde 100644
@@ -2010,12 +2010,10 @@ static int gbe_probe(struct netcp_device *netcp_device, struct device *dev,
 quit:
 	if (gbe_dev->hw_stats)
 		devm_kfree(dev, gbe_dev->hw_stats);
-	if (gbe_dev->ale)
-		cpsw_ale_destroy(gbe_dev->ale);
+	cpsw_ale_destroy(gbe_dev->ale);
 	if (gbe_dev->ss_regs)
 		devm_iounmap(dev, gbe_dev->ss_regs);
-	if (interfaces)
-		of_node_put(interfaces);
+	of_node_put(interfaces);
 	devm_kfree(dev, gbe_dev);
 	return ret;
 }
Signature · 1 line
2.2.2
maintainer
#761 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 17:34:54 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 17:18:48 +0100

The meta_delete() function could be called in four cases by the em_meta_change() function during error handling even if the passed variable "meta" contained still a null pointer.

* This implementation detail could be improved by adjustments for jump labels.

Quoted 7 lines

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Let us delete also unnecessary checks for the variables "err" and "meta" there.

I kind of like the way the code is now, branching to the end of the function even when cleanups are not necessary.

Inter-function return statements make code harder to audit, for locking errors, resource leaks, etc.

#795 lore raw

Re: [PATCH 2/3] md/bitmap: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring
Quoted 103 lines · On Tue, 03 Feb 2015 11:19:58 +0100 walter harms <[email protected]> wrote:

Am 03.02.2015 10:07, schrieb NeilBrown:

Quoted 88 lines · On Tue, 03 Feb 2015 09:48:01 +0100 walter harms <[email protected]> wrote:
Quoted 87 lines

Am 02.02.2015 20:46, schrieb NeilBrown:

Quoted 68 lines
Quoted 34 lines · On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:10:57 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

* This issue was detected by using the Coccinelle software.

* Let us also move an assignment for the variable "pages" to the place directly before it is really needed for a loop.

* Let us also move another kfree() call into a block which should belong to a previous check for the variable "bp".

---
 drivers/md/bitmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +2 -3
index da3604e..47d72df 100644
@@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
 	bitmap_file_unmap(&bitmap->storage);
 
 	bp = bitmap->counts.bp;
-	pages = bitmap->counts.pages;
 
 	/* free all allocated memory */
-
-	if (bp) /* deallocate the page memory */
+	if (bp) { /* deallocate the page memory */
+		pages = bitmap->counts.pages;

drivers/md/bitmap.c static void bitmap_free(struct bitmap *bitmap) · line 1600

Quoted 10 lines
drivers/md/bitmap.c +3 -2
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
-	kfree(bp);
+		kfree(bp);
+	}
 	kfree(bitmap);
 }
 

Hi,
I'm somewhat amused that you removed a test for one kfree, but imposed a test on another. I realised the second test was already there, but why not just:

drivers/md/bitmap.c +1 -1
index da3604e73e8a..ad13b2e1bf1f 100644
@@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap)
 
 	if (bp) /* deallocate the page memory */
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
 	kfree(bp);
 	kfree(bitmap);
Quoted 6 lines

It makes the intention of the patch much clearer.

I'd probably prefer to leave the code as it is. I don't think either patch is really an improvement in readability, and readability trumps performance in places like this.

hello Neil,
just for my curiosity.
is it possible that a bp[k] exists but bp[k].hijacked is 0 ? if that case: kfree(bp) would free an object in use. otherwise hijacked seems useless here as it is possible to free everything.

Quoted 9 lines
Quoted 2 lines

re,
wh

If .hijacked is 0, the .map is a pointer (that would need to be freed) or is NULL.
If .hijacked is 1, then .map has been re-tasked as 2 16-bit counters. They are probably bother zero at this point, but I think it is safer to completely skip the 'free' if 'hijacked' is set as in that case 'map' isn't a pointer.

It seems i was not clear enough, sorry about that.

Quoted 7 lines

we have a loop to kfree(bp[k].map), thats fine how it is done.

I am wondering about the kfree(bp) after the loop.
if bp[k].map is not freed for what ever reason how can it be freed later after a kfree(bp) ?

what is what i am missing ? Is there a hidden copy ?

If bp[k].map is a pointer, it will be freed.
If bp[k].map is not a pointer (because it has been hijacked), then there is nothing to free.

So after the loop, all bp[k].maps that were allocated will have been freed.

Does that help?

NeilBrown

Quoted 6 lines

re,
wh

#762 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

In reply to David Miller
Quoted 6 lines
Quoted 6 lines

The meta_delete() function could be called in four cases by the em_meta_change() function during error handling even if the passed variable "meta" contained still a null pointer.

* This implementation detail could be improved by adjustments for jump labels.

Quoted 8 lines
Quoted 5 lines

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Let us delete also unnecessary checks for the variables "err" and "meta" there.

I kind of like the way the code is now, branching to the end of the function even when cleanups are not necessary.

I would appreciate if the affected exception handling can become also a bit more efficient.

Regards,
Markus

#796 lore raw

Re: [PATCH 2/3] md/bitmap: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

Am 04.02.2015 07:48, schrieb NeilBrown:

Quoted 117 lines · On Tue, 03 Feb 2015 11:19:58 +0100 walter harms <[email protected]> wrote:
Quoted 104 lines

Am 03.02.2015 10:07, schrieb NeilBrown:

Quoted 88 lines · On Tue, 03 Feb 2015 09:48:01 +0100 walter harms <[email protected]> wrote:
Quoted 87 lines

Am 02.02.2015 20:46, schrieb NeilBrown:

Quoted 68 lines
Quoted 34 lines · On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:10:57 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

* This issue was detected by using the Coccinelle software.

* Let us also move an assignment for the variable "pages" to the place directly before it is really needed for a loop.

* Let us also move another kfree() call into a block which should belong to a previous check for the variable "bp".

---
 drivers/md/bitmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +2 -3
index da3604e..47d72df 100644
@@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
 	bitmap_file_unmap(&bitmap->storage);
 
 	bp = bitmap->counts.bp;
-	pages = bitmap->counts.pages;
 
 	/* free all allocated memory */
-
-	if (bp) /* deallocate the page memory */
+	if (bp) { /* deallocate the page memory */
+		pages = bitmap->counts.pages;

drivers/md/bitmap.c static void bitmap_free(struct bitmap *bitmap) · line 1600

Quoted 10 lines
drivers/md/bitmap.c +3 -2
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
-	kfree(bp);
+		kfree(bp);
+	}
 	kfree(bitmap);
 }
 

Hi,
I'm somewhat amused that you removed a test for one kfree, but imposed a test on another. I realised the second test was already there, but why not just:

drivers/md/bitmap.c +1 -1
index da3604e73e8a..ad13b2e1bf1f 100644
@@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap)
 
 	if (bp) /* deallocate the page memory */
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
 	kfree(bp);
 	kfree(bitmap);
Quoted 6 lines

It makes the intention of the patch much clearer.

I'd probably prefer to leave the code as it is. I don't think either patch is really an improvement in readability, and readability trumps performance in places like this.

hello Neil,
just for my curiosity.
is it possible that a bp[k] exists but bp[k].hijacked is 0 ? if that case: kfree(bp) would free an object in use. otherwise hijacked seems useless here as it is possible to free everything.

Quoted 9 lines
Quoted 2 lines

re,
wh

If .hijacked is 0, the .map is a pointer (that would need to be freed) or is NULL.
If .hijacked is 1, then .map has been re-tasked as 2 16-bit counters. They are probably bother zero at this point, but I think it is safer to completely skip the 'free' if 'hijacked' is set as in that case 'map' isn't a pointer.

It seems i was not clear enough, sorry about that.

Quoted 7 lines

we have a loop to kfree(bp[k].map), thats fine how it is done.

I am wondering about the kfree(bp) after the loop.
if bp[k].map is not freed for what ever reason how can it be freed later after a kfree(bp) ?

what is what i am missing ? Is there a hidden copy ?

If bp[k].map is a pointer, it will be freed.
If bp[k].map is not a pointer (because it has been hijacked), then there is nothing to free.

Quoted 6 lines

So after the loop, all bp[k].maps that were allocated will have been freed.

Does that help?

NeilBrown

thx for explanation,

i am happy now, no further questions.

re,
wh

#836 lore raw

PATCH 1/1 cxgb4: Delete an unnecessary check before the function call "release_firmware"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 11:28:43 +0100

The release_firmware() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +1 -2
index 1147e1e..6d08b8c 100644
@@ -5129,8 +5129,7 @@ static int adap_init0(struct adapter *adap)
 				 state, &reset);
 
 		/* Cleaning up */
-		if (fw != NULL)
-			release_firmware(fw);
+		release_firmware(fw);
 		t4_free_mem(card_fw);
 
 		if (ret < 0)
Signature · 1 line
2.2.2
#838 lore raw

PATCH 1/1 myri10ge: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 12:32:14 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/myricom/myri10ge/myri10ge.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/myricom/myri10ge/myri10ge.c +1 -2
index 71af98b..1412f5a 100644
@@ -4226,8 +4226,7 @@ static void myri10ge_remove(struct pci_dev *pdev)
 		mtrr_del(mgp->mtrr, mgp->iomem_base, mgp->board_span);
 #endif
 	myri10ge_free_slices(mgp);
-	if (mgp->msix_vectors != NULL)
-		kfree(mgp->msix_vectors);
+	kfree(mgp->msix_vectors);
 	dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
 			  mgp->cmd, mgp->cmd_bus);
 
Signature · 1 line
2.2.2
#840 lore raw

PATCH 1/1 net: fec: Delete unnecessary checks before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 12:56:42 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/freescale/fec_main.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +2 -5
index 1c7a7e4..29fd7e3 100644
@@ -2584,12 +2584,9 @@ static void fec_enet_free_queue(struct net_device *ndev)
 		}
 
 	for (i = 0; i < fep->num_rx_queues; i++)
-		if (fep->rx_queue[i])
-			kfree(fep->rx_queue[i]);
-
+		kfree(fep->rx_queue[i]);
 	for (i = 0; i < fep->num_tx_queues; i++)
-		if (fep->tx_queue[i])
-			kfree(fep->tx_queue[i]);
+		kfree(fep->tx_queue[i]);
 }
 
 static int fec_enet_alloc_queue(struct net_device *ndev)
Signature · 1 line
2.2.2
#842 lore raw

PATCH 1/1 netxen: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 13:17:48 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c +1 -3
index a47fe67..7d1b524 100644
@@ -176,9 +176,7 @@ netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count)
 static void
 netxen_free_sds_rings(struct netxen_recv_context *recv_ctx)
 {
-	if (recv_ctx->sds_rings != NULL)
-		kfree(recv_ctx->sds_rings);
-
+	kfree(recv_ctx->sds_rings);
 	recv_ctx->sds_rings = NULL;
 }
 
Signature · 1 line
2.2.2
#844 lore raw

PATCH 1/1 qlogic: Deletion of unnecessary checks before two function calls

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 14:07:56 +0100

The functions kfree() and vfree() perform also input parameter validation. Thus the test around their calls is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c   | 24 ++++++++--------------
 .../net/ethernet/qlogic/qlcnic/qlcnic_minidump.c   |  3 +--
 2 files changed, 9 insertions(+), 18 deletions(-)
drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c +8 -16
index 2528c3f..a430a34a 100644
@@ -294,9 +294,7 @@ int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
 
 void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
 {
-	if (recv_ctx->sds_rings != NULL)
-		kfree(recv_ctx->sds_rings);
-
+	kfree(recv_ctx->sds_rings);
 	recv_ctx->sds_rings = NULL;
 }
 
@@ -1257,8 +1255,7 @@ qlcnic_check_options(struct qlcnic_adapter *adapter)
 	if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) {
 		if (fw_dump->tmpl_hdr = NULL ||
 				adapter->fw_version > prev_fw_version) {
-			if (fw_dump->tmpl_hdr)
-				vfree(fw_dump->tmpl_hdr);
+			vfree(fw_dump->tmpl_hdr);
 			if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
 				dev_info(&pdev->dev,
 					"Supports FW dump capability\n");
@@ -2374,13 +2371,12 @@ void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter)
 
 	for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
 		tx_ring = &adapter->tx_ring[ring];
-		if (tx_ring && tx_ring->cmd_buf_arr != NULL) {
+		if (tx_ring) {
 			vfree(tx_ring->cmd_buf_arr);
 			tx_ring->cmd_buf_arr = NULL;
 		}
 	}
-	if (adapter->tx_ring != NULL)
-		kfree(adapter->tx_ring);
+	kfree(adapter->tx_ring);
 }
 
 int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter,
@@ -2758,13 +2754,9 @@ static void qlcnic_remove(struct pci_dev *pdev)
 	}
 
 	qlcnic_dcb_free(adapter->dcb);
-
 	qlcnic_detach(adapter);
-
-	if (adapter->npars != NULL)
-		kfree(adapter->npars);
-	if (adapter->eswitch != NULL)
-		kfree(adapter->eswitch);
+	kfree(adapter->npars);
+	kfree(adapter->eswitch);
 
 	if (qlcnic_82xx_check(adapter))
 		qlcnic_clr_all_drv_state(adapter, 0);
@@ -2932,13 +2924,13 @@ void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
 
 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
 {
-	if (adapter->fhash.fmax && adapter->fhash.fhead)
+	if (adapter->fhash.fmax)
 		kfree(adapter->fhash.fhead);
 
 	adapter->fhash.fhead = NULL;
 	adapter->fhash.fmax = 0;
 
-	if (adapter->rx_fhash.fmax && adapter->rx_fhash.fhead)
+	if (adapter->rx_fhash.fmax)
 		kfree(adapter->rx_fhash.fhead);
 
 	adapter->rx_fhash.fmax = 0;
drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c +1 -2
index c9f57fb..332bb8a 100644
@@ -1407,8 +1407,7 @@ void qlcnic_83xx_get_minidump_template(struct qlcnic_adapter *adapter)
 	current_version = qlcnic_83xx_get_fw_version(adapter);
 
 	if (fw_dump->tmpl_hdr = NULL || current_version > prev_version) {
-		if (fw_dump->tmpl_hdr)
-			vfree(fw_dump->tmpl_hdr);
+		vfree(fw_dump->tmpl_hdr);
 		if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
 			dev_info(&pdev->dev, "Supports FW dump capability\n");
 	}
Signature · 1 line
2.2.2
#829 lore raw

Re: [PATCH] cpufreq-dt: Delete an unnecessary check before the function call "cpufreq_cooling_unregister"

In reply to SF Markus Elfring
Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 19:21:21 +0100

The cpufreq_cooling_unregister() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Queued up for 3.20, thanks!

Quoted 19 lines
---
 drivers/cpufreq/cpufreq-dt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cpufreq/cpufreq-dt.c +1 -2
index fde97d6..bab67db 100644
@@ -320,8 +320,7 @@ static int cpufreq_exit(struct cpufreq_policy *policy)
 {
 	struct private_data *priv = policy->driver_data;
 
-	if (priv->cdev)
-		cpufreq_cooling_unregister(priv->cdev);
+	cpufreq_cooling_unregister(priv->cdev);
 	dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table);
 	of_free_opp_table(priv->cpu_dev);
 	clk_put(policy->clk);
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#846 lore raw

PATCH 1/1 net: Mellanox: Delete unnecessary checks before the function call "vunmap"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 15:17:00 +0100

The vunmap() function performs also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/mellanox/mlx4/alloc.c      | 2 +-
 drivers/net/ethernet/mellanox/mlx5/core/alloc.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx4/alloc.c +1 -1
index 963dd7e..06faa51 100644
@@ -660,7 +660,7 @@ void mlx4_buf_free(struct mlx4_dev *dev, int size, struct mlx4_buf *buf)
 		dma_free_coherent(&dev->pdev->dev, size, buf->direct.buf,
 				  buf->direct.map);
 	else {
-		if (BITS_PER_LONG = 64 && buf->direct.buf)
+		if (BITS_PER_LONG = 64)
 			vunmap(buf->direct.buf);
 
 		for (i = 0; i < buf->nbufs; ++i)
drivers/net/ethernet/mellanox/mlx5/core/alloc.c +1 -1
index 56779c1..201ca6d 100644
@@ -121,7 +121,7 @@ void mlx5_buf_free(struct mlx5_core_dev *dev, struct mlx5_buf *buf)
 		dma_free_coherent(&dev->pdev->dev, buf->size, buf->direct.buf,
 				  buf->direct.map);
 	else {
-		if (BITS_PER_LONG = 64 && buf->direct.buf)
+		if (BITS_PER_LONG = 64)
 			vunmap(buf->direct.buf);
 
 		for (i = 0; i < buf->nbufs; i++)
Signature · 1 line
2.2.2
Acked-by on v1 1/1
#847 lore raw

Re: [PATCH] net: Mellanox: Delete unnecessary checks before the function call "vunmap"

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 15:17:00 +0100

The vunmap() function performs also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

#851 lore raw

PATCH 1/1 net: ep93xx_eth: Delete unnecessary checks before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 15:56:58 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/cirrus/ep93xx_eth.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/cirrus/ep93xx_eth.c +2 -4
index 3a12c09..de9f7c9 100644
@@ -475,8 +475,7 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep)
 		if (d)
 			dma_unmap_single(dev, d, PKT_BUF_SIZE, DMA_FROM_DEVICE);
 
-		if (ep->rx_buf[i] != NULL)
-			kfree(ep->rx_buf[i]);
+		kfree(ep->rx_buf[i]);
 	}
 
 	for (i = 0; i < TX_QUEUE_ENTRIES; i++) {
@@ -486,8 +485,7 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep)
 		if (d)
 			dma_unmap_single(dev, d, PKT_BUF_SIZE, DMA_TO_DEVICE);
 
-		if (ep->tx_buf[i] != NULL)
-			kfree(ep->tx_buf[i]);
+		kfree(ep->tx_buf[i]);
 	}
 
 	dma_free_coherent(dev, sizeof(struct ep93xx_descs), ep->descs,
Signature · 1 line
2.2.2
#852 lore raw

RE: [PATCH] net: ep93xx_eth: Delete unnecessary checks before the function call "kfree"

Quoted 25 lines · Markus Elfring

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/cirrus/ep93xx_eth.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/cirrus/ep93xx_eth.c +1 -2
index 3a12c09..de9f7c9 100644
@@ -475,8 +475,7 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep)
 		if (d)
 			dma_unmap_single(dev, d, PKT_BUF_SIZE, DMA_FROM_DEVICE);
 
-		if (ep->rx_buf[i] != NULL)
-			kfree(ep->rx_buf[i]);
+		kfree(ep->rx_buf[i]);
 	}
 
 	for (i = 0; i < TX_QUEUE_ENTRIES; i++) {

drivers/net/ethernet/cirrus/ep93xx_eth.c static void ep93xx_free_buffers(struct ep93xx_priv *ep) · line 491

Quoted 9 lines
drivers/net/ethernet/cirrus/ep93xx_eth.c +1 -2
@@ -486,8 +485,7 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep)
 		if (d)
 			dma_unmap_single(dev, d, PKT_BUF_SIZE, DMA_TO_DEVICE);
 
-		if (ep->tx_buf[i] != NULL)
-			kfree(ep->tx_buf[i]);
+		kfree(ep->tx_buf[i]);
 	}
 
 	dma_free_coherent(dev, sizeof(struct ep93xx_descs), ep->descs,

Thanks

#854 lore raw

cover CW1200: Deletion of an unnecessary check

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 17:31:00 +0100

Another update suggestion was taken into account after a patch was applied from static source code analysis.

Markus Elfring (2):
Delete an unnecessary check before the function call "release_firmware" Less function calls in cw1200_load_firmware_cw1200() after error detection

 drivers/net/wireless/cw1200/fwio.c | 40 +++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 16 deletions(-)
Signature · 1 line
2.2.2
#855 lore raw

PATCH 1/2 CW1200: Delete an unnecessary check before the function call "release_firmware"

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 16:32:15 +0100

The release_firmware() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/wireless/cw1200/fwio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/wireless/cw1200/fwio.c +1 -2
index 6f1b9aa..581dfde 100644
@@ -246,8 +246,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 
 error:
 	kfree(buf);
-	if (firmware)
-		release_firmware(firmware);
+	release_firmware(firmware);
 	return ret;
 
 #undef APB_WRITE
Signature · 1 line
2.2.2
#857 lore raw

PATCH 2/2 CW1200: Less function calls in cw1200_load_firmware_cw1200() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 17:28:41 +0100

The functions kfree() and release_firmware() were called in a few cases by the cw1200_load_firmware_cw1200() function during error handling even if the passed variables contained still a null pointer.

Corresponding implementation details could be improved by adjustments for jump targets.

---
 drivers/net/wireless/cw1200/fwio.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)
drivers/net/wireless/cw1200/fwio.c +23 -14
index 581dfde..30e7646 100644
@@ -66,25 +66,31 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 	do { \
 		ret = cw1200_apb_write_32(priv, CW1200_APB(reg), (val)); \
 		if (ret < 0) \
-			goto error; \
+			goto exit; \
+	} while (0)
+#define APB_WRITE2(reg, val) \
+	do { \
+		ret = cw1200_apb_write_32(priv, CW1200_APB(reg), (val)); \
+		if (ret < 0) \
+			goto free_buffer; \
 	} while (0)
 #define APB_READ(reg, val) \
 	do { \
 		ret = cw1200_apb_read_32(priv, CW1200_APB(reg), &(val)); \
 		if (ret < 0) \
-			goto error; \
+			goto free_buffer; \
 	} while (0)
 #define REG_WRITE(reg, val) \
 	do { \
 		ret = cw1200_reg_write_32(priv, (reg), (val)); \
 		if (ret < 0) \
-			goto error; \
+			goto exit; \
 	} while (0)
 #define REG_READ(reg, val) \
 	do { \
 		ret = cw1200_reg_read_32(priv, (reg), &(val)); \
 		if (ret < 0) \
-			goto error; \
+			goto exit; \
 	} while (0)
 
 	switch (priv->hw_revision) {
@@ -142,14 +148,14 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 	ret = request_firmware(&firmware, fw_path, priv->pdev);
 	if (ret) {
 		pr_err("Can't load firmware file %s.\n", fw_path);
-		goto error;
+		goto exit;
 	}
 
 	buf = kmalloc(DOWNLOAD_BLOCK_SIZE, GFP_KERNEL | GFP_DMA);
 	if (!buf) {
 		pr_err("Can't allocate firmware load buffer.\n");
 		ret = -ENOMEM;
-		goto error;
+		goto firmware_release;
 	}
 
 	/* Check if the bootloader is ready */
@@ -163,7 +169,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 	if (val32 != DOWNLOAD_I_AM_HERE) {
 		pr_err("Bootloader is not ready.\n");
 		ret = -ETIMEDOUT;
-		goto error;
+		goto free_buffer;
 	}
 
 	/* Calculcate number of download blocks */
@@ -171,7 +177,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 
 	/* Updating the length in Download Ctrl Area */
 	val32 = firmware->size; /* Explicit cast from size_t to u32 */
-	APB_WRITE(DOWNLOAD_IMAGE_SIZE_REG, val32);
+	APB_WRITE2(DOWNLOAD_IMAGE_SIZE_REG, val32);
 
 	/* Firmware downloading loop */
 	for (block = 0; block < num_blocks; block++) {
@@ -183,7 +189,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 		if (val32 != DOWNLOAD_PENDING) {
 			pr_err("Bootloader reported error %d.\n", val32);
 			ret = -EIO;
-			goto error;
+			goto free_buffer;
 		}
 
 		/* loop until put - get <= 24K */
@@ -198,7 +204,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 		if ((put - get) > (DOWNLOAD_FIFO_SIZE - DOWNLOAD_BLOCK_SIZE)) {
 			pr_err("Timeout waiting for FIFO.\n");
 			ret = -ETIMEDOUT;
-			goto error;
+			goto free_buffer;
 		}
 
 		/* calculate the block size */
@@ -220,12 +226,12 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 		if (ret < 0) {
 			pr_err("Can't write firmware block @ %d!\n",
 			       put & (DOWNLOAD_FIFO_SIZE - 1));
-			goto error;
+			goto free_buffer;
 		}
 
 		/* update the put register */
 		put += block_size;
-		APB_WRITE(DOWNLOAD_PUT_REG, put);
+		APB_WRITE2(DOWNLOAD_PUT_REG, put);
 	} /* End of firmware download loop */
 
 	/* Wait for the download completion */
@@ -238,18 +244,21 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 	if (val32 != DOWNLOAD_SUCCESS) {
 		pr_err("Wait for download completion failed: 0x%.8X\n", val32);
 		ret = -ETIMEDOUT;
-		goto error;
+		goto free_buffer;
 	} else {
 		pr_info("Firmware download completed.\n");
 		ret = 0;
 	}
 
-error:
+free_buffer:
 	kfree(buf);
+firmware_release:
 	release_firmware(firmware);
+exit:
 	return ret;
 
 #undef APB_WRITE
+#undef APB_WRITE2
 #undef APB_READ
 #undef REG_WRITE
 #undef REG_READ
Signature · 1 line
2.2.2
#858 lore raw

PATCH 1/1 ath9k: Delete an unnecessary check before the function call "relay_close"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 18:48:28 +0100

The relay_close() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/wireless/ath/ath9k/common-spectral.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath9k/common-spectral.c +1 -1
index ec93ddf..5cee231 100644
@@ -582,7 +582,7 @@ static struct rchan_callbacks rfs_spec_scan_cb = {
 
 void ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv)
 {
-	if (config_enabled(CONFIG_ATH9K_DEBUGFS) && spec_priv->rfs_chan_spec_scan) {
+	if (config_enabled(CONFIG_ATH9K_DEBUGFS)) {
 		relay_close(spec_priv->rfs_chan_spec_scan);
 		spec_priv->rfs_chan_spec_scan = NULL;
 	}
Signature · 1 line
2.2.2
#860 lore raw

PATCH 1/1 ath10k: Delete unnecessary checks before the function call "release_firmware"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 19:30:23 +0100

The release_firmware() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/wireless/ath/ath10k/core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/wireless/ath/ath10k/core.c +4 -4
index 2d0671e..45171ad 100644
@@ -393,16 +393,16 @@ static int ath10k_download_fw(struct ath10k *ar, enum ath10k_firmware_mode mode)
 
 static void ath10k_core_free_firmware_files(struct ath10k *ar)
 {
-	if (ar->board && !IS_ERR(ar->board))
+	if (!IS_ERR(ar->board))
 		release_firmware(ar->board);
 
-	if (ar->otp && !IS_ERR(ar->otp))
+	if (!IS_ERR(ar->otp))
 		release_firmware(ar->otp);
 
-	if (ar->firmware && !IS_ERR(ar->firmware))
+	if (!IS_ERR(ar->firmware))
 		release_firmware(ar->firmware);
 
-	if (ar->cal_file && !IS_ERR(ar->cal_file))
+	if (!IS_ERR(ar->cal_file))
 		release_firmware(ar->cal_file);
 
 	ar->board = NULL;
Signature · 1 line
2.2.2
#862 lore raw

PATCH 1/1 orinoco: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 19:53:11 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/wireless/orinoco/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/orinoco/main.c +1 -1
index 38ec8d1..c410180 100644
@@ -2342,7 +2342,7 @@ void free_orinocodev(struct orinoco_private *priv)
 	list_for_each_entry_safe(sd, sdtemp, &priv->scan_list, list) {
 		list_del(&sd->list);
 
-		if ((sd->len > 0) && sd->buf)
+		if (sd->len > 0)
 			kfree(sd->buf);
 		kfree(sd);
 	}
Signature · 1 line
2.2.2
#864 lore raw

PATCH 1/1 HostAP: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 20:06:39 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/wireless/hostap/hostap_ap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/hostap/hostap_ap.c +1 -1
index 5965255..fd8d83d 100644
@@ -145,7 +145,7 @@ static void ap_free_sta(struct ap_data *ap, struct sta_info *sta)
 	if (sta->aid > 0)
 		ap->sta_aid[sta->aid - 1] = NULL;
 
-	if (!sta->ap && sta->u.sta.challenge)
+	if (!sta->ap)
 		kfree(sta->u.sta.challenge);
 	del_timer_sync(&sta->timer);
 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
Signature · 1 line
2.2.2
#866 lore raw

PATCH 1/1 net: brcm80211: Delete unnecessary checks before two function calls

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 20:28:49 +0100

The functions brcmu_pkt_buf_free_skb() and usb_free_urb() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

---
 drivers/net/wireless/brcm80211/brcmfmac/sdio.c | 3 +--
 drivers/net/wireless/brcm80211/brcmfmac/usb.c  | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/net/wireless/brcm80211/brcmfmac/sdio.c +1 -2
index 99a3776..5b5520b 100644
@@ -2543,8 +2543,7 @@ static void brcmf_sdio_bus_stop(struct device *dev)
 	brcmu_pktq_flush(&bus->txq, true, NULL, NULL);
 
 	/* Clear any held glomming stuff */
-	if (bus->glomd)
-		brcmu_pkt_buf_free_skb(bus->glomd);
+	brcmu_pkt_buf_free_skb(bus->glomd);
 	brcmf_sdio_free_glom(bus);
 
 	/* Clear rx control and wake any waiters */
drivers/net/wireless/brcm80211/brcmfmac/usb.c +1 -1
index 4572def..10c684c 100644
@@ -421,7 +421,7 @@ fail:
 	brcmf_err("fail!\n");
 	while (!list_empty(q)) {
 		req = list_entry(q->next, struct brcmf_usbreq, list);
-		if (req && req->urb)
+		if (req)
 			usb_free_urb(req->urb);
 		list_del(q->next);
 	}
Signature · 1 line
2.2.2
#868 lore raw

PATCH 1/1 SGI-XPC: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 20:50:31 +0100

The kfree() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/misc/sgi-xp/xpc_partition.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/misc/sgi-xp/xpc_partition.c +1 -2
index 6956f7e..0e32431 100644
@@ -98,8 +98,7 @@ xpc_get_rsvd_page_pa(int nasid)
 			len = L1_CACHE_ALIGN(len);
 
 		if (len > buf_len) {
-			if (buf_base != NULL)
-				kfree(buf_base);
+			kfree(buf_base);
 			buf_len = L1_CACHE_ALIGN(len);
 			buf = xpc_kmalloc_cacheline_aligned(buf_len, GFP_KERNEL,
 							    &buf_base);
Signature · 1 line
2.2.2
#869 lore raw

PATCH 1/1 macintosh: Delete an unnecessary check before the function call "of_node_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 21:32:27 +0100

The of_node_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/macintosh/smu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/macintosh/smu.c +1 -2
index 10ae69b..d531f80 100644
@@ -557,8 +557,7 @@ int __init smu_init (void)
 	return 0;
 
 fail_msg_node:
-	if (smu->msg_node)
-		of_node_put(smu->msg_node);
+	of_node_put(smu->msg_node);
 fail_db_node:
 	of_node_put(smu->db_node);
 fail_bootmem:
Signature · 1 line
2.2.2
#871 lore raw

PATCH 1/1 GPU-DRM-Exynos: Delete unnecessary checks before two function calls

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 21:54:45 +0100

The functions phy_power_on() and vunmap() perform also input parameter validation. Thus the test around their calls is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/exynos/exynos_dp_core.c   | 6 ++----
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/drm/exynos/exynos_dp_core.c +2 -4
index 34d46aa..306cf1d 100644
@@ -1057,14 +1057,12 @@ static int exynos_dp_create_connector(struct exynos_drm_display *display,
 
 static void exynos_dp_phy_init(struct exynos_dp_device *dp)
 {
-	if (dp->phy)
-		phy_power_on(dp->phy);
+	phy_power_on(dp->phy);
 }
 
 static void exynos_dp_phy_exit(struct exynos_dp_device *dp)
 {
-	if (dp->phy)
-		phy_power_off(dp->phy);
+	phy_power_off(dp->phy);
 }
 
 static void exynos_dp_poweron(struct exynos_drm_display *display)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +1 -1
index e12ea90..0dd448a 100644
@@ -313,7 +313,7 @@ static void exynos_drm_fbdev_destroy(struct drm_device *dev,
 	struct exynos_drm_gem_obj *exynos_gem_obj = exynos_fbd->exynos_gem_obj;
 	struct drm_framebuffer *fb;
 
-	if (is_drm_iommu_supported(dev) && exynos_gem_obj->buffer->kvaddr)
+	if (is_drm_iommu_supported(dev))
 		vunmap(exynos_gem_obj->buffer->kvaddr);
 
 	/* release drm framebuffer and real buffer */
Signature · 1 line
2.2.2
#876 lore raw

PATCH 1/1 GPU-DRM-OMAP: Delete unnecessary checks before two function calls

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 22:22:36 +0100

The functions framebuffer_release() and vunmap() perform also input parameter validation. Thus the test around their calls is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/omapdrm/omap_fbdev.c | 3 +--
 drivers/gpu/drm/omapdrm/omap_gem.c   | 5 ++---
 2 files changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/drm/omapdrm/omap_fbdev.c +1 -2
index d292d24..fcc02b0 100644
@@ -270,8 +270,7 @@ fail_unlock:
 fail:
 
 	if (ret) {
-		if (fbi)
-			framebuffer_release(fbi);
+		framebuffer_release(fbi);
 		if (fb) {
 			drm_framebuffer_unregister_private(fb);
 			drm_framebuffer_remove(fb);
drivers/gpu/drm/omapdrm/omap_gem.c +2 -3
index aeb91ed..18a4137 100644
@@ -1292,12 +1292,11 @@ void omap_gem_free_object(struct drm_gem_object *obj)
 		if (omap_obj->pages)
 			omap_gem_detach_pages(obj);
 
-		if (!is_shmem(obj)) {
+		if (!is_shmem(obj))
 			dma_free_writecombine(dev->dev, obj->size,
 					omap_obj->vaddr, omap_obj->paddr);
-		} else if (omap_obj->vaddr) {
+		else
 			vunmap(omap_obj->vaddr);
-		}
 	}
 
 	/* don't free externally allocated syncobj */
Signature · 1 line
2.2.2
maintainer Applied
#831 lore raw

Re: [PATCH] IBM-EMAC: Delete an unnecessary check before the function call "of_dev_put"

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Tue, 03 Feb 2015 19:51:38 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 19:47:33 +0100

The of_dev_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Applied.