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 2 of 7

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

PATCH 1/1 firmware class: Deletion of an unnecessary check before the function call "vunmap"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 11:38:38 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/base/firmware_class.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/base/firmware_class.c +1 -2
index 3d785eb..532662c 100644
@@ -591,8 +591,7 @@ static int fw_map_pages_buf(struct firmware_buf *buf)
 	if (!buf->is_paged_buf)
 		return 0;
 
-	if (buf->data)
-		vunmap(buf->data);
+	vunmap(buf->data);
 	buf->data = vmap(buf->pages, buf->nr_pages, 0, PAGE_KERNEL_RO);
 	if (!buf->data)
 		return -ENOMEM;
Signature · 1 line
2.1.3
#309 lore raw

PATCH 1/1 PM-wakeup: Deletion of an unnecessary check before the function call "wakeup_source_unregister"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 12:21:24 +0100

The wakeup_source_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/base/power/wakeup.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/base/power/wakeup.c +1 -2
index eb1bd2e..87dfc1d 100644
@@ -267,8 +267,7 @@ int device_wakeup_disable(struct device *dev)
 		return -EINVAL;
 
 	ws = device_wakeup_detach(dev);
-	if (ws)
-		wakeup_source_unregister(ws);
+	wakeup_source_unregister(ws);
 
 	return 0;
 }
Signature · 1 line
2.1.3
#310 lore raw

Re: [PATCH 1/1] PM-wakeup: Deletion of an unnecessary check before the function call "wakeup_source_unregister"

drivers/base/power/wakeup.c int device_wakeup_disable(struct device *dev) · line 270

Quoted 9 lines · SF Markus Elfring
drivers/base/power/wakeup.c +1 -2
@@ -267,8 +267,7 @@ int device_wakeup_disable(struct device *dev)
 		return -EINVAL;
 
 	ws = device_wakeup_detach(dev);
-	if (ws)
-		wakeup_source_unregister(ws);
+	wakeup_source_unregister(ws);

In the original code, it's clear that the programmer thought about what happens when the device_wakeup_detach() returns NULL but in the new code that's not clear.

I guess the information is still there in the git archive, but why hide the good code by covering it with confusing code?

regards,
dan carpenter

#322 lore raw

PATCH 1/1 drbd: Deletion of an unnecessary check before the function call "lc_destroy"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 13:33:32 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/block/drbd/drbd_nl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/block/drbd/drbd_nl.c +1 -2
index 1cd47df..0bcb3e0 100644
@@ -1115,8 +1115,7 @@ static int drbd_check_al_size(struct drbd_device *device, struct disk_conf *dc)
 		lc_destroy(n);
 		return -EBUSY;
 	} else {
-		if (t)
-			lc_destroy(t);
+		lc_destroy(t);
 	}
 	drbd_md_mark_dirty(device); /* we changed device->act_log->nr_elemens */
 	return 0;
Signature · 1 line
2.1.3
#311 lore raw

Re: [PATCH 1/1] PM-wakeup: Deletion of an unnecessary check before the function call "wakeup_source_unregister"

In reply to Dan Carpenter

Am 19.11.2014 13:09, schrieb Dan Carpenter:

Quoted 15 lines · SF Markus Elfring

drivers/base/power/wakeup.c int device_wakeup_disable(struct device *dev) · line 270

Quoted 9 lines
drivers/base/power/wakeup.c +1 -2
@@ -267,8 +267,7 @@ int device_wakeup_disable(struct device *dev)
 		return -EINVAL;
 
 	ws = device_wakeup_detach(dev);
-	if (ws)
-		wakeup_source_unregister(ws);
+	wakeup_source_unregister(ws);

In the original code, it's clear that the programmer thought about what happens when the device_wakeup_detach() returns NULL but in the new code that's not clear.

Quoted 3 lines

I guess the information is still there in the git archive, but why hide the good code by covering it with confusing code?

hi,
just to add an other point of view ...

device_wakeup_detach returns dev->power.wakeup what is never NULL in this case. (not visible here but a few line before exactly this is checked)

so this code can be compacted to:
wakeup_source_unregister(device_wakeup_detach(dev));

--readability

let the maintainer decide this byte-saving vs readability

re,
wh

#312 lore raw

Re: [PATCH 1/1] PM-wakeup: Deletion of an unnecessary check before the function call "wakeup_source_unregister"

Quoted 2 lines · walter harms

device_wakeup_detach returns dev->power.wakeup what is never NULL in this case. (not visible here but a few line before exactly this is checked)

Huh? I don't see a NULL check.

I think you may be confusing "dev->power.can_wakeup" with "dev->power.wakeup"?

regards,
dan carpenter

#324 lore raw

PATCH 1/1 agp/intel-gtt: Deletion of unnecessary checks before the function call "pci_dev_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 14:24:20 +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/char/agp/intel-gtt.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/char/agp/intel-gtt.c +2 -4
index 9a024f8..db5877e 100644
@@ -1434,10 +1434,8 @@ void intel_gmch_remove(void)
 	if (--intel_private.refcount)
 		return;
 
-	if (intel_private.pcidev)
-		pci_dev_put(intel_private.pcidev);
-	if (intel_private.bridge_dev)
-		pci_dev_put(intel_private.bridge_dev);
+	pci_dev_put(intel_private.pcidev);
+	pci_dev_put(intel_private.bridge_dev);
 	intel_private.driver = NULL;
 }
 EXPORT_SYMBOL(intel_gmch_remove);
Signature · 1 line
2.1.3
#281 lore raw

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

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

From: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 20:37:05 +0100

The functions free_percpu() and module_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

@IPVS folks: Since this involves a nf_tables specific chunk, ack your chunks and I'll put this into nf-next to speed up things.

Thanks.

Quoted 84 lines

This issue was detected by using the Coccinelle software.

---
 net/netfilter/ipvs/ip_vs_ctl.c   | 3 +--
 net/netfilter/ipvs/ip_vs_pe.c    | 3 +--
 net/netfilter/ipvs/ip_vs_sched.c | 3 +--
 net/netfilter/ipvs/ip_vs_sync.c  | 3 +--
 net/netfilter/nf_tables_api.c    | 3 +--
 5 files changed, 5 insertions(+), 10 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +1 -2
index fd3f444..7c5e40a 100644
@@ -465,8 +465,7 @@ __ip_vs_bind_svc(struct ip_vs_dest *dest, struct ip_vs_service *svc)
 
 static void ip_vs_service_free(struct ip_vs_service *svc)
 {
-	if (svc->stats.cpustats)
-		free_percpu(svc->stats.cpustats);
+	free_percpu(svc->stats.cpustats);
 	kfree(svc);
 }
 
net/netfilter/ipvs/ip_vs_pe.c +1 -2
index 1a82b29..0df17ca 100644
@@ -37,8 +37,7 @@ struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name)
 			rcu_read_unlock();
 			return pe;
 		}
-		if (pe->module)
-			module_put(pe->module);
+		module_put(pe->module);
 	}
 	rcu_read_unlock();
 
net/netfilter/ipvs/ip_vs_sched.c +1 -2
index 4dbcda6..199760c 100644
@@ -104,8 +104,7 @@ static struct ip_vs_scheduler *ip_vs_sched_getbyname(const char *sched_name)
 			mutex_unlock(&ip_vs_sched_mutex);
 			return sched;
 		}
-		if (sched->module)
-			module_put(sched->module);
+		module_put(sched->module);
 	}
 
 	mutex_unlock(&ip_vs_sched_mutex);
net/netfilter/ipvs/ip_vs_sync.c +1 -2
index eadffb2..cafe28d 100644
@@ -820,8 +820,7 @@ ip_vs_conn_fill_param_sync(struct net *net, int af, union ip_vs_sync_conn *sc,
 
 		p->pe_data = kmemdup(pe_data, pe_data_len, GFP_ATOMIC);
 		if (!p->pe_data) {
-			if (p->pe->module)
-				module_put(p->pe->module);
+			module_put(p->pe->module);
 			return -ENOMEM;
 		}
 		p->pe_data_len = pe_data_len;
net/netfilter/nf_tables_api.c +1 -2
index deeb95f..b115f54 100644
@@ -3472,8 +3472,7 @@ static int nf_tables_abort(struct sk_buff *skb)
 			break;
 		case NFT_MSG_NEWCHAIN:
 			if (nft_trans_chain_update(trans)) {
-				if (nft_trans_chain_stats(trans))
-					free_percpu(nft_trans_chain_stats(trans));
+				free_percpu(nft_trans_chain_stats(trans));
 
 				nft_trans_destroy(trans);
 			} else {
Signature · 1 line
2.1.3
#313 lore raw

Re: [PATCH 1/1] PM-wakeup: Deletion of an unnecessary check before the function call "wakeup_source_unregister"

In reply to Dan Carpenter

Am 19.11.2014 14:05, schrieb Dan Carpenter:

Quoted 10 lines · walter harms
Quoted 2 lines

device_wakeup_detach returns dev->power.wakeup what is never NULL in this case. (not visible here but a few line before exactly this is checked)

Huh? I don't see a NULL check.

I think you may be confusing "dev->power.can_wakeup" with "dev->power.wakeup"?

mea culpa,
you are right dev->power.can_wakeup != dev->power.wakeup

therefore device_wakeup_detach(dev) CAN return NULL

re,
wh

#326 lore raw

PATCH 1/1 char: tpm: Deletion of unnecessary checks before the function call "tpm_dev_vendor_release"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 14:44:15 +0100

The tpm_dev_vendor_release() 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/char/tpm/tpm_i2c_atmel.c   | 3 +--
 drivers/char/tpm/tpm_i2c_nuvoton.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/char/tpm/tpm_i2c_atmel.c +1 -2
index 7727292..19c3a7b 100644
@@ -202,8 +202,7 @@ static int i2c_atmel_remove(struct i2c_client *client)
 	struct device *dev = &(client->dev);
 	struct tpm_chip *chip = dev_get_drvdata(dev);
 
-	if (chip)
-		tpm_dev_vendor_release(chip);
+	tpm_dev_vendor_release(chip);
 	tpm_remove_hardware(dev);
 	kfree(chip);
 	return 0;
drivers/char/tpm/tpm_i2c_nuvoton.c +1 -2
index 7b158ef..8d09628 100644
@@ -625,8 +625,7 @@ static int i2c_nuvoton_remove(struct i2c_client *client)
 	struct device *dev = &(client->dev);
 	struct tpm_chip *chip = dev_get_drvdata(dev);
 
-	if (chip)
-		tpm_dev_vendor_release(chip);
+	tpm_dev_vendor_release(chip);
 	tpm_remove_hardware(dev);
 	kfree(chip);
 	return 0;
Signature · 1 line
2.1.3
#327 lore raw

PATCH 1/1 EDAC: Deletion of unnecessary checks before the function call "pci_dev_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 16:00:13 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/edac/i3000_edac.c      | 3 +--
 drivers/edac/i3200_edac.c      | 3 +--
 drivers/edac/i82443bxgx_edac.c | 3 +--
 drivers/edac/x38_edac.c        | 3 +--
 4 files changed, 4 insertions(+), 8 deletions(-)
drivers/edac/i3000_edac.c +1 -2
index cd28b96..5cb36a6 100644
@@ -542,8 +542,7 @@ fail1:
 	pci_unregister_driver(&i3000_driver);
 
 fail0:
-	if (mci_pdev)
-		pci_dev_put(mci_pdev);
+	pci_dev_put(mci_pdev);
 
 	return pci_rc;
 }
drivers/edac/i3200_edac.c +1 -2
index aa98b13..4ad062b 100644
@@ -523,8 +523,7 @@ fail1:
 	pci_unregister_driver(&i3200_driver);
 
 fail0:
-	if (mci_pdev)
-		pci_dev_put(mci_pdev);
+	pci_dev_put(mci_pdev);
 
 	return pci_rc;
 }
drivers/edac/i82443bxgx_edac.c +1 -2
index d730e276..b4705d9 100644
@@ -458,8 +458,7 @@ static void __exit i82443bxgx_edacmc_exit(void)
 	if (!i82443bxgx_registered)
 		i82443bxgx_edacmc_remove_one(mci_pdev);
 
-	if (mci_pdev)
-		pci_dev_put(mci_pdev);
+	pci_dev_put(mci_pdev);
 }
 
 module_init(i82443bxgx_edacmc_init);
drivers/edac/x38_edac.c +1 -2
index e644b52..7c5cdc6 100644
@@ -500,8 +500,7 @@ fail1:
 	pci_unregister_driver(&x38_driver);
 
 fail0:
-	if (mci_pdev)
-		pci_dev_put(mci_pdev);
+	pci_dev_put(mci_pdev);
 
 	return pci_rc;
 }
Signature · 1 line
2.1.3
#329 lore raw

PATCH 1/1 DRM-EDID: Deletion of an unnecessary check before the function call "release_firmware"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 16:33:17 +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/drm_edid_load.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/drm_edid_load.c +1 -2
index 0a235fe..732cb6f 100644
@@ -254,8 +254,7 @@ static void *edid_load(struct drm_connector *connector, const char *name,
 	    name, connector_name);
 
 out:
-	if (fw)
-		release_firmware(fw);
+	release_firmware(fw);
 	return edid;
 }
 
Signature · 1 line
2.1.3
#331 lore raw

PATCH 1/1 DRM-tilcdc: Deletion of an unnecessary check before the function call "drm_fbdev_cma_hotplug_event"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 17:05:20 +0100

The drm_fbdev_cma_hotplug_event() 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/tilcdc/tilcdc_drv.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/tilcdc/tilcdc_drv.c +1 -2
index 000428e..335b1dc 100644
@@ -58,8 +58,7 @@ static struct drm_framebuffer *tilcdc_fb_create(struct drm_device *dev,
 static void tilcdc_fb_output_poll_changed(struct drm_device *dev)
 {
 	struct tilcdc_drm_private *priv = dev->dev_private;
-	if (priv->fbdev)
-		drm_fbdev_cma_hotplug_event(priv->fbdev);
+	drm_fbdev_cma_hotplug_event(priv->fbdev);
 }
 
 static const struct drm_mode_config_funcs mode_config_funcs = {
Signature · 1 line
2.1.3
#333 lore raw

PATCH 1/1 DRM-UDL: Deletion of an unnecessary check before the function call "vunmap"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 17:33:32 +0100

The vunmap() function performes 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/udl/udl_gem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/udl/udl_gem.c +1 -2
index 8044f5f..2979625 100644
@@ -164,8 +164,7 @@ void udl_gem_vunmap(struct udl_gem_object *obj)
 		return;
 	}
 
-	if (obj->vmapping)
-		vunmap(obj->vmapping);
+	vunmap(obj->vmapping);
 
 	udl_gem_put_pages(obj);
 }
Signature · 1 line
2.1.3
maintainer Applied
#328 lore raw

Re: [PATCH 1/1] EDAC: Deletion of unnecessary checks before the function call "pci_dev_put"

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

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 16:00:13 +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, thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
#290 lore raw

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

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

From: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 21:21:16 +0100

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

This issue was detected by using the Coccinelle software.

---
  net/sched/cls_bpf.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
net/sched/cls_bpf.c +0 -0
index 0e30d58..f323944 100644

net/sched/cls_bpf.c static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp, · line 218

Quoted 9 lines
net/sched/cls_bpf.c +1 -2
@@ -212,8 +212,7 @@ static int cls_bpf_modify_existing(struct net *net, struct tcf_proto *tp,
 
  	if (fp_old)
  		bpf_prog_destroy(fp_old);
-	if (bpf_old)
-		kfree(bpf_old);
+	kfree(bpf_old);
 
  	return 0;
 

Maybe I need some coffee but I can't figure out what this patch is against...

# grep bpf_old ./net/sched/cls_bpf.c
#

Marcus, what tree are you looking at?

Signature · 1 line
John Fastabend         Intel Corporation
#335 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 17:50:19 +0100

The vfree() function performes 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/vmwgfx/vmwgfx_drv.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -2
index 14b2f50..f9a67b8 100644
@@ -889,8 +889,7 @@ static int vmw_driver_unload(struct drm_device *dev)
 
 	if (dev_priv->ctx.res_ht_initialized)
 		drm_ht_remove(&dev_priv->ctx.res_ht);
-	if (dev_priv->ctx.cmd_bounce)
-		vfree(dev_priv->ctx.cmd_bounce);
+	vfree(dev_priv->ctx.cmd_bounce);
 	if (dev_priv->enable_fb) {
 		vmw_fb_close(dev_priv);
 		vmw_kms_restore_vga(dev_priv);
Signature · 1 line
2.1.3
#291 lore raw

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

In reply to John Fastabend
Quoted 2 lines · John Fastabend
Quoted 1 line · SF Markus Elfring

From: Markus Elfring <[email protected]>

...

Quoted 6 lines
Quoted 6 lines
      if (fp_old)
          bpf_prog_destroy(fp_old);
net/sched/cls_bpf.c +1 -2
-    if (bpf_old)
-        kfree(bpf_old);
+    kfree(bpf_old);
Quoted 8 lines
Quoted 2 lines
      return 0;

Maybe I need some coffee but I can't figure out what this patch is against...

# grep bpf_old ./net/sched/cls_bpf.c
#

Coffee is always good. :)

Yeah, you actually removed this in commit 1f947bf151e90ec ("net:
sched: rcu'ify cls_bpf"), so looks like Markus's tree is not up to date ...

#344 lore raw

PATCH 1/1 HID-picoLCD: Deletion of unnecessary checks before three function calls

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 18:30:22 +0100

The functions backlight_device_unregister(), lcd_device_unregister() and rc_unregister_device() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/hid/hid-picolcd_backlight.c | 3 +--
 drivers/hid/hid-picolcd_cir.c       | 3 +--
 drivers/hid/hid-picolcd_lcd.c       | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)
drivers/hid/hid-picolcd_backlight.c +1 -2
index a32c5f8..808807a 100644
@@ -94,8 +94,7 @@ void picolcd_exit_backlight(struct picolcd_data *data)
 	struct backlight_device *bdev = data->backlight;
 
 	data->backlight = NULL;
-	if (bdev)
-		backlight_device_unregister(bdev);
+	backlight_device_unregister(bdev);
 }
 
 int picolcd_resume_backlight(struct picolcd_data *data)
drivers/hid/hid-picolcd_cir.c +1 -2
index 045f8eb..9628651 100644
@@ -145,7 +145,6 @@ void picolcd_exit_cir(struct picolcd_data *data)
 	struct rc_dev *rdev = data->rc_dev;
 
 	data->rc_dev = NULL;
-	if (rdev)
-		rc_unregister_device(rdev);
+	rc_unregister_device(rdev);
 }
 
drivers/hid/hid-picolcd_lcd.c +1 -2
index 89821c2..22dcbe1 100644
@@ -92,8 +92,7 @@ void picolcd_exit_lcd(struct picolcd_data *data)
 	struct lcd_device *ldev = data->lcd;
 
 	data->lcd = NULL;
-	if (ldev)
-		lcd_device_unregister(ldev);
+	lcd_device_unregister(ldev);
 }
 
 int picolcd_resume_lcd(struct picolcd_data *data)
Signature · 1 line
2.1.3
#348 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 19:19:21 +0100

The functions kfree() and pci_dev_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/infiniband/hw/mlx4/main.c         | 3 +--
 drivers/infiniband/hw/mthca/mthca_reset.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/infiniband/hw/mlx4/main.c +1 -2
index 8b72cf3..50dee1a 100644
@@ -2512,8 +2512,7 @@ static void do_slave_init(struct mlx4_ib_dev *ibdev, int slave, int do_init)
 		if (!dm[i]) {
 			pr_err("failed to allocate memory for tunneling qp update work struct\n");
 			for (i = 0; i < dev->caps.num_ports; i++) {
-				if (dm[i])
-					kfree(dm[i]);
+				kfree(dm[i]);
 			}
 			goto out;
 		}
drivers/infiniband/hw/mthca/mthca_reset.c +1 -2
index 74c6a94..c521654 100644
@@ -279,8 +279,7 @@ good:
 	}
 
 out:
-	if (bridge)
-		pci_dev_put(bridge);
+	pci_dev_put(bridge);
 	kfree(bridge_header);
 	kfree(hca_header);
 
Signature · 1 line
2.1.3
#293 lore raw

Re: net: sched: Deletion of an unnecessary check before the function call "kfree"

Quoted 6 lines · SF Markus Elfring
Quoted 1 line

Marcus, what tree are you looking at?

I dared to base this update suggestion on the source files for Linux 3.17.3. Are newer software developments relevant here?

https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/log/net/sched/

Pointing to linux-next and saying you based your changes on 3.17.3 is confusing, please look correctly when you provide a link ...

Again, John's commit 1f947bf151e90ec0b removed the relevant part in cls_bpf_modify_existing() that you're trying to modify:

$ git grep -n bpf_old net/sched/cls_bpf.c
$

Therefore, this patch is not needed.

Thanks !

#357 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 20:48:26 +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/isdn/mISDN/l1oip_codec.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/isdn/mISDN/l1oip_codec.c +2 -4
index a601c84..9b033be 100644
@@ -312,10 +312,8 @@ l1oip_ulaw_to_alaw(u8 *data, int len, u8 *result)
 void
 l1oip_4bit_free(void)
 {
-	if (table_dec)
-		vfree(table_dec);
-	if (table_com)
-		vfree(table_com);
+	vfree(table_dec);
+	vfree(table_com);
 	table_com = NULL;
 	table_dec = NULL;
 }
