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 6

Subsystems (270)
lore
Share & tools
lore
Applied
#498 lore raw

Re: [PATCH v3] video-lp8788: Delete a check before backlight_device_unregister()

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

From: Markus Elfring <[email protected]>
Date: Wed, 1 Jul 2015 12:08:31 +0200

The backlight_device_unregister() 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.

---
 drivers/video/backlight/lp8788_bl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Applied, thanks.

Quoted 14 lines
drivers/video/backlight/lp8788_bl.c +1 -2
index e418d5b..5d583d7 100644
@@ -221,8 +221,7 @@ static void lp8788_backlight_unregister(struct lp8788_bl *bl)
 {
 	struct backlight_device *bl_dev = bl->bl_dev;
 
-	if (bl_dev)
-		backlight_device_unregister(bl_dev);
+	backlight_device_unregister(bl_dev);
 }
 
 static ssize_t lp8788_get_bl_ctl_mode(struct device *dev,
Signature · 8 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
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
#499 lore raw

cover staging: android: ion: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 23 Nov 2014 19:13:56 +0100

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

Markus Elfring (2):
Deletion of unnecessary checks before two function calls One function call less in ion_buffer_create() after error detection

 drivers/staging/android/ion/ion.c              | 9 +++------
 drivers/staging/android/ion/ion_dummy_driver.c | 6 ++----
 drivers/staging/android/ion/tegra/tegra_ion.c  | 6 ++----
 3 files changed, 7 insertions(+), 14 deletions(-)
Signature · 1 line
2.1.3
#500 lore raw

PATCH 1/2 staging: android: ion: Deletion of unnecessary checks before two function calls

From: Markus Elfring <[email protected]>
Date: Sun, 23 Nov 2014 18:48:15 +0100

The functions ion_heap_destroy() and vfree() perform also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/staging/android/ion/ion.c              | 6 ++----
 drivers/staging/android/ion/ion_dummy_driver.c | 6 ++----
 drivers/staging/android/ion/tegra/tegra_ion.c  | 6 ++----
 3 files changed, 6 insertions(+), 12 deletions(-)
drivers/staging/android/ion/ion.c +2 -4
index 2703609..df12cc3 100644
@@ -263,8 +263,7 @@ err:
 	heap->ops->unmap_dma(heap, buffer);
 	heap->ops->free(buffer);
 err1:
-	if (buffer->pages)
-		vfree(buffer->pages);
+	vfree(buffer->pages);
 err2:
 	kfree(buffer);
 	return ERR_PTR(ret);
@@ -276,8 +275,7 @@ void ion_buffer_destroy(struct ion_buffer *buffer)
 		buffer->heap->ops->unmap_kernel(buffer->heap, buffer);
 	buffer->heap->ops->unmap_dma(buffer->heap, buffer);
 	buffer->heap->ops->free(buffer);
-	if (buffer->pages)
-		vfree(buffer->pages);
+	vfree(buffer->pages);
 	kfree(buffer);
 }
 
drivers/staging/android/ion/ion_dummy_driver.c +2 -4
index 3a45e79..d06bf52 100644
@@ -112,10 +112,8 @@ static int __init ion_dummy_init(void)
 	}
 	return 0;
 err:
-	for (i = 0; i < dummy_ion_pdata.nr; i++) {
-		if (heaps[i])
-			ion_heap_destroy(heaps[i]);
-	}
+	for (i = 0; i < dummy_ion_pdata.nr; ++i)
+		ion_heap_destroy(heaps[i]);
 	kfree(heaps);
 
 	if (carveout_ptr) {
drivers/staging/android/ion/tegra/tegra_ion.c +2 -4
index 11c7cce..5b8ef0e 100644
@@ -54,10 +54,8 @@ static int tegra_ion_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, idev);
 	return 0;
 err:
-	for (i = 0; i < num_heaps; i++) {
-		if (heaps[i])
-			ion_heap_destroy(heaps[i]);
-	}
+	for (i = 0; i < num_heaps; ++i)
+		ion_heap_destroy(heaps[i]);
 	return err;
 }
 
Signature · 1 line
2.1.3
Acked-by on v1 1/2
#501 lore raw

Re: [PATCH 1/2] staging: android: ion: Deletion of unnecessary checks before two function calls

Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 23 Nov 2014 18:48:15 +0100

The functions ion_heap_destroy() and vfree() perform also input parameter validation. Thus the test around the call is not needed.

Quoted 8 lines

This issue was detected by using the Coccinelle software.

---
 drivers/staging/android/ion/ion.c              | 6 ++----
 drivers/staging/android/ion/ion_dummy_driver.c | 6 ++----
 drivers/staging/android/ion/tegra/tegra_ion.c  | 6 ++----
 3 files changed, 6 insertions(+), 12 deletions(-)
#502 lore raw

PATCH 2/2 staging: android: ion: One function call less in ion_buffer_create() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 23 Nov 2014 19:12:29 +0100

The jump label "err1" was used by the ion_buffer_create() function in case of a memory allocation failure just to pass a null pointer to a vfree() function call by a data structure element.
This implementation detail could be improved by the deletion of this inappropriate jump label.

---
 drivers/staging/android/ion/ion.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/android/ion/ion.c +1 -2
index df12cc3..7a26b85 100644
@@ -226,7 +226,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
 		buffer->pages = vmalloc(sizeof(struct page *) * num_pages);
 		if (!buffer->pages) {
 			ret = -ENOMEM;
-			goto err1;
+			goto err2;
 		}
 
 		for_each_sg(table->sgl, sg, table->nents, i) {
@@ -262,7 +262,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
 err:
 	heap->ops->unmap_dma(heap, buffer);
 	heap->ops->free(buffer);
-err1:
 	vfree(buffer->pages);
 err2:
 	kfree(buffer);
Signature · 1 line
2.1.3
#503 lore raw

Re: [PATCH 2/2] staging: android: ion: One function call less in ion_buffer_create() after error detection

Quoted 28 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 23 Nov 2014 19:12:29 +0100

The jump label "err1" was used by the ion_buffer_create() function in case of a memory allocation failure just to pass a null pointer to a vfree() function call by a data structure element.
This implementation detail could be improved by the deletion of this inappropriate jump label.

---
 drivers/staging/android/ion/ion.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/android/ion/ion.c +1 -1
index df12cc3..7a26b85 100644
@@ -226,7 +226,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
 		buffer->pages = vmalloc(sizeof(struct page *) * num_pages);
 		if (!buffer->pages) {
 			ret = -ENOMEM;
-			goto err1;
+			goto err2;
 		}
 
 		for_each_sg(table->sgl, sg, table->nents, i) {

drivers/staging/android/ion/ion.c static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, · line 266

Quoted 6 lines
drivers/staging/android/ion/ion.c +0 -1
@@ -262,7 +262,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
 err:
 	heap->ops->unmap_dma(heap, buffer);
 	heap->ops->free(buffer);
-err1:
 	vfree(buffer->pages);
 err2:

Now we have "err" and "err2", which doesn't make much sense, please fix up.

#504 lore raw

Re: [PATCH 2/2] staging: android: ion: One function call less in ion_buffer_create() after error detection

Quoted 12 lines
Quoted 12 lines
drivers/staging/android/ion/ion.c +1 -1
index df12cc3..7a26b85 100644
@@ -226,7 +226,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
 		buffer->pages = vmalloc(sizeof(struct page *) * num_pages);
 		if (!buffer->pages) {
 			ret = -ENOMEM;
-			goto err1;
+			goto err2;
 		}
 
Quoted 11 lines

drivers/staging/android/ion/ion.c static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, · line 266

Quoted 8 lines
drivers/staging/android/ion/ion.c +0 -1
 		for_each_sg(table->sgl, sg, table->nents, i) {
@@ -262,7 +262,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
 err:
 	heap->ops->unmap_dma(heap, buffer);
 	heap->ops->free(buffer);
-err1:
 	vfree(buffer->pages);
 err2:

Now we have "err" and "err2", which doesn't make much sense, please fix up.

How do you want this source code to be improved? Should I introduce longer names for the affected jump labels?

Regards,
Markus

#505 lore raw

Re: [PATCH 2/2] staging: android: ion: One function call less in ion_buffer_create() after error det

In reply to SF Markus Elfring

Am 27.11.2014 15:25, schrieb SF Markus Elfring:

Quoted 24 lines
Quoted 12 lines
Quoted 12 lines
drivers/staging/android/ion/ion.c +1 -1
index df12cc3..7a26b85 100644
@@ -226,7 +226,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
 		buffer->pages = vmalloc(sizeof(struct page *) * num_pages);
 		if (!buffer->pages) {
 			ret = -ENOMEM;
-			goto err1;
+			goto err2;
 		}
 
Quoted 11 lines

drivers/staging/android/ion/ion.c static struct ion_buffer *ion_buffer_create(struct ion_heap *heap, · line 266

Quoted 8 lines
drivers/staging/android/ion/ion.c +0 -1
 		for_each_sg(table->sgl, sg, table->nents, i) {
@@ -262,7 +262,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
 err:
 	heap->ops->unmap_dma(heap, buffer);
 	heap->ops->free(buffer);
-err1:
 	vfree(buffer->pages);
 err2:

Now we have "err" and "err2", which doesn't make much sense, please fix up.

Quoted 3 lines

How do you want this source code to be improved? Should I introduce longer names for the affected jump labels?

hi markus,
the confusion arises because the errX are numbered and now on in the sequence is missing.

So far i see you can renumber them or give more descriptiv names.

hope that helps,
re,
wh

#506 lore raw

PATCH 1/1 Sony-laptop: Deletion of an unnecessary check before the function call "pci_dev_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 24 Nov 2014 22:00:21 +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/platform/x86/sony-laptop.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/platform/x86/sony-laptop.c +1 -2
index 26ad9ff..22b173d 100644
@@ -3717,8 +3717,7 @@ static void sony_pic_detect_device_type(struct sony_pic_dev *dev)
 	dev->event_types = type2_events;
 
 out:
-	if (pcidev)
-		pci_dev_put(pcidev);
+	pci_dev_put(pcidev);
 
 	pr_info("detected Type%d model\n",
 		dev->model = SONYPI_DEVICE_TYPE1 ? 1 :
Signature · 1 line
2.1.3
#507 lore raw

Re: [PATCH 1/1] Sony-laptop: Deletion of an unnecessary check before the function call "pci_dev_put"

Quoted 10 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 24 Nov 2014 22:00:21 +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.

Thanks Markus, queued.

Signature · 2 lines
Darren Hart
Intel Open Source Technology Center
#508 lore raw

PATCH 1/1 platform: x86: Deletion of checks before backlight_device_unregister()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 24 Nov 2014 20:30:29 +0100

The backlight_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.

---
 drivers/platform/x86/asus-laptop.c    | 3 +--
 drivers/platform/x86/asus-wmi.c       | 3 +--
 drivers/platform/x86/eeepc-laptop.c   | 3 +--
 drivers/platform/x86/fujitsu-laptop.c | 6 ++----
 drivers/platform/x86/ideapad-laptop.c | 3 +--
 drivers/platform/x86/intel_oaktrail.c | 3 +--
 drivers/platform/x86/msi-wmi.c        | 3 +--
 drivers/platform/x86/sony-laptop.c    | 3 +--
 drivers/platform/x86/toshiba_acpi.c   | 3 +--
 9 files changed, 10 insertions(+), 20 deletions(-)
drivers/platform/x86/asus-laptop.c +1 -2
index 7f4dc6f..11fac1a 100644
@@ -843,8 +843,7 @@ static int asus_backlight_init(struct asus_laptop *asus)
 
 static void asus_backlight_exit(struct asus_laptop *asus)
 {
-	if (asus->backlight_device)
-		backlight_device_unregister(asus->backlight_device);
+	backlight_device_unregister(asus->backlight_device);
 	asus->backlight_device = NULL;
 }
 
drivers/platform/x86/asus-wmi.c +1 -2
index 21fc932..7543a56 100644
@@ -1308,8 +1308,7 @@ static int asus_wmi_backlight_init(struct asus_wmi *asus)
 
 static void asus_wmi_backlight_exit(struct asus_wmi *asus)
 {
-	if (asus->backlight_device)
-		backlight_device_unregister(asus->backlight_device);
+	backlight_device_unregister(asus->backlight_device);
 
 	asus->backlight_device = NULL;
 }
drivers/platform/x86/eeepc-laptop.c +1 -2
index bd533c2..9bc7eb7 100644
@@ -1158,8 +1158,7 @@ static int eeepc_backlight_init(struct eeepc_laptop *eeepc)
 
 static void eeepc_backlight_exit(struct eeepc_laptop *eeepc)
 {
-	if (eeepc->backlight_device)
-		backlight_device_unregister(eeepc->backlight_device);
+	backlight_device_unregister(eeepc->backlight_device);
 	eeepc->backlight_device = NULL;
 }
 
drivers/platform/x86/fujitsu-laptop.c +2 -4
index 87aa28c..f1a670b 100644
@@ -1147,8 +1147,7 @@ fail_hotkey1:
 fail_hotkey:
 	platform_driver_unregister(&fujitsupf_driver);
 fail_backlight:
-	if (fujitsu->bl_device)
-		backlight_device_unregister(fujitsu->bl_device);
+	backlight_device_unregister(fujitsu->bl_device);
 fail_sysfs_group:
 	sysfs_remove_group(&fujitsu->pf_device->dev.kobj,
 			   &fujitsupf_attribute_group);
@@ -1172,8 +1171,7 @@ static void __exit fujitsu_cleanup(void)
 
 	platform_driver_unregister(&fujitsupf_driver);
 
-	if (fujitsu->bl_device)
-		backlight_device_unregister(fujitsu->bl_device);
+	backlight_device_unregister(fujitsu->bl_device);
 
 	sysfs_remove_group(&fujitsu->pf_device->dev.kobj,
 			   &fujitsupf_attribute_group);
drivers/platform/x86/ideapad-laptop.c +1 -2
index ed494f3..3163061 100644
@@ -729,8 +729,7 @@ static int ideapad_backlight_init(struct ideapad_private *priv)
 
 static void ideapad_backlight_exit(struct ideapad_private *priv)
 {
-	if (priv->blightdev)
-		backlight_device_unregister(priv->blightdev);
+	backlight_device_unregister(priv->blightdev);
 	priv->blightdev = NULL;
 }
 
drivers/platform/x86/intel_oaktrail.c +1 -2
index 4bc9604..0dd72cf 100644
@@ -271,8 +271,7 @@ static int oaktrail_backlight_init(void)
 
 static void oaktrail_backlight_exit(void)
 {
-	if (oaktrail_bl_device)
-		backlight_device_unregister(oaktrail_bl_device);
+	backlight_device_unregister(oaktrail_bl_device);
 }
 
 static int oaktrail_probe(struct platform_device *pdev)
drivers/platform/x86/msi-wmi.c +1 -2
index 70222f2..6d2bac0 100644
@@ -354,8 +354,7 @@ static void __exit msi_wmi_exit(void)
 		sparse_keymap_free(msi_wmi_input_dev);
 		input_unregister_device(msi_wmi_input_dev);
 	}
-	if (backlight)
-		backlight_device_unregister(backlight);
+	backlight_device_unregister(backlight);
 }
 
 module_init(msi_wmi_init);
drivers/platform/x86/sony-laptop.c +1 -2
index 26ad9ff..a48cdc7 100644
@@ -3141,8 +3141,7 @@ static void sony_nc_backlight_setup(void)
 
 static void sony_nc_backlight_cleanup(void)
 {
-	if (sony_bl_props.dev)
-		backlight_device_unregister(sony_bl_props.dev);
+	backlight_device_unregister(sony_bl_props.dev);
 }
 
 static int sony_nc_add(struct acpi_device *device)
drivers/platform/x86/toshiba_acpi.c +1 -2
index d0dce73..703a68a 100644
@@ -1647,8 +1647,7 @@ static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
 		rfkill_destroy(dev->bt_rfk);
 	}
 
-	if (dev->backlight_dev)
-		backlight_device_unregister(dev->backlight_dev);
+	backlight_device_unregister(dev->backlight_dev);
 
 	if (dev->illumination_supported)
 		led_classdev_unregister(&dev->led_dev);
Signature · 1 line
2.1.3
#509 lore raw

Re: [PATCH 1/1] platform: x86: Deletion of checks before backlight_device_unregister()

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 24 Nov 2014 20:30:29 +0100

The backlight_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.

Thanks Markus, queued.

Signature · 2 lines
Darren Hart
Intel Open Source Technology Center
Acked-by on v1 1/1
#510 lore raw

Re: [PATCH 1/1] platform: x86: Deletion of checks before backlight_device_unregister()

In reply to SF Markus Elfring

Hi Markus,

Quoted 8 lines · Le lundi 24 novembre 2014, 20:40:22 SF Markus Elfring a écrit :

From: Markus Elfring <[email protected]>
Date: Mon, 24 Nov 2014 20:30:29 +0100

The backlight_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.

What script was used ? Is it in scripts/coccinelle ?

Quoted 5 lines
drivers/platform/x86/msi-wmi.c +0 -0
index 70222f2..6d2bac0 100644

drivers/platform/x86/msi-wmi.c static void __exit msi_wmi_exit(void) · line 360

Quoted 9 lines
drivers/platform/x86/msi-wmi.c +1 -2
@@ -354,8 +354,7 @@ static void __exit msi_wmi_exit(void)
 		sparse_keymap_free(msi_wmi_input_dev);
 		input_unregister_device(msi_wmi_input_dev);
 	}
-	if (backlight)
-		backlight_device_unregister(backlight);
+	backlight_device_unregister(backlight);
 }
 
 module_init(msi_wmi_init);

For this part:

Regards,

Anisse
--
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

#511 lore raw

Re: [PATCH 1/1] platform: x86: Deletion of checks before backlight_device_unregister()

Quoted 3 lines
Quoted 1 line

This issue was detected by using the Coccinelle software.

What script was used ?

A semantic patch approach which I published on the mailing lists in March is in action on my software development system for a while.

Quoted 1 line

Is it in scripts/coccinelle ?

Not yet.

I hope that the involved update suggestions got sufficient positive feedback to integrate five scripts there.

Regards,
Markus

#512 lore raw

Re: [PATCH 1/1] platform: x86: Deletion of checks before backlight_device_unregister()

Quoted 8 lines · SF Markus Elfring
Quoted 3 lines
Quoted 1 line

This issue was detected by using the Coccinelle software.

What script was used ?

A semantic patch approach which I published on the mailing lists in March is in action on my software development system for a while.

Quoted 6 lines
Quoted 1 line

Is it in scripts/coccinelle ?

Not yet.

I hope that the involved update suggestions got sufficient positive feedback to integrate five scripts there.

The current scripts are very complicated, involving the interaction between multiple scripts and a database, and I think they are not very suitable for make coccicheck. Also, the idea of removing the null checks is not appropriate in all contexts. Perhaps it could be possible to add a script to the Linux kernel that handles a number of common cases for which removing the null test is widely considered to be desirable.

julia

#513 lore raw

Re: [PATCH 1/1] platform: x86: Deletion of checks before backlight_device_unregister()

Quoted 19 lines · Julia Lawall
Quoted 8 lines · SF Markus Elfring
Quoted 3 lines
Quoted 1 line

This issue was detected by using the Coccinelle software.

What script was used ?

A semantic patch approach which I published on the mailing lists in March is in action on my software development system for a while.

Quoted 6 lines
Quoted 1 line

Is it in scripts/coccinelle ?

Not yet.

I hope that the involved update suggestions got sufficient positive feedback to integrate five scripts there.

Quoted 9 lines

The current scripts are very complicated, involving the interaction between multiple scripts and a database, and I think they are not very suitable for make coccicheck. Also, the idea of removing the null checks is not appropriate in all contexts. Perhaps it could be possible to add a script to the Linux kernel that handles a number of common cases for which removing the null test is widely considered to be desirable.

julia

Julia, do you have any particular objection to this specific patch? I didn't see a reason to prevent it going in.

Signature · 2 lines
Darren Hart
Intel Open Source Technology Center
#514 lore raw

Re: [PATCH 1/1] platform: x86: Deletion of checks before backlight_device_unregister()

Quoted 27 lines · Darren Hart
Quoted 26 lines · Julia Lawall
Quoted 8 lines · SF Markus Elfring
Quoted 3 lines
Quoted 1 line

This issue was detected by using the Coccinelle software.

What script was used ?

A semantic patch approach which I published on the mailing lists in March is in action on my software development system for a while.

Quoted 6 lines
Quoted 1 line

Is it in scripts/coccinelle ?

Not yet.

I hope that the involved update suggestions got sufficient positive feedback to integrate five scripts there.

The current scripts are very complicated, involving the interaction between multiple scripts and a database, and I think they are not very suitable for make coccicheck. Also, the idea of removing the null checks is not appropriate in all contexts. Perhaps it could be possible to add a script to the Linux kernel that handles a number of common cases for which removing the null test is widely considered to be desirable.

Quoted 5 lines
Quoted 2 lines

julia

Julia, do you have any particular objection to this specific patch? I didn't see a reason to prevent it going in.

Sorry if I was unclear. If there is no problem with the current patch, I have no objection to it. I don't think that the semantic patch that caused this patch to be generated is suitable for inclusion in the Linux kernel.

julia

#515 lore raw

Re: platform: x86: Deletion of checks before backlight_device_unregister()

In reply to Darren Hart
Quoted 2 lines

Julia, do you have any particular objection to this specific patch? I didn't see a reason to prevent it going in.

Thanks for your interest around this concrete update suggestion.

* Would you like to distinguish the consequences a bit more for results from the application of the semantic patch language?

* Where do you prefer to store special extensions for Coccinelle's script collection

Regards,
Markus

#516 lore raw

Re: [PATCH 1/1] platform: x86: Deletion of checks before backlight_device_unregister()

In reply to Darren Hart
Quoted 2 lines · Darren Hart

Julia, do you have any particular objection to this specific patch? I didn't see a reason to prevent it going in.

I hate these patches...

We're saying "these functions have sanity checks so let's pass nonsense values to them, it's fine." It makes the code harder to understand. There is no way for a human being to remember the complete list of functions with sanity checks and which don't have sanity checks.

Markus has introduced quite a few bugs as well (people have so far managed to catch his bugs before they were committed). He so far has resisted any suggestion that he should manually review his patches before sending them.

Btw do have a scripts/coccinelle/free/ifnullfree.cocci which removes checks before kfree, debugfs_remove, debugfs_remove_recursive, and usb_free_urb.

regards,
dan carpenter

#517 lore raw

Re: platform: x86: Deletion of checks before backlight_device_unregister()

Quoted 2 lines

There is no way for a human being to remember the complete list of functions with sanity checks and which don't have sanity checks.

I understand also this software development challenge.

Quoted 1 line

Markus has introduced quite a few bugs as well

I have only found other opinions about specific update suggestions. Which of such "bugs" are real mistakes?
Are you looking for a better consensus?

Quoted 1 line

(people have so far managed to catch his bugs before they were committed).

Would you like to refer to any concrete software developers?

Quoted 2 lines

He so far has resisted any suggestion that he should manually review his patches before sending them.

I am performing source code review to some degree. My approach does partly not fit to your expectations.

Regards,
Markus

#518 lore raw

PATCH 1/1 Siano: Deletion of an unnecessary check before the function call "rc_unregister_device"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 24 Nov 2014 22:32:30 +0100

The rc_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/common/siano/smsir.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/common/siano/smsir.c +1 -2
index 273043e..35d0e88 100644
@@ -107,8 +107,7 @@ int sms_ir_init(struct smscore_device_t *coredev)
 
 void sms_ir_exit(struct smscore_device_t *coredev)
 {
-	if (coredev->ir.dev)
-		rc_unregister_device(coredev->ir.dev);
+	rc_unregister_device(coredev->ir.dev);
 
 	sms_log("");
 }
Signature · 1 line
2.1.3
#519 lore raw

PATCH 1/1 staging: olpc_dcon: Deletion of a check before backlight_device_unregister()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 24 Nov 2014 22:58:48 +0100

The backlight_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.

---
 drivers/staging/olpc_dcon/olpc_dcon.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/olpc_dcon/olpc_dcon.c +1 -2
index eb83b28..6a9a881 100644
@@ -682,8 +682,7 @@ static int dcon_remove(struct i2c_client *client)
 
 	free_irq(DCON_IRQ, dcon);
 
-	if (dcon->bl_dev)
-		backlight_device_unregister(dcon->bl_dev);
+	backlight_device_unregister(dcon->bl_dev);
 
 	if (dcon_device != NULL)
 		platform_device_unregister(dcon_device);
Signature · 1 line
2.1.3
#520 lore raw

PATCH 1/1 GPU-DRM-MSM-Adreno: Deletion of unnecessary checks before the function call "release_firmware"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 25 Nov 2014 13:44:20 +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/gpu/drm/msm/adreno/adreno_gpu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/msm/adreno/adreno_gpu.c +2 -4
index 655ce5b..757052c 100644
@@ -404,9 +404,7 @@ void adreno_gpu_cleanup(struct adreno_gpu *gpu)
 			msm_gem_put_iova(gpu->memptrs_bo, gpu->base.id);
 		drm_gem_object_unreference(gpu->memptrs_bo);
 	}
-	if (gpu->pm4)
-		release_firmware(gpu->pm4);
-	if (gpu->pfp)
-		release_firmware(gpu->pfp);
+	release_firmware(gpu->pm4);
+	release_firmware(gpu->pfp);
 	msm_gpu_cleanup(&gpu->base);
 }