Signature · 1 line
2.1.3
maintainer Applied
#279 lore raw

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

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 20:16:05 +0100

Quoted 9 lines

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

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

maintainer Applied
#288 lore raw

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

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 21:08:39 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 21:03:13 +0100

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

#359 lore raw

PATCH 1/1 bcache: Deletion of an unnecessary check before the function call "kobject_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 21:25:39 +0100

The kobject_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/md/bcache/super.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/bcache/super.c +1 -2
index d4713d0..1443c55 100644
@@ -2076,8 +2076,7 @@ static void bcache_exit(void)
 {
 	bch_debug_exit();
 	bch_request_exit();
-	if (bcache_kobj)
-		kobject_put(bcache_kobj);
+	kobject_put(bcache_kobj);
 	if (bcache_wq)
 		destroy_workqueue(bcache_wq);
 	if (bcache_major)
Signature · 1 line
2.1.3
#361 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 21:48:10 +0100

The functions dm_table_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/md/dm-ioctl.c           |  3 +--
 drivers/md/dm-snap-persistent.c | 12 ++++--------
 2 files changed, 5 insertions(+), 10 deletions(-)
drivers/md/dm-ioctl.c +1 -2
index 5152142..0b925a4 100644
@@ -1050,8 +1050,7 @@ static int do_resume(struct dm_ioctl *param)
 	 * Since dm_swap_table synchronizes RCU, nobody should be in
 	 * read-side critical section already.
 	 */
-	if (old_map)
-		dm_table_destroy(old_map);
+	dm_table_destroy(old_map);
 
 	if (!r)
 		__dev_status(md, param);
drivers/md/dm-snap-persistent.c +4 -8
index d6e8817..4b29bac 100644
@@ -200,16 +200,13 @@ err_area:
 
 static void free_area(struct pstore *ps)
 {
-	if (ps->area)
-		vfree(ps->area);
+	vfree(ps->area);
 	ps->area = NULL;
 
-	if (ps->zero_area)
-		vfree(ps->zero_area);
+	vfree(ps->zero_area);
 	ps->zero_area = NULL;
 
-	if (ps->header_area)
-		vfree(ps->header_area);
+	vfree(ps->header_area);
 	ps->header_area = NULL;
 }
 
@@ -605,8 +602,7 @@ static void persistent_dtr(struct dm_exception_store *store)
 	free_area(ps);
 
 	/* Allocated in persistent_read_metadata */
-	if (ps->callbacks)
-		vfree(ps->callbacks);
+	vfree(ps->callbacks);
 
 	kfree(ps);
 }
Signature · 1 line
2.1.3
maintainer Applied
#277 lore raw

Re: [PATCH 0/2] fs-udf: Deletion of two unnecessary checks

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

From: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 18:33:08 +0100

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

I've merged both patches. Thanks.

Honza

Quoted 11 lines

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

 fs/udf/super.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
Signature · 1 line
2.1.3
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Applied
#358 lore raw

Re: [PATCH 1/1] mISDN: Deletion of unnecessary checks before the function call "vfree"

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 20:55:18 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 20:48:26 +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.

maintainer Acked-by on v1 1/1
#284 lore raw

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

In reply to SF Markus Elfring

Hello,

Quoted 10 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 20:37:05 +0100

The functions free_percpu() and module_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Pablo, the IPVS parts look ok to me,

Quoted 80 lines
---
 net/netfilter/ipvs/ip_vs_ctl.c   | 3 +--
 net/netfilter/ipvs/ip_vs_pe.c    | 3 +--
 net/netfilter/ipvs/ip_vs_sched.c | 3 +--
 net/netfilter/ipvs/ip_vs_sync.c  | 3 +--
 net/netfilter/nf_tables_api.c    | 3 +--
 5 files changed, 5 insertions(+), 10 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +1 -2
index fd3f444..7c5e40a 100644
@@ -465,8 +465,7 @@ __ip_vs_bind_svc(struct ip_vs_dest *dest, struct ip_vs_service *svc)
 
 static void ip_vs_service_free(struct ip_vs_service *svc)
 {
-	if (svc->stats.cpustats)
-		free_percpu(svc->stats.cpustats);
+	free_percpu(svc->stats.cpustats);
 	kfree(svc);
 }
 
net/netfilter/ipvs/ip_vs_pe.c +1 -2
index 1a82b29..0df17ca 100644
@@ -37,8 +37,7 @@ struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name)
 			rcu_read_unlock();
 			return pe;
 		}
-		if (pe->module)
-			module_put(pe->module);
+		module_put(pe->module);
 	}
 	rcu_read_unlock();
 
net/netfilter/ipvs/ip_vs_sched.c +1 -2
index 4dbcda6..199760c 100644
@@ -104,8 +104,7 @@ static struct ip_vs_scheduler *ip_vs_sched_getbyname(const char *sched_name)
 			mutex_unlock(&ip_vs_sched_mutex);
 			return sched;
 		}
-		if (sched->module)
-			module_put(sched->module);
+		module_put(sched->module);
 	}
 
 	mutex_unlock(&ip_vs_sched_mutex);
net/netfilter/ipvs/ip_vs_sync.c +1 -2
index eadffb2..cafe28d 100644
@@ -820,8 +820,7 @@ ip_vs_conn_fill_param_sync(struct net *net, int af, union ip_vs_sync_conn *sc,
 
 		p->pe_data = kmemdup(pe_data, pe_data_len, GFP_ATOMIC);
 		if (!p->pe_data) {
-			if (p->pe->module)
-				module_put(p->pe->module);
+			module_put(p->pe->module);
 			return -ENOMEM;
 		}
 		p->pe_data_len = pe_data_len;
net/netfilter/nf_tables_api.c +1 -2
index deeb95f..b115f54 100644
@@ -3472,8 +3472,7 @@ static int nf_tables_abort(struct sk_buff *skb)
 			break;
 		case NFT_MSG_NEWCHAIN:
 			if (nft_trans_chain_update(trans)) {
-				if (nft_trans_chain_stats(trans))
-					free_percpu(nft_trans_chain_stats(trans));
+				free_percpu(nft_trans_chain_stats(trans));
 
 				nft_trans_destroy(trans);
 			} else {
Signature · 1 line
2.1.3

Regards

--
Julian Anastasov <[email protected]>

maintainer Acked-by
#285 lore raw

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

Quoted 12 lines · Julian Anastasov

Hello,

Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 20:37:05 +0100

The functions free_percpu() and module_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

Quoted 7 lines
Quoted 3 lines

This issue was detected by using the Coccinelle software.

Pablo, the IPVS parts look ok to me,

Quoted 87 lines
Quoted 81 lines
---
 net/netfilter/ipvs/ip_vs_ctl.c   | 3 +--
 net/netfilter/ipvs/ip_vs_pe.c    | 3 +--
 net/netfilter/ipvs/ip_vs_sched.c | 3 +--
 net/netfilter/ipvs/ip_vs_sync.c  | 3 +--
 net/netfilter/nf_tables_api.c    | 3 +--
 5 files changed, 5 insertions(+), 10 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +1 -2
index fd3f444..7c5e40a 100644
@@ -465,8 +465,7 @@ __ip_vs_bind_svc(struct ip_vs_dest *dest, struct ip_vs_service *svc)
 
 static void ip_vs_service_free(struct ip_vs_service *svc)
 {
-	if (svc->stats.cpustats)
-		free_percpu(svc->stats.cpustats);
+	free_percpu(svc->stats.cpustats);
 	kfree(svc);
 }
 
net/netfilter/ipvs/ip_vs_pe.c +1 -2
index 1a82b29..0df17ca 100644
@@ -37,8 +37,7 @@ struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name)
 			rcu_read_unlock();
 			return pe;
 		}
-		if (pe->module)
-			module_put(pe->module);
+		module_put(pe->module);
 	}
 	rcu_read_unlock();
 
net/netfilter/ipvs/ip_vs_sched.c +1 -2
index 4dbcda6..199760c 100644
@@ -104,8 +104,7 @@ static struct ip_vs_scheduler *ip_vs_sched_getbyname(const char *sched_name)
 			mutex_unlock(&ip_vs_sched_mutex);
 			return sched;
 		}
-		if (sched->module)
-			module_put(sched->module);
+		module_put(sched->module);
 	}
 
 	mutex_unlock(&ip_vs_sched_mutex);
net/netfilter/ipvs/ip_vs_sync.c +1 -2
index eadffb2..cafe28d 100644
@@ -820,8 +820,7 @@ ip_vs_conn_fill_param_sync(struct net *net, int af, union ip_vs_sync_conn *sc,
 
 		p->pe_data = kmemdup(pe_data, pe_data_len, GFP_ATOMIC);
 		if (!p->pe_data) {
-			if (p->pe->module)
-				module_put(p->pe->module);
+			module_put(p->pe->module);
 			return -ENOMEM;
 		}
 		p->pe_data_len = pe_data_len;
net/netfilter/nf_tables_api.c +1 -2
index deeb95f..b115f54 100644
@@ -3472,8 +3472,7 @@ static int nf_tables_abort(struct sk_buff *skb)
 			break;
 		case NFT_MSG_NEWCHAIN:
 			if (nft_trans_chain_update(trans)) {
-				if (nft_trans_chain_stats(trans))
-					free_percpu(nft_trans_chain_stats(trans));
+				free_percpu(nft_trans_chain_stats(trans));
 
 				nft_trans_destroy(trans);
 			} else {
Signature · 1 line
2.1.3

Regards

--
Julian Anastasov <[email protected]>

#216 lore raw

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

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

index 3995f54..f1e7d45 100644

kernel/kprobes.c +0 -0
@@ -1527,8 +1527,7 @@ int register_kprobe(struct kprobe *p)
 out:
 	mutex_unlock(&kprobe_mutex);
 
Quoted 7 lines

kernel/kprobes.c int register_kprobe(struct kprobe *p) · line 1530

Quoted 3 lines
kernel/kprobes.c +1 -2
-	if (probed_mod)
-		module_put(probed_mod);
+	module_put(probed_mod);

This is OK, but I you request a comment line over there so that code reader can understand it is safe to pass a NULL pointer to module_put().

Quoted 2 lines

Do you want that I replace the shown null pointer check by a short comment which repeats an expectation for the affected function call?

No, not "want". IMHO, if try_module_get(mod) is done only when mod!=NULL, we shouldn't call module_put(mod) when mod=NULL (even if it is possible), because those get/put method must be used as a pair, for the better understandings.

Thank you,

Signature · 4 lines
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
Reviewed-by on v1 1/1
#330 lore raw

Re: [PATCH 1/1] DRM-EDID: Deletion of an unnecessary check before the function call "release_firmware"

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

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 16:33:17 +0100

The release_firmware() function tests whether its argument is NULL and

then

Review

Quoted 10 lines

returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/drm_edid_load.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/drm_edid_load.c

drivers/gpu/drm/drm_edid_load.c static void *edid_load(struct drm_connector

Quoted 4 lines

index 0a235fe..732cb6f 100644

drivers/gpu/drm/drm_edid_load.c +0 -0
@@ -254,8 +254,7 @@ static void *edid_load(struct drm_connector

*connector, const char *name,

drivers/gpu/drm/drm_edid_load.c static void *edid_load(struct drm_connector *connector, const char *name, · line 260

Quoted 9 lines
drivers/gpu/drm/drm_edid_load.c +1 -2
            name, connector_name);
 
 out:
-       if (fw)
-               release_firmware(fw);
+       release_firmware(fw);
        return edid;
 }
 

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

Reviewed-by on v1 1/1
#332 lore raw

Re: [PATCH 1/1] DRM-tilcdc: Deletion of an unnecessary check before the function call "drm_fbdev_cma_hotplug_event"

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

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 17:05:20 +0100

The drm_fbdev_cma_hotplug_event() 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/tilcdc/tilcdc_drv.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/tilcdc/tilcdc_drv.c +1 -2
index 000428e..335b1dc 100644
@@ -58,8 +58,7 @@ static struct drm_framebuffer *tilcdc_fb_create(struct 
 drm_device *dev,
 static void tilcdc_fb_output_poll_changed(struct drm_device *dev)
 {
 	struct tilcdc_drm_private *priv = dev->dev_private;
-	if (priv->fbdev)
-		drm_fbdev_cma_hotplug_event(priv->fbdev);
+	drm_fbdev_cma_hotplug_event(priv->fbdev);
 }
 
Quoted 1 line

static const struct drm_mode_config_funcs mode_config_funcs = {

Reviewed-by on v1 1/1
#334 lore raw

Re: [PATCH 1/1] DRM-UDL: Deletion of an unnecessary check before the function call "vunmap"

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

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 17:33:32 +0100

The vunmap() function performes 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/udl/udl_gem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/udl/udl_gem.c +0 -0
index 8044f5f..2979625 100644

drivers/gpu/drm/udl/udl_gem.c void udl_gem_vunmap(struct udl_gem_object *obj) · line 170

Quoted 9 lines
drivers/gpu/drm/udl/udl_gem.c +1 -2
@@ -164,8 +164,7 @@ void udl_gem_vunmap(struct udl_gem_object *obj)
 		return;
 	}
 
-	if (obj->vmapping)
-		vunmap(obj->vmapping);
+	vunmap(obj->vmapping);
 
 	udl_gem_put_pages(obj);
 }
Reviewed-by on v1 1/1
#336 lore raw

Re: [PATCH 1/1] DRM-vmwgfx: Deletion of an unnecessary check before the function call "vfree"

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

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 17:50:19 +0100

The vfree() function performes 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/vmwgfx/vmwgfx_drv.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +0 -0
index 14b2f50..f9a67b8 100644

drivers/gpu/drm/vmwgfx/vmwgfx_drv.c static int vmw_driver_unload(struct drm_device *dev) · line 895

Quoted 9 lines
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -2
@@ -889,8 +889,7 @@ static int vmw_driver_unload(struct drm_device *dev)
 
 	if (dev_priv->ctx.res_ht_initialized)
 		drm_ht_remove(&dev_priv->ctx.res_ht);
-	if (dev_priv->ctx.cmd_bounce)
-		vfree(dev_priv->ctx.cmd_bounce);
+	vfree(dev_priv->ctx.cmd_bounce);
 	if (dev_priv->enable_fb) {
 		vmw_fb_close(dev_priv);
 		vmw_kms_restore_vga(dev_priv);
#362 lore raw

cover DVB-frontends: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 23:30:37 +0100

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

Markus Elfring (3):
DVB-frontends: Deletion of unnecessary checks before the function
call "release_firmware"
m88ds3103: One function call less in m88ds3103_init() after error detection
si2168: One function call less in si2168_init() after error detection

 drivers/media/dvb-frontends/drx39xyj/drxj.c |  3 +--
 drivers/media/dvb-frontends/drxk_hard.c     |  3 +--
 drivers/media/dvb-frontends/m88ds3103.c     | 12 ++++++------
 drivers/media/dvb-frontends/si2168.c        | 10 +++++-----
 4 files changed, 13 insertions(+), 15 deletions(-)
Signature · 1 line
2.1.3
#364 lore raw

PATCH 2/3 m88ds3103: One function call less in m88ds3103_init() after error detection

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 23:20:51 +0100

The release_firmware() function was called in some cases by the m88ds3103_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/dvb-frontends/m88ds3103.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/media/dvb-frontends/m88ds3103.c +6 -5
index e88f0f6..82da715 100644
@@ -590,7 +590,7 @@ static int m88ds3103_init(struct dvb_frontend *fe)
 
 	ret = m88ds3103_wr_reg(priv, 0xb2, 0x01);
 	if (ret)
-		goto err;
+		goto error_fw_release;
 
 	for (remaining = fw->size; remaining > 0;
 			remaining -= (priv->cfg->i2c_wr_max - 1)) {
@@ -604,13 +604,13 @@ static int m88ds3103_init(struct dvb_frontend *fe)
 			dev_err(&priv->i2c->dev,
 					"%s: firmware download failed=%d\n",
 					KBUILD_MODNAME, ret);
-			goto err;
+			goto error_fw_release;
 		}
 	}
 
 	ret = m88ds3103_wr_reg(priv, 0xb2, 0x00);
 	if (ret)
-		goto err;
+		goto error_fw_release;
 
 	release_firmware(fw);
 	fw = NULL;
@@ -636,9 +636,10 @@ skip_fw_download:
 	priv->warm = true;
 
 	return 0;
-err:
-	release_firmware(fw);
 
+error_fw_release:
+	release_firmware(fw);
+err:
 	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
 	return ret;
 }
Signature · 1 line
2.1.3
#363 lore raw

PATCH 1/3 DVB-frontends: Deletion of unnecessary checks before the function call "release_firmware"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 22:27:24 +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/dvb-frontends/drx39xyj/drxj.c | 3 +--
 drivers/media/dvb-frontends/drxk_hard.c     | 3 +--
 drivers/media/dvb-frontends/m88ds3103.c     | 3 +--
 drivers/media/dvb-frontends/si2168.c        | 3 +--
 4 files changed, 4 insertions(+), 8 deletions(-)
drivers/media/dvb-frontends/drx39xyj/drxj.c +1 -2
index 7ca7a21..08e6ca5 100644
@@ -12255,8 +12255,7 @@ static void drx39xxj_release(struct dvb_frontend *fe)
 	kfree(demod->my_ext_attr);
 	kfree(demod->my_common_attr);
 	kfree(demod->my_i2c_dev_addr);
-	if (demod->firmware)
-		release_firmware(demod->firmware);
+	release_firmware(demod->firmware);
 	kfree(demod);
 	kfree(state);
 }
drivers/media/dvb-frontends/drxk_hard.c +1 -2
index cce94a7..f871478 100644
@@ -6309,8 +6309,7 @@ static void drxk_release(struct dvb_frontend *fe)
 	struct drxk_state *state = fe->demodulator_priv;
 
 	dprintk(1, "\n");
-	if (state->fw)
-		release_firmware(state->fw);
+	release_firmware(state->fw);
 
 	kfree(state);
 }
drivers/media/dvb-frontends/m88ds3103.c +1 -2
index dfe0c2f..e88f0f6 100644
@@ -637,8 +637,7 @@ skip_fw_download:
 
 	return 0;
 err:
-	if (fw)
-		release_firmware(fw);
+	release_firmware(fw);
 
 	dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
 	return ret;
drivers/media/dvb-frontends/si2168.c +1 -2
index 8f81d97..6a455f9 100644
@@ -469,8 +469,7 @@ static int si2168_init(struct dvb_frontend *fe)
 
 	return 0;
 err:
-	if (fw)
-		release_firmware(fw);
+	release_firmware(fw);
 
 	dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret);
 	return ret;
Signature · 1 line
2.1.3
#365 lore raw

PATCH 3/3 si2168: One function call less in si2168_init() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 23:23:15 +0100

The release_firmware() function was called in some cases by the si2168_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/dvb-frontends/si2168.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/media/dvb-frontends/si2168.c +5 -4
index 6a455f9..b8c6372 100644
@@ -428,7 +428,7 @@ static int si2168_init(struct dvb_frontend *fe)
 			dev_err(&s->client->dev,
 					"%s: firmware file '%s' not found\n",
 					KBUILD_MODNAME, fw_file);
-			goto err;
+			goto error_fw_release;
 		}
 	}
 
@@ -448,7 +448,7 @@ static int si2168_init(struct dvb_frontend *fe)
 			dev_err(&s->client->dev,
 					"%s: firmware download failed=%d\n",
 					KBUILD_MODNAME, ret);
-			goto err;
+			goto error_fw_release;
 		}
 	}
 
@@ -468,9 +468,10 @@ static int si2168_init(struct dvb_frontend *fe)
 	s->active = true;
 
 	return 0;
-err:
-	release_firmware(fw);
 
+error_fw_release:
+	release_firmware(fw);
+err:
 	dev_dbg(&s->client->dev, "%s: failed=%d\n", __func__, ret);
 	return ret;
 }
Signature · 1 line
2.1.3
#294 lore raw

Re: net: sched: Deletion of an unnecessary check before the function call "kfree"

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

Marcus, what tree are you looking at?

I dared to base this update suggestion on the source files for Linux 3.17.3. Are newer software developments relevant here?

You should always use linux-next. You should update it every day.

julia

Quoted 10 lines

https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/log/net/sched/

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

#295 lore raw

Re: net: sched: Deletion of an unnecessary check before the function call "kfree"

Quoted 8 lines · Julia Lawall
Quoted 4 lines · SF Markus Elfring
Quoted 1 line

Marcus, what tree are you looking at?

I dared to base this update suggestion on the source files for Linux 3.17.3. Are newer software developments relevant here?

You should always use linux-next. You should update it every day.

Well, if you send in cleanups to netdev, you should always target the net-next tree:

git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git

#366 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 10:49:07 +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/firewire/firedtv-ci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/firewire/firedtv-ci.c +1 -2
index e5ebdbf..e63f582 100644
@@ -253,6 +253,5 @@ int fdtv_ca_register(struct firedtv *fdtv)
 
 void fdtv_ca_release(struct firedtv *fdtv)
 {
-	if (fdtv->cadev)
-		dvb_unregister_device(fdtv->cadev);
+	dvb_unregister_device(fdtv->cadev);
 }