Signature · 1 line
2.1.3
Reviewed-by on v1 1/1
#521 lore raw

Re: [PATCH 1/1] GPU-DRM-MSM-Adreno: Deletion of unnecessary checks before the function call "release_firmware"

Quoted 1 line · SF Markus Elfring

From: Markus Elfring <[email protected]>

You can probably get rid of this if you configure your emailer properly.

Quoted 1 line

Date: Tue, 25 Nov 2014 13:44:20 +0100

This is odd. I've never seen git send-email generate these.

I didn't notice with your earlier patches, but the subject prefix is wrong. Please use something more consistent with existing patches, in this case: "drm/msm: ..." or "drm/msm/adreno: ..."

Quoted 16 lines

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/gpu/drm/msm/adreno/adreno_gpu.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/msm/adreno/adreno_gpu.c +0 -0
index 655ce5b..757052c 100644
@@ -404,9 +404,7 @@ void adreno_gpu_cleanup(struct adreno_gpu *gpu)
 			msm_gem_put_iova(gpu->memptrs_bo, gpu->base.id);

drivers/gpu/drm/msm/adreno/adreno_gpu.c void adreno_gpu_cleanup(struct adreno_gpu *gpu) · line 410

Quoted 10 lines
drivers/gpu/drm/msm/adreno/adreno_gpu.c +2 -4
 		drm_gem_object_unreference(gpu->memptrs_bo);
 	}
-	if (gpu->pm4)
-		release_firmware(gpu->pm4);
-	if (gpu->pfp)
-		release_firmware(gpu->pfp);
+	release_firmware(gpu->pm4);
+	release_firmware(gpu->pfp);
 	msm_gpu_cleanup(&gpu->base);
 }

Besides the subject prefix,

#522 lore raw

PATCH 1/1 GPU-DRM-MSM: Deletion of unnecessary checks before two function calls

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 25 Nov 2014 14:30:28 +0100

The functions framebuffer_release() and vunmap() perform also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/msm/msm_fbdev.c | 3 +--
 drivers/gpu/drm/msm/msm_gem.c   | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/msm/msm_fbdev.c +1 -2
index ab5bfd2..fd5a6f3 100644
@@ -193,8 +193,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/msm/msm_gem.c +1 -2
index 4b1b82a..157cf21 100644
@@ -543,8 +543,7 @@ void msm_gem_free_object(struct drm_gem_object *obj)
 			drm_free_large(msm_obj->pages);
 
 	} else {
-		if (msm_obj->vaddr)
-			vunmap(msm_obj->vaddr);
+		vunmap(msm_obj->vaddr);
 		put_pages(obj);
 	}
 
Signature · 1 line
2.1.3
Reviewed-by on v1 1/1
#523 lore raw

Re: [PATCH 1/1] GPU-DRM-MSM: Deletion of unnecessary checks before two function calls

Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 25 Nov 2014 14:30:28 +0100

The functions framebuffer_release() and vunmap() perform also input parameter validation. Thus the test around the call is not needed.

Quoted 7 lines

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/msm/msm_fbdev.c | 3 +--
 drivers/gpu/drm/msm/msm_gem.c   | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

This needs the same fix for the subject prefix that I mentioned for your other patch, otherwise:

Perhaps a good idea would be to send all of these patches with the subject prefix fixed up as a second version and threaded in a series. That makes it easier for people to pick them up (assuming Dave will take them directly).

Thierry

#524 lore raw

Re: [PATCH 1/1] GPU-DRM-MSM: Deletion of unnecessary checks before two function calls

Quoted 18 lines · Thierry Reding
Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 25 Nov 2014 14:30:28 +0100

The functions framebuffer_release() and vunmap() perform also input parameter validation. Thus the test around the call is not needed.

Quoted 7 lines

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/msm/msm_fbdev.c | 3 +--
 drivers/gpu/drm/msm/msm_gem.c   | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

This needs the same fix for the subject prefix that I mentioned for your other patch, otherwise:

Quoted 7 lines

Perhaps a good idea would be to send all of these patches with the subject prefix fixed up as a second version and threaded in a series. That makes it easier for people to pick them up (assuming Dave will take them directly).

no worries, I'll fix up the subject lines when I apply..

BR,
-R

Quoted 7 lines

Thierry

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#525 lore raw

Re: [PATCH 1/1] GPU-DRM-MSM: Deletion of unnecessary checks before two function calls

In reply to SF Markus Elfring

btw, I have these two queued up on msm-next, thanks

BR,
-R

Quoted 45 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 25 Nov 2014 14:30:28 +0100

The functions framebuffer_release() and vunmap() perform also input parameter validation. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/msm/msm_fbdev.c | 3 +--
 drivers/gpu/drm/msm/msm_gem.c   | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/msm/msm_fbdev.c +1 -2
index ab5bfd2..fd5a6f3 100644
@@ -193,8 +193,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/msm/msm_gem.c +1 -3
index 4b1b82a..157cf21 100644
@@ -543,8 +543,7 @@ void msm_gem_free_object(struct drm_gem_object *obj)
                        drm_free_large(msm_obj->pages);
 
        } else {
-               if (msm_obj->vaddr)
-                       vunmap(msm_obj->vaddr);
+               vunmap(msm_obj->vaddr);
                put_pages(obj);
        }
 
--

2.1.3

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#526 lore raw

PATCH 1/1 IMX-DRM-core: Deletion of a check before drm_fbdev_cma_restore_mode()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 25 Nov 2014 16:06:19 +0100

The drm_fbdev_cma_restore_mode() 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/imx-drm/imx-drm-core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/imx-drm/imx-drm-core.c +1 -2
index 6b22106..0a1ecef 100644
@@ -64,8 +64,7 @@ static void imx_drm_driver_lastclose(struct drm_device *drm)
 #if IS_ENABLED(CONFIG_DRM_IMX_FB_HELPER)
 	struct imx_drm_device *imxdrm = drm->dev_private;
 
-	if (imxdrm->fbhelper)
-		drm_fbdev_cma_restore_mode(imxdrm->fbhelper);
+	drm_fbdev_cma_restore_mode(imxdrm->fbhelper);
 #endif
 }
 
Signature · 1 line
2.1.3
#527 lore raw

PATCH 1/1 staging: ozwpan: Deletion of unnecessary checks before the function call "oz_free_urb_link"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 25 Nov 2014 16:51:08 +0100

The oz_free_urb_link() 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/ozwpan/ozhcd.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/ozwpan/ozhcd.c +2 -4
index 30bd928..c9b6d98 100644
@@ -411,8 +411,7 @@ static void oz_complete_urb(struct usb_hcd *hcd, struct urb *urb,
 	}
 	spin_lock(&g_tasklet_lock);
 	spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
-	if (cancel_urbl)
-		oz_free_urb_link(cancel_urbl);
+	oz_free_urb_link(cancel_urbl);
 }
 
 /*
@@ -581,8 +580,7 @@ static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir,
 		}
 	}
 	spin_unlock_bh(&port->ozhcd->hcd_lock);
-	if (urbl)
-		oz_free_urb_link(urbl);
+	oz_free_urb_link(urbl);
 	return urbl ? 0 : -EIDRM;
 }
 
Signature · 1 line
2.1.3
#528 lore raw

PATCH 1/1 HID: Wacom: Deletion of an unnecessary check before the function call "vfree"

In reply to SF Markus Elfring

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.

---
 drivers/net/ethernet/sun/cassini.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/sun/cassini.c +1 -2
index 37f87ff..d745808 100644
@@ -5179,8 +5179,7 @@ static void cas_remove_one(struct pci_dev *pdev)
 	cp = netdev_priv(dev);
 	unregister_netdev(dev);
 
-	if (cp->fw_data)
-		vfree(cp->fw_data);
+	vfree(cp->fw_data);
 
 	mutex_lock(&cp->pm_mutex);
 	cancel_work_sync(&cp->reset_task);
Signature · 1 line
2.1.3
#529 lore raw

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

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.

---
 drivers/net/ethernet/sun/cassini.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/sun/cassini.c +1 -2
index 37f87ff..d745808 100644
@@ -5179,8 +5179,7 @@ static void cas_remove_one(struct pci_dev *pdev)
 	cp = netdev_priv(dev);
 	unregister_netdev(dev);
 
-	if (cp->fw_data)
-		vfree(cp->fw_data);
+	vfree(cp->fw_data);
 
 	mutex_lock(&cp->pm_mutex);
 	cancel_work_sync(&cp->reset_task);
Signature · 1 line
2.1.3
maintainer Applied
#530 lore raw

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

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.

#531 lore raw

PATCH 1/1 HID: Wacom: Deletion of unnecessary checks before the function call "input_free_device"

In reply to SF Markus Elfring

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

The input_free_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/hid/wacom_sys.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/hid/wacom_sys.c +2 -4
index eb55316..21ced00 100644
@@ -1099,10 +1099,8 @@ static void wacom_free_inputs(struct wacom *wacom)
 {
 	struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
 
-	if (wacom_wac->input)
-		input_free_device(wacom_wac->input);
-	if (wacom_wac->pad_input)
-		input_free_device(wacom_wac->pad_input);
+	input_free_device(wacom_wac->input);
+	input_free_device(wacom_wac->pad_input);
 	wacom_wac->input = NULL;
 	wacom_wac->pad_input = NULL;
 }
Signature · 1 line
2.1.3
#532 lore raw

PATCH v2 1/1 HID: Wacom: Delete unnecessary checks before the function call "input_free_device"

From: Markus Elfring <[email protected]>
Date: Thu, 9 Jul 2015 08:00:10 +0200

The input_free_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/hid/wacom_sys.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/hid/wacom_sys.c +3 -6
index 4c0ffca..936ad77 100644
@@ -1149,12 +1149,9 @@ static void wacom_free_inputs(struct wacom *wacom)
 {
 	struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
 
-	if (wacom_wac->pen_input)
-		input_free_device(wacom_wac->pen_input);
-	if (wacom_wac->touch_input)
-		input_free_device(wacom_wac->touch_input);
-	if (wacom_wac->pad_input)
-		input_free_device(wacom_wac->pad_input);
+	input_free_device(wacom_wac->pen_input);
+	input_free_device(wacom_wac->touch_input);
+	input_free_device(wacom_wac->pad_input);
 	wacom_wac->pen_input = NULL;
 	wacom_wac->touch_input = NULL;
 	wacom_wac->pad_input = NULL;
Signature · 1 line
2.4.5
#533 lore raw

Re: [PATCH v2] HID: Wacom: Delete unnecessary checks before the function call "input_free_device"

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 9 Jul 2015 08:00:10 +0200

The input_free_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.

This is really on a "is it worth it?" borderline, but anyway ... applied to for-4.3/upstream.

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#534 lore raw

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

In reply to SF Markus Elfring

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.

---
 drivers/net/ipvlan/ipvlan_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ipvlan/ipvlan_main.c +1 -2
index 96b71b0..feb1853 100644
@@ -125,8 +125,7 @@ static void ipvlan_uninit(struct net_device *dev)
 	struct ipvl_dev *ipvlan = netdev_priv(dev);
 	struct ipvl_port *port = ipvlan->port;
 
-	if (ipvlan->pcpu_stats)
-		free_percpu(ipvlan->pcpu_stats);
+	free_percpu(ipvlan->pcpu_stats);
 
 	port->count -= 1;
 	if (!port->count)
Signature · 1 line
2.1.3
Acked-by on v1 1/1
#535 lore raw

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

Quoted 9 lines · SF Markus Elfring

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.

Quoted 25 lines
---
 drivers/net/ipvlan/ipvlan_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ipvlan/ipvlan_main.c +1 -3
index 96b71b0..feb1853 100644
@@ -125,8 +125,7 @@ static void ipvlan_uninit(struct net_device *dev)
        struct ipvl_dev *ipvlan = netdev_priv(dev);
        struct ipvl_port *port = ipvlan->port;
 
-       if (ipvlan->pcpu_stats)
-               free_percpu(ipvlan->pcpu_stats);
+       free_percpu(ipvlan->pcpu_stats);
 
        port->count -= 1;
        if (!port->count)
--

2.1.3

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

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.

#537 lore raw

PATCH 1/1 fs-notify: Deletion of an unnecessary check before the function call "iput"

In reply to SF Markus Elfring

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

The iput() 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/notify/inode_mark.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/notify/inode_mark.c +1 -2
index 3daf513..d8157a6 100644
@@ -231,8 +231,7 @@ void fsnotify_unmount_inodes(struct list_head *list)
 		 */
 		spin_unlock(&inode_sb_list_lock);
 