Signature · 1 line
2.1.3
#368 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 11:13:16 +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/i2c/ir-kbd-i2c.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/i2c/ir-kbd-i2c.c +1 -2
index 8311f1a..175a761 100644
@@ -464,8 +464,7 @@ static int ir_remove(struct i2c_client *client)
 	cancel_delayed_work_sync(&ir->work);
 
 	/* unregister device */
-	if (ir->rc)
-		rc_unregister_device(ir->rc);
+	rc_unregister_device(ir->rc);
 
 	/* free memory */
 	return 0;
Signature · 1 line
2.1.3
#369 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 11:44:20 +0100

The functions i2c_put_adapter() and release_firmware() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/media/platform/exynos4-is/fimc-is.c   | 6 ++----
 drivers/media/platform/s3c-camif/camif-core.c | 3 +--
 2 files changed, 3 insertions(+), 6 deletions(-)
drivers/media/platform/exynos4-is/fimc-is.c +2 -4
index 5476dce..a1db27b 100644
@@ -428,8 +428,7 @@ static void fimc_is_load_firmware(const struct firmware *fw, void *context)
 	 * needed around for copying to the IS working memory every
 	 * time before the Cortex-A5 is restarted.
 	 */
-	if (is->fw.f_w)
-		release_firmware(is->fw.f_w);
+	release_firmware(is->fw.f_w);
 	is->fw.f_w = fw;
 done:
 	mutex_unlock(&is->lock);
@@ -937,8 +936,7 @@ static int fimc_is_remove(struct platform_device *pdev)
 	vb2_dma_contig_cleanup_ctx(is->alloc_ctx);
 	fimc_is_put_clocks(is);
 	fimc_is_debugfs_remove(is);
-	if (is->fw.f_w)
-		release_firmware(is->fw.f_w);
+	release_firmware(is->fw.f_w);
 	fimc_is_free_cpu_memory(is);
 
 	return 0;
drivers/media/platform/s3c-camif/camif-core.c +1 -2
index b385747..3b09b5b 100644
@@ -256,8 +256,7 @@ static void camif_unregister_sensor(struct camif_dev *camif)
 	v4l2_device_unregister_subdev(sd);
 	camif->sensor.sd = NULL;
 	i2c_unregister_device(client);
-	if (adapter)
-		i2c_put_adapter(adapter);
+	i2c_put_adapter(adapter);
 }
 
 static int camif_create_media_links(struct camif_dev *camif)
Signature · 1 line
2.1.3
#370 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 13:01:32 +0100

The functions input_free_device() and rc_close() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/media/rc/lirc_dev.c | 3 +--
 drivers/media/rc/rc-main.c  | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/media/rc/lirc_dev.c +1 -2
index dc5cbff..5c232e6 100644
@@ -518,8 +518,7 @@ int lirc_dev_fop_close(struct inode *inode, struct file *file)
 
 	WARN_ON(mutex_lock_killable(&lirc_dev_lock));
 
-	if (ir->d.rdev)
-		rc_close(ir->d.rdev);
+	rc_close(ir->d.rdev);
 
 	ir->open--;
 	if (ir->attached) {
drivers/media/rc/rc-main.c +1 -2
index 8d3b74c..66df9fb 100644
@@ -1298,8 +1298,7 @@ void rc_free_device(struct rc_dev *dev)
 	if (!dev)
 		return;
 
-	if (dev->input_dev)
-		input_free_device(dev->input_dev);
+	input_free_device(dev->input_dev);
 
 	put_device(&dev->dev);
 
Signature · 1 line
2.1.3
maintainer Applied
#286 lore raw

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

In reply to Simon Horman
Quoted 15 lines · Simon Horman
Quoted 14 lines · Julian Anastasov

Hello,

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 18 Nov 2014 20:37:05 +0100

The functions free_percpu() and module_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Pablo, the IPVS parts look ok to me,

Applied, thanks.

#371 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 13:26:36 +0100

The functions pvr2_hdw_destroy(), rc_unregister_device() 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/media/usb/au0828/au0828-input.c     | 3 +--
 drivers/media/usb/em28xx/em28xx-input.c     | 3 +--
 drivers/media/usb/pvrusb2/pvrusb2-context.c | 2 +-
 drivers/media/usb/s2255/s2255drv.c          | 3 +--
 4 files changed, 4 insertions(+), 7 deletions(-)
drivers/media/usb/au0828/au0828-input.c +1 -2
index fd0d3a90..3357141 100644
@@ -353,8 +353,7 @@ void au0828_rc_unregister(struct au0828_dev *dev)
 	if (!ir)
 		return;
 
-	if (ir->rc)
-		rc_unregister_device(ir->rc);
+	rc_unregister_device(ir->rc);
 
 	/* done */
 	kfree(ir);
drivers/media/usb/em28xx/em28xx-input.c +1 -2
index ed843bd..67a22f4 100644
@@ -838,8 +838,7 @@ static int em28xx_ir_fini(struct em28xx *dev)
 	if (!ir)
 		goto ref_put;
 
-	if (ir->rc)
-		rc_unregister_device(ir->rc);
+	rc_unregister_device(ir->rc);
 
 	/* done */
 	kfree(ir);
drivers/media/usb/pvrusb2/pvrusb2-context.c +1 -1
index 7c19ff7..c8761c7 100644
@@ -80,7 +80,7 @@ static void pvr2_context_set_notify(struct pvr2_context *mp, int fl)
 static void pvr2_context_destroy(struct pvr2_context *mp)
 {
 	pvr2_trace(PVR2_TRACE_CTXT,"pvr2_context %p (destroy)",mp);
-	if (mp->hdw) pvr2_hdw_destroy(mp->hdw);
+	pvr2_hdw_destroy(mp->hdw);
 	pvr2_context_set_notify(mp, 0);
 	mutex_lock(&pvr2_context_mutex);
 	if (mp->exist_next) {
drivers/media/usb/s2255/s2255drv.c +1 -2
index 2c90186..3cab886 100644
@@ -1976,8 +1976,7 @@ static int s2255_release_sys_buffers(struct s2255_vc *vc)
 {
 	unsigned long i;
 	for (i = 0; i < SYS_FRAMES; i++) {
-		if (vc->buffer.frame[i].lpvbits)
-			vfree(vc->buffer.frame[i].lpvbits);
+		vfree(vc->buffer.frame[i].lpvbits);
 		vc->buffer.frame[i].lpvbits = NULL;
 	}
 	return 0;
Signature · 1 line
2.1.3
#372 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 13:50:43 +0100

The functions kfree() and pci_dev_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/mtd/chips/cfi_cmdset_0001.c | 3 +--
 drivers/mtd/devices/pmc551.c        | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/mtd/chips/cfi_cmdset_0001.c +1 -2
index 3096f3d..286b97a 100644
@@ -2654,8 +2654,7 @@ static void cfi_intelext_destroy(struct mtd_info *mtd)
 	kfree(cfi);
 	for (i = 0; i < mtd->numeraseregions; i++) {
 		region = &mtd->eraseregions[i];
-		if (region->lockmap)
-			kfree(region->lockmap);
+		kfree(region->lockmap);
 	}
 	kfree(mtd->eraseregions);
 }
drivers/mtd/devices/pmc551.c +1 -2
index f02603e..708b7e8 100644
@@ -812,8 +812,7 @@ static int __init init_pmc551(void)
 	}
 
 	/* Exited early, reference left over */
-	if (PCI_Device)
-		pci_dev_put(PCI_Device);
+	pci_dev_put(PCI_Device);
 
 	if (!pmc551list) {
 		printk(KERN_NOTICE "pmc551: not detected\n");
Signature · 1 line
2.1.3
#374 lore raw

PATCH 1/1 IBM-EMAC: Deletion of unnecessary checks before the function call "of_dev_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 14:22:47 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/ibm/emac/core.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +8 -16
index 87bd953..3f3fba9 100644
@@ -2323,16 +2323,11 @@ static int emac_check_deps(struct emac_instance *dev,
 
 static void emac_put_deps(struct emac_instance *dev)
 {
-	if (dev->mal_dev)
-		of_dev_put(dev->mal_dev);
-	if (dev->zmii_dev)
-		of_dev_put(dev->zmii_dev);
-	if (dev->rgmii_dev)
-		of_dev_put(dev->rgmii_dev);
-	if (dev->mdio_dev)
-		of_dev_put(dev->mdio_dev);
-	if (dev->tah_dev)
-		of_dev_put(dev->tah_dev);
+	of_dev_put(dev->mal_dev);
+	of_dev_put(dev->zmii_dev);
+	of_dev_put(dev->rgmii_dev);
+	of_dev_put(dev->mdio_dev);
+	of_dev_put(dev->tah_dev);
 }
 
 static int emac_of_bus_notify(struct notifier_block *nb, unsigned long action,
@@ -2371,8 +2366,7 @@ static int emac_wait_deps(struct emac_instance *dev)
 	bus_unregister_notifier(&platform_bus_type, &emac_of_bus_notifier);
 	err = emac_check_deps(dev, deps) ? 0 : -ENODEV;
 	for (i = 0; i < EMAC_DEP_COUNT; i++) {
-		if (deps[i].node)
-			of_node_put(deps[i].node);
+		of_node_put(deps[i].node);
 		if (err && deps[i].ofdev)
 			of_dev_put(deps[i].ofdev);
 	}
@@ -2383,8 +2377,7 @@ static int emac_wait_deps(struct emac_instance *dev)
 		dev->tah_dev = deps[EMAC_DEP_TAH_IDX].ofdev;
 		dev->mdio_dev = deps[EMAC_DEP_MDIO_IDX].ofdev;
 	}
-	if (deps[EMAC_DEP_PREV_IDX].ofdev)
-		of_dev_put(deps[EMAC_DEP_PREV_IDX].ofdev);
+	of_dev_put(deps[EMAC_DEP_PREV_IDX].ofdev);
 	return err;
 }
 
@@ -3113,8 +3106,7 @@ static void __exit emac_exit(void)
 
 	/* Destroy EMAC boot list */
 	for (i = 0; i < EMAC_BOOT_LIST_SIZE; i++)
-		if (emac_boot_list[i])
-			of_node_put(emac_boot_list[i]);
+		of_node_put(emac_boot_list[i]);
 }
 
 module_init(emac_init);
Signature · 1 line
2.1.3
#376 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 14:47:12 +0100

The functions kfree() and of_node_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/xilinx/ll_temac_main.c   | 3 +--
 drivers/net/ethernet/xilinx/xilinx_emaclite.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/xilinx/ll_temac_main.c +1 -2
index fda5891..af60867 100644
@@ -224,8 +224,7 @@ static void temac_dma_bd_release(struct net_device *ndev)
 		dma_free_coherent(ndev->dev.parent,
 				sizeof(*lp->tx_bd_v) * TX_BD_NUM,
 				lp->tx_bd_v, lp->tx_bd_p);
-	if (lp->rx_skb)
-		kfree(lp->rx_skb);
+	kfree(lp->rx_skb);
 }
 
 /**
drivers/net/ethernet/xilinx/xilinx_emaclite.c +1 -2
index 28dbbdc..2485879 100644
@@ -1200,8 +1200,7 @@ static int xemaclite_of_remove(struct platform_device *of_dev)
 
 	unregister_netdev(ndev);
 
-	if (lp->phy_node)
-		of_node_put(lp->phy_node);
+	of_node_put(lp->phy_node);
 	lp->phy_node = NULL;
 
 	xemaclite_remove_ndev(ndev);
Signature · 1 line
2.1.3
#379 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 15:15:21 +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/hyperv/netvsc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/hyperv/netvsc.c +1 -2
index da2d346..ffe7481 100644
@@ -548,8 +548,7 @@ int netvsc_device_remove(struct hv_device *device)
 	vmbus_close(device->channel);
 
 	/* Release all resources */
-	if (net_device->sub_cb_buf)
-		vfree(net_device->sub_cb_buf);
+	vfree(net_device->sub_cb_buf);
 
 	kfree(net_device);
 	return 0;
Signature · 1 line
2.1.3
maintainer
#306 lore raw

Re: [PATCH 1/1] crypto-drbg: Deletion of unnecessary checks before the function call "kzfree"

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

From: Markus Elfring <[email protected]>
Date: Wed, 19 Nov 2014 10:11:04 +0100

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

Sorry but you're too late as someone else has already fixed this :)

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer Reviewed-by on v1 1/1
#367 lore raw

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

In reply to SF Markus Elfring
Quoted 9 lines · On Nov 20 SF Markus Elfring wrote:

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 10:49:07 +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.

Quoted 16 lines
---
 drivers/media/firewire/firedtv-ci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/firewire/firedtv-ci.c +1 -2
index e5ebdbf..e63f582 100644
@@ -253,6 +253,5 @@ int fdtv_ca_register(struct firedtv *fdtv)
 
 void fdtv_ca_release(struct firedtv *fdtv)
 {
-	if (fdtv->cadev)
-		dvb_unregister_device(fdtv->cadev);
+	dvb_unregister_device(fdtv->cadev);
 }
Signature · 3 lines
Stefan Richter
-===-==- =-= =-=--
http://arcgraph.de/sr/
#392 lore raw

PATCH 1/1 net: USB: Deletion of unnecessary checks before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 16:11:56 +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/usb/asix_devices.c | 3 +--
 drivers/net/usb/hso.c          | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/net/usb/asix_devices.c +1 -2
index 5d19409..8a7582b 100644
@@ -499,8 +499,7 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
 
 static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf)
 {
-	if (dev->driver_priv)
-		kfree(dev->driver_priv);
+	kfree(dev->driver_priv);
 }
 
 static const struct ethtool_ops ax88178_ethtool_ops = {
drivers/net/usb/hso.c +1 -2
index babda7d..9c5aa92 100644
@@ -2746,8 +2746,7 @@ exit:
 		tty_unregister_device(tty_drv, serial->minor);
 		kfree(serial);
 	}
-	if (hso_dev)
-		kfree(hso_dev);
+	kfree(hso_dev);
 	return NULL;
 
 }
Signature · 1 line
2.1.3
#394 lore raw

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

In reply to SF Markus Elfring

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

The functions brcmu_pkt_buf_free_skb() and release_firmware() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c | 3 +--
 drivers/net/wireless/brcm80211/brcmfmac/firmware.c | 3 +--
 drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c   | 3 +--
 drivers/net/wireless/brcm80211/brcmsmac/main.c     | 3 +--
 4 files changed, 4 insertions(+), 8 deletions(-)
drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c +1 -2
index f55f625..8ff7037 100644
@@ -2539,8 +2539,7 @@ static void brcmf_sdio_bus_stop(struct device *dev)
 	brcmu_pktq_flush(&bus->txq, true, NULL, NULL);
 
 	/* Clear any held glomming stuff */
-	if (bus->glomd)
-		brcmu_pkt_buf_free_skb(bus->glomd);
+	brcmu_pkt_buf_free_skb(bus->glomd);
 	brcmf_sdio_free_glom(bus);
 
 	/* Clear rx control and wake any waiters */
drivers/net/wireless/brcm80211/brcmfmac/firmware.c +1 -2
index 8ea9f28..3a2d014 100644
@@ -262,8 +262,7 @@ static void brcmf_fw_request_nvram_done(const struct firmware *fw, void *ctx)
 
 fail:
 	brcmf_dbg(TRACE, "failed: dev=%s\n", dev_name(fwctx->dev));
-	if (fwctx->code)
-		release_firmware(fwctx->code);
+	release_firmware(fwctx->code);
 	device_release_driver(fwctx->dev);
 	kfree(fwctx);
 }
drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c +1 -2
index 8f8b937..0cb00dc 100644
@@ -506,8 +506,7 @@ static int brcmf_msgbuf_query_dcmd(struct brcmf_pub *drvr, int ifidx,
 		memcpy(buf, skb->data, (len < msgbuf->ioctl_resp_ret_len) ?
 				       len : msgbuf->ioctl_resp_ret_len);
 	}
-	if (skb)
-		brcmu_pkt_buf_free_skb(skb);
+	brcmu_pkt_buf_free_skb(skb);
 
 	return msgbuf->ioctl_resp_status;
 }
drivers/net/wireless/brcm80211/brcmsmac/main.c +1 -2
index 1b47482..ce538a1 100644
@@ -1009,8 +1009,7 @@ brcms_c_dotxstatus(struct brcms_c_info *wlc, struct tx_status *txs)
 		if (txh)
 			trace_brcms_txdesc(&wlc->hw->d11core->dev, txh,
 					   sizeof(*txh));
-		if (p)
-			brcmu_pkt_buf_free_skb(p);
+		brcmu_pkt_buf_free_skb(p);
 	}
 
 	if (dma && queue < NFIFO) {
Signature · 1 line
2.1.3
#399 lore raw

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

In reply to SF Markus Elfring

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

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

This issue was detected by using the Coccinelle software.

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

PATCH 1/1 SCSI-OSD: Deletion of an unnecessary check before the function call "put_disk"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 18:11:28 +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/scsi/osd/osd_uld.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/osd/osd_uld.c +1 -2
index e1d9a4c..3d82ee1 100644
@@ -408,8 +408,7 @@ static void __remove(struct device *dev)
 	OSD_INFO("osd_remove %s\n",
 		 oud->disk ? oud->disk->disk_name : NULL);
 
-	if (oud->disk)
-		put_disk(oud->disk);
+	put_disk(oud->disk);
 	ida_remove(&osd_minor_ida, oud->minor);
 
 	kfree(oud);
Signature · 1 line
2.1.3
Reviewed-by on v1 1/1
#377 lore raw

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

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

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 14:47:12 +0100

The functions kfree() and of_node_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Sören
--
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

#405 lore raw

PATCH 1/1 SCSI: Deletion of unnecessary checks before the function call "put_device"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 18:48:52 +0100

The put_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/scsi/hosts.c      | 3 +--
 drivers/scsi/scsi_sysfs.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/scsi/hosts.c +1 -2
index 6de80e3..57afb19 100644
@@ -337,8 +337,7 @@ static void scsi_host_dev_release(struct device *dev)
 
 	kfree(shost->shost_data);
 
-	if (parent)
-		put_device(parent);
+	put_device(parent);
 	kfree(shost);
 }
 
drivers/scsi/scsi_sysfs.c +1 -2
index 8b4105a..c977c99 100644
@@ -426,8 +426,7 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
 	kfree(sdev->inquiry);
 	kfree(sdev);
 
-	if (parent)
-		put_device(parent);
+	put_device(parent);
 }
 
 static void scsi_device_dev_release(struct device *dev)
Signature · 1 line
2.1.3
Acked-by on v1 1/1
#395 lore raw

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

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

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

The functions brcmu_pkt_buf_free_skb() and release_firmware() 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.

Goodo for coccinelle and you for running it.

Quoted 64 lines
---
  drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c | 3 +--
  drivers/net/wireless/brcm80211/brcmfmac/firmware.c | 3 +--
  drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c   | 3 +--
  drivers/net/wireless/brcm80211/brcmsmac/main.c     | 3 +--
  4 files changed, 4 insertions(+), 8 deletions(-)
drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c +1 -2
index f55f625..8ff7037 100644
@@ -2539,8 +2539,7 @@ static void brcmf_sdio_bus_stop(struct device *dev)
  	brcmu_pktq_flush(&bus->txq, true, NULL, NULL);
 
  	/* Clear any held glomming stuff */
-	if (bus->glomd)
-		brcmu_pkt_buf_free_skb(bus->glomd);
+	brcmu_pkt_buf_free_skb(bus->glomd);
  	brcmf_sdio_free_glom(bus);
 
  	/* Clear rx control and wake any waiters */
drivers/net/wireless/brcm80211/brcmfmac/firmware.c +1 -2
index 8ea9f28..3a2d014 100644
@@ -262,8 +262,7 @@ static void brcmf_fw_request_nvram_done(const struct firmware *fw, void *ctx)
 
  fail:
  	brcmf_dbg(TRACE, "failed: dev=%s\n", dev_name(fwctx->dev));
-	if (fwctx->code)
-		release_firmware(fwctx->code);
+	release_firmware(fwctx->code);
  	device_release_driver(fwctx->dev);
  	kfree(fwctx);
  }
drivers/net/wireless/brcm80211/brcmfmac/msgbuf.c +1 -2
index 8f8b937..0cb00dc 100644
@@ -506,8 +506,7 @@ static int brcmf_msgbuf_query_dcmd(struct brcmf_pub *drvr, int ifidx,
  		memcpy(buf, skb->data, (len<  msgbuf->ioctl_resp_ret_len) ?
  				       len : msgbuf->ioctl_resp_ret_len);
  	}
-	if (skb)
-		brcmu_pkt_buf_free_skb(skb);
+	brcmu_pkt_buf_free_skb(skb);
 
  	return msgbuf->ioctl_resp_status;
  }
drivers/net/wireless/brcm80211/brcmsmac/main.c +1 -2
index 1b47482..ce538a1 100644
@@ -1009,8 +1009,7 @@ brcms_c_dotxstatus(struct brcms_c_info *wlc, struct tx_status *txs)
  		if (txh)
  			trace_brcms_txdesc(&wlc->hw->d11core->dev, txh,
  					   sizeof(*txh));
-		if (p)
-			brcmu_pkt_buf_free_skb(p);
+		brcmu_pkt_buf_free_skb(p);
  	}
 
  	if (dma&&  queue<  NFIFO) {
maintainer
#380 lore raw

RE: [PATCH 1/1] net: Hyper-V: Deletion of an unnecessary check before the function call "vfree"

In reply to SF Markus Elfring

DQoNCj4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0NCj4gRnJvbTogU0YgTWFya3VzIEVsZnJp bmcgW21haWx0bzplbGZyaW5nQHVzZXJzLnNvdXJjZWZvcmdlLm5ldF0NCj4gU2VudDogVGh1cnNk YXksIE5vdmVtYmVyIDIwLCAyMDE0IDk6MjUgQU0NCj4gVG86IEhhaXlhbmcgWmhhbmc7IEtZIFNy aW5pdmFzYW47IGRldmVsQGxpbnV4ZHJpdmVycHJvamVjdC5vcmc7DQo+IG5ldGRldkB2Z2VyLmtl cm5lbC5vcmcNCj4gQ2M6IExLTUw7IGtlcm5lbC1qYW5pdG9yc0B2Z2VyLmtlcm5lbC5vcmc7IEp1 bGlhIExhd2FsbA0KPiBTdWJqZWN0OiBbUEFUQ0ggMS8xXSBuZXQ6IEh5cGVyLVY6IERlbGV0aW9u IG9mIGFuIHVubmVjZXNzYXJ5IGNoZWNrDQo+IGJlZm9yZSB0aGUgZnVuY3Rpb24gY2FsbCAidmZy ZWUiDQo+IA0KPiBGcm9tOiBNYXJrdXMgRWxmcmluZyA8ZWxmcmluZ0B1c2Vycy5zb3VyY2Vmb3Jn ZS5uZXQ+DQo+IERhdGU6IFRodSwgMjAgTm92IDIwMTQgMTU6MTU6MjEgKzAxMDANCj4gDQo+IFRo ZSB2ZnJlZSgpIGZ1bmN0aW9uIHBlcmZvcm1zIGFsc28gaW5wdXQgcGFyYW1ldGVyIHZhbGlkYXRp b24uIFRodXMgdGhlDQo+IHRlc3QNCj4gYXJvdW5kIHRoZSBjYWxsIGlzIG5vdCBuZWVkZWQuDQo+ IA0KPiBUaGlzIGlzc3VlIHdhcyBkZXRlY3RlZCBieSB1c2luZyB0aGUgQ29jY2luZWxsZSBzb2Z0 d2FyZS4NCj4gDQo+IFNpZ25lZC1vZmYtYnk6IE1hcmt1cyBFbGZyaW5nIDxlbGZyaW5nQHVzZXJz LnNvdXJjZWZvcmdlLm5ldD4NCg0KU2lnbmVkLW9mZi1ieTogSGFpeWFuZyBaaGFuZyA8aGFpeWFu Z3pAbWljcm9zb2Z0LmNvbT4NCg0KVGhhbmtzIQ0KDQo

#407 lore raw

PATCH 1/1 SCSI-libfc: Deletion of an unnecessary check before the function call "fc_fcp_ddp_done"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 20:10:19 +0100

The fc_fcp_ddp_done() 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/scsi/libfc/fc_exch.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/libfc/fc_exch.c +1 -2
index 1b3a094..aad6f48 100644
@@ -2120,8 +2120,7 @@ static struct fc_seq *fc_exch_seq_send(struct fc_lport *lport,
 	spin_unlock_bh(&ep->ex_lock);
 	return sp;
 err:
-	if (fsp)
-		fc_fcp_ddp_done(fsp);
+	fc_fcp_ddp_done(fsp);
 	rc = fc_exch_done_locked(ep);
 	spin_unlock_bh(&ep->ex_lock);
 	if (!rc)
Signature · 1 line
2.1.3
#410 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 20:37:30 +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/scsi/eata_pio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/eata_pio.c +1 -2
index 8319d2b..707f64d 100644
@@ -122,8 +122,7 @@ static int eata_pio_release(struct Scsi_Host *sh)
 			release_region(sh->io_port, sh->n_io_port);
 	}
 	/* At this point the PCI reference can go */
-	if (hd->pdev)
-		pci_dev_put(hd->pdev);
+	pci_dev_put(hd->pdev);
 	return 1;
 }
 
Signature · 1 line
2.1.3
#412 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 23:18:56 +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/scsi/aic94xx/aic94xx_init.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/aic94xx/aic94xx_init.c +1 -2
index c56741f..0bfdcba 100644
@@ -597,8 +597,7 @@ static void asd_destroy_ha_caches(struct asd_ha_struct *asd_ha)
 	if (asd_ha->hw_prof.scb_ext)
 		asd_free_coherent(asd_ha, asd_ha->hw_prof.scb_ext);
 
-	if (asd_ha->hw_prof.ddb_bitmap)
-		kfree(asd_ha->hw_prof.ddb_bitmap);
+	kfree(asd_ha->hw_prof.ddb_bitmap);
 	asd_ha->hw_prof.ddb_bitmap = NULL;
 
 	for (i = 0; i < ASD_MAX_PHYS; i++) {
Signature · 1 line
2.1.3
#414 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 23:43:17 +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/scsi/bfa/bfad_debugfs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/bfa/bfad_debugfs.c +1 -2
index 8e83d04..a72170f 100644
@@ -399,8 +399,7 @@ bfad_debugfs_release_fwtrc(struct inode *inode, struct file *file)
 	if (!fw_debug)
 		return 0;
 
-	if (fw_debug->debug_buffer)
-		vfree(fw_debug->debug_buffer);
+	vfree(fw_debug->debug_buffer);
 
 	file->private_data = NULL;
 	kfree(fw_debug);
Signature · 1 line
2.1.3
maintainer Acked-by on v1 1/1
#415 lore raw

RE: [PATCH 1/1] SCSI-bfa: Deletion of an unnecessary check before the function call "vfree"

Patch looks good.
Thanks!

-----Original Message-----
From: SF Markus Elfring [mailto:[email protected]]
Sent: 21 November 2014 04:17
To: Anil Gurumurthy; James E. J. Bottomley; Sudarsana Kalluru; linux-scsi
Cc: linux-kernel; [email protected]; Julia Lawall
Subject: [PATCH 1/1] SCSI-bfa: Deletion of an unnecessary check before the function call "vfree"

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 23:43:17 +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/scsi/bfa/bfad_debugfs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/bfa/bfad_debugfs.c +1 -2
@@ -399,8 +399,7 @@ bfad_debugfs_release_fwtrc(struct inode *inode, struct file *file)
 	if (!fw_debug)
 		return 0;
 
-	if (fw_debug->debug_buffer)
-		vfree(fw_debug->debug_buffer);
+	vfree(fw_debug->debug_buffer);
 
 	file->private_data = NULL;
 	kfree(fw_debug);

--
2.1.3

#417 lore raw

PATCH 1/1 SCSI-libcxgbi: Deletion of an unnecessary check before the function call "dst_release"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 09:15:10 +0100

The dst_release() 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/scsi/cxgbi/libcxgbi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/cxgbi/libcxgbi.c +1 -2
index addd1dd..95d2654 100644
@@ -798,8 +798,7 @@ void cxgbi_sock_closed(struct cxgbi_sock *csk)
 		return;
 	if (csk->saddr.sin_port)
 		sock_put_port(csk);
-	if (csk->dst)
-		dst_release(csk->dst);
+	dst_release(csk->dst);
 	csk->cdev->csk_release_offload_resources(csk);
 	cxgbi_sock_set_state(csk, CTP_CLOSED);
 	cxgbi_inform_iscsi_conn_closing(csk);
Signature · 1 line
2.1.3
#419 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 09:39:43 +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/scsi/fnic/fnic_debugfs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/fnic/fnic_debugfs.c +1 -2
index 2c613bd..ec70e6d 100644
@@ -102,8 +102,7 @@ void fnic_debugfs_terminate(void)
 	debugfs_remove(fnic_trace_debugfs_root);
 	fnic_trace_debugfs_root = NULL;
 
-	if (fc_trc_flag)
-		vfree(fc_trc_flag);
+	vfree(fc_trc_flag);
 }
 
 /*
Signature · 1 line
2.1.3
#421 lore raw

PATCH 1/1 target: Deletion of unnecessary checks before the function call "module_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 10:25:45 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/target/iscsi/iscsi_target_transport.c | 3 +--
 drivers/target/target_core_hba.c              | 6 ++----
 2 files changed, 3 insertions(+), 6 deletions(-)
drivers/target/iscsi/iscsi_target_transport.c +1 -2
index 882728f..08217d6 100644
@@ -26,8 +26,7 @@ struct iscsit_transport *iscsit_get_transport(int type)
 
 void iscsit_put_transport(struct iscsit_transport *t)
 {
-	if (t->owner)
-		module_put(t->owner);
+	module_put(t->owner);
 }
 
 int iscsit_register_transport(struct iscsit_transport *t)
drivers/target/target_core_hba.c +2 -4
index a25051a..e6e496f 100644
@@ -137,8 +137,7 @@ core_alloc_hba(const char *plugin_name, u32 plugin_dep_id, u32 hba_flags)
 	return hba;
 
 out_module_put:
-	if (hba->transport->owner)
-		module_put(hba->transport->owner);
+	module_put(hba->transport->owner);
 	hba->transport = NULL;
 out_free_hba:
 	kfree(hba);
@@ -159,8 +158,7 @@ core_delete_hba(struct se_hba *hba)
 	pr_debug("CORE_HBA[%d] - Detached HBA from Generic Target"
 			" Core\n", hba->hba_id);
 
-	if (hba->transport->owner)
-		module_put(hba->transport->owner);
+	module_put(hba->transport->owner);
 
 	hba->transport = NULL;
 	kfree(hba);
Signature · 1 line
2.1.3
#423 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 11:06:33 +0100

The functions cpufreq_cooling_unregister() and thermal_zone_device_unregister() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/thermal/samsung/exynos_thermal_common.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/thermal/samsung/exynos_thermal_common.c +2 -4
index 3f5ad25..1cbb9d0 100644
@@ -417,12 +417,10 @@ void exynos_unregister_thermal(struct thermal_sensor_conf *sensor_conf)
 
 	th_zone = sensor_conf->pzone_data;
 
-	if (th_zone->therm_dev)
-		thermal_zone_device_unregister(th_zone->therm_dev);
+	thermal_zone_device_unregister(th_zone->therm_dev);
 
 	for (i = 0; i < th_zone->cool_dev_size; i++) {
-		if (th_zone->cool_dev[i])
-			cpufreq_cooling_unregister(th_zone->cool_dev[i]);
+		cpufreq_cooling_unregister(th_zone->cool_dev[i]);
 	}
 
 	dev_info(sensor_conf->dev,
Signature · 1 line
2.1.3
#424 lore raw

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

Quoted 21 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 11:06:33 +0100

The functions cpufreq_cooling_unregister() and thermal_zone_device_unregister() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/thermal/samsung/exynos_thermal_common.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/thermal/samsung/exynos_thermal_common.c +0 -0
index 3f5ad25..1cbb9d0 100644
@@ -417,12 +417,10 @@ void exynos_unregister_thermal(struct thermal_sensor_conf *sensor_conf)
 
 	th_zone = sensor_conf->pzone_data;

drivers/thermal/samsung/exynos_thermal_common.c void exynos_unregister_thermal(struct thermal_sensor_conf *sensor_conf) · line 424

Quoted 10 lines
drivers/thermal/samsung/exynos_thermal_common.c +2 -4
 
-	if (th_zone->therm_dev)
-		thermal_zone_device_unregister(th_zone->therm_dev);
+	thermal_zone_device_unregister(th_zone->therm_dev);
 
 	for (i = 0; i < th_zone->cool_dev_size; i++) {
-		if (th_zone->cool_dev[i])
-			cpufreq_cooling_unregister(th_zone->cool_dev[i]);
+		cpufreq_cooling_unregister(th_zone->cool_dev[i]);
 	}

Now you have unnecessary {}

julia

Quoted 6 lines
drivers/thermal/samsung/exynos_thermal_common.c +0 -1
 	dev_info(sensor_conf->dev,
--

2.1.3

#427 lore raw

PATCH 1/1 thunderbolt: Deletion of unnecessary checks before the function call "ring_free"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 11:30:18 +0100

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

---
 drivers/thunderbolt/ctl.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/thunderbolt/ctl.c +2 -4
index 799634b..55b9bdf 100644
@@ -520,10 +520,8 @@ err:
 void tb_ctl_free(struct tb_ctl *ctl)
 {
 	int i;
-	if (ctl->rx)
-		ring_free(ctl->rx);
-	if (ctl->tx)
-		ring_free(ctl->tx);
+	ring_free(ctl->rx);
+	ring_free(ctl->tx);
 
 	/* free RX packets */
 	for (i = 0; i < TB_CTL_RX_PKG_COUNT; i++)
Signature · 1 line
2.1.3
maintainer
#428 lore raw

Re: [PATCH 1/1] thunderbolt: Deletion of unnecessary checks before the function call "ring_free"

Hi Markus,

ring_free does not check for null:
http://lxr.free-electrons.com/source/drivers/thunderbolt/nhi.c#L398

Maybe your software confuses the method with:
http://lxr.free-electrons.com/source/drivers/char/tpm/xen-tpmfront.c#L268

Andreas

Quoted 33 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 11:30:18 +0100

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

---
 drivers/thunderbolt/ctl.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/thunderbolt/ctl.c +2 -5
index 799634b..55b9bdf 100644
@@ -520,10 +520,8 @@ err:
 void tb_ctl_free(struct tb_ctl *ctl)
 {
        int i;
-       if (ctl->rx)
-               ring_free(ctl->rx);
-       if (ctl->tx)
-               ring_free(ctl->tx);
+       ring_free(ctl->rx);
+       ring_free(ctl->tx);
 
        /* free RX packets */
        for (i = 0; i < TB_CTL_RX_PKG_COUNT; i++)
--

2.1.3

#440 lore raw

PATCH 1/1 tty-hvsi_lib: Deletion of an unnecessary check before the function call "tty_kref_put"

In reply to SF Markus Elfring

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

The tty_kref_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/tty/hvc/hvsi_lib.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/tty/hvc/hvsi_lib.c +1 -2
index 7ae6c29..a270f04 100644
@@ -405,8 +405,7 @@ void hvsilib_close(struct hvsi_priv *pv, struct hvc_struct *hp)
 		hvsi_send_close(pv);
 	}
 
-	if (pv->tty)
-		tty_kref_put(pv->tty);
+	tty_kref_put(pv->tty);
 	pv->tty = NULL;
 }
 
Signature · 1 line
2.1.3
#429 lore raw

Re: thunderbolt: Deletion of unnecessary checks before the function call "ring_free"

In reply to Andreas Noever
Quoted 5 lines

ring_free does not check for null:
http://lxr.free-electrons.com/source/drivers/thunderbolt/nhi.c#L398

Maybe your software confuses the method with:
http://lxr.free-electrons.com/source/drivers/char/tpm/xen-tpmfront.c#L268

Thanks for your feedback.

I am sorry for a bit of confusion here.

1. Would it make sense that a variant for the thunderbolt ring_free() function will also perform input parameter validation?

2. Are any additional prefixes appropriate so that further name space conflicts can be better avoided?

Regards,
Markus

#441 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 13:42:29 +0100

The functions put_device() and tty_kref_put() test whether their argument is NULL and then return immediately.
Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/tty/tty_io.c   | 6 ++----
 drivers/tty/tty_port.c | 3 +--
 2 files changed, 3 insertions(+), 6 deletions(-)
drivers/tty/tty_io.c +2 -4
index 848c17a..3302789 100644
@@ -169,8 +169,7 @@ void free_tty_struct(struct tty_struct *tty)
 {
 	if (!tty)
 		return;
-	if (tty->dev)
-		put_device(tty->dev);
+	put_device(tty->dev);
 	kfree(tty->write_buf);
 	tty->magic = 0xDEADDEAD;
 	kfree(tty);
@@ -1612,8 +1611,7 @@ static void release_tty(struct tty_struct *tty, int idx)
 		tty->link->port->itty = NULL;
 	cancel_work_sync(&tty->port->buf.work);
 
-	if (tty->link)
-		tty_kref_put(tty->link);
+	tty_kref_put(tty->link);
 	tty_kref_put(tty);
 }
 
drivers/tty/tty_port.c +1 -2
index 1b93357..856c064 100644
@@ -193,8 +193,7 @@ void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty)
 	unsigned long flags;
 
 	spin_lock_irqsave(&port->lock, flags);
-	if (port->tty)
-		tty_kref_put(port->tty);
+	tty_kref_put(port->tty);
 	port->tty = tty_kref_get(tty);
 	spin_unlock_irqrestore(&port->lock, flags);
 }
Signature · 1 line
2.1.3
#425 lore raw

Re: thermal: Exynos: Deletion of unnecessary checks before two function calls

In reply to Julia Lawall
Quoted 7 lines

drivers/thermal/samsung/exynos_thermal_common.c void exynos_unregister_thermal(struct thermal_sensor_conf *sensor_conf) · line 424

Quoted 5 lines
drivers/thermal/samsung/exynos_thermal_common.c +1 -2
 	for (i = 0; i < th_zone->cool_dev_size; i++) {
-		if (th_zone->cool_dev[i])
-			cpufreq_cooling_unregister(th_zone->cool_dev[i]);
+		cpufreq_cooling_unregister(th_zone->cool_dev[i]);
 	}

Now you have unnecessary {}

How are the chances that your source code transformation tool can also consider the deletion of curly brackets in such an use case?

Can any more pretty-printing rules be integrated from a specific coding style configuration?

Regards,
Markus

#442 lore raw

PATCH 1/1 USB: gadget: function: Deletion of an unnecessary check before the function call "rndis_add_hdr"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 14:51:43 +0100

The rndis_add_hdr() 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/usb/gadget/function/f_rndis.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/gadget/function/f_rndis.c +1 -2
index ddb09dc..da56a5f 100644
@@ -375,8 +375,7 @@ static struct sk_buff *rndis_add_header(struct gether *port,
 	struct sk_buff *skb2;
 
 	skb2 = skb_realloc_headroom(skb, sizeof(struct rndis_packet_msg_type));
-	if (skb2)
-		rndis_add_hdr(skb2);
+	rndis_add_hdr(skb2);
 
 	dev_kfree_skb(skb);
 	return skb2;
Signature · 1 line
2.1.3
#443 lore raw

PATCH 1/1 USB: PCI-quirks: Deletion of unnecessary checks before the function call "pci_dev_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 15:20:12 +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/usb/host/pci-quirks.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/usb/host/pci-quirks.c +4 -8
index 2f3aceb..dd483c1 100644
@@ -233,10 +233,8 @@ commit:
 
 		spin_unlock_irqrestore(&amd_lock, flags);
 
-		if (info.nb_dev)
-			pci_dev_put(info.nb_dev);
-		if (info.smbus_dev)
-			pci_dev_put(info.smbus_dev);
+		pci_dev_put(info.nb_dev);
+		pci_dev_put(info.smbus_dev);
 
 	} else {
 		/* no race - commit the result */
@@ -447,10 +445,8 @@ void usb_amd_dev_put(void)
 
 	spin_unlock_irqrestore(&amd_lock, flags);
 
-	if (nb)
-		pci_dev_put(nb);
-	if (smbus)
-		pci_dev_put(smbus);
+	pci_dev_put(nb);
+	pci_dev_put(smbus);
 }
 EXPORT_SYMBOL_GPL(usb_amd_dev_put);
 
Signature · 1 line
2.1.3
#444 lore raw

PATCH 1/1 USB-SIS: Deletion of an unnecessary check before the function call "usb_put_dev"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 15:50:44 +0100

The usb_put_dev() 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/usb/misc/sisusbvga/sisusb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/misc/sisusbvga/sisusb.c +1 -2
index 633caf6..022dc00 100644
@@ -2472,8 +2472,7 @@ sisusb_delete(struct kref *kref)
 	if (!sisusb)
 		return;
 
-	if (sisusb->sisusb_dev)
-		usb_put_dev(sisusb->sisusb_dev);
+	usb_put_dev(sisusb->sisusb_dev);
 
 	sisusb->sisusb_dev = NULL;
 	sisusb_free_buffers(sisusb);
Signature · 1 line
2.1.3
#445 lore raw

PATCH 1/1 USB: serial: Deletion of an unnecessary check before the function call "release_firmware"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 16:15:34 +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/usb/serial/mxuport.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/serial/mxuport.c +1 -2
index ab1d690..3653ec1 100644
@@ -1101,8 +1101,7 @@ static int mxuport_probe(struct usb_serial *serial,
 	 */
 	usb_set_serial_data(serial, (void *)id->driver_info);
 out:
-	if (fw_p)
-		release_firmware(fw_p);
+	release_firmware(fw_p);
 	return err;
 }
 
Signature · 1 line
2.1.3
#446 lore raw

Re: [PATCH 1/1] USB: serial: Deletion of an unnecessary check before the function call "release_firmware"

Quoted 18 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 16:15:34 +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/usb/serial/mxuport.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/serial/mxuport.c +0 -0
index ab1d690..3653ec1 100644