-		if (need_iput_tmp)
-			iput(need_iput_tmp);
+		iput(need_iput_tmp);
 
 		/* for each watch, send FS_UNMOUNT and then remove it */
 		fsnotify(inode, FS_UNMOUNT, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
Signature · 1 line
2.1.3
#538 lore raw

Re: [PATCH] fs-notify: Deletion of an unnecessary check before the function call "iput"

Quoted 19 lines

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

The iput() 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/notify/inode_mark.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/notify/inode_mark.c +0 -0
index 3daf513..d8157a6 100644

fs/notify/inode_mark.c void fsnotify_unmount_inodes(struct list_head *list) · line 237

Quoted 9 lines
fs/notify/inode_mark.c +1 -2
@@ -231,8 +231,7 @@ void fsnotify_unmount_inodes(struct list_head *list)
 		 */
 		spin_unlock(&inode_sb_list_lock);
 
-		if (need_iput_tmp)
-			iput(need_iput_tmp);
+		iput(need_iput_tmp);
 
 		/* for each watch, send FS_UNMOUNT and then remove it */
 		fsnotify(inode, FS_UNMOUNT, inode, FSNOTIFY_EVENT_INODE, NULL, 0);

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

Regards,
Markus

#539 lore raw

PATCH 1/1 fs-namei: Deletion of an unnecessary check before the function call "iput"

In reply to SF Markus Elfring

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

The iput() 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/namei.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/namei.c +1 -2
index ca81416..ce69074 100644
@@ -3759,8 +3759,7 @@ exit2:
 		dput(dentry);
 	}
 	mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
-	if (inode)
-		iput(inode);	/* truncate the inode here */
+	iput(inode);	/* truncate the inode here */
 	inode = NULL;
 	if (delegated_inode) {
 		error = break_deleg_wait(&delegated_inode);
Signature · 1 line
2.1.3
#540 lore raw

PATCH 1/1 XFS: Deletion of unnecessary checks before two function calls

In reply to SF Markus Elfring

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

The functions xfs_blkdev_put() and xfs_qm_dqrele() 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.

---
 fs/xfs/xfs_qm.c    | 12 +++++-------
 fs/xfs/xfs_super.c |  3 +--
 2 files changed, 6 insertions(+), 9 deletions(-)
fs/xfs/xfs_qm.c +5 -7
index d68f230..9a4b50a 100644
@@ -1749,23 +1749,21 @@ xfs_qm_vop_dqalloc(
 	xfs_iunlock(ip, lockflags);
 	if (O_udqpp)
 		*O_udqpp = uq;
-	else if (uq)
+	else
 		xfs_qm_dqrele(uq);
 	if (O_gdqpp)
 		*O_gdqpp = gq;
-	else if (gq)
+	else
 		xfs_qm_dqrele(gq);
 	if (O_pdqpp)
 		*O_pdqpp = pq;
-	else if (pq)
+	else
 		xfs_qm_dqrele(pq);
 	return 0;
 
 error_rele:
-	if (gq)
-		xfs_qm_dqrele(gq);
-	if (uq)
-		xfs_qm_dqrele(uq);
+	xfs_qm_dqrele(gq);
+	xfs_qm_dqrele(uq);
 	return error;
 }
 
fs/xfs/xfs_super.c +1 -2
index 206b97f..97eaa25 100644
@@ -796,8 +796,7 @@ xfs_open_devices(
  out_free_ddev_targ:
 	xfs_free_buftarg(mp, mp->m_ddev_targp);
  out_close_rtdev:
-	if (rtdev)
-		xfs_blkdev_put(rtdev);
+	xfs_blkdev_put(rtdev);
  out_close_logdev:
 	if (logdev && logdev != ddev)
 		xfs_blkdev_put(logdev);
Signature · 1 line
2.1.3
Reviewed-by on v1 1/1
#541 lore raw

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

Quoted 10 lines · SF Markus Elfring

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

The functions xfs_blkdev_put() and xfs_qm_dqrele() 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.

Looks fine.

Signature · 2 lines
Dave Chinner
[email protected]
#542 lore raw

PATCH 1/1 XFS: Delete unnecessary checks before the function call "xfs_qm_dqrele"

From: Markus Elfring <[email protected]>
Date: Fri, 26 Jun 2015 11:05:41 +0200

The xfs_qm_dqrele() 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/xfs/xfs_qm_syscalls.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/xfs/xfs_qm_syscalls.c +3 -3
index 3640c6e..6deee1e 100644
@@ -735,15 +735,15 @@ xfs_dqrele_inode(
 	}
 
 	xfs_ilock(ip, XFS_ILOCK_EXCL);
-	if ((flags & XFS_UQUOTA_ACCT) && ip->i_udquot) {
+	if (flags & XFS_UQUOTA_ACCT) {
 		xfs_qm_dqrele(ip->i_udquot);
 		ip->i_udquot = NULL;
 	}
-	if ((flags & XFS_GQUOTA_ACCT) && ip->i_gdquot) {
+	if (flags & XFS_GQUOTA_ACCT) {
 		xfs_qm_dqrele(ip->i_gdquot);
 		ip->i_gdquot = NULL;
 	}
-	if ((flags & XFS_PQUOTA_ACCT) && ip->i_pdquot) {
+	if (flags & XFS_PQUOTA_ACCT) {
 		xfs_qm_dqrele(ip->i_pdquot);
 		ip->i_pdquot = NULL;
 	}
Signature · 1 line
2.4.4
#543 lore raw

Re: [PATCH] XFS: Delete unnecessary checks before the function call "xfs_qm_dqrele"

Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Jun 2015 11:05:41 +0200

The xfs_qm_dqrele() function tests whether its argument is NULL and then returns immediately.

True.

Quoted 1 line

Thus the test around the call is not needed.

But wrong.

xfs_dqrele_inode() gets called on every inode in the inode cache, and this change results in a cacheline in every inode being dirtied even if they don't have dquots attached. Given the inode cache can hold tens to hundreds of millions of inodes on large machines, we don't want to dirty any cachelines we don't need to while walking the inode cache and releasing dquots...

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#544 lore raw

Re: XFS: Fine-tuning for checks before the function call "xfs_qm_dqrele"?

Quoted 6 lines

xfs_dqrele_inode() gets called on every inode in the inode cache, and this change results in a cacheline in every inode being dirtied even if they don't have dquots attached. Given the inode cache can hold tens to hundreds of millions of inodes on large machines, we don't want to dirty any cachelines we don't need to while walking the inode cache and releasing dquots...

Would it make sense to annotate checks before such function calls as "LIKELY"?

Regards,
Markus

#545 lore raw

Re: XFS: Fine-tuning for checks before the function call "xfs_qm_dqrele"?

Quoted 9 lines · SF Markus Elfring
Quoted 6 lines

xfs_dqrele_inode() gets called on every inode in the inode cache, and this change results in a cacheline in every inode being dirtied even if they don't have dquots attached. Given the inode cache can hold tens to hundreds of millions of inodes on large machines, we don't want to dirty any cachelines we don't need to while walking the inode cache and releasing dquots...

Would it make sense to annotate checks before such function calls as "LIKELY"?

No - it will be random as to whether the inodes have dquots attached or not and so a static hint is always going to be wrong for someone....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#546 lore raw

PATCH 1/1 fs-DLM: Deletion of unnecessary checks before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 29 Nov 2014 17:55: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.

---
 fs/dlm/lockspace.c | 3 +--
 fs/dlm/memory.c    | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
fs/dlm/lockspace.c +1 -2
index f3e7278..b660b93 100644
@@ -674,8 +674,7 @@ static int new_lockspace(const char *name, const char *cluster,
  out_lkbidr:
 	idr_destroy(&ls->ls_lkbidr);
 	for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++) {
-		if (ls->ls_remove_names[i])
-			kfree(ls->ls_remove_names[i]);
+		kfree(ls->ls_remove_names[i]);
 	}
  out_rsbtbl:
 	vfree(ls->ls_rsbtbl);
fs/dlm/memory.c +1 -2
index 7cd24bc..2d2eaa0 100644
@@ -86,8 +86,7 @@ void dlm_free_lkb(struct dlm_lkb *lkb)
 		struct dlm_user_args *ua;
 		ua = lkb->lkb_ua;
 		if (ua) {
-			if (ua->lksb.sb_lvbptr)
-				kfree(ua->lksb.sb_lvbptr);
+			kfree(ua->lksb.sb_lvbptr);
 			kfree(ua);
 		}
 	}
Signature · 1 line
2.1.3
#547 lore raw

PATCH 1/1 fs-DLM: Delete unnecessary checks before the function call "kfree"

From: Markus Elfring <[email protected]>
Date: Fri, 26 Jun 2015 14:00:06 +0200

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.

---
 fs/dlm/lockspace.c | 6 ++----
 fs/dlm/memory.c    | 3 +--
 2 files changed, 3 insertions(+), 6 deletions(-)
fs/dlm/lockspace.c +2 -4
index f3e7278..41c53b3 100644
@@ -673,10 +673,8 @@ static int new_lockspace(const char *name, const char *cluster,
 	kfree(ls->ls_recover_buf);
  out_lkbidr:
 	idr_destroy(&ls->ls_lkbidr);
-	for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++) {
-		if (ls->ls_remove_names[i])
-			kfree(ls->ls_remove_names[i]);
-	}
+	for (i = 0; i < DLM_REMOVE_NAMES_MAX; i++)
+		kfree(ls->ls_remove_names[i]);
  out_rsbtbl:
 	vfree(ls->ls_rsbtbl);
  out_lsfree:
fs/dlm/memory.c +1 -2
index 7cd24bc..2d2eaa0 100644
@@ -86,8 +86,7 @@ void dlm_free_lkb(struct dlm_lkb *lkb)
 		struct dlm_user_args *ua;
 		ua = lkb->lkb_ua;
 		if (ua) {
-			if (ua->lksb.sb_lvbptr)
-				kfree(ua->lksb.sb_lvbptr);
+			kfree(ua->lksb.sb_lvbptr);
 			kfree(ua);
 		}
 	}
Signature · 1 line
2.4.4
#548 lore raw

PATCH 1/1 SPI-txx9: Deletion of an unnecessary check before the function call "clk_disable"

In reply to SF Markus Elfring

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

The clk_disable() 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/spi/spi-txx9.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/spi-txx9.c +1 -2
index 0da7c67..9190124 100644
@@ -402,8 +402,7 @@ exit_busy:
 exit:
 	if (c->workqueue)
 		destroy_workqueue(c->workqueue);
-	if (c->clk)
-		clk_disable(c->clk);
+	clk_disable(c->clk);
 	spi_master_put(master);
 	return ret;
 }
Signature · 1 line
2.1.3
maintainer Applied
#549 lore raw

Re: [PATCH 1/1] SPI-txx9: Deletion of an unnecessary check before the function call "clk_disable"

Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 29 Nov 2014 18:34:20 +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, but please do try to use subject lines matching the style for the subsystem.

#550 lore raw

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

In reply to SF Markus Elfring

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.

---
 drivers/net/ethernet/pasemi/pasemi_mac.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/pasemi/pasemi_mac.c +2 -4
index 30d934d..44e8d7d 100644
@@ -1837,10 +1837,8 @@ pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	return err;
 
 out:
-	if (mac->iob_pdev)
-		pci_dev_put(mac->iob_pdev);
-	if (mac->dma_pdev)
-		pci_dev_put(mac->dma_pdev);
+	pci_dev_put(mac->iob_pdev);
+	pci_dev_put(mac->dma_pdev);
 
 	free_netdev(dev);
 out_disable_device:
Signature · 1 line
2.1.3
#551 lore raw

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

drivers/net/ethernet/pasemi/pasemi_mac.c pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 1844

Quoted 11 lines · SF Markus Elfring

out:

drivers/net/ethernet/pasemi/pasemi_mac.c +2 -4
-	if (mac->iob_pdev)
-		pci_dev_put(mac->iob_pdev);
-	if (mac->dma_pdev)
-		pci_dev_put(mac->dma_pdev);
+	pci_dev_put(mac->iob_pdev);
+	pci_dev_put(mac->dma_pdev);
 
 	free_netdev(dev);
 out_disable_device:

Hi,

I know there has been some criticism about those kind of "code improvements" already but i would like to point out just one more thing:

Some of those NULL pointer checks on input parameters may have been added subsequently to functions. So there may be older kernel versions out there in which those checks dont exists in some cases. If some of the now "cleaned up" code is backported to such a kernel chances are good that those missing checks are overseen. And then neither caller nor callee is doing the NULL pointer check.

Quite frankly i would vote for the opposite approach: Never rely on the callee do to checks for NULL and do it always in the caller. An exception could be for calls on a fast path. But most of those checks are done on error paths anyway.

Just my 2 cents.

Regards,
Lino

#552 lore raw

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

Quoted 26 lines · Lino Sanfilippo

drivers/net/ethernet/pasemi/pasemi_mac.c pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent) · line 1844

Quoted 11 lines · SF Markus Elfring

out:

drivers/net/ethernet/pasemi/pasemi_mac.c +2 -4
-	if (mac->iob_pdev)
-		pci_dev_put(mac->iob_pdev);
-	if (mac->dma_pdev)
-		pci_dev_put(mac->dma_pdev);
+	pci_dev_put(mac->iob_pdev);
+	pci_dev_put(mac->dma_pdev);
 
 	free_netdev(dev);
 out_disable_device:

Hi,

I know there has been some criticism about those kind of "code improvements" already but i would like to point out just one more thing:

Some of those NULL pointer checks on input parameters may have been added subsequently to functions. So there may be older kernel versions out there in which those checks dont exists in some cases. If some of the now "cleaned up" code is backported to such a kernel chances are good that those missing checks are overseen. And then neither caller nor callee is doing the NULL pointer check.

Quoted 4 lines

Quite frankly i would vote for the opposite approach: Never rely on the callee do to checks for NULL and do it always in the caller. An exception could be for calls on a fast path. But most of those checks are done on error paths anyway.

I have heard of at least one case where the problem you are raising happened in practice...

julia

#553 lore raw

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

Quoted 5 lines · Julia Lawall

I have heard of at least one case where the problem you are raising happened in practice...

julia

If one case is known then there are probably a lot more that have not been discovered yet.
Maybe this topic should be clarified somewhere (e.g. in "CodingStyle")? On the other hand i always found it obvious that its the callers responsibility to only pass sane parameters to the called functions...

Regards,
Lino

#554 lore raw

Re: net-PA Semi: Deletion of unnecessary checks before the function call "pci_dev_put"

Quoted 3 lines

Maybe this topic should be clarified somewhere (e.g. in "CodingStyle")? On the other hand i always found it obvious that its the callers responsibility to only pass sane parameters to the called functions...

Can you imagine that any more source code places which would benefit from check adjustments because of defensive programming?

Regards,
Markus

#555 lore raw

Re: net-PA Semi: Deletion of unnecessary checks before the function call "pci_dev_put"

Quoted 7 lines · SF Markus Elfring
Quoted 3 lines

Maybe this topic should be clarified somewhere (e.g. in "CodingStyle")? On the other hand i always found it obvious that its the callers responsibility to only pass sane parameters to the called functions...

Can you imagine that any more source code places which would benefit from check adjustments because of defensive programming?

I am not sure if i understand your question correctly. But i would not call sanity checks for function parameters "defensive programming". I would rather call it not being totally careless. So to me the question if those checks should be done or not is different from the question whether there are code parts that would benefit from an adjustment to defensive programming.

Regards,
Lino

#556 lore raw

Re: net-PA Semi: Deletion of unnecessary checks before the function call "pci_dev_put"

In reply to Lino Sanfilippo
Quoted 9 lines

I know there has been some criticism about those kind of "code improvements" already but i would like to point out just one more thing:

Some of those NULL pointer checks on input parameters may have been added subsequently to functions. So there may be older kernel versions out there in which those checks dont exists in some cases. If some of the now "cleaned up" code is backported to such a kernel chances are good that those missing checks are overseen. And then neither caller nor callee is doing the NULL pointer check.

I guess that the Coccinelle software can also help you in this use case. How do you think about to shield against "unwanted" or unexpected collateral evolutions with additional inline functions?

I assume that a few backporters can tell you more about their corresponding software development experiences.
http://www.do-not-panic.com/2014/04/automatic-linux-kernel-backporting-with-coccinelle.html

Regards,
Markus

maintainer
#557 lore raw

Re: net-PA Semi: Deletion of unnecessary checks before the function call "pci_dev_put"

Quoted 10 lines · SF Markus Elfring
Quoted 6 lines

Some of those NULL pointer checks on input parameters may have been added subsequently to functions. So there may be older kernel versions out there in which those checks dont exists in some cases. If some of the now "cleaned up" code is backported to such a kernel chances are good that those missing checks are overseen. And then neither caller nor callee is doing the NULL pointer check.

I assume that a few backporters can tell you more about their corresponding software development experiences.
http://www.do-not-panic.com/2014/04/automatic-linux-kernel-backporting-with-coccinelle.html

In such cases we just provide an appropriate wrapper and replace callers of the original function by callers of the wrapper, typically with a #define.

So this kind of evolution is no problem for the (automated) backports using the backports project - although it can be difficult to detect such a thing is needed.

johannes

#558 lore raw

Re: net-PA Semi: Deletion of unnecessary checks before the function call "pci_dev_put"

Quoted 13 lines · Johannes Berg
Quoted 10 lines · SF Markus Elfring
Quoted 6 lines

Some of those NULL pointer checks on input parameters may have been added subsequently to functions. So there may be older kernel versions out there in which those checks dont exists in some cases. If some of the now "cleaned up" code is backported to such a kernel chances are good that those missing checks are overseen. And then neither caller nor callee is doing the NULL pointer check.

I assume that a few backporters can tell you more about their corresponding software development experiences.
http://www.do-not-panic.com/2014/04/automatic-linux-kernel-backporting-with-coccinelle.html

Quoted 7 lines

In such cases we just provide an appropriate wrapper and replace callers of the original function by callers of the wrapper, typically with a #define.

So this kind of evolution is no problem for the (automated) backports using the backports project - although it can be difficult to detect such a thing is needed.

That is exactly the problem...

julia

maintainer
#559 lore raw

Re: net-PA Semi: Deletion of unnecessary checks before the function call "pci_dev_put"

Quoted 5 lines · Julia Lawall
Quoted 3 lines

So this kind of evolution is no problem for the (automated) backports using the backports project - although it can be difficult to detect such a thing is needed.

That is exactly the problem...

I'm not convinced though that it should stop such progress in mainline.

johannes

#560 lore raw

Re: net-PA Semi: Deletion of unnecessary checks before the function call "pci_dev_put"

Quoted 9 lines · Johannes Berg
Quoted 5 lines · Julia Lawall
Quoted 3 lines

So this kind of evolution is no problem for the (automated) backports using the backports project - although it can be difficult to detect such a thing is needed.

That is exactly the problem...

I'm not convinced though that it should stop such progress in mainline.

Is it progress? These patches match the code look simpler by passing hiding the NULL check inside a function call. Calling pci_dev_put(NULL) doesn't make sense. Just because a sanity check exists doesn't mean we should do insane things.

It's easy enough to store which functions have a sanity check in a database, but to rememember all that as a human being trying to read the code is impossible.

If we really wanted to make this code cleaner we would introduce more error labels with better names.

regards,
dan carpenter

#561 lore raw

Re: net-PA Semi: Deletion of unnecessary checks before the function call "pci_dev_put"

Quoted 7 lines · Dan Carpenter
Quoted 6 lines · Johannes Berg
Quoted 4 lines · Julia Lawall
Quoted 3 lines

So this kind of evolution is no problem for the (automated) backports using the backports project - although it can be difficult to detect such a thing is needed.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

That is exactly the problem...

I'm not convinced though that it should stop such progress in mainline.

Is it progress?

I like to think of progress as using tools to help fix code where we know it can be made simpler with a small ammendment: if you can extend the tools to also vet for safety for backports to avoid crashes even better.

So its a small evolution but we can do better, which is the point you and Julia are making.

Quoted 4 lines

These patches match the code look simpler by passing
hiding the NULL check inside a function call. Calling pci_dev_put(NULL) doesn't make sense. Just because a sanity check exists doesn't mean we should do insane things.

It'd crash the system if the function call didn't have the check in place but having the code in question call pci_dev_put(NULL) is also ludicrious. Either way in this case I think we shouldn't go beyond analyzing the function call and if the error check was present before as it is a real case that has introduced crashes before which Julia wanted to flag.

Quoted 2 lines

It's easy enough to store which functions have a sanity check in a database,

This is easy but it adds complexities which I'd prefer to keep on some other people's workstations. For the developer I think we should strive to only have: a) git b) Coccinelle c) smatch.