drivers/usb/serial/mxuport.c static int mxuport_probe(struct usb_serial *serial, · line 1104

Quoted 6 lines
drivers/usb/serial/mxuport.c +1 -2
@@ -1101,8 +1101,7 @@ static int mxuport_probe(struct usb_serial *serial,
 	 */
 	usb_set_serial_data(serial, (void *)id->driver_info);
 out:
-	if (fw_p)
-		release_firmware(fw_p);
+	release_firmware(fw_p);

I think that the if should stay. There were two cases on the allocation, so there should be two cases on the release.

julia

Quoted 11 lines
drivers/usb/serial/mxuport.c +0 -1
 	return err;
 }
 
--

2.1.3

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

#450 lore raw

PATCH 1/1 USB-IP: Deletion of unnecessary checks before the function call "usb_put_dev"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 16:33:18 +0100

The usb_put_dev() 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/usb/usbip/vhci_hcd.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/usb/usbip/vhci_hcd.c +3 -6
index c02374b..cc1b03e 100644
@@ -518,8 +518,7 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
 			dev_info(dev, "SetAddress Request (%d) to port %d\n",
 				 ctrlreq->wValue, vdev->rhport);
 
-			if (vdev->udev)
-				usb_put_dev(vdev->udev);
+			usb_put_dev(vdev->udev);
 			vdev->udev = usb_get_dev(urb->dev);
 
 			spin_lock(&vdev->ud.lock);
@@ -539,8 +538,7 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
 				usbip_dbg_vhci_hc(
 					"Not yet?:Get_Descriptor to device 0 (get max pipe size)\n");
 
-			if (vdev->udev)
-				usb_put_dev(vdev->udev);
+			usb_put_dev(vdev->udev);
 			vdev->udev = usb_get_dev(urb->dev);
 			goto out;
 
@@ -831,8 +829,7 @@ static void vhci_device_reset(struct usbip_device *ud)
 	vdev->speed  = 0;
 	vdev->devid  = 0;
 
-	if (vdev->udev)
-		usb_put_dev(vdev->udev);
+	usb_put_dev(vdev->udev);
 	vdev->udev = NULL;
 
 	if (ud->tcp_socket) {
Signature · 1 line
2.1.3
#447 lore raw

Re: USB: serial: Deletion of an unnecessary check before the function call "release_firmware"

In reply to Julia Lawall
Quoted 5 lines
Quoted 5 lines
drivers/usb/serial/mxuport.c +0 -0
index ab1d690..3653ec1 100644
@@ -1101,8 +1101,7 @@ static int mxuport_probe(struct usb_serial *serial,
Quoted 8 lines

drivers/usb/serial/mxuport.c static int mxuport_probe(struct usb_serial *serial, · line 1104

Quoted 6 lines
drivers/usb/serial/mxuport.c +1 -2
 	 */
 	usb_set_serial_data(serial, (void *)id->driver_info);
 out:
-	if (fw_p)
-		release_firmware(fw_p);
+	release_firmware(fw_p);

I think that the if should stay.

I have got an other opinion.

Quoted 2 lines

There were two cases on the allocation, so there should be two cases on the release.

I find that this implementation detail does not really matter for the necessity of a null pointer check directly before such a function call.

Regards,
Markus

#426 lore raw

PATCH v2 1/1 thermal: Exynos: Deletion of unnecessary checks before two function calls

In reply to Julia Lawall

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 17:11:49 +0100

The functions cpufreq_cooling_unregister() and thermal_zone_device_unregister() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/thermal/samsung/exynos_thermal_common.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/thermal/samsung/exynos_thermal_common.c +3 -6
index 3f5ad25..b6be572 100644
@@ -417,13 +417,10 @@ void exynos_unregister_thermal(struct thermal_sensor_conf *sensor_conf)
 
 	th_zone = sensor_conf->pzone_data;
 
-	if (th_zone->therm_dev)
-		thermal_zone_device_unregister(th_zone->therm_dev);
+	thermal_zone_device_unregister(th_zone->therm_dev);
 
-	for (i = 0; i < th_zone->cool_dev_size; i++) {
-		if (th_zone->cool_dev[i])
-			cpufreq_cooling_unregister(th_zone->cool_dev[i]);
-	}
+	for (i = 0; i < th_zone->cool_dev_size; ++i)
+		cpufreq_cooling_unregister(th_zone->cool_dev[i]);
 
 	dev_info(sensor_conf->dev,
 		"Exynos: Kernel Thermal management unregistered\n");
Signature · 1 line
2.1.3
#452 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 18:34:48 +0100

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

---
 sound/core/seq/oss/seq_oss_init.c | 9 +++------
 sound/core/sgbuf.c                | 3 +--
 2 files changed, 4 insertions(+), 8 deletions(-)
sound/core/seq/oss/seq_oss_init.c +3 -6
index b9184d2..b0e32e1 100644
@@ -403,14 +403,11 @@ free_devinfo(void *private)
 {
 	struct seq_oss_devinfo *dp = (struct seq_oss_devinfo *)private;
 
-	if (dp->timer)
-		snd_seq_oss_timer_delete(dp->timer);
+	snd_seq_oss_timer_delete(dp->timer);
 		
-	if (dp->writeq)
-		snd_seq_oss_writeq_delete(dp->writeq);
+	snd_seq_oss_writeq_delete(dp->writeq);
 
-	if (dp->readq)
-		snd_seq_oss_readq_delete(dp->readq);
+	snd_seq_oss_readq_delete(dp->readq);
 	
 	kfree(dp);
 }
sound/core/sgbuf.c +1 -2
index 0a41850..84fffab 100644
@@ -39,8 +39,7 @@ int snd_free_sgbuf_pages(struct snd_dma_buffer *dmab)
 	if (! sgbuf)
 		return -EINVAL;
 
-	if (dmab->area)
-		vunmap(dmab->area);
+	vunmap(dmab->area);
 	dmab->area = NULL;
 
 	tmpb.dev.type = SNDRV_DMA_TYPE_DEV;
Signature · 1 line
2.1.3
maintainer Acked-by on v1 1/1
#451 lore raw

Re: [PATCH 1/1] USB-IP: Deletion of unnecessary checks before the function call "usb_put_dev"

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

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 16:33:18 +0100

The usb_put_dev() 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/usb/usbip/vhci_hcd.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/usb/usbip/vhci_hcd.c +3 -7
index c02374b..cc1b03e 100644
@@ -518,8 +518,7 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
                        dev_info(dev, "SetAddress Request (%d) to port %d\n",
                                 ctrlreq->wValue, vdev->rhport);
 
-                       if (vdev->udev)
-                               usb_put_dev(vdev->udev);
+                       usb_put_dev(vdev->udev);
                        vdev->udev = usb_get_dev(urb->dev);
 
                        spin_lock(&vdev->ud.lock);
@@ -539,8 +538,7 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
                                usbip_dbg_vhci_hc(
                                        "Not yet?:Get_Descriptor to device 0 (get max pipe size)\n");
 
-                       if (vdev->udev)
-                               usb_put_dev(vdev->udev);
+                       usb_put_dev(vdev->udev);
                        vdev->udev = usb_get_dev(urb->dev);
                        goto out;
 
@@ -831,8 +829,7 @@ static void vhci_device_reset(struct usbip_device *ud)
        vdev->speed  = 0;
        vdev->devid  = 0;
 
-       if (vdev->udev)
-               usb_put_dev(vdev->udev);
+       usb_put_dev(vdev->udev);
        vdev->udev = NULL;
 
        if (ud->tcp_socket) {
--
Quoted 2 lines

2.1.3

#448 lore raw

Re: USB: serial: Deletion of an unnecessary check before the function call "release_firmware"

In reply to SF Markus Elfring
Quoted 14 lines · SF Markus Elfring
Quoted 5 lines
Quoted 5 lines
drivers/usb/serial/mxuport.c +0 -0
index ab1d690..3653ec1 100644
@@ -1101,8 +1101,7 @@ static int mxuport_probe(struct usb_serial *serial,
Quoted 8 lines

drivers/usb/serial/mxuport.c static int mxuport_probe(struct usb_serial *serial, · line 1104

Quoted 6 lines
drivers/usb/serial/mxuport.c +1 -2
 	 */
 	usb_set_serial_data(serial, (void *)id->driver_info);
 out:
-	if (fw_p)
-		release_firmware(fw_p);
+	release_firmware(fw_p);

I think that the if should stay.

Quoted 8 lines

I have got an other opinion.

Quoted 2 lines

There were two cases on the allocation, so there should be two cases on the release.

I find that this implementation detail does not really matter for the necessity of a null pointer check directly before such a function call.

Conceptually, if it is clear 10 lines above that nothing was allocated, and there is a fallback to existing data (according to the comment above) it is strange to be releasing something.

julia

#454 lore raw

PATCH 1/1 ALSA: es1688_lib: Deletion of an unnecessary check before the function call "release_and_free_resource"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 19:05:50 +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/isa/es1688/es1688_lib.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/isa/es1688/es1688_lib.c +1 -2
index b3b4f15..fb259491 100644
@@ -614,8 +614,7 @@ static int snd_es1688_free(struct snd_es1688 *chip)
 {
 	if (chip->hardware != ES1688_HW_UNDEF)
 		snd_es1688_init(chip, 0);
-	if (chip->res_port)
-		release_and_free_resource(chip->res_port);
+	release_and_free_resource(chip->res_port);
 	if (chip->irq >= 0)
 		free_irq(chip->irq, (void *) chip);
 	if (chip->dma8 >= 0) {
Signature · 1 line
2.1.3
#430 lore raw

Re: thunderbolt: Deletion of unnecessary checks before the function call "ring_free"

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

2. Are any additional prefixes appropriate so that further name space conflicts can be better avoided?

To avoid possible external naming conflicts, add tb_ prefix to various ring_<foo> structs and functions.

Other miscellanea:

o typo/spelling fixes (releated/related, loose/lose)
o argument alignment
o comment formatting

---
Perhaps something like this?

unsigned/compiled/untested

 drivers/thunderbolt/ctl.c      |  41 ++++++-------
 drivers/thunderbolt/nhi.c      | 133 +++++++++++++++++++++--------------------
 drivers/thunderbolt/nhi.h      |  47 ++++++++-------
 drivers/thunderbolt/nhi_regs.h |  16 ++---
 4 files changed, 121 insertions(+), 116 deletions(-)
drivers/thunderbolt/ctl.c +21 -20
index 799634b..52783e0 100644
@@ -17,7 +17,7 @@
 struct ctl_pkg {
 	struct tb_ctl *ctl;
 	void *buffer;
-	struct ring_frame frame;
+	struct tb_ring_frame frame;
 };
 
 #define TB_CTL_RX_PKG_COUNT 10
@@ -319,8 +319,8 @@ static struct ctl_pkg *tb_ctl_pkg_alloc(struct tb_ctl *ctl)
 
 /* RX/TX handling */
 
-static void tb_ctl_tx_callback(struct tb_ring *ring, struct ring_frame *frame,
-			       bool canceled)
+static void tb_ctl_tx_callback(struct tb_ring *ring,
+			       struct tb_ring_frame *frame, bool canceled)
 {
 	struct ctl_pkg *pkg = container_of(frame, typeof(*pkg), frame);
 	tb_ctl_pkg_free(pkg);
@@ -357,7 +357,7 @@ static int tb_ctl_tx(struct tb_ctl *ctl, void *data, size_t len,
 	cpu_to_be32_array(pkg->buffer, data, len / 4);
 	*(__be32 *) (pkg->buffer + len) = tb_crc(pkg->buffer, len);
 
-	res = ring_tx(ctl->tx, &pkg->frame);
+	res = tb_ring_tx(ctl->tx, &pkg->frame);
 	if (res) /* ring is stopped */
 		tb_ctl_pkg_free(pkg);
 	return res;
@@ -386,16 +386,16 @@ static void tb_ctl_handle_plug_event(struct tb_ctl *ctl,
 
 static void tb_ctl_rx_submit(struct ctl_pkg *pkg)
 {
-	ring_rx(pkg->ctl->rx, &pkg->frame); /*
-					     * We ignore failures during stop.
-					     * All rx packets are referenced
-					     * from ctl->rx_packets, so we do
-					     * not loose them.
-					     */
+	tb_ring_rx(pkg->ctl->rx, &pkg->frame);
+	/*
+	 * We ignore failures during stop.
+	 * All rx packets are referenced from ctl->rx_packets,
+	 * so we do not lose them.
+	 */
 }
 
-static void tb_ctl_rx_callback(struct tb_ring *ring, struct ring_frame *frame,
-			       bool canceled)
+static void tb_ctl_rx_callback(struct tb_ring *ring,
+			       struct tb_ring_frame *frame, bool canceled)
 {
 	struct ctl_pkg *pkg = container_of(frame, typeof(*pkg), frame);
 
@@ -488,11 +488,11 @@ struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, hotplug_cb cb, void *cb_data)
 	if (!ctl->frame_pool)
 		goto err;
 
-	ctl->tx = ring_alloc_tx(nhi, 0, 10);
+	ctl->tx = tb_ring_alloc_tx(nhi, 0, 10);
 	if (!ctl->tx)
 		goto err;
 
-	ctl->rx = ring_alloc_rx(nhi, 0, 10);
+	ctl->rx = tb_ring_alloc_rx(nhi, 0, 10);
 	if (!ctl->rx)
 		goto err;
 
@@ -521,9 +521,9 @@ void tb_ctl_free(struct tb_ctl *ctl)
 {
 	int i;
 	if (ctl->rx)
-		ring_free(ctl->rx);
+		tb_ring_free(ctl->rx);
 	if (ctl->tx)
-		ring_free(ctl->tx);
+		tb_ring_free(ctl->tx);
 
 	/* free RX packets */
 	for (i = 0; i < TB_CTL_RX_PKG_COUNT; i++)
@@ -542,8 +542,9 @@ void tb_ctl_start(struct tb_ctl *ctl)
 {
 	int i;
 	tb_ctl_info(ctl, "control channel starting...\n");
-	ring_start(ctl->tx); /* is used to ack hotplug packets, start first */
-	ring_start(ctl->rx);
+	/* is used to ack hotplug packets, start first */
+	tb_ring_start(ctl->tx);
+	tb_ring_start(ctl->rx);
 	for (i = 0; i < TB_CTL_RX_PKG_COUNT; i++)
 		tb_ctl_rx_submit(ctl->rx_packets[i]);
 }
@@ -558,8 +559,8 @@ void tb_ctl_start(struct tb_ctl *ctl)
  */
 void tb_ctl_stop(struct tb_ctl *ctl)
 {
-	ring_stop(ctl->rx);
-	ring_stop(ctl->tx);
+	tb_ring_stop(ctl->rx);
+	tb_ring_stop(ctl->tx);
 
 	if (!kfifo_is_empty(&ctl->response_fifo))
 		tb_ctl_WARN(ctl, "dangling response in response_fifo\n");
drivers/thunderbolt/nhi.c +68 -65

310 lines not on this page · raw message

drivers/thunderbolt/nhi.h +24 -23

98 lines not on this page · raw message

drivers/thunderbolt/nhi_regs.h +8 -8
index 86b996c..23b7059 100644
@@ -9,7 +9,7 @@
 
 #include <linux/types.h>
 
-enum ring_flags {
+enum tb_ring_flags {
 	RING_FLAG_ISOCH_ENABLE = 1 << 27, /* TX only? */
 	RING_FLAG_E2E_FLOW_CONTROL = 1 << 28,
 	RING_FLAG_PCI_NO_SNOOP = 1 << 29,
@@ -17,7 +17,7 @@ enum ring_flags {
 	RING_FLAG_ENABLE = 1 << 31,
 };
 
-enum ring_desc_flags {
+enum tb_ring_desc_flags {
 	RING_DESC_ISOCH = 0x1, /* TX only? */
 	RING_DESC_COMPLETED = 0x2, /* set by NHI */
 	RING_DESC_POSTED = 0x4, /* always set this */
@@ -25,17 +25,17 @@ enum ring_desc_flags {
 };
 
 /**
- * struct ring_desc - TX/RX ring entry
+ * struct tb_ring_desc - TX/RX ring entry
  *
  * For TX set length/eof/sof.
  * For RX length/eof/sof are set by the NHI.
  */
-struct ring_desc {
+struct tb_ring_desc {
 	u64 phys;
 	u32 length:12;
 	u32 eof:4;
 	u32 sof:4;
-	enum ring_desc_flags flags:12;
+	enum tb_ring_desc_flags flags:12;
 	u32 time; /* write zero */
 } __packed;
 
@@ -43,7 +43,7 @@ struct ring_desc {
 
 /*
  * 16 bytes per entry, one entry for every hop (REG_HOP_COUNT)
- * 00: physical pointer to an array of struct ring_desc
+ * 00: physical pointer to an array of struct tb_ring_desc
  * 08: ring tail (set by NHI)
  * 10: ring head (index of first non posted descriptor)
  * 12: descriptor count
@@ -52,7 +52,7 @@ struct ring_desc {
 
 /*
  * 16 bytes per entry, one entry for every hop (REG_HOP_COUNT)
- * 00: physical pointer to an array of struct ring_desc
+ * 00: physical pointer to an array of struct tb_ring_desc
  * 08: ring head (index of first not posted descriptor)
  * 10: ring tail (set by NHI)
  * 12: descriptor count
@@ -70,7 +70,7 @@ struct ring_desc {
 
 /*
  * 32 bytes per entry, one entry for every hop (REG_HOP_COUNT)
- * 00: enum ring_flags
+ * 00: enum tb_ring_flags
  *     If RING_FLAG_E2E_FLOW_CONTROL is set then bits 13-23 must be set to
  *     the corresponding TX hop id.
  * 04: EOF/SOF mask (ignored for RING_FLAG_RAW rings)
#456 lore raw

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

In reply to SF Markus Elfring

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

The functions release_and_free_resource() and snd_util_memhdr_free() 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.

---
 sound/isa/sb/emu8000_synth.c | 3 +--
 sound/isa/sb/sb_common.c     | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
sound/isa/sb/emu8000_synth.c +1 -2
index 4e3fcfb..95b39be 100644
@@ -105,8 +105,7 @@ static int snd_emu8000_delete_device(struct snd_seq_device *dev)
 		snd_device_free(dev->card, hw->pcm);
 	if (hw->emu)
 		snd_emux_free(hw->emu);
-	if (hw->memhdr)
-		snd_util_memhdr_free(hw->memhdr);
+	snd_util_memhdr_free(hw->memhdr);
 	hw->emu = NULL;
 	hw->memhdr = NULL;
 	return 0;
sound/isa/sb/sb_common.c +1 -2
index 3ef9906..f22b448 100644
@@ -184,8 +184,7 @@ static int snd_sbdsp_probe(struct snd_sb * chip)
 
 static int snd_sbdsp_free(struct snd_sb *chip)
 {
-	if (chip->res_port)
-		release_and_free_resource(chip->res_port);
+	release_and_free_resource(chip->res_port);
 	if (chip->irq >= 0)
 		free_irq(chip->irq, (void *) chip);
 #ifdef CONFIG_ISA
Signature · 1 line
2.1.3
Applied
#453 lore raw

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

In reply to SF Markus Elfring

At Fri, 21 Nov 2014 18:40:49 +0100,

Quoted 10 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 18:34:48 +0100

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

Applied, thanks.

Takashi

Quoted 44 lines
---
 sound/core/seq/oss/seq_oss_init.c | 9 +++------
 sound/core/sgbuf.c                | 3 +--
 2 files changed, 4 insertions(+), 8 deletions(-)
sound/core/seq/oss/seq_oss_init.c +3 -6
index b9184d2..b0e32e1 100644
@@ -403,14 +403,11 @@ free_devinfo(void *private)
 {
 	struct seq_oss_devinfo *dp = (struct seq_oss_devinfo *)private;
 
-	if (dp->timer)
-		snd_seq_oss_timer_delete(dp->timer);
+	snd_seq_oss_timer_delete(dp->timer);
 
-	if (dp->writeq)
-		snd_seq_oss_writeq_delete(dp->writeq);
+	snd_seq_oss_writeq_delete(dp->writeq);
 
-	if (dp->readq)
-		snd_seq_oss_readq_delete(dp->readq);
+	snd_seq_oss_readq_delete(dp->readq);
 
 	kfree(dp);
 }
sound/core/sgbuf.c +1 -2
index 0a41850..84fffab 100644
@@ -39,8 +39,7 @@ int snd_free_sgbuf_pages(struct snd_dma_buffer *dmab)
 	if (! sgbuf)
 		return -EINVAL;
 
-	if (dmab->area)
-		vunmap(dmab->area);
+	vunmap(dmab->area);
 	dmab->area = NULL;
 
 	tmpb.dev.type = SNDRV_DMA_TYPE_DEV;
Signature · 1 line
2.1.3
Applied
#455 lore raw

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

In reply to SF Markus Elfring

At Fri, 21 Nov 2014 19:11:47 +0100,

Quoted 10 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 19:05:50 +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.

Applied, thanks.

Takashi

Quoted 21 lines
---
 sound/isa/es1688/es1688_lib.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/isa/es1688/es1688_lib.c +1 -2
index b3b4f15..fb259491 100644
@@ -614,8 +614,7 @@ static int snd_es1688_free(struct snd_es1688 *chip)
 {
 	if (chip->hardware != ES1688_HW_UNDEF)
 		snd_es1688_init(chip, 0);
-	if (chip->res_port)
-		release_and_free_resource(chip->res_port);
+	release_and_free_resource(chip->res_port);
 	if (chip->irq >= 0)
 		free_irq(chip->irq, (void *) chip);
 	if (chip->dma8 >= 0) {
Signature · 1 line
2.1.3
Applied
#457 lore raw

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

In reply to SF Markus Elfring

At Fri, 21 Nov 2014 19:35:18 +0100,

Quoted 11 lines · SF Markus Elfring

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

The functions release_and_free_resource() and snd_util_memhdr_free() 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.

Applied, thanks.

Takashi

Quoted 36 lines
---
 sound/isa/sb/emu8000_synth.c | 3 +--
 sound/isa/sb/sb_common.c     | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
sound/isa/sb/emu8000_synth.c +1 -2
index 4e3fcfb..95b39be 100644
@@ -105,8 +105,7 @@ static int snd_emu8000_delete_device(struct snd_seq_device *dev)
 		snd_device_free(dev->card, hw->pcm);
 	if (hw->emu)
 		snd_emux_free(hw->emu);
-	if (hw->memhdr)
-		snd_util_memhdr_free(hw->memhdr);
+	snd_util_memhdr_free(hw->memhdr);
 	hw->emu = NULL;
 	hw->memhdr = NULL;
 	return 0;
sound/isa/sb/sb_common.c +1 -2
index 3ef9906..f22b448 100644
@@ -184,8 +184,7 @@ static int snd_sbdsp_probe(struct snd_sb * chip)
 
 static int snd_sbdsp_free(struct snd_sb *chip)
 {
-	if (chip->res_port)
-		release_and_free_resource(chip->res_port);
+	release_and_free_resource(chip->res_port);
 	if (chip->irq >= 0)
 		free_irq(chip->irq, (void *) chip);
 #ifdef CONFIG_ISA
Signature · 1 line
2.1.3
#458 lore raw

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

In reply to SF Markus Elfring

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

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

This issue was detected by using the Coccinelle software.

---
 drivers/ide/ide.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/ide/ide.c +1 -2
index 2ce6268..e29b02c 100644
@@ -101,8 +101,7 @@ void ide_device_put(ide_drive_t *drive)
 	struct device *host_dev = drive->hwif->host->dev[0];
 	struct module *module = host_dev ? host_dev->driver->owner : NULL;
 
-	if (module)
-		module_put(module);
+	module_put(module);
 #endif
 	put_device(&drive->gendev);
 }
Signature · 1 line
2.1.3
maintainer Applied
#375 lore raw

Re: [PATCH 1/1] IBM-EMAC: Deletion of unnecessary checks before the function call "of_dev_put"

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 14:28:25 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 14:22:47 +0100

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

This issue was detected by using the Coccinelle software.

Applied.

maintainer Applied
#378 lore raw

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

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 14:50:26 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 14:47:12 +0100

The functions kfree() and of_node_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Applied.

maintainer
#381 lore raw

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

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 15:25:27 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 15:15:21 +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.

This does not apply to the net-next tree, please respin.

maintainer Applied
#393 lore raw

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

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 16:16:16 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 16:11:56 +0100

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

This issue was detected by using the Coccinelle software.

Applied.

#422 lore raw

Re: [PATCH 1/1] target: Deletion of unnecessary checks before the function call "module_put"

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

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 10:25:45 +0100

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

Quoted 8 lines

This issue was detected by using the Coccinelle software.

---
 drivers/target/iscsi/iscsi_target_transport.c | 3 +--
 drivers/target/target_core_hba.c              | 6 ++----
 2 files changed, 3 insertions(+), 6 deletions(-)

Applied to target-pending/for-next.

Thanks Markus!

--nab

#382 lore raw

Re: net: Hyper-V: Deletion of an unnecessary check before the function call "vfree"

In reply to David Miller
Quoted 1 line

This does not apply to the net-next tree, please respin.

Thanks for your reply.

How do you think about to try out the scripts which I published in March to get more constructive feedback?
Will they run faster for another analysis on current Linux source files with your test systems (than my computer)?

Regards,
Markus

maintainer
#383 lore raw

Re: net: Hyper-V: Deletion of an unnecessary check before the function call "vfree"

From: SF Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 23:15:42 +0100

Quoted 6 lines
Quoted 1 line

This does not apply to the net-next tree, please respin.

Thanks for your reply.

How do you think about to try out the scripts which I published in March to get more constructive feedback?

This has nothing to do with me asking you to frame your patches against the correct tree.

If I had time to investigate automation of changes using such tools, I would participate in such discussions, but I don't.

#460 lore raw

PATCH 1/1 Deletion of unnecessary checks before the function call "unw_remove_unwind_table"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 21 Nov 2014 23:57:28 +0100

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

This issue was detected by using the Coccinelle software.

---
 arch/ia64/kernel/module.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
arch/ia64/kernel/module.c +2 -4
index 24603be..30ff27d 100644
@@ -946,8 +946,6 @@ module_finalize (const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, struct module *mo
 void
 module_arch_cleanup (struct module *mod)
 {
-	if (mod->arch.init_unw_table)
-		unw_remove_unwind_table(mod->arch.init_unw_table);
-	if (mod->arch.core_unw_table)
-		unw_remove_unwind_table(mod->arch.core_unw_table);
+	unw_remove_unwind_table(mod->arch.init_unw_table);
+	unw_remove_unwind_table(mod->arch.core_unw_table);
 }
Signature · 1 line
2.1.3
#462 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 22 Nov 2014 10:50:33 +0100

The functions clk_disable(), of_node_put() and omap_device_delete() 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.

---
 arch/arm/mach-omap2/omap_device.c | 3 +--
 arch/arm/mach-omap2/omap_hwmod.c  | 3 +--
 arch/arm/mach-omap2/timer.c       | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)
arch/arm/mach-omap2/omap_device.c +1 -2
index d22c30d..5108859 100644
@@ -199,8 +199,7 @@ static int _omap_device_notifier_call(struct notifier_block *nb,
 
 	switch (event) {
 	case BUS_NOTIFY_DEL_DEVICE:
-		if (pdev->archdata.od)
-			omap_device_delete(pdev->archdata.od);
+		omap_device_delete(pdev->archdata.od);
 		break;
 	case BUS_NOTIFY_ADD_DEVICE:
 		if (pdev->dev.of_node)
arch/arm/mach-omap2/omap_hwmod.c +1 -2
index 9e91a4e..e2406c4 100644
@@ -917,8 +917,7 @@ static int _disable_clocks(struct omap_hwmod *oh)
 
 	pr_debug("omap_hwmod: %s: disabling clocks\n", oh->name);
 
-	if (oh->_clk)
-		clk_disable(oh->_clk);
+	clk_disable(oh->_clk);
 
 	p = oh->slave_ports.next;
 
arch/arm/mach-omap2/timer.c +1 -2
index 43d03fb..5b428a0 100644
@@ -205,8 +205,7 @@ static void __init omap_dmtimer_init(void)
 	/* If we are a secure device, remove any secure timer nodes */
 	if ((omap_type() != OMAP2_DEVICE_TYPE_GP)) {
 		np = omap_get_timer_dt(omap_timer_match, "ti,timer-secure");
-		if (np)
-			of_node_put(np);
+		of_node_put(np);
 	}
 }
 
Signature · 1 line
2.1.3
#469 lore raw

PATCH 1/1 ARM-kernel: Deletion of unnecessary checks before two function calls

In reply to SF Markus Elfring

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

The functions smp_set_ops() and unwind_table_del() 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.

---
 arch/arm/kernel/module.c | 3 +--
 arch/arm/kernel/setup.c  | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
arch/arm/kernel/module.c +1 -2
index 6a4dffe..3dffad1 100644
@@ -350,7 +350,6 @@ module_arch_cleanup(struct module *mod)
 	int i;
 
 	for (i = 0; i < ARM_SEC_MAX; i++)
-		if (mod->arch.unwind[i])
-			unwind_table_del(mod->arch.unwind[i]);
+		unwind_table_del(mod->arch.unwind[i]);
 #endif
 }
arch/arm/kernel/setup.c +1 -1
index 84db893d..a7018a2 100644
@@ -929,7 +929,7 @@ void __init setup_arch(char **cmdline_p)
 		if (!mdesc->smp_init || !mdesc->smp_init()) {
 			if (psci_smp_available())
 				smp_set_ops(&psci_smp_ops);
-			else if (mdesc->smp)
+			else
 				smp_set_ops(mdesc->smp);
 		}
 		smp_init_cpus();
Signature · 1 line
2.1.3
#470 lore raw

PATCH 1/1 x86: PCI-Calgary: Deletion of an unnecessary check before the function call "free_tce_table"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 22 Nov 2014 12:55:28 +0100

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

This issue was detected by using the Coccinelle software.

---
 arch/x86/kernel/pci-calgary_64.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kernel/pci-calgary_64.c +1 -2
index 0497f71..d22a386 100644
@@ -1476,8 +1476,7 @@ cleanup:
 	for (--bus; bus >= 0; --bus) {
 		struct calgary_bus_info *info = &bus_info[bus];
 
-		if (info->tce_space)
-			free_tce_table(info->tce_space);
+		free_tce_table(info->tce_space);
 	}
 	return -ENOMEM;
 }
Signature · 1 line
2.1.3
#473 lore raw

PATCH 1/1 x86: AMD-perf_event: Deletion of unnecessary checks before the function call "free_percpu"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 22 Nov 2014 14:01:27 +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.

---
 arch/x86/kernel/cpu/perf_event_amd_uncore.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/perf_event_amd_uncore.c +2 -4
index 30790d7..4856232 100644
@@ -592,11 +592,9 @@ fail_online:
 fail_l2:
 	if (cpu_has_perfctr_nb)
 		perf_pmu_unregister(&amd_nb_pmu);
-	if (amd_uncore_l2)
-		free_percpu(amd_uncore_l2);
+	free_percpu(amd_uncore_l2);
 fail_nb:
-	if (amd_uncore_nb)
-		free_percpu(amd_uncore_nb);
+	free_percpu(amd_uncore_nb);
 
 fail_nodev:
 	return ret;
Signature · 1 line
2.1.3
#476 lore raw

PATCH 1/1 s390/pci: Deletion of unnecessary checks before the function call "debug_unregister"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 22 Nov 2014 15:00:55 +0100

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

This issue was detected by using the Coccinelle software.

---
 arch/s390/pci/pci_debug.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
arch/s390/pci/pci_debug.c +2 -4
index eec598c..18403a7 100644
@@ -158,10 +158,8 @@ int __init zpci_debug_init(void)
 
 void zpci_debug_exit(void)
 {
-	if (pci_debug_msg_id)
-		debug_unregister(pci_debug_msg_id);
-	if (pci_debug_err_id)
-		debug_unregister(pci_debug_err_id);
+	debug_unregister(pci_debug_msg_id);
+	debug_unregister(pci_debug_err_id);
 
 	debugfs_remove(debugfs_root);
 }
Signature · 1 line
2.1.3
#478 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 22 Nov 2014 16:18:20 +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.

---
 arch/powerpc/platforms/83xx/usb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/powerpc/platforms/83xx/usb.c +1 -2
index 1ad748b..5c31d82 100644
@@ -162,8 +162,7 @@ int mpc831x_usb_cfg(void)
 
 	iounmap(immap);
 
-	if (immr_node)
-		of_node_put(immr_node);
+	of_node_put(immr_node);
 
 	/* Map USB SOC space */
 	ret = of_address_to_resource(np, 0, &res);
Signature · 1 line
2.1.3
#479 lore raw

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

In reply to SF Markus Elfring

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

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

This issue was detected by using the Coccinelle software.

---
 drivers/video/fbdev/sh_mobile_lcdcfb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/fbdev/sh_mobile_lcdcfb.c +1 -2
index 2bcc84a..cfde21d 100644
@@ -2181,8 +2181,7 @@ sh_mobile_lcdc_channel_fb_cleanup(struct sh_mobile_lcdc_chan *ch)
 	if (!info || !info->device)
 		return;
 
-	if (ch->sglist)
-		vfree(ch->sglist);
+	vfree(ch->sglist);
 
 	fb_dealloc_cmap(&info->cmap);
 	framebuffer_release(info);
Signature · 1 line
2.1.3
#384 lore raw

Re: net: Hyper-V: Deletion of an unnecessary check before the function call "vfree"

In reply to David Miller
Quoted 2 lines

This has nothing to do with me asking you to frame your patches against the correct tree.

I imagine than someone other can also pick up this update suggestion (a simple change of two lines) quicker before I might try another software build again from a different commit as a base.

Regards,
Markus

#385 lore raw

Re: net: Hyper-V: Deletion of an unnecessary check before the function call "vfree"

Quoted 6 lines · SF Markus Elfring
Quoted 2 lines

This has nothing to do with me asking you to frame your patches against the correct tree.

I imagine than someone other can also pick up this update suggestion (a simple change of two lines) quicker before I might try another software build again from a different commit as a base.

I have no idea why someone would do that.

If you don't bother resubmit, nobody will.

maintainer
#387 lore raw

Re: net: Hyper-V: Deletion of an unnecessary check before the function call "vfree"

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Sun, 23 Nov 2014 01:51:24 +0100

Quoted 6 lines
Quoted 2 lines

This has nothing to do with me asking you to frame your patches against the correct tree.

I imagine than someone other can also pick up this update suggestion (a simple change of two lines) quicker before I might try another software build again from a different commit as a base.

Whereas if you learn how to base your changes cleanly on the correct base now, all of your future submissions will go quickly and smoothly into my tree.

#386 lore raw

Re: net: Hyper-V: Deletion of an unnecessary check before the function call "vfree"

In reply to Eric Dumazet
Quoted 5 lines
Quoted 3 lines

I imagine than someone other can also pick up this update suggestion (a simple change of two lines) quicker before I might try another software build again from a different commit as a base.

I have no idea why someone would do that.

I imagine that other software users (besides me) like developers and testers might also become curious to try the proposed changes out.

How much will they eventually help to run Linux components a bit faster?

Quoted 1 line

If you don't bother resubmit, nobody will.

I hope that there are more possibilities for anticipation and acceptance of source code improvement potentials.
Would you also like to contribute a bit more fine-tuning for the affected software versions?

Regards,
Markus

#388 lore raw

Re: net: Hyper-V: Deletion of an unnecessary check before the function call "vfree"

In reply to David Miller
Quoted 3 lines

Whereas if you learn how to base your changes cleanly on the correct base now, all of your future submissions will go quickly and smoothly into my tree.

My reluctance to work with more Linux repositories will evolve over time. The faster affected software versions can be rebuilt the more it will become interesting to try even more source code improvements out, won't it?

I find it nice that you could accept update suggestions for a few other Linux components already.

Regards,
Markus

#481 lore raw

PATCH 1/1 video: uvesafb: Deletion of an unnecessary check before the function call "uvesafb_free"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 23 Nov 2014 11:00:26 +0100

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

---
 drivers/video/fbdev/uvesafb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/fbdev/uvesafb.c +1 -2
index 509d452..f718627 100644
@@ -1219,8 +1219,7 @@ static int uvesafb_release(struct fb_info *info, int user)
 	uvesafb_vbe_state_restore(par, par->vbe_state_orig);
 out:
 	atomic_dec(&par->ref_count);
-	if (task)
-		uvesafb_free(task);
+	uvesafb_free(task);
 	return 0;
 }
 
Signature · 1 line
2.1.3
#482 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 23 Nov 2014 11:40:47 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/video/fbdev/udlfb.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/video/fbdev/udlfb.c +3 -6
index 77b890e..01fff0c 100644
@@ -922,8 +922,7 @@ static void dlfb_free(struct kref *kref)
 {
 	struct dlfb_data *dev = container_of(kref, struct dlfb_data, kref);
 
-	if (dev->backing_buffer)
-		vfree(dev->backing_buffer);
+	vfree(dev->backing_buffer);
 
 	kfree(dev->edid);
 
@@ -953,8 +952,7 @@ static void dlfb_free_framebuffer(struct dlfb_data *dev)
 			fb_dealloc_cmap(&info->cmap);
 		if (info->monspecs.modedb)
 			fb_destroy_modedb(info->monspecs.modedb);
-		if (info->screen_base)
-			vfree(info->screen_base);
+		vfree(info->screen_base);
 
 		fb_destroy_modelist(&info->modelist);
 
@@ -1203,8 +1201,7 @@ static int dlfb_realloc_framebuffer(struct dlfb_data *dev, struct fb_info *info)
 		if (!new_back)
 			pr_info("No shadow/backing buffer allocated\n");
 		else {
-			if (dev->backing_buffer)
-				vfree(dev->backing_buffer);
+			vfree(dev->backing_buffer);
 			dev->backing_buffer = new_back;
 		}
 	}
Signature · 1 line
2.1.3
#483 lore raw

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

In reply to SF Markus Elfring

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

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

This issue was detected by using the Coccinelle software.

---
 drivers/video/fbdev/smscufx.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/video/fbdev/smscufx.c +2 -4
index d513ed6..9279e5f 100644
@@ -1142,8 +1142,7 @@ static void ufx_free_framebuffer_work(struct work_struct *work)
 		fb_dealloc_cmap(&info->cmap);
 	if (info->monspecs.modedb)
 		fb_destroy_modedb(info->monspecs.modedb);
-	if (info->screen_base)
-		vfree(info->screen_base);
+	vfree(info->screen_base);
 
 	fb_destroy_modelist(&info->modelist);
 
@@ -1743,8 +1742,7 @@ error:
 				fb_dealloc_cmap(&info->cmap);
 			if (info->monspecs.modedb)
 				fb_destroy_modedb(info->monspecs.modedb);
-			if (info->screen_base)
-				vfree(info->screen_base);
+			vfree(info->screen_base);
 
 			fb_destroy_modelist(&info->modelist);
 
Signature · 1 line
2.1.3
#204 lore raw

Re: [Cocci] [PATCH 1/1] kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"

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

No, it's not. You should just try to write the most readable software you can instead of removing if statements because you can.

Additional safety checks have also got an effect on source code readability, haven't they?

Normally, tests only hurt readability if they cannot be false or cannot be true. Making a choice apparent when there really is a choice would seem to aid understanding. Program analysis tools can also potentially exploit this information, which you are so systmatically removing.

julia

#484 lore raw

PATCH 1/1 video: fbdev-SIS: Deletion of unnecessary checks before the function call "pci_dev_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 23 Nov 2014 12:55:25 +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/video/fbdev/sis/sis_main.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/video/fbdev/sis/sis_main.c +5 -9
index 3f12a2d..6548a3e 100644
@@ -5989,7 +5989,7 @@ static int sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	if(!ivideo->sisvga_enabled) {
 		if(pci_enable_device(pdev)) {
-			if(ivideo->nbridge) pci_dev_put(ivideo->nbridge);
+			pci_dev_put(ivideo->nbridge);
 			framebuffer_release(sis_fb_info);
 			return -EIO;
 		}
@@ -6202,10 +6202,8 @@ error_0:	iounmap(ivideo->video_vbase);
 error_1:	release_mem_region(ivideo->video_base, ivideo->video_size);
 error_2:	release_mem_region(ivideo->mmio_base, ivideo->mmio_size);
 error_3:	vfree(ivideo->bios_abase);
-		if(ivideo->lpcdev)
-			pci_dev_put(ivideo->lpcdev);
-		if(ivideo->nbridge)
-			pci_dev_put(ivideo->nbridge);
+		pci_dev_put(ivideo->lpcdev);
+		pci_dev_put(ivideo->nbridge);
 		if(!ivideo->sisvga_enabled)
 			pci_disable_device(pdev);
 		framebuffer_release(sis_fb_info);
@@ -6505,11 +6503,9 @@ static void sisfb_remove(struct pci_dev *pdev)
 
 	vfree(ivideo->bios_abase);
 
-	if(ivideo->lpcdev)
-		pci_dev_put(ivideo->lpcdev);
+	pci_dev_put(ivideo->lpcdev);
 
-	if(ivideo->nbridge)
-		pci_dev_put(ivideo->nbridge);
+	pci_dev_put(ivideo->nbridge);
 
 #ifdef CONFIG_MTRR
 	/* Release MTRR region */
Signature · 1 line
2.1.3
#485 lore raw

PATCH 1/1 video: fbdev-OMAP2: Deletion of unnecessary checks before the function call "i2c_put_adapter"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 23 Nov 2014 14:07:22 +0100

The i2c_put_adapter() 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/video/fbdev/omap2/displays-new/connector-dvi.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/video/fbdev/omap2/displays-new/connector-dvi.c +3 -6
index 74de2bc..196c61a 100644
@@ -262,8 +262,7 @@ static int dvic_probe_pdata(struct platform_device *pdev)
 
 	in = omap_dss_find_output(pdata->source);
 	if (in = NULL) {
-		if (ddata->i2c_adapter)
-			i2c_put_adapter(ddata->i2c_adapter);
+		i2c_put_adapter(ddata->i2c_adapter);
 
 		dev_err(&pdev->dev, "Failed to find video source\n");
 		return -EPROBE_DEFER;
@@ -352,8 +351,7 @@ static int dvic_probe(struct platform_device *pdev)
 err_reg:
 	omap_dss_put_device(ddata->in);
 
-	if (ddata->i2c_adapter)
-		i2c_put_adapter(ddata->i2c_adapter);
+	i2c_put_adapter(ddata->i2c_adapter);
 
 	return r;
 }
@@ -371,8 +369,7 @@ static int __exit dvic_remove(struct platform_device *pdev)
 
 	omap_dss_put_device(in);
 
-	if (ddata->i2c_adapter)
-		i2c_put_adapter(ddata->i2c_adapter);
+	i2c_put_adapter(ddata->i2c_adapter);
 
 	return 0;
 }
Signature · 1 line
2.1.3
#205 lore raw

Re: kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"

In reply to Julia Lawall
Quoted 3 lines

Normally, tests only hurt readability if they cannot be false or cannot be true. Making a choice apparent when there really is a choice would seem to aid understanding.

I agree also to such facts.

Quoted 1 line

Program analysis tools can also potentially exploit this information,

The published semantic patch scripts correspond to this desire.

Quoted 1 line

which you are so systmatically removing.

I try to delete redundant checks in various function implementations as much as possible.

Regards,
Markus

#431 lore raw

Re: thunderbolt: Deletion of unnecessary checks before the function call "ring_free"

In reply to Joe Perches
Quoted 5 lines
Quoted 2 lines

2. Are any additional prefixes appropriate so that further name space conflicts can be better avoided?

To avoid possible external naming conflicts, add tb_ prefix to various ring_<foo> structs and functions.

Do you imagine that any XEN software developers need also to reconsider this implementation detail?
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/drivers/char/tpm/xen-tpmfront.c?idü14f9c1272f62c3e8d01300f52467c0d9af50f9#n268

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

#486 lore raw

PATCH 1/1 video: mx3fb: Deletion of an unnecessary check before the function call "backlight_device_unregister"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 23 Nov 2014 15:15: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/video/fbdev/mx3fb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/fbdev/mx3fb.c +1 -2
index c645a0a..b2d2151 100644
@@ -334,8 +334,7 @@ static void mx3fb_init_backlight(struct mx3fb_data *fbd)
 
 static void mx3fb_exit_backlight(struct mx3fb_data *fbd)
 {
-	if (fbd->bl)
-		backlight_device_unregister(fbd->bl);
+	backlight_device_unregister(fbd->bl);
 }
 
 static void mx3fb_dma_done(void *);
Signature · 1 line
2.1.3
#487 lore raw

PATCH 1/1 video: fbdev-MMP: Deletion of an unnecessary check before the function call "mmp_unregister_path"

In reply to SF Markus Elfring

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

The mmp_unregister_path() 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/video/fbdev/mmp/hw/mmp_ctrl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/fbdev/mmp/hw/mmp_ctrl.c +1 -2
index 8621a9f..3c12bd8 100644
@@ -441,8 +441,7 @@ static void path_deinit(struct mmphw_path_plat *path_plat)
 	if (!path_plat)
 		return;
 
-	if (path_plat->path)
-		mmp_unregister_path(path_plat->path);
+	mmp_unregister_path(path_plat->path);
 }
 
 static int mmphw_probe(struct platform_device *pdev)
Signature · 1 line
2.1.3
#432 lore raw

Re: thunderbolt: Deletion of unnecessary checks before the function call "ring_free"

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

2. Are any additional prefixes appropriate so that further name space conflicts can be better avoided?

To avoid possible external naming conflicts, add tb_ prefix to various ring_<foo> structs and functions.

Do you imagine that any XEN software developers need also to reconsider this implementation detail?
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/drivers/char/tpm/xen-tpmfront.c?idü14f9c1272f62c3e8d01300f52467c0d9af50f9#n268

I think static functions can be named whatever
the developer chooses.

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

#488 lore raw

PATCH 1/1 video: fbdev-VIA: Deletion of an unnecessary check before the function call "framebuffer_release"

In reply to SF Markus Elfring

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

The framebuffer_release() 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/video/fbdev/via/viafbdev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/fbdev/via/viafbdev.c +1 -2
index 325c43c..f9718f0 100644
@@ -1937,8 +1937,7 @@ out_fb1_unreg_lcd_cle266:
 out_dealloc_cmap:
 	fb_dealloc_cmap(&viafbinfo->cmap);
 out_fb1_release:
-	if (viafbinfo1)
-		framebuffer_release(viafbinfo1);
+	framebuffer_release(viafbinfo1);
 out_fb_release:
 	i2c_bus_free(viaparinfo->shared);
 	framebuffer_release(viafbinfo);
Signature · 1 line
2.1.3
#433 lore raw

Re: thunderbolt: Deletion of unnecessary checks before the function call "ring_free"

In reply to Joe Perches
Quoted 4 lines
Quoted 1 line

https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/drivers/char/tpm/xen-tpmfront.c?idü14f9c1272f62c3e8d01300f52467c0d9af50f9#n268

I think static functions can be named whatever
the developer chooses.

I agree also that this implementation detail is correct in principle.

Is a renaming of such identifiers feasible so that the probability of other name clashes can be reduced and corresponding static source code analysis might become a bit easier?

How do you prefer to handle name space issues?

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

maintainer
#437 lore raw

Re: thunderbolt: Deletion of unnecessary checks before the function call "ring_free"

In reply to Joe Perches
Quoted 7 lines · Joe Perches
Quoted 6 lines · SF Markus Elfring
Quoted 5 lines
Quoted 2 lines

2. Are any additional prefixes appropriate so that further name space conflicts can be better avoided?

To avoid possible external naming conflicts, add tb_ prefix to various ring_<foo> structs and functions.

Quoted 6 lines
Quoted 3 lines

Do you imagine that any XEN software developers need also to reconsider this implementation detail?
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/drivers/char/tpm/xen-tpmfront.c?idü14f9c1272f62c3e8d01300f52467c0d9af50f9#n268

I think static functions can be named whatever
the developer chooses.

Do symbols which are not exported (no EXPORT_SYMBOL_(GPL)) cause conflicts? I was under the impression that those are module private. If they are indeed private then I would prefer to not rename them. --
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

#434 lore raw

Re: thunderbolt: Deletion of unnecessary checks before the function call "ring_free"

In reply to SF Markus Elfring
Quoted 10 lines · SF Markus Elfring
Quoted 4 lines
Quoted 1 line

https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/drivers/char/tpm/xen-tpmfront.c?idü14f9c1272f62c3e8d01300f52467c0d9af50f9#n268

I think static functions can be named whatever
the developer chooses.

I agree also that this implementation detail is correct in principle.

Is a renaming of such identifiers feasible so that the probability of other name clashes can be reduced and corresponding static source code analysis might become a bit easier?

Why not just make the static source code analysis aware of the problem? You can treat static functions differently that non-static ones. There is no need to change the code.

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

#438 lore raw

Re: thunderbolt: Deletion of unnecessary checks before the function call "ring_free"

In reply to Andreas Noever
Quoted 8 lines · Andreas Noever
Quoted 7 lines · Joe Perches
Quoted 6 lines · SF Markus Elfring
Quoted 5 lines
Quoted 2 lines

2. Are any additional prefixes appropriate so that further name space conflicts can be better avoided?

To avoid possible external naming conflicts, add tb_ prefix to various ring_<foo> structs and functions.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Do you imagine that any XEN software developers need also to reconsider this implementation detail?
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/drivers/char/tpm/xen-tpmfront.c?idü14f9c1272f62c3e8d01300f52467c0d9af50f9#n268

I think static functions can be named whatever
the developer chooses.

Do symbols which are not exported (no EXPORT_SYMBOL_(GPL)) cause conflicts?

If the symbol is not static, yes.

eg: the static uses of "debug" as a control
variable vs the non-static uses of <prefix>debug
when shared among multiple objects in a single
driver.

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

#489 lore raw

PATCH 1/1 video: uvesafb: Deletion of an unnecessary check before the function call "platform_device_put"

In reply to SF Markus Elfring

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

The platform_device_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/video/fbdev/uvesafb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/fbdev/uvesafb.c +1 -2
index 509d452..17b2e8c 100644
@@ -1923,8 +1923,7 @@ static int uvesafb_init(void)
 			err = -ENOMEM;
 
 		if (err) {
-			if (uvesafb_device)
-				platform_device_put(uvesafb_device);
+			platform_device_put(uvesafb_device);
 			platform_driver_unregister(&uvesafb_driver);
 			cn_del_callback(&uvesafb_cn_id);
 			return err;
Signature · 1 line
2.1.3
#490 lore raw

PATCH 1/1 backlight: lp8788: Deletion of an unnecessary check before the function call "backlight_device_unregister"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 23 Nov 2014 17:33:08 +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/video/backlight/lp8788_bl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/backlight/lp8788_bl.c +1 -2
index d6c4f6a..24a055c 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 · 1 line
2.1.3
#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
maintainer
#389 lore raw

Re: net: Hyper-V: Deletion of an unnecessary check before the function call "vfree"

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Sun, 23 Nov 2014 08:18:31 +0100

Quoted 11 lines
Quoted 3 lines

Whereas if you learn how to base your changes cleanly on the correct base now, all of your future submissions will go quickly and smoothly into my tree.

My reluctance to work with more Linux repositories will evolve over time. The faster affected software versions can be rebuilt the more it will become interesting to try even more source code improvements out, won't it?

I find it nice that you could accept update suggestions for a few other Linux components already.

You are seriously starting to waste our time.

Either resubmit your changes against a clean base, or more on.

Seriously, all I am purely interested in is seeing properly submitted patches, reviewing them, and then integrating them. Anything else is pure noise to me.

Thanks.

#500 lore raw

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

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

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

Re: thunderbolt: Deletion of unnecessary checks before the function call "ring_free"

In reply to Julia Lawall
Quoted 1 line

Why not just make the static source code analysis aware of the problem?

This is also possible, of course.

Quoted 1 line

You can treat static functions differently that non-static ones.

I have added this detail to my ideas around the next fine-tuning for the published semantic patch approach.

Quoted 1 line

There is no need to change the code.

Can name space prefixes help to make source code a bit safer eventually?

Regards,
Markus

#436 lore raw

Re: thunderbolt: Deletion of unnecessary checks before the function call "ring_free"

Quoted 7 lines · SF Markus Elfring
Quoted 1 line

Why not just make the static source code analysis aware of the problem?

This is also possible, of course.

Quoted 1 line

You can treat static functions differently that non-static ones.

Quoted 7 lines

I have added this detail to my ideas around the next fine-tuning for the published semantic patch approach.

Quoted 1 line

There is no need to change the code.

Can name space prefixes help to make source code a bit safer eventually?

Not really.
Adding prefixes can make code unnecessarily more verbose though.

#507 lore raw

Re: [PATCH 1/1] Sony-laptop: Deletion of an unnecessary check 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: 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
#509 lore raw

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

In reply to SF Markus Elfring
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
#206 lore raw

Re: kernel-audit: Deletion of an unnecessary check before the function call "audit_log_end"

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

Program analysis tools can also potentially exploit this information,

The published semantic patch scripts correspond to this desire.

Sorry for that.

I have deleted the Smatch check for this so it no longer warns about:

	if (foo)
		kfree(foo);

regards,
dan carpenter

maintainer
#449 lore raw

Re: USB: serial: Deletion of an unnecessary check before the function call "release_firmware"

In reply to Julia Lawall
Quoted 22 lines · Julia Lawall
Quoted 20 lines · SF Markus Elfring
Quoted 5 lines
Quoted 5 lines
drivers/usb/serial/mxuport.c +0 -0
index ab1d690..3653ec1 100644
@@ -1101,8 +1101,7 @@ static int mxuport_probe(struct usb_serial *serial,
Quoted 8 lines

drivers/usb/serial/mxuport.c static int mxuport_probe(struct usb_serial *serial, · line 1104

Quoted 6 lines
drivers/usb/serial/mxuport.c +1 -2
 	 */
 	usb_set_serial_data(serial, (void *)id->driver_info);
 out:
-	if (fw_p)
-		release_firmware(fw_p);
+	release_firmware(fw_p);

I think that the if should stay.

I have got an other opinion.

Quoted 2 lines

There were two cases on the allocation, so there should be two cases on the release.

Quoted 6 lines
Quoted 2 lines

I find that this implementation detail does not really matter for the necessity of a null pointer check directly before such a function call.

Conceptually, if it is clear 10 lines above that nothing was allocated, and there is a fallback to existing data (according to the comment above) it is strange to be releasing something.

I agree with Julia here and will not apply this one.

Thanks,
Johan

#491 lore raw

Re: [PATCH 1/1] backlight: lp8788: Deletion of an unnecessary check before the function call "backlight_device_unregister"

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

From: Markus Elfring <[email protected]>
Date: Sun, 23 Nov 2014 17:33:08 +0100

What format is this?

Can you use git format-patch and git send-email instead please?

Quoted 24 lines

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/video/backlight/lp8788_bl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/backlight/lp8788_bl.c +1 -2
index d6c4f6a..24a055c 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
#492 lore raw

Re: [PATCH 1/1] backlight: lp8788: Deletion of an unnecessary check before the function call "backlight_device_unregister"

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

From: Markus Elfring <[email protected]>
Date: Sun, 23 Nov 2014 17:33:08 +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.

Also the $SUBJECT should be less than 75 chars.

Quoted 21 lines

This issue was detected by using the Coccinelle software.

---
 drivers/video/backlight/lp8788_bl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/backlight/lp8788_bl.c +1 -2
index d6c4f6a..24a055c 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
#493 lore raw

PATCH v2 1/1 backlight: lp8788: Deletion of a check before backlight_device_unregister()

From: Markus Elfring <[email protected]>

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/video/backlight/lp8788_bl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/backlight/lp8788_bl.c +1 -2
index d6c4f6a..24a055c 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 · 1 line
2.1.3
#477 lore raw

Re: [PATCH 1/1] s390/pci: Deletion of unnecessary checks before the function call "debug_unregister"

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

From: Markus Elfring <[email protected]>
Date: Sat, 22 Nov 2014 15:00:55 +0100

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

This issue was detected by using the Coccinelle software.

---
 arch/s390/pci/pci_debug.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
arch/s390/pci/pci_debug.c +0 -0
index eec598c..18403a7 100644
@@ -158,10 +158,8 @@ int __init zpci_debug_init(void)
 
 void zpci_debug_exit(void)

arch/s390/pci/pci_debug.c int __init zpci_debug_init(void) · line 165

Quoted 10 lines
arch/s390/pci/pci_debug.c +2 -4
 {
-	if (pci_debug_msg_id)
-		debug_unregister(pci_debug_msg_id);
-	if (pci_debug_err_id)
-		debug_unregister(pci_debug_err_id);
+	debug_unregister(pci_debug_msg_id);
+	debug_unregister(pci_debug_err_id);
 
 	debugfs_remove(debugfs_root);
 }

Applied.

Thanks,
Sebastian

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

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

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

In reply to Anisse Astier
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

#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
#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
#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
Acked-by on v1 1/1
#471 lore raw

Re: [PATCH 1/1] x86: PCI-Calgary: Deletion of an unnecessary check before the function call "free_tce_table"

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

From: Markus Elfring <[email protected]>
Date: Sat, 22 Nov 2014 12:55:28 +0100

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

Looks good to me

Quoted 21 lines
---
 arch/x86/kernel/pci-calgary_64.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kernel/pci-calgary_64.c +1 -3
index 0497f71..d22a386 100644
@@ -1476,8 +1476,7 @@ cleanup:
        for (--bus; bus >= 0; --bus) {
                struct calgary_bus_info *info = &bus_info[bus];
 
-               if (info->tce_space)
-                       free_tce_table(info->tce_space);
+               free_tce_table(info->tce_space);
        }
        return -ENOMEM;
 }
--

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

PATCH v2 1/1 net: Hyper-V: Deletion of an unnecessary check before the function call "vfree"

In reply to David Miller

From: Markus Elfring <[email protected]>
Date: Tue, 25 Nov 2014 22:33:45 +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/hyperv/netvsc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/hyperv/netvsc.c +1 -3
index 6b46311..6fc834e 100644
@@ -561,9 +561,7 @@ int netvsc_device_remove(struct hv_device *device)
 	vmbus_close(device->channel);
 
 	/* Release all resources */
-	if (net_device->sub_cb_buf)
-		vfree(net_device->sub_cb_buf);
-
+	vfree(net_device->sub_cb_buf);
 	free_netvsc_device(net_device);
 	return 0;
 }
Signature · 1 line
2.1.3
maintainer Applied
#391 lore raw

Re: [PATCH v2] net: Hyper-V: Deletion of an unnecessary check before the function call "vfree"

From: SF Markus Elfring <[email protected]>
Date: Tue, 25 Nov 2014 22:55:34 +0100

Quoted 10 lines

From: Markus Elfring <[email protected]>
Date: Tue, 25 Nov 2014 22:33:45 +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.

maintainer Applied
#152 lore raw

Re: [1/1] fs-ext4: Deletion of an unnecessary check before the function call "iput"

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

From: Markus Elfring <[email protected]>
Date: Sat, 15 Nov 2014 19:04:06 +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.

Thanks, applied.

- Ted

Applied
#373 lore raw

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

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

From: Markus Elfring <[email protected]>
Date: Thu, 20 Nov 2014 13:50:43 +0100

The functions kfree() and pci_dev_put() test whether their argument is NULL and then return immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Applied to l2-mtd.git.

Brian

#503 lore raw

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

In reply to SF Markus Elfring
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

#512 lore raw

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

In reply to SF Markus Elfring
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

#160 lore raw

PATCH v2 1/1 fs-fat: Less function calls in fat_fill_super() after error detection

In reply to Julia Lawall

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

The iput() function was called in an inefficient way by the implementation of the fat_fill_super() function in case of an allocation failure. The corresponding source code was improved by deletion of two unnecessary null pointer checks and a few adjustments for jump labels.

---
 fs/fat/inode.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
fs/fat/inode.c +10 -8
index 756aead..a39afe8 100644
@@ -1716,20 +1716,20 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
 
 	fsinfo_inode = new_inode(sb);
 	if (!fsinfo_inode)
-		goto out_fail;
+		goto fsinfo_inode_failure;
 	fsinfo_inode->i_ino = MSDOS_FSINFO_INO;
 	sbi->fsinfo_inode = fsinfo_inode;
 	insert_inode_hash(fsinfo_inode);
 
 	root_inode = new_inode(sb);
 	if (!root_inode)
-		goto out_fail;
+		goto failure_exit;
 	root_inode->i_ino = MSDOS_ROOT_INO;
 	root_inode->i_version = 1;
 	error = fat_read_root(root_inode);
 	if (error < 0) {
 		iput(root_inode);
-		goto out_fail;
+		goto failure_exit;
 	}
 	error = -ENOMEM;
 	insert_inode_hash(root_inode);
@@ -1737,7 +1737,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
 	sb->s_root = d_make_root(root_inode);
 	if (!sb->s_root) {
 		fat_msg(sb, KERN_ERR, "get root inode failed");
-		goto out_fail;
+		goto failure_exit;
 	}
 
 	if (sbi->options.discard) {
@@ -1756,11 +1756,13 @@ out_invalid:
 	if (!silent)
 		fat_msg(sb, KERN_INFO, "Can't find a valid FAT filesystem");
 
+failure_exit:
+	iput(fsinfo_inode);
+
+fsinfo_inode_failure:
+	iput(fat_inode);
+
 out_fail:
-	if (fsinfo_inode)
-		iput(fsinfo_inode);
-	if (fat_inode)
-		iput(fat_inode);
 	unload_nls(sbi->nls_io);
 	unload_nls(sbi->nls_disk);
 	if (sbi->options.iocharset != fat_default_iocharset)
Signature · 1 line
2.1.3
maintainer
#161 lore raw

Re: [PATCH v2] fs-fat: Less function calls in fat_fill_super() after error detection

Quoted 7 lines · SF Markus Elfring

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

The iput() function was called in an inefficient way by the implementation of the fat_fill_super() function in case of an allocation failure. The corresponding source code was improved by deletion of two unnecessary null pointer checks and a few adjustments for jump labels.

iput() checks NULL of inode. What is wrong just remove NULL check, instead of adding new jump labels?

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#162 lore raw

Re: [PATCH v2] fs-fat: Less function calls in fat_fill_super() after error detection

Quoted 5 lines · OGAWA Hirofumi
Quoted 3 lines · SF Markus Elfring

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

Quoted 7 lines
Quoted 4 lines

The iput() function was called in an inefficient way by the implementation of the fat_fill_super() function in case of an allocation failure. The corresponding source code was improved by deletion of two unnecessary null pointer checks and a few adjustments for jump labels.

iput() checks NULL of inode. What is wrong just remove NULL check, instead of adding new jump labels?

Personally, I prefer that code that can be statically determined not to need to be executed not to be executed. It can make the code easier to understand, because each function is only called when doing so is useful, and it can be helpful to static analysis.

julia

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

Re: [PATCH v2] fs-fat: Less function calls in fat_fill_super() after error detection

In reply to Julia Lawall
Quoted 7 lines · Julia Lawall
Quoted 2 lines

iput() checks NULL of inode. What is wrong just remove NULL check, instead of adding new jump labels?

Personally, I prefer that code that can be statically determined not to need to be executed not to be executed. It can make the code easier to understand, because each function is only called when doing so is useful, and it can be helpful to static analysis.

Hm, first of all, we want to prevent the bugs. More labels are more chances of bug (and we don't care micro optimize on this error path), isn't it? Increasing the chance of bugs and bothers developers for analyzer sounds like strange.

(And we are initializing those for avoiding to be bothered by choosing correct label. If we really care micro optimize, initialization of those should not be required and should not be touched on other paths, and gcc can warn its usage.)

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#529 lore raw

PATCH 1/1 net: cassini: 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
#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
#164 lore raw

Re: fs-fat: Less function calls in fat_fill_super() after error detection

In reply to OGAWA Hirofumi
Quoted 2 lines

More labels are more chances of bug (and we don't care micro optimize on this error path), isn't it?

I would prefer that a few jump targets can be redirected so that unnecessary function calls (and corresponding checks) can be avoided.

Quoted 2 lines

Increasing the chance of bugs and bothers developers for analyzer sounds like strange.

There are different opinions around source code clarity.

Quoted 2 lines

(And we are initializing those for avoiding to be bothered by choosing correct label.

Pointer initialisation is convenient and safe in some use cases, isn't it?

Quoted 3 lines

If we really care micro optimize, initialization of those should not be required and should not be touched on other paths, and gcc can warn its usage.)

I imagine that a software optimiser can eventually perform better job if unneeded statements could be omitted, couldn't it?

Regards,
Markus

#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
#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
#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
maintainer Acked-by
#165 lore raw

Re: fs-fat: Less function calls in fat_fill_super() after error detection

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

More labels are more chances of bug (and we don't care micro optimize on this error path), isn't it?

I would prefer that a few jump targets can be redirected so that unnecessary function calls (and corresponding checks) can be avoided.

It is from real bugs in my experience, it saw several times those (mine and other guys, in linux and others). And I think it doesn't have value to maintain labels for micro optimization in *this error path* though.

So, if you or analyzer can check bugs by the patches affect to those label usage in future,

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#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
#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
#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
#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
#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
#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
#551 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

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

#624 lore raw

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

In reply to SF Markus Elfring
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

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

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

In reply to Lino Sanfilippo
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

#625 lore raw

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

In reply to Eric Dumazet
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

#555 lore raw

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

In reply to SF Markus Elfring
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

#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
Reviewed-by on v1 1/1
#541 lore raw

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

In reply to SF Markus Elfring
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]
#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

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

Re: [PATCH v2] fs-fat: Less function calls in fat_fill_super() after error detection

In reply to OGAWA Hirofumi
Quoted 10 lines · OGAWA Hirofumi
Quoted 7 lines · Julia Lawall
Quoted 2 lines

iput() checks NULL of inode. What is wrong just remove NULL check, instead of adding new jump labels?

Personally, I prefer that code that can be statically determined not to need to be executed not to be executed. It can make the code easier to understand, because each function is only called when doing so is useful, and it can be helpful to static analysis.

Quoted 4 lines

Hm, first of all, we want to prevent the bugs. More labels are more chances of bug (and we don't care micro optimize on this error path), isn't it? Increasing the chance of bugs and bothers developers for analyzer sounds like strange.

Oh wow! Absolutely not. "One Err Bugs" are one of the most common kinds of bugs we have in the kernel. This is where you have just one error label and the bugs look like this:

err:

	kfree(foo->bar);
	kfree(foo);

but foo is NULL. Mixing the error paths together it always creates confusion. I fix so many of these bugs... We get a few new ones every week.

Meanwhile Markus's error labels are absolutely useless. They give no indication of what going to the label does.

regards,
dan carpenter

#167 lore raw

Re: [PATCH v2] fs-fat: Less function calls in fat_fill_super() after error detection

Quoted 20 lines · Dan Carpenter
Quoted 10 lines · OGAWA Hirofumi
Quoted 7 lines · Julia Lawall
Quoted 2 lines

iput() checks NULL of inode. What is wrong just remove NULL check, instead of adding new jump labels?

Personally, I prefer that code that can be statically determined not to need to be executed not to be executed. It can make the code easier to understand, because each function is only called when doing so is useful, and it can be helpful to static analysis.

Quoted 4 lines

Hm, first of all, we want to prevent the bugs. More labels are more chances of bug (and we don't care micro optimize on this error path), isn't it? Increasing the chance of bugs and bothers developers for analyzer sounds like strange.

Oh wow! Absolutely not. "One Err Bugs" are one of the most common kinds of bugs we have in the kernel. This is where you have just one error label and the bugs look like this:

Quoted 7 lines

err:

	kfree(foo->bar);
	kfree(foo);

but foo is NULL. Mixing the error paths together it always creates confusion. I fix so many of these bugs... We get a few new ones every week.

Just for concreteness, from drivers/clk/st/clkgen-mux.c (- indicates lines of interest, not lines to remove):

@@ -722,7 +722,6 @@ void __init st_of_clkgen_vcc_setup(struc

                return;

        clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
-       if (!clk_data)
                goto err;

        clk_data->clk_num = VCC_MAX_CHANNELS;
@@ -808,7 +807,6 @@ void __init st_of_clkgen_vcc_setup(struc
        return;

err:

-       for (i = 0; i < clk_data->clk_num; i++) {
                struct clk_composite *composite;

                if (!clk_data->clks[i])

julia

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"

In reply to SF Markus Elfring

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

#568 lore raw

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

In reply to SF Markus Elfring

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

#168 lore raw

Re: [PATCH v2] fs-fat: Less function calls in fat_fill_super() after error detection

In reply to Dan Carpenter
Quoted 2 lines

Mixing the error paths together it always creates confusion. I fix so many of these bugs... We get a few new ones every week.

Would you like to get help here from any other automatic semantic patch approaches?

Quoted 2 lines

Meanwhile Markus's error labels are absolutely useless. They give no indication of what going to the label does.

Which names would be better acceptable for you?

Regards,
Markus

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"

In reply to SF Markus Elfring
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,

Reviewed-by on v1 1/1
#523 lore raw

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

In reply to SF Markus Elfring
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

#570 lore raw

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

In reply to SF Markus Elfring
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

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

Re: [PATCH v2] fs-fat: Less function calls in fat_fill_super() after error detection

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

Meanwhile Markus's error labels are absolutely useless. They give no indication of what going to the label does.

Which names would be better acceptable for you?

You named it after the goto location but the label name should be based on the label location to say what the goto does. Something like "err_put_fsinfo", "err_put_fat", and "err_unload" or like that.

regards,
dan carpenter

maintainer Applied
#549 lore raw

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

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

maintainer
#557 lore raw

Re: 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
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

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

#170 lore raw

Re: [PATCH v2] fs-fat: Less function calls in fat_fill_super() after error detection

In reply to Dan Carpenter
Quoted 4 lines
Quoted 1 line

Which names would be better acceptable for you?

You named it after the goto location but the label name should be based on the label location to say what the goto does.

I find it easier occasionally to name a label similarly to the jump target. It seems that there are a few variations used for the affected identifiers.

Quoted 1 line

Something like "err_put_fsinfo", "err_put_fat", and "err_unload" or like that.

How do you think about to provide a patch with your preferred names if my chances are lower to suggest the pleasing ones directly in my first tries?

Regards,
Markus

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

In reply to SF Markus Elfring
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

#171 lore raw

Re: [PATCH v2] fs-fat: Less function calls in fat_fill_super() after error detection

In reply to SF Markus Elfring
Quoted 6 lines · SF Markus Elfring
Quoted 4 lines
Quoted 1 line

Which names would be better acceptable for you?

You named it after the goto location but the label name should be based on the label location to say what the goto does.

I find it easier occasionally to name a label similarly to the jump target.

That is a useless thing to do.

Quoted 1 line

It seems that there are a few variations used for the affected identifiers.

There is a lot of crap code in the kernel, yes.

regards,
dan carpenter

#172 lore raw

Re: [PATCH v2] fs-fat: Less function calls in fat_fill_super() after error detection

Quoted 6 lines · Dan Carpenter
Quoted 5 lines · SF Markus Elfring
Quoted 4 lines
Quoted 1 line

Which names would be better acceptable for you?

You named it after the goto location but the label name should be based on the label location to say what the goto does.

Quoted 7 lines
Quoted 1 line

I find it easier occasionally to name a label similarly to the jump target.

That is a useless thing to do.

Quoted 1 line

It seems that there are a few variations used for the affected identifiers.

There is a lot of crap code in the kernel, yes.

Does the label naming strategy appear in the conding style documentation anywhere? There are so many variants that just from looking at the code, it is hard to guess what is the best strategy. For example, out1, out2, etc are pretty uninformative, but they are concise and easy to spell correctly.

julia

#173 lore raw

PATCH 1/1 CodingStyle: add some more error handling guidelines

I added a paragraph on choosing label names, and updated the example code to use a better label name. I also cleaned up the example code to more modern style by moving the allocation out of the initializer and changing the NULL check.

Perhaps the most common type of error handling bug in the kernel is "one err bugs". CodingStyle already says that we should "avoid nesting" by using error labels and one err style error handling tends to have multiple indent levels, so this was already bad style. But I've added a new paragraph explaining how to avoid one err bugs by using multiple error labels which is, hopefully, more clear.

Documentation/CodingStyle +22 -5
index 9f28b14..9c8a234 100644
@@ -392,7 +392,12 @@ The goto statement comes in handy when a function exits from multiple
 locations and some common work such as cleanup has to be done.  If there is no
 cleanup needed then just return directly.
 
-The rationale is:
+Choose label names which say what the goto does or why the goto exists.  An
+example of a good name could be "out_buffer:" if the goto frees "buffer".  Avoid
+using GW-BASIC names like "err1:" and "err2:".  Also don't name them after the
+goto location like "err_kmalloc_failed:"
+
+The rationale for using gotos is:
 
 - unconditional statements are easier to understand and follow
 - nesting is reduced
@@ -403,9 +408,10 @@ The rationale is:
 int fun(int a)
 {
 	int result = 0;
-	char *buffer = kmalloc(SIZE);
+	char *buffer;
 
-	if (buffer == NULL)
+	buffer = kmalloc(SIZE);
+	if (!buffer)
 		return -ENOMEM;
 
 	if (condition1) {
@@ -413,14 +419,25 @@ int fun(int a)
 			...
 		}
 		result = 1;
-		goto out;
+		goto out_buffer;
 	}
 	...
-out:
+out_buffer:
 	kfree(buffer);
 	return result;
 }
 
+A common type of bug to be aware of it "one err bugs" which look like this:
+
+err:
+	kfree(foo->bar);
+	kfree(foo);
+	return ret;
+
+The bug in this code is that on some exit paths "foo" is NULL.  Normally the
+fix for this is to split it up into two error labels "err_bar:" and "err_foo:".
+
+
 		Chapter 8: Commenting
 
 Comments are good, but there is also a danger of over-commenting.  NEVER
Acked-by on v1 1/1
#174 lore raw

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

Documentation/CodingStyle The rationale is: · line 413

Quoted 9 lines
Documentation/CodingStyle +2 -2
@@ -403,9 +408,10 @@ The rationale is:
 int fun(int a)
 {
 	int result = 0;
-	char *buffer = kmalloc(SIZE);
+	char *buffer;
 
-	if (buffer == NULL)
+	buffer = kmalloc(SIZE);

kmalloc actually takes two arguments. Perhaps it would be better to show something that looks like a valid call.

Otherwise,

julia

Quoted 37 lines
Documentation/CodingStyle +14 -3
+	if (!buffer)
 		return -ENOMEM;
 
 	if (condition1) {
@@ -413,14 +419,25 @@ int fun(int a)
...
 		}
 		result = 1;
-		goto out;
+		goto out_buffer;
 	}
...
-out:
+out_buffer:
 	kfree(buffer);
 	return result;
 }
 
+A common type of bug to be aware of it "one err bugs" which look like this:
+
+err:
+	kfree(foo->bar);
+	kfree(foo);
+	return ret;
+
+The bug in this code is that on some exit paths "foo" is NULL.  Normally the
+fix for this is to split it up into two error labels "err_bar:" and "err_foo:".
+
+
 		Chapter 8: Commenting
 
 Comments are good, but there is also a danger of over-commenting.  NEVER
--

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

Acked-by on v1 1/2
#501 lore raw

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

In reply to SF Markus Elfring
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(-)
#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
#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
#175 lore raw

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

In reply to Julia Lawall
Quoted 2 lines · On Tue, 2 Dec 2014 10:09:02 +0100 (CET) Julia Lawall <[email protected]>…

kmalloc actually takes two arguments. Perhaps it would be better to show something that looks like a valid call.

Agreed; I took the liberty of sticking in a GFP_KERNEL as I applied the patch with Julia's ack.

Thanks,

jon

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

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

In reply to Julia Lawall
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

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

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

In reply to SF Markus Elfring

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

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

In reply to SF Markus Elfring

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

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

#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

Applied
#659 lore raw

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

In reply to SF Markus Elfring

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

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

In reply to Dan Carpenter
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

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

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

In reply to SF Markus Elfring
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);
#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
#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

Applied
#672 lore raw

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

In reply to SF Markus Elfring

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

[Cocci] Determination of the number for named function parameters

In reply to Julia Lawall
Quoted 3 lines

It is clear that there is some problem with ... matching a parameter-typed metavariable. This could be considered reasonable, because ... is not a (single) parameter.

How is the software support evolving for variadic macros and functions?

Does the OCaml scripting interface provide more information (besides the SmPL API) which can be useful in advanced source code analysis?

Regards,
Markus

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

[Cocci] Determination of the number for named function parameters

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

It is clear that there is some problem with ... matching a parameter-typed metavariable. This could be considered reasonable, because ... is not a (single) parameter.

How is the software support evolving for variadic macros and functions?

For functions, someone is working on it.

Quoted 2 lines

Does the OCaml scripting interface provide more information (besides the SmPL API) which can be useful in advanced source code analysis?

No.

julia

#674 lore raw

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

In reply to SF Markus Elfring
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

#1515 lore raw

[Cocci] Determination of the number for named function parameters

In reply to Julia Lawall
Quoted 4 lines
Quoted 2 lines

Does the OCaml scripting interface provide more information (besides the SmPL API) which can be useful in advanced source code analysis?

No.

How is the status about an abstract syntax tree interface which was mentioned in a wiki article a while ago?

Regards,
Markus

#1516 lore raw

[Cocci] Determination of the number for named function parameters

Quoted 7 lines · SF Markus Elfring
Quoted 4 lines
Quoted 2 lines

Does the OCaml scripting interface provide more information (besides the SmPL API) which can be useful in advanced source code analysis?

No.

How is the status about an abstract syntax tree interface which was mentioned in a wiki article a while ago?

No idea what you are referring to. In an ocaml script, if you declare a metavariable as:

(a,b) << r.e;

then b is the abstract syntax tree of e. You can eg process it using the visitors available visitor_c.ml.

julia

#1517 lore raw

[Cocci] Determination of the number for named function parameters

Quoted 6 lines

In an ocaml script, if you declare a metavariable as:

(a,b) << r.e;

then b is the abstract syntax tree of e. You can eg process it using the visitors available visitor_c.ml.

I am looking for more descriptions around the following information from the manual.

"...
The file parsing_c/ast_c.ml in the Coccinelle implementation gives some information about the structure of the abstract syntax tree.
..."

Regards,
Markus

#1518 lore raw

[Cocci] Determination of the number for named function parameters

Quoted 7 lines · SF Markus Elfring
Quoted 6 lines

In an ocaml script, if you declare a metavariable as:

(a,b) << r.e;

then b is the abstract syntax tree of e. You can eg process it using the visitors available visitor_c.ml.

Quoted 6 lines

I am looking for more descriptions around the following information from the manual.

"...
The file parsing_c/ast_c.ml in the Coccinelle implementation gives some information about the structure of the abstract syntax tree.
..."

That's all the information there is.

julia

#665 lore raw

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

In reply to Takashi Iwai
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

#176 lore raw

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

In reply to Dan Carpenter

Documentation/CodingStyle The goto statement comes in handy when a function exits from multiple · line 398

Quoted 13 lines
Documentation/CodingStyle +4 -1
index 9f28b14..9c8a234 100644
@@ -392,7 +392,12 @@ The goto statement comes in handy when a function exits from multiple
 locations and some common work such as cleanup has to be done.  If there is no
 cleanup needed then just return directly.
 
-The rationale is:
+Choose label names which say what the goto does or why the goto exists.  An
+[...]  Avoid
+using GW-BASIC names like "err1:" and "err2:".  Also don't name them after the
+goto location like "err_kmalloc_failed:"

I find this documentation approach not safe and clear enough so far.

* How should the reference to an other programming language help in the understanding of the recommended naming convention for jump labels?

* To which source code place should the word "location" refer to?
- jump source
- jump target

Regards,
Markus

#177 lore raw

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

Quoted 16 lines · SF Markus Elfring

Documentation/CodingStyle The goto statement comes in handy when a function exits from multiple · line 398

Quoted 13 lines
Documentation/CodingStyle +4 -1
index 9f28b14..9c8a234 100644
@@ -392,7 +392,12 @@ The goto statement comes in handy when a function exits from multiple
  locations and some common work such as cleanup has to be done.  If there is no
  cleanup needed then just return directly.
 
-The rationale is:
+Choose label names which say what the goto does or why the goto exists.  An
+[...]  Avoid
+using GW-BASIC names like "err1:" and "err2:".  Also don't name them after the
+goto location like "err_kmalloc_failed:"

I find this documentation approach not safe and clear enough so far.

Quoted 6 lines

* How should the reference to an other programming language help in the understanding of the recommended naming convention for jump labels?

* To which source code place should the word "location" refer to?
- jump source
- jump target

I think you digested the paragraph in too small bits. The term "goto location" looks synonymous to "jump source" to me.

Regards,
Arend

Quoted 6 lines

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

#666 lore raw

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

In reply to SF Markus Elfring

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

#179 lore raw

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

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

* To which source code place should the word "location" refer to?
- jump source
- jump target

jump target.

regards,
dan carpenter

#178 lore raw

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

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

* To which source code place should the word "location" refer to?
- jump source
- jump target

I think you digested the paragraph in too small bits.

I would prefer to reduce the probability for misunderstandings of the proposed wording a bit more.

Quoted 1 line

The term "goto location" looks synonymous to "jump source" to me.

I would interpret it differently because of the specific placement of this key word before an other term.

Regards,
Markus

#180 lore raw

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

In reply to Dan Carpenter
Quoted 7 lines · Dan Carpenter
Quoted 4 lines · SF Markus Elfring

* To which source code place should the word "location" refer to?
- jump source
- jump target

jump target.

I think you mean source? Or it really is ambiguous. The example was err_kmalloc_failed, which seems source-related.

julia

#187 lore raw

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

In reply to Dan Carpenter
Quoted 5 lines
Quoted 3 lines

* To which source code place should the word "location" refer to?
- jump source
- jump target

jump target.

Thanks for the clarification of your intention.

I wonder then why I got the feedback "That is a useless thing to do." from you yesterday.
I hope that we can still clarify our different opinions about specific implementation details in constructive ways.

Regards,
Markus

#181 lore raw

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

In reply to Julia Lawall
Quoted 4 lines · Julia Lawall
Quoted 2 lines · Dan Carpenter
Quoted 1 line · SF Markus Elfring
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

* To which source code place should the word "location" refer to?
- jump source
- jump target

jump target.

I think you mean source? Or it really is ambiguous. The example was err_kmalloc_failed, which seems source-related.

Yeah. You're right. I misread Markus's email. The goto location is where the goto is. The label location is where the label is.

regards,
dan carpenter

#188 lore raw

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

In reply to SF Markus Elfring

Sorry. I misread your email. If the code looks like this:

	foo = kmalloc();
	if (!foo)
		goto kmalloc_failed;

The "kmalloc_failed" doesn't add any information. We can see that kmalloc failed from the context.

regards,
dan carpenter

#189 lore raw

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

Quoted 7 lines

Sorry. I misread your email. If the code looks like this:

	foo = kmalloc();
	if (!foo)
		goto kmalloc_failed;

The "kmalloc_failed" doesn't add any information.

I find that this such a name approach would fit to your expectation of a source-oriented labeling of these identifiers.

Quoted 1 line

We can see that kmalloc failed from the context.

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

Regards,
Markus

#190 lore raw

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

Quoted 8 lines · SF Markus Elfring
Quoted 7 lines

Sorry. I misread your email. If the code looks like this:

	foo = kmalloc();
	if (!foo)
		goto kmalloc_failed;

The "kmalloc_failed" doesn't add any information.

Quoted 8 lines

I find that this such a name approach would fit to your expectation of a source-oriented labeling of these identifiers.

Quoted 1 line

We can see that kmalloc failed from the context.

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

I think Dan wants the label to be descriptive about the tasks needed in the exception handling itself. This makes sense as the exception handling steps may be reused for different failures in the code.

void foo(void)

{
	if (check_a())
		goto do_bar;

	sub_foo1();

	if (checck_b())
		goto do_bar;

	sub_foo2();
	return;

do_bar:

	bar();
}

Regards,
Arend

Quoted 6 lines

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