Quoted 2 lines

but to rememember all that as a human being trying to read the code is impossible.

Agreed. The problem statement presented by Julia is part of the effort of addressing the "how do we evolve faster" problem on Linux kernel development, what you describe adds to the mix of the complexities, and while Oleg does note that part of this is academic there are those of us who are making things which are academic immediately practical and a reality for Linux. This is also how we evolve faster :)

Quoted 2 lines

If we really wanted to make this code cleaner we would introduce more error labels with better names.

Can you describe a bit more what you mean here? If we had a label *in code* on the caller, perhaps a comment, I can see tool-wise how it'd remove the requirement for a database for immediate analysis for safety here, ie, we hunt for a label on the code; but other than that its unclear what you mean here.

If you folks agree with my simplication tool analsysi for safety can we devise a tag for whitelisting this check for a series of routines? Where would we put it, in the kernel or a tools package? If in the kernel we could end up sharing it, so I think that's be better. Perhaps scripts/safety/ ? Maybe use a header that describes the safety check that is vetted by the rule present, followed by a list of routines vetted?

Then the Cocci file can preload this and a rule that wants this paranoid check can include this db file for safety ?

The safety here would require vetting thirough history in git that the routine has a check in place throughout the routines's history up to a certain point. I propose we only care up to what kernels are listed on kernel.org as supported.

Luis

#562 lore raw

Re: net-PA Semi: Deletion of unnecessary checks before the function call "pci_dev_put"

In reply to Johannes Berg
Quoted 9 lines · Johannes Berg
Quoted 5 lines · Julia Lawall
Quoted 3 lines

So this kind of evolution is no problem for the (automated) backports using the backports project - although it can be difficult to detect such a thing is needed.

That is exactly the problem...

I'm not convinced though that it should stop such progress in mainline.

I believe this case requires a bit more information explained as to why it was explained. The "form" of change this patch has is of the type that can crash systems if the NULL pointer check on the caller implementation was only added later. We might be able to grammatically check for this situation in the future if we had a white list / black list / kernel revision where the NULL check was added but for now we don't have that and as such care is just required on the developer in consideration for backports.

It should be up to the maintainer to appreciate the gains of doing something differently to make it easier for backporting. I obviously think its a good thing to consider, its extra work though, so only if the maintainer has some appreciation for backporting would this make sense.

In this particular case I've reviewed Julia's concern and I've determined that the patch is safe up to at least v2.6.12-rc2 (which is where our git history begins on Linus' tree), this is because the check for NULL has been there since then:

git show 1da177e drivers/pci/pci-driver.c

+void pci_dev_put(struct pci_dev *dev)
+{
+ if (dev)
+ put_device(&dev->dev);
+}

So this type of wide collateral evolution should not cause panics. Because of this:

But note -- I still think its only good for us to vet these, if we can't why not? If the maintainer doesn't give a shit that's different, but if there are folks out there willing to help with vetting then well, why not :)

PS. Including something like historical vetting as I did above on the commit log should help folks.

Luis

Acked-by on v1 1/1
#563 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
Quoted 10 lines · SF Markus Elfring

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.

For this particular case:

Note that the "this might cause problems with backports" case is mostly academic in the scope of _this particular driver_. It's still a very valid discussion and issue though.

So I'll be happy to give the ack on this driver, but the larger problem needs consideration still.

-Olof

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.

#565 lore raw

PATCH 1/1 ACPI: Deletion of an unnecessary check before the function call "pci_dev_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 30 Nov 2014 10:59:10 +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/acpi/ioapic.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/acpi/ioapic.c +1 -2
index 9a631a6..35963d3 100644
@@ -185,8 +185,7 @@ exit_disable:
 	if (dev)
 		pci_disable_device(dev);
 exit_put:
-	if (dev)
-		pci_dev_put(dev);
+	pci_dev_put(dev);
 exit_free:
 	kfree(ioapic);
 exit:
Signature · 1 line
2.1.3
#566 lore raw

cover net-PPP: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 30 Nov 2014 17:25:40 +0100

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

Markus Elfring (3):
Deletion of unnecessary checks before the function call "kfree" Less function calls in mppe_alloc() after error detection Delete an unnecessary assignment

 drivers/net/ppp/ppp_mppe.c | 32 +++++++++++++-------------------
 1 file changed, 13 insertions(+), 19 deletions(-)
Signature · 1 line
2.1.3
#567 lore raw

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

From: Markus Elfring <[email protected]>
Date: Sun, 30 Nov 2014 17:02:07 +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 | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/net/ppp/ppp_mppe.c +6 -8
index 911b216..7e44212 100644
@@ -238,8 +238,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)
@@ -256,13 +255,12 @@ 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)
+			crypto_free_hash(state->sha1);
+		if (state->arc4)
+			crypto_free_blkcipher(state->arc4);
+		kfree(state);
 	}
 }
 
Signature · 1 line
2.1.3
#568 lore raw

Re: [PATCH 1/3] net-PPP: Deletion of unnecessary checks before the function call "kfree"

Hello.

Quoted 18 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 30 Nov 2014 17:02:07 +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 | 14 ++++++--------
  1 file changed, 6 insertions(+), 8 deletions(-)
drivers/net/ppp/ppp_mppe.c +0 -0
index 911b216..7e44212 100644

drivers/net/ppp/ppp_mppe.c static void *mppe_alloc(unsigned char *options, int optlen) · line 241

Quoted 6 lines
drivers/net/ppp/ppp_mppe.c +1 -2
@@ -238,8 +238,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);

Please keep this line aligned to the others.

drivers/net/ppp/ppp_mppe.c static void *mppe_alloc(unsigned char *options, int optlen) · line 244

Quoted 3 lines
drivers/net/ppp/ppp_mppe.c +0 -0
  	    if (state->sha1)
  		crypto_free_hash(state->sha1);
  	    if (state->arc4)

[...]

WBR, Sergei

#569 lore raw

Re: [PATCH 1/3] net-PPP: Deletion of unnecessary checks before the function call "kfree"

Quoted 7 lines
Quoted 7 lines
drivers/net/ppp/ppp_mppe.c +0 -0
index 911b216..7e44212 100644
@@ -238,8 +238,7 @@ static void *mppe_alloc(unsigned char *options, int optlen)
      return (void *)state;
 
Quoted 6 lines

drivers/net/ppp/ppp_mppe.c static void *mppe_alloc(unsigned char *options, int optlen) · line 241

Quoted 4 lines
drivers/net/ppp/ppp_mppe.c +1 -2
      out_free:
-        if (state->sha1_digest)
-        kfree(state->sha1_digest);
+    kfree(state->sha1_digest);

Please keep this line aligned to the others.

Can it be that the previous source code contained unwanted space characters at this place?
Do you want indentation fixes as a separate update step?

Regards,
Markus

#570 lore raw

Re: [PATCH 1/3] net-PPP: Deletion of unnecessary checks before the function call "kfree"

Quoted 14 lines · SF Markus Elfring
Quoted 7 lines
Quoted 7 lines
drivers/net/ppp/ppp_mppe.c +0 -0
index 911b216..7e44212 100644
@@ -238,8 +238,7 @@ static void *mppe_alloc(unsigned char *options, int optlen)
       return (void *)state;
 
Quoted 6 lines

drivers/net/ppp/ppp_mppe.c static void *mppe_alloc(unsigned char *options, int optlen) · line 241

Quoted 4 lines
drivers/net/ppp/ppp_mppe.c +1 -2
       out_free:
-        if (state->sha1_digest)
-        kfree(state->sha1_digest);
+    kfree(state->sha1_digest);

Please keep this line aligned to the others.

Quoted 2 lines

Can it be that the previous source code contained unwanted space characters at this place?

Yes, it seems so.

Quoted 1 line

Do you want indentation fixes as a separate update step?

Yes, that would be better to keep it separate.

Quoted 2 lines

Regards,
Markus

WBR, Sergei

#571 lore raw

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

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
#573 lore raw

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

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

#577 lore raw

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

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

#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

#580 lore raw

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

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.

#581 lore raw

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

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

#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 ...
#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.

#585 lore raw

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

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.

#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
#593 lore raw

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

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

#594 lore raw

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

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

#595 lore raw

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

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

#596 lore raw

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

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

#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
#598 lore raw

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

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

#599 lore raw

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

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

#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

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.

#602 lore raw

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

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

#609 lore raw

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

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.

#610 lore raw

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

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

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.

#612 lore raw

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

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

#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.

#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

#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 ...
#622 lore raw

PATCH 2/3 net-PPP: Less function calls in mppe_alloc() after error detection

In reply to SF Markus Elfring

From 06c1a0fff81142dfa6d933479e17bb1b45ab9dc7 Mon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Sun, 30 Nov 2014 17:07:34 +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 | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
drivers/net/ppp/ppp_mppe.c +11 -13
index 7e44212..962c1a0 100644
@@ -197,11 +197,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);
@@ -213,16 +213,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],
@@ -237,14 +237,12 @@ static void *mppe_alloc(unsigned char *options, int optlen)
 
 	return (void *)state;
 
-	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:
+out_free_hash:
+	crypto_free_hash(state->sha1);
+out_free_blkcipher:
+	crypto_free_blkcipher(state->arc4);
+out_free:
+	kfree(state);
 	return NULL;
 }
 
Signature · 1 line
2.1.3
#623 lore raw

PATCH 3/3 net-PPP: Delete an unnecessary assignment

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 30 Nov 2014 17:17:36 +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 962c1a0..d913bc9 100644
@@ -205,10 +205,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
#624 lore raw

Re: [PATCH 3/3] net-PPP: Delete an unnecessary assignment

Quoted 22 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 30 Nov 2014 17:17:36 +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 +0 -0
index 962c1a0..d913bc9 100644
@@ -205,10 +205,8 @@ static void *mppe_alloc(unsigned char *options, int optlen)
 

drivers/net/ppp/ppp_mppe.c static void *mppe_alloc(unsigned char *options, int optlen) · line 212

Quoted 10 lines
drivers/net/ppp/ppp_mppe.c +1 -3
 
 	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)) {

I have no idea why its a patch on its own, and why state->arc4 gets special treatment while state->sha1 does not.

This definitely belongs to the previous patch, refactoring error handling in mppe_alloc()

Also, it seems your patches do not fix bugs, so so you need to target net-next tree, as explained in Documentation/networking/netdev-FAQ.txt

#625 lore raw

Re: [PATCH 3/3] net-PPP: Delete an unnecessary assignment

Quoted 2 lines

I have no idea why its a patch on its own, and why state->arc4 gets special treatment while state->sha1 does not.

I did not fiddle with the data structure element "sha1" because I assumed that it might be still relevant for the call of a function like crypto_free_blkcipher().

Quoted 2 lines

This definitely belongs to the previous patch, refactoring error handling in mppe_alloc()

I have got different preferences for change distribution over several patches here.
I find it safer to tackle an assignment clean-up after adjustments for jump labels.

Quoted 2 lines

Also, it seems your patches do not fix bugs, so so you need to target net-next tree, as explained in Documentation/networking/netdev-FAQ.txt

Do you want that I resend my update suggestion?

Regards,
Markus

#626 lore raw

cover tuners: Deletion of two unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 30 Nov 2014 20:50:15 +0100

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

Markus Elfring (2):
Deletion of unnecessary checks before the function call "release_firmware" One function call less in si2157_init() after error detection

 drivers/media/tuners/si2157.c | 9 ++++-----
 drivers/media/tuners/xc5000.c | 3 +--
 2 files changed, 5 insertions(+), 7 deletions(-)
Signature · 1 line
2.1.3
#627 lore raw

PATCH 1/2 tuners: Deletion of unnecessary checks before the function call "release_firmware"

From: Markus Elfring <[email protected]>
Date: Sun, 30 Nov 2014 19:05:48 +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/media/tuners/si2157.c | 3 +--
 drivers/media/tuners/xc5000.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/media/tuners/si2157.c +1 -2
index 8e57696..e17ab1f 100644
@@ -196,8 +196,7 @@ warm:
 	return 0;
 
 err:
-	if (fw)
-		release_firmware(fw);
+	release_firmware(fw);
 
 	dev_dbg(&s->client->dev, "failed=%d\n", ret);
 	return ret;
drivers/media/tuners/xc5000.c +1 -2
index 705c258..2a039de 100644
@@ -1336,8 +1336,7 @@ static int xc5000_release(struct dvb_frontend *fe)
 
 	if (priv) {
 		cancel_delayed_work(&priv->timer_sleep);
-		if (priv->firmware)
-			release_firmware(priv->firmware);
+		release_firmware(priv->firmware);
 		hybrid_tuner_release_state(priv);
 	}
 
Signature · 1 line
2.1.3
#628 lore raw

PATCH 2/2 tuners-si2157: One function call less in si2157_init() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 30 Nov 2014 20:48:24 +0100

The release_firmware() function was called in some cases by the si2157_init() function during error handling even if the passed variable contained still a null pointer. This implementation detail could be improved
by the introduction of another jump label.

---
 drivers/media/tuners/si2157.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/tuners/si2157.c +4 -4
index e17ab1f..2180de9 100644
@@ -157,7 +157,7 @@ static int si2157_init(struct dvb_frontend *fe)
 		dev_err(&s->client->dev, "firmware file '%s' is invalid\n",
 				fw_file);
 		ret = -EINVAL;
-		goto err;
+		goto fw_release_exit;
 	}
 
 	dev_info(&s->client->dev, "downloading firmware from file '%s'\n",
@@ -173,7 +173,7 @@ static int si2157_init(struct dvb_frontend *fe)
 			dev_err(&s->client->dev,
 					"firmware download failed=%d\n",
 					ret);
-			goto err;
+			goto fw_release_exit;
 		}
 	}
 
@@ -195,9 +195,9 @@ warm:
 	s->active = true;
 	return 0;
 
-err:
+fw_release_exit:
 	release_firmware(fw);
-
+err:
 	dev_dbg(&s->client->dev, "failed=%d\n", ret);
 	return ret;
 }
Signature · 1 line
2.1.3
#629 lore raw

PATCH 1/1 ddbridge: Deletion of an unnecessary check before the function call "dvb_unregister_device"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 30 Nov 2014 22:50:20 +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/pci/ddbridge/ddbridge-core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/pci/ddbridge/ddbridge-core.c +1 -2
index c82e855..9e3492e 100644
@@ -1118,8 +1118,7 @@ static void ddb_ports_detach(struct ddb *dev)
 			dvb_input_detach(port->input[1]);
 			break;
 		case DDB_PORT_CI:
-			if (port->output->dev)
-				dvb_unregister_device(port->output->dev);
+			dvb_unregister_device(port->output->dev);
 			if (port->en) {
 				ddb_input_stop(port->input[0]);
 				ddb_output_stop(port->output);
Signature · 1 line
2.1.3
#630 lore raw

PATCH 1/1 V4L2: Deletion of an unnecessary check before the function call "vb2_put_vma"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 30 Nov 2014 23:10:51 +0100

The vb2_put_vma() 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/videobuf2-vmalloc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/v4l2-core/videobuf2-vmalloc.c +1 -2
index 3966b12..fba944e 100644
@@ -154,8 +154,7 @@ static void vb2_vmalloc_put_userptr(void *buf_priv)
 		}
 		kfree(buf->pages);
 	} else {
-		if (buf->vma)
-			vb2_put_vma(buf->vma);
+		vb2_put_vma(buf->vma);
 		iounmap(buf->vaddr);
 	}
 	kfree(buf);
Signature · 1 line
2.1.3
Acked-by on v1 1/1
#631 lore raw

Re: [PATCH 1/1] [media] V4L2: Deletion of an unnecessary check before the function call "vb2_put_vma"

Hello,

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 30 Nov 2014 23:10:51 +0100

The vb2_put_vma() 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.

Quoted 9 lines
---
  drivers/media/v4l2-core/videobuf2-vmalloc.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/v4l2-core/videobuf2-vmalloc.c +0 -0
index 3966b12..fba944e 100644

drivers/media/v4l2-core/videobuf2-vmalloc.c static void vb2_vmalloc_put_userptr(void *buf_priv) · line 160

Quoted 9 lines
drivers/media/v4l2-core/videobuf2-vmalloc.c +1 -2
@@ -154,8 +154,7 @@ static void vb2_vmalloc_put_userptr(void *buf_priv)
  		}
  		kfree(buf->pages);
  	} else {
-		if (buf->vma)
-			vb2_put_vma(buf->vma);
+		vb2_put_vma(buf->vma);
  		iounmap(buf->vaddr);
  	}
  	kfree(buf);

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland
#632 lore raw

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

In reply to 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.

---
 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;
 }
 
Signature · 1 line
2.1.3
reviewer Applied
#633 lore raw

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

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;
 }
 
#634 lore raw

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

In reply to 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.

---
 drivers/dma/dmaengine.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dma/dmaengine.c +1 -2
index 24bfaf0..e057935 100644
@@ -330,8 +330,7 @@ static int __init dma_channel_table_init(void)
 	if (err) {
 		pr_err("initialization failure\n");
 		for_each_dma_cap_mask(cap, dma_cap_mask_all)
-			if (channel_table[cap])
-				free_percpu(channel_table[cap]);
+			free_percpu(channel_table[cap]);
 	}
 
 	return err;
Signature · 1 line
2.1.3
Applied
#635 lore raw

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

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
#636 lore raw

PATCH 1/1 block-rbd: Delete a check before ceph_put_snap_context()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 1 Dec 2014 11:18:21 +0100

The ceph_put_snap_context() 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/rbd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/block/rbd.c +1 -2
index 27b71a0..3c34ab5 100644
@@ -3405,8 +3405,7 @@ err_rq:
 	if (result)
 		rbd_warn(rbd_dev, "%s %llx at %llx result %d",
 			 obj_op_name(op_type), length, offset, result);
-	if (snapc)
-		ceph_put_snap_context(snapc);
+	ceph_put_snap_context(snapc);
 	blk_end_request_all(rq, result);
 }
 
Signature · 1 line
2.1.3
#637 lore raw

Re: [PATCH 1/1] block-rbd: Delete a check before ceph_put_snap_context()

Quoted 18 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 1 Dec 2014 11:18:21 +0100

The ceph_put_snap_context() 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/rbd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/block/rbd.c +0 -0
index 27b71a0..3c34ab5 100644

drivers/block/rbd.c err_rq: · line 3411

Quoted 9 lines
drivers/block/rbd.c +1 -2
@@ -3405,8 +3405,7 @@ err_rq:
        if (result)
                rbd_warn(rbd_dev, "%s %llx at %llx result %d",
                         obj_op_name(op_type), length, offset, result);
-       if (snapc)
-               ceph_put_snap_context(snapc);
+       ceph_put_snap_context(snapc);
        blk_end_request_all(rq, result);
 }
 

I squashed it into your "ceph: Deletion of unnecessary checks before two function calls", which deals with ceph_put_snap_context() in fs/ceph.

Thanks,

Ilya

#638 lore raw

PATCH 1/1 block-skd: Deletion of an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 1 Dec 2014 18:15:46 +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/skd_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/block/skd_main.c +1 -2
index 1e46eb2..c4b0259 100644
@@ -3998,8 +3998,7 @@ static int skd_acquire_msix(struct skd_device *skdev)
 	return 0;
 
 msix_out:
-	if (entries)
-		kfree(entries);
+	kfree(entries);
 	skd_release_msix(skdev);
 	return rc;
 }
Signature · 1 line
2.1.3
#639 lore raw

Re: [PATCH] block-skd: Deletion of an unnecessary check before the function call "kfree"

Quoted 19 lines

From: Markus Elfring <[email protected]>
Date: Mon, 1 Dec 2014 18:15:46 +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/skd_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/block/skd_main.c +0 -0
index 1e46eb2..c4b0259 100644

drivers/block/skd_main.c static int skd_acquire_msix(struct skd_device *skdev) · line 4004

Quoted 9 lines
drivers/block/skd_main.c +1 -2
@@ -3998,8 +3998,7 @@ static int skd_acquire_msix(struct skd_device *skdev)
 	return 0;
 
 msix_out:
-	if (entries)
-		kfree(entries);
+	kfree(entries);
 	skd_release_msix(skdev);
 	return rc;
 }

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

Regards,
Markus

#640 lore raw

PATCH 1/1 block-rsxx: Deletion of an unnecessary check before the function call "vfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 1 Dec 2014 19:19:25 +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/block/rsxx/dma.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/block/rsxx/dma.c +1 -2
index cf8cd29..0181387 100644
@@ -960,8 +960,7 @@ failed_dma_setup:
 			ctrl->done_wq = NULL;
 		}
 
-		if (ctrl->trackers)
-			vfree(ctrl->trackers);
+		vfree(ctrl->trackers);
 
 		if (ctrl->status.buf)
 			pci_free_consistent(card->dev, STATUS_BUFFER_SIZE8,
Signature · 1 line
2.1.3
#641 lore raw

Re: [PATCH] block-rsxx: Deletion of an unnecessary check before the function call "vfree"

Quoted 19 lines

From: Markus Elfring <[email protected]>
Date: Mon, 1 Dec 2014 19:19:25 +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/block/rsxx/dma.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/block/rsxx/dma.c +0 -0
index cf8cd29..0181387 100644

drivers/block/rsxx/dma.c failed_dma_setup: · line 966

Quoted 9 lines
drivers/block/rsxx/dma.c +1 -2
@@ -960,8 +960,7 @@ failed_dma_setup:
 			ctrl->done_wq = NULL;
 		}
 
-		if (ctrl->trackers)
-			vfree(ctrl->trackers);
+		vfree(ctrl->trackers);
 
 		if (ctrl->status.buf)
 			pci_free_consistent(card->dev, STATUS_BUFFER_SIZE8,

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

Regards,
Markus

#642 lore raw

PATCH 1/1 lirc_zilog: Deletion of unnecessary checks before the function call "vfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 1 Dec 2014 19:49:39 +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/staging/media/lirc/lirc_zilog.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/media/lirc/lirc_zilog.c +2 -4
index 3259aac..50b255a 100644
@@ -729,11 +729,9 @@ static int send_boot_data(struct IR_tx *tx)
 static void fw_unload_locked(void)
 {
 	if (tx_data) {
-		if (tx_data->code_sets)
-			vfree(tx_data->code_sets);
+		vfree(tx_data->code_sets);
 
-		if (tx_data->datap)
-			vfree(tx_data->datap);
+		vfree(tx_data->datap);
 
 		vfree(tx_data);
 		tx_data = NULL;
Signature · 1 line
2.1.3
#643 lore raw

cover mn88473: Delete an unnecessary check

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 1 Dec 2014 23:16:34 +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 mn88473_init() after error detection

 drivers/staging/media/mn88473/mn88473.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.1.3
#644 lore raw

PATCH 1/2 mn88473: Deletion of an unnecessary check before the function call "release_firmware"

From: Markus Elfring <[email protected]>
Date: Mon, 1 Dec 2014 22:55:29 +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/mn88473/mn88473.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/media/mn88473/mn88473.c +1 -2
index 1659335..52180bb 100644
@@ -262,8 +262,7 @@ static int mn88473_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.1.3
#645 lore raw

PATCH 2/2 mn88473: One function call less in mn88473_init() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 1 Dec 2014 23:15:20 +0100

The release_firmware() function was called by the mn88473_init() function even if a previous function call "request_firmware" failed.
This implementation detail could be improved by the introduction of another jump label.

---
 drivers/staging/media/mn88473/mn88473.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/media/mn88473/mn88473.c +3 -2
index 52180bb..a333744 100644
@@ -225,7 +225,7 @@ static int mn88473_init(struct dvb_frontend *fe)
 	ret = request_firmware(&fw, fw_file, &client->dev);
 	if (ret) {
 		dev_err(&client->dev, "firmare file '%s' not found\n", fw_file);
-		goto err;
+		goto err_request_firmware;
 	}
 
 	dev_info(&client->dev, "downloading firmware from file '%s'\n",
@@ -261,9 +261,10 @@ static int mn88473_init(struct dvb_frontend *fe)
 	dev->warm = true;
 
 	return 0;
+
 err:
 	release_firmware(fw);
-
+err_request_firmware:
 	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
Signature · 1 line
2.1.3
#646 lore raw

PATCH 1/1 lustre: Deletion of unnecessary checks before three function calls

In reply to SF Markus Elfring

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

The functions free_ll_remote_perm(), free_rmtperm_hash() and iput() test whether their argument is NULL and then return immediately. Thus the test around their calls is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/staging/lustre/lustre/llite/remote_perm.c | 5 ++---
 drivers/staging/lustre/lustre/llite/statahead.c   | 3 +--
 2 files changed, 3 insertions(+), 5 deletions(-)
drivers/staging/lustre/lustre/llite/remote_perm.c +2 -3
index c05a912..a581826 100644
@@ -194,7 +194,7 @@ int ll_update_remote_perm(struct inode *inode, struct mdt_remote_perm *perm)
 
 	if (!lli->lli_remote_perms)
 		lli->lli_remote_perms = perm_hash;
-	else if (perm_hash)
+	else
 		free_rmtperm_hash(perm_hash);
 
 	head = lli->lli_remote_perms + remote_perm_hashfunc(perm->rp_uid);
@@ -209,8 +209,7 @@ again:
 			continue;
 		if (tmp->lrp_fsgid != perm->rp_fsgid)
 			continue;
-		if (lrp)
-			free_ll_remote_perm(lrp);
+		free_ll_remote_perm(lrp);
 		lrp = tmp;
 		break;
 	}
drivers/staging/lustre/lustre/llite/statahead.c +1 -2
index 227854b..6ad9dd0 100644
@@ -334,8 +334,7 @@ static void ll_sa_entry_put(struct ll_statahead_info *sai,
 		LASSERT(ll_sa_entry_unhashed(entry));
 
 		ll_sa_entry_cleanup(sai, entry);
-		if (entry->se_inode)
-			iput(entry->se_inode);
+		iput(entry->se_inode);
 
 		OBD_FREE(entry, entry->se_size);
 		atomic_dec(&sai->sai_cache_count);
Signature · 1 line
2.1.3
#647 lore raw

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

In reply to 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.

---
 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
Applied
#648 lore raw

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

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
#649 lore raw

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

In reply to 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.

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 88e5df4..8869971 100644
@@ -842,12 +842,9 @@ static int fsi_clk_disable(struct device *dev,
 		return -EINVAL;
 
 	if (1 == clock->count--) {
-		if (clock->xck)
-			clk_disable(clock->xck);
-		if (clock->ick)
-			clk_disable(clock->ick);
-		if (clock->div)
-			clk_disable(clock->div);
+		clk_disable(clock->xck);
+		clk_disable(clock->ick);
+		clk_disable(clock->div);
 	}
 
 	return 0;
Signature · 1 line
2.1.3
maintainer Applied
#650 lore raw

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

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.

#651 lore raw

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

In reply to 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 issue was detected by using the Coccinelle software.

---
 sound/soc/ux500/mop500.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
sound/soc/ux500/mop500.c +2 -4
index 7f7093b..4e0c0e5 100644
@@ -63,10 +63,8 @@ static void mop500_of_node_put(void)
 	int i;
 
 	for (i = 0; i < 2; i++) {
-		if (mop500_dai_links[i].cpu_of_node)
-			of_node_put(mop500_dai_links[i].cpu_of_node);
-		if (mop500_dai_links[i].codec_of_node)
-			of_node_put(mop500_dai_links[i].codec_of_node);
+		of_node_put(mop500_dai_links[i].cpu_of_node);
+		of_node_put(mop500_dai_links[i].codec_of_node);
 	}
 }
 
Signature · 1 line
2.1.3
maintainer
#652 lore raw

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

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.

#654 lore raw

PATCH 1/1 ALSA: asihpi: Deletion of an unnecessary check before the function call "vfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 2 Dec 2014 18:05:32 +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/pci/asihpi/hpioctl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/pci/asihpi/hpioctl.c +1 -2
index e457eb8..6aa677e 100644
@@ -547,8 +547,7 @@ void asihpi_adapter_remove(struct pci_dev *pci_dev)
 	if (pa->irq)
 		free_irq(pa->irq, pa);
 
-	if (pa->p_buffer)
-		vfree(pa->p_buffer);
+	vfree(pa->p_buffer);
 
 	if (1)
 		dev_info(&pci_dev->dev,
Signature · 1 line
2.1.3
Applied
#655 lore raw

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

At Tue, 02 Dec 2014 18:11:02 +0100,

Quoted 10 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 2 Dec 2014 18:05:32 +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, thanks.

Takashi

Quoted 21 lines
---
 sound/pci/asihpi/hpioctl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/pci/asihpi/hpioctl.c +1 -2
index e457eb8..6aa677e 100644
@@ -547,8 +547,7 @@ void asihpi_adapter_remove(struct pci_dev *pci_dev)
 	if (pa->irq)
 		free_irq(pa->irq, pa);
 
-	if (pa->p_buffer)
-		vfree(pa->p_buffer);
+	vfree(pa->p_buffer);
 
 	if (1)
 		dev_info(&pci_dev->dev,
Signature · 1 line
2.1.3
#656 lore raw

PATCH 1/1 ALSA: echoaudio: Deletion of a check before release_and_free_resource()

In reply to SF Markus Elfring

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

The release_and_free_resource() 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/echoaudio/echoaudio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/pci/echoaudio/echoaudio.c +1 -2
index 60e4003..21228ad 100644
@@ -1875,8 +1875,7 @@ static int snd_echo_free(struct echoaudio *chip)
 	if (chip->dsp_registers)
 		iounmap(chip->dsp_registers);
 
-	if (chip->iores)
-		release_and_free_resource(chip->iores);
+	release_and_free_resource(chip->iores);
 
 
 	pci_disable_device(chip->pci);
Signature · 1 line
2.1.3
Applied
#657 lore raw

Re: [PATCH 1/1] ALSA: echoaudio: Deletion of a check before release_and_free_resource()

At Tue, 02 Dec 2014 18:38:25 +0100,

Quoted 10 lines · SF Markus Elfring

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

The release_and_free_resource() 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, applied.

Takashi

Quoted 21 lines
---
 sound/pci/echoaudio/echoaudio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/pci/echoaudio/echoaudio.c +1 -2
index 60e4003..21228ad 100644
@@ -1875,8 +1875,7 @@ static int snd_echo_free(struct echoaudio *chip)
 	if (chip->dsp_registers)
 		iounmap(chip->dsp_registers);
 
-	if (chip->iores)
-		release_and_free_resource(chip->iores);
+	release_and_free_resource(chip->iores);
 
 
 	pci_disable_device(chip->pci);
Signature · 1 line
2.1.3
#658 lore raw

PATCH 1/1 ALSA: trident: Deletion of a check before snd_util_memhdr_free()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 2 Dec 2014 18:52:21 +0100

The snd_util_memhdr_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/pci/trident/trident_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/pci/trident/trident_main.c +1 -2
index da875dc..57cd757 100644
@@ -3702,8 +3702,7 @@ static int snd_trident_free(struct snd_trident *trident)
 		free_irq(trident->irq, trident);
 	if (trident->tlb.buffer.area) {
 		outl(0, TRID_REG(trident, NX_TLBC));
-		if (trident->tlb.memhdr)
-			snd_util_memhdr_free(trident->tlb.memhdr);
+		snd_util_memhdr_free(trident->tlb.memhdr);
 		if (trident->tlb.silent_page.area)
 			snd_dma_free_pages(&trident->tlb.silent_page);
 		vfree(trident->tlb.shadow_entries);
Signature · 1 line
2.1.3
Applied
#659 lore raw

Re: [PATCH 1/1] ALSA: trident: Deletion of a check before snd_util_memhdr_free()

At Tue, 02 Dec 2014 18:56:30 +0100,

Quoted 10 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 2 Dec 2014 18:52:21 +0100

The snd_util_memhdr_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.

Applied, thanks.

Takashi

Quoted 21 lines
---
 sound/pci/trident/trident_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/pci/trident/trident_main.c +1 -2
index da875dc..57cd757 100644
@@ -3702,8 +3702,7 @@ static int snd_trident_free(struct snd_trident *trident)
 		free_irq(trident->irq, trident);
 	if (trident->tlb.buffer.area) {
 		outl(0, TRID_REG(trident, NX_TLBC));
-		if (trident->tlb.memhdr)
-			snd_util_memhdr_free(trident->tlb.memhdr);
+		snd_util_memhdr_free(trident->tlb.memhdr);
 		if (trident->tlb.silent_page.area)
 			snd_dma_free_pages(&trident->tlb.silent_page);
 		vfree(trident->tlb.shadow_entries);
Signature · 1 line
2.1.3
#660 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 2 Dec 2014 20:35:41 +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 "kfree" One function call less in get_daio_rsc() after error detection

 sound/pci/ctxfi/ctdaio.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
Signature · 1 line
2.1.3
#661 lore raw

PATCH 1/2 ALSA: ctxfi: Deletion of an unnecessary check before the function call "kfree"

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

The kfree() 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/pci/ctxfi/ctdaio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/ctxfi/ctdaio.c +1 -1
index c1c3f88..1712332 100644
@@ -577,7 +577,7 @@ static int get_daio_rsc(struct daio_mgr *mgr,
 error:
 	if (dao)
 		kfree(dao);
-	else if (dai)
+	else
 		kfree(dai);
 
 	spin_lock_irqsave(&mgr->mgr_lock, flags);
Signature · 1 line
2.1.3
#662 lore raw

Re: [PATCH 1/2] ALSA: ctxfi: Deletion of an unnecessary check before the function call "kfree"

Quoted 18 lines · SF Markus Elfring

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

The kfree() 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/pci/ctxfi/ctdaio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/ctxfi/ctdaio.c +0 -0
index c1c3f88..1712332 100644

sound/pci/ctxfi/ctdaio.c static int get_daio_rsc(struct daio_mgr *mgr, · line 583

Quoted 8 lines
sound/pci/ctxfi/ctdaio.c +1 -1
@@ -577,7 +577,7 @@ static int get_daio_rsc(struct daio_mgr *mgr,
 error:
 	if (dao)
 		kfree(dao);
-	else if (dai)
+	else
 		kfree(dai);
 
 	spin_lock_irqsave(&mgr->mgr_lock, flags);

I think this not nice and would prefer something like:

---
 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);
#663 lore raw

PATCH 2/2 ALSA: ctxfi: One function call less in get_daio_rsc() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 2 Dec 2014 20:33:51 +0100

The kfree() function was called in two cases by the get_daio_rsc() function during error handling even if the passed variable contained still a null pointer. This implementation detail could be improved
by adjustments for jump labels.

---
 sound/pci/ctxfi/ctdaio.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
sound/pci/ctxfi/ctdaio.c +10 -10
index 1712332..a12489e 100644
@@ -549,22 +549,22 @@ static int get_daio_rsc(struct daio_mgr *mgr,
 		dao = kzalloc(sizeof(*dao), GFP_KERNEL);
 		if (!dao) {
 			err = -ENOMEM;
-			goto error;
+			goto alloc_error;
 		}
 		err = dao_rsc_init(dao, desc, mgr);
 		if (err)
-			goto error;
+			goto dao_init_error;
 
 		*rdaio = &dao->daio;
 	} else {
 		dai = kzalloc(sizeof(*dai), GFP_KERNEL);
 		if (!dai) {
 			err = -ENOMEM;
-			goto error;
+			goto alloc_error;
 		}
 		err = dai_rsc_init(dai, desc, mgr);
 		if (err)
-			goto error;
+			goto dai_init_error;
 
 		*rdaio = &dai->daio;
 	}
@@ -574,12 +574,12 @@ static int get_daio_rsc(struct daio_mgr *mgr,
 
 	return 0;
 
-error:
-	if (dao)
-		kfree(dao);
-	else
-		kfree(dai);
-
+dao_init_error:
+	kfree(dao);
+	goto alloc_error;
+dai_init_error:
+	kfree(dai);
+alloc_error:
 	spin_lock_irqsave(&mgr->mgr_lock, flags);
 	daio_mgr_put_rsc(&mgr->mgr, desc->type);
 	spin_unlock_irqrestore(&mgr->mgr_lock, flags);
Signature · 1 line
2.1.3
#664 lore raw

Re: [PATCH 0/2] ALSA: ctxfi: Delete an unnecessary check before kfree()

In reply to SF Markus Elfring

At Tue, 02 Dec 2014 21:50:26 +0100,

Quoted 10 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 2 Dec 2014 20:35:41 +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 "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.

Takashi

#665 lore raw

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

Quoted 5 lines
Quoted 2 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.

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

Regards,
Markus

#666 lore raw

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

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

Quoted 8 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.

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

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

Takashi

#667 lore raw

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

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?

#668 lore raw

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

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);
Applied
#670 lore raw

Re: [PATCH] ALSA: ctxfi: Neaten get_daio_rsc

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);
#671 lore raw

PATCH 1/1 ALSA: i2sbus: Deletion of unnecessary checks before the function call "release_and_free_resource"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 2 Dec 2014 22:50:24 +0100

The release_and_free_resource() 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 a80d5ea..4e2b4fb 100644
@@ -79,8 +79,7 @@ static void i2sbus_release_dev(struct device *dev)
  	if (i2sdev->out.dbdma) iounmap(i2sdev->out.dbdma);
  	if (i2sdev->in.dbdma) iounmap(i2sdev->in.dbdma);
 	for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++)
-		if (i2sdev->allocated_resource[i])
-			release_and_free_resource(i2sdev->allocated_resource[i]);
+		release_and_free_resource(i2sdev->allocated_resource[i]);
 	free_dbdma_descriptor_ring(i2sdev, &i2sdev->out.dbdma_ring);
 	free_dbdma_descriptor_ring(i2sdev, &i2sdev->in.dbdma_ring);
 	for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++)
@@ -323,8 +322,7 @@ static int i2sbus_add_dev(struct macio_dev *macio,
 	if (dev->out.dbdma) iounmap(dev->out.dbdma);
 	if (dev->in.dbdma) iounmap(dev->in.dbdma);
 	for (i=0;i<3;i++)
-		if (dev->allocated_resource[i])
-			release_and_free_resource(dev->allocated_resource[i]);
+		release_and_free_resource(dev->allocated_resource[i]);
 	mutex_destroy(&dev->lock);
 	kfree(dev);
 	return 0;
Signature · 1 line
2.1.3
Applied
#672 lore raw

Re: [PATCH] ALSA: i2sbus: Deletion of unnecessary checks before the function call "release_and_free_resource"

At Tue, 02 Dec 2014 22:55:57 +0100,

Quoted 10 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 2 Dec 2014 22:50:24 +0100

The release_and_free_resource() 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, applied.

Takashi

Quoted 31 lines
---
 sound/aoa/soundbus/i2sbus/core.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
sound/aoa/soundbus/i2sbus/core.c +2 -4
index a80d5ea..4e2b4fb 100644
@@ -79,8 +79,7 @@ static void i2sbus_release_dev(struct device *dev)
  	if (i2sdev->out.dbdma) iounmap(i2sdev->out.dbdma);
  	if (i2sdev->in.dbdma) iounmap(i2sdev->in.dbdma);
 	for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++)
-		if (i2sdev->allocated_resource[i])
-			release_and_free_resource(i2sdev->allocated_resource[i]);
+		release_and_free_resource(i2sdev->allocated_resource[i]);
 	free_dbdma_descriptor_ring(i2sdev, &i2sdev->out.dbdma_ring);
 	free_dbdma_descriptor_ring(i2sdev, &i2sdev->in.dbdma_ring);
 	for (i = aoa_resource_i2smmio; i <= aoa_resource_rxdbdma; i++)
@@ -323,8 +322,7 @@ static int i2sbus_add_dev(struct macio_dev *macio,
 	if (dev->out.dbdma) iounmap(dev->out.dbdma);
 	if (dev->in.dbdma) iounmap(dev->in.dbdma);
 	for (i=0;i<3;i++)
-		if (dev->allocated_resource[i])
-			release_and_free_resource(dev->allocated_resource[i]);
+		release_and_free_resource(dev->allocated_resource[i]);
 	mutex_destroy(&dev->lock);
 	kfree(dev);
 	return 0;
Signature · 1 line
2.1.3
#673 lore raw

PATCH 1/1 ARM: DaVinci: Deletion of an unnecessary check before the function call "__clk_disable"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 3 Dec 2014 09:01:33 +0100

The __clk_disable() 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/arm/mach-davinci/clock.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm/mach-davinci/clock.c +1 -2
index c70bb0a..8f2c2d8 100644
@@ -55,8 +55,7 @@ static void __clk_disable(struct clk *clk)
 		else if (clk->clk_disable)
 			clk->clk_disable(clk);
 	}
-	if (clk->parent)
-		__clk_disable(clk->parent);
+	__clk_disable(clk->parent);
 }
 
 int davinci_clk_reset(struct clk *clk, bool reset)
Signature · 1 line
2.1.3
#674 lore raw

Re: ARM: DaVinci: Deletion of an unnecessary check before the function call "__clk_disable"

Quoted 2 lines

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

I was a bit too quick to send you this notification. I stumbled once more on the detail that my source code analysis approach is incomplete for static functions so far.

https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/arch/arm/mach-davinci/clock.c?id§ca2bcf2d2ef15c343a12f2a4c2e06380a0f495#n47
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/drivers/clk/clk.c?idMc7ed32f398fa76b9e1d243a852420b1dad0150#n846

I would like to apologise for confusion I introduced here.

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

#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
#677 lore raw

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

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
#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

#679 lore raw

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

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

#683 lore raw

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

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
#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

#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
#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
maintainer
#703 lore raw

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

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.

#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
maintainer Applied
#708 lore raw

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

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.

#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
maintainer Applied
#710 lore raw

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

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.

#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
#714 lore raw

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

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

#715 lore raw

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

In reply to SF Markus Elfring

Someone was just mentioning in another thread that removing the check from iounmap() is not portable to other arches and then I remembered that Markus removed a bunch of these.

We should consider reverting this, perhaps?

regards,
dan carpenter

Quoted 476 lines · 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 · 6 lines
2.2.1

--
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
maintainer
#716 lore raw

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

Quoted 5 lines · Dan Carpenter

Someone was just mentioning in another thread that removing the check from iounmap() is not portable to other arches and then I remembered that Markus removed a bunch of these.

We should consider reverting this, perhaps?

Can't we teach all architectures? Not that reverting it would be a problem.

johannes

#717 lore raw

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

Quoted 9 lines · Johannes Berg
Quoted 5 lines · Dan Carpenter

Someone was just mentioning in another thread that removing the check from iounmap() is not portable to other arches and then I remembered that Markus removed a bunch of these.

We should consider reverting this, perhaps?

Can't we teach all architectures? Not that reverting it would be a problem.

We probably should. I just didn't want to suggest it, in case it sounds like volunteering... I'm not going to be able to do it because I'm on the road for a bit.

regards,
dan carpenter

#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
#719 lore raw

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

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
#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
#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
#722 lore raw

PATCH 1/1 IOMMU-Tegra: gart: Delete an unnecessary check before the function call "vfree"

In reply to SF Markus Elfring

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 +1 -2
index f722a0c..07a795a 100644
@@ -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;
 }
Signature · 1 line
2.2.2
#723 lore raw

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

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
#729 lore raw

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

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

#730 lore raw

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

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

#731 lore raw

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

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

#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

#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

#738 lore raw

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

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

#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
#743 lore raw

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

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
#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
#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
#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