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 4 of 6

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

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

In reply to SF Markus Elfring

Hi,

Quoted 68 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 17:18:48 +0100

The meta_delete() function could be called in four cases by the em_meta_change() function during error handling even if the passed variable "meta" contained still a null pointer.

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

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Let us delete also unnecessary checks for the variables "err" and "meta" there.

---
 net/sched/em_meta.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
net/sched/em_meta.c +6 -6
index b5294ce..2aa67b1 100644
@@ -866,23 +866,23 @@ static int em_meta_change(struct net *net, void *data, int len,
 
 	err = nla_parse(tb, TCA_EM_META_MAX, data, len, meta_policy);
 	if (err < 0)
-		goto errout;
+		return err;
 
 	err = -EINVAL;
 	if (tb[TCA_EM_META_HDR] = NULL)
-		goto errout;
+		goto exit;
 	hdr = nla_data(tb[TCA_EM_META_HDR]);
 
 	if (TCF_META_TYPE(hdr->left.kind) != TCF_META_TYPE(hdr->right.kind) ||
 	    TCF_META_TYPE(hdr->left.kind) > TCF_META_TYPE_MAX ||
 	    TCF_META_ID(hdr->left.kind) > TCF_META_ID_MAX ||
 	    TCF_META_ID(hdr->right.kind) > TCF_META_ID_MAX)
-		goto errout;
+		goto exit;
 
 	meta = kzalloc(sizeof(*meta), GFP_KERNEL);
 	if (meta = NULL) {
 		err = -ENOMEM;
-		goto errout;
+		goto exit;
 	}
 
 	memcpy(&meta->lvalue.hdr, &hdr->left, sizeof(hdr->left));
@@ -891,20 +891,20 @@ static int em_meta_change(struct net *net, void *data, int len,
 	if (!meta_is_supported(&meta->lvalue) ||
 	    !meta_is_supported(&meta->rvalue)) {
 		err = -EOPNOTSUPP;
-		goto errout;
+		goto delete_meta;
 	}
 
 	if (meta_change_data(&meta->lvalue, tb[TCA_EM_META_LVALUE]) < 0 ||
 	    meta_change_data(&meta->rvalue, tb[TCA_EM_META_RVALUE]) < 0)
-		goto errout;
+		goto delete_meta;
 
 	m->datalen = sizeof(*meta);
 	m->data = (unsigned long) meta;
 

net/sched/em_meta.c static int em_meta_change(struct net *net, void *data, int len, · line 909

Quoted 10 lines
net/sched/em_meta.c +4 -4
-	err = 0;
-errout:
-	if (err && meta)
-		meta_delete(meta);
+	return 0;
+delete_meta:
+	meta_delete(meta);
+exit:
 	return err;
 }

Why do you use that exit label if it does nothing more than returning the error value? Also if nla_parse fails you dont use it but return the error directly. While using a label which is used only to return an error may be a matter of taste, its at least inconsistent to do both in a function, use such a label in one case and return immediately in another, isnt it?

Regards,
Lino

#754 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

Quoted 10 lines

net/sched/em_meta.c static int em_meta_change(struct net *net, void *data, int len, · line 909

Quoted 3 lines
net/sched/em_meta.c +1 -0
+exit:
 	return err;
 }

Why do you use that exit label if it does nothing more than returning the error value? Also if nla_parse fails you dont use it but return the error directly. While using a label which is used only to return an error may be a matter of taste, its at least inconsistent to do both in a function, use such a label in one case and return immediately in another, isnt it?

I find that all these cases correspond to the current Linux coding style documentation, doesn't it?

Regards,
Markus

#755 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

Quoted 4 lines · SF Markus Elfring

I find that all these cases correspond to the current Linux coding style documentation, doesn't it?

Sure, I think it does. But it was not coding style violation what I was reffering to.

Regards,
Lino

#756 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

Quoted 4 lines
Quoted 2 lines

I find that all these cases correspond to the current Linux coding style documentation, doesn't it?

Sure, I think it does.

Thanks for your acknowledgement.

Quoted 1 line

But it was not coding style violation what I was reffering to.

Do you suggest any fine-tuning for the affected documentation so that I would tweak my update suggestion once more?

Regards,
Markus

#757 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

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

I find that all these cases correspond to the current Linux coding style documentation, doesn't it?

Sure, I think it does.

Quoted 8 lines

Thanks for your acknowledgement.

Quoted 1 line

But it was not coding style violation what I was reffering to.

Do you suggest any fine-tuning for the affected documentation so that I would tweak my update suggestion once more?

No I dont think that any documentation has to be adjusted. If you agree with me you should adjust the patch accordingly and resend it. Otherwise keep it as it is.

Regards,
Lino

#758 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

In reply to SF Markus Elfring

net/sched/em_meta.c static int em_meta_change(struct net *net, void *data, int len, · line 907

Quoted 3 lines · SF Markus Elfring
net/sched/em_meta.c +0 -3
-errout:
-	if (err && meta)
-		meta_delete(meta);

Since this patch seems to be about optimization and cleanup you should probably also remove the now unnecessary initialization of "meta" with NULL at the beginning of the function...

Regards,
Lino

#759 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

Quoted 7 lines

net/sched/em_meta.c static int em_meta_change(struct net *net, void *data, int len, · line 907

Quoted 3 lines
net/sched/em_meta.c +0 -3
-errout:
-	if (err && meta)
-		meta_delete(meta);

Since this patch seems to be about optimization and cleanup you should probably also remove the now unnecessary initialization of "meta" with NULL at the beginning of the function...

Will the optimiser of the C compiler drop any remaining unnecessary variable initialisations?

Do you want another update step here?

Regards,
Markus

#760 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

Quoted 11 lines · SF Markus Elfring
Quoted 7 lines

net/sched/em_meta.c static int em_meta_change(struct net *net, void *data, int len, · line 907

Quoted 3 lines
net/sched/em_meta.c +0 -3
-errout:
-	if (err && meta)
-		meta_delete(meta);

Since this patch seems to be about optimization and cleanup you should probably also remove the now unnecessary initialization of "meta" with NULL at the beginning of the function...

Will the optimiser of the C compiler drop any remaining unnecessary variable initialisations?

I dont know if that matters, since the code is not only used by compilers but also read by humans.

Quoted 2 lines

Do you want another update step here?

I am not the one who decides if this patch is acceptable or not. But I vote for a removal of that assignment (as a part of the same patch).

Regards,
Lino

maintainer
#761 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 17:34:54 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 17:18:48 +0100

The meta_delete() function could be called in four cases by the em_meta_change() function during error handling even if the passed variable "meta" contained still a null pointer.

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

Quoted 7 lines

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Let us delete also unnecessary checks for the variables "err" and "meta" there.

I kind of like the way the code is now, branching to the end of the function even when cleanups are not necessary.

Inter-function return statements make code harder to audit, for locking errors, resource leaks, etc.

#762 lore raw

Re: [PATCH] net: sched: One function call less in em_meta_change() after error detection

Quoted 6 lines
Quoted 6 lines

The meta_delete() function could be called in four cases by the em_meta_change() function during error handling even if the passed variable "meta" contained still a null pointer.

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

Quoted 8 lines
Quoted 5 lines

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Let us delete also unnecessary checks for the variables "err" and "meta" there.

I kind of like the way the code is now, branching to the end of the function even when cleanups are not necessary.

I would appreciate if the affected exception handling can become also a bit more efficient.

Regards,
Markus

#763 lore raw

PATCH 1/1 net: sctp: Deletion of an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 18:10:03 +0100

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

This issue was detected by using the Coccinelle software.

---
 net/sctp/associola.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/sctp/associola.c +1 -2
index f791edd..3c2aefc 100644
@@ -391,8 +391,7 @@ void sctp_association_free(struct sctp_association *asoc)
 	sctp_asconf_queue_teardown(asoc);
 
 	/* Free pending address space being deleted */
-	if (asoc->asconf_addr_del_pending != NULL)
-		kfree(asoc->asconf_addr_del_pending);
+	kfree(asoc->asconf_addr_del_pending);
 
 	/* AUTH - Free the endpoint shared keys */
 	sctp_auth_destroy_keys(&asoc->endpoint_shared_keys);
Signature · 1 line
2.2.2
Acked-by on v1 1/1
#764 lore raw

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

Quoted 31 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 18:10:03 +0100

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

This issue was detected by using the Coccinelle software.

---
 net/sctp/associola.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/sctp/associola.c +1 -2
index f791edd..3c2aefc 100644
@@ -391,8 +391,7 @@ void sctp_association_free(struct sctp_association *asoc)
 	sctp_asconf_queue_teardown(asoc);
 
 	/* Free pending address space being deleted */
-	if (asoc->asconf_addr_del_pending != NULL)
-		kfree(asoc->asconf_addr_del_pending);
+	kfree(asoc->asconf_addr_del_pending);
 
 	/* AUTH - Free the endpoint shared keys */
 	sctp_auth_destroy_keys(&asoc->endpoint_shared_keys);
Signature · 1 line
2.2.2

Sure, seems reasonable

maintainer Applied
#765 lore raw

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

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 18:15:59 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 18:10:03 +0100

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

This issue was detected by using the Coccinelle software.

Applied to net-next, thanks.

#766 lore raw

cover netlabel: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 22:00:14 +0100

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

Markus Elfring (3):
Deletion of an unnecessary check before the function call "cipso_v4_doi_putdef" Deletion of an unnecessary check before the function call "cipso_v4_doi_free" Less function calls in netlbl_mgmt_add_common() after error detection

 net/netlabel/netlabel_cipso_v4.c |  3 +--
 net/netlabel/netlabel_mgmt.c     | 47 ++++++++++++++++++++--------------------
 2 files changed, 24 insertions(+), 26 deletions(-)
Signature · 1 line
2.2.2
#767 lore raw

PATCH 1/3 netlabel: Deletion of an unnecessary check before the function call "cipso_v4_doi_putdef"

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 19:09:50 +0100

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

This issue was detected by using the Coccinelle software.

---
 net/netlabel/netlabel_mgmt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/netlabel/netlabel_mgmt.c +1 -2
index 8b3b789..f5807f5 100644
@@ -242,8 +242,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 	return 0;
 
 add_failure:
-	if (cipsov4)
-		cipso_v4_doi_putdef(cipsov4);
+	cipso_v4_doi_putdef(cipsov4);
 	if (entry)
 		kfree(entry->domain);
 	kfree(addrmap);
Signature · 1 line
2.2.2
maintainer Acked-by on v1 1/3
#768 lore raw

Re: [PATCH 1/3] netlabel: Deletion of an unnecessary check before the function call "cipso_v4_doi_putdef"

Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 19:09:50 +0100

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

Quoted 6 lines

This issue was detected by using the Coccinelle software.

---
 net/netlabel/netlabel_mgmt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 17 lines
net/netlabel/netlabel_mgmt.c +1 -3
index 8b3b789..f5807f5 100644
@@ -242,8 +242,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
        return 0;
 
 add_failure:
-       if (cipsov4)
-               cipso_v4_doi_putdef(cipsov4);
+       cipso_v4_doi_putdef(cipsov4);
        if (entry)
                kfree(entry->domain);
        kfree(addrmap);
--

2.2.2

Signature · 2 lines
paul moore
www.paul-moore.com
#769 lore raw

PATCH 2/3 netlabel: Deletion of an unnecessary check before the function call "cipso_v4_doi_free"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 19:35:59 +0100

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

This issue was detected by using the Coccinelle software.

---
 net/netlabel/netlabel_cipso_v4.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/netlabel/netlabel_cipso_v4.c +1 -2
index 1796253..7fd1104 100644
@@ -324,8 +324,7 @@ static int netlbl_cipsov4_add_std(struct genl_info *info,
 	return 0;
 
 add_std_failure:
-	if (doi_def)
-		cipso_v4_doi_free(doi_def);
+	cipso_v4_doi_free(doi_def);
 	return ret_val;
 }
 
Signature · 1 line
2.2.2
maintainer Acked-by on v1 2/3
#770 lore raw

Re: [PATCH 2/3] netlabel: Deletion of an unnecessary check before the function call "cipso_v4_doi_free"

Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 19:35:59 +0100

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

Quoted 6 lines

This issue was detected by using the Coccinelle software.

---
 net/netlabel/netlabel_cipso_v4.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 17 lines
net/netlabel/netlabel_cipso_v4.c +1 -3
index 1796253..7fd1104 100644
@@ -324,8 +324,7 @@ static int netlbl_cipsov4_add_std(struct genl_info *info,
        return 0;
 
 add_std_failure:
-       if (doi_def)
-               cipso_v4_doi_free(doi_def);
+       cipso_v4_doi_free(doi_def);
        return ret_val;
 }
 
--

2.2.2

Signature · 2 lines
paul moore
www.paul-moore.com
#771 lore raw

PATCH 3/3 netlabel: Less function calls in netlbl_mgmt_add_common() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 21:55:48 +0100

The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases by the netlbl_mgmt_add_common() function during error handling even if the passed variables contained still a null pointer.

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

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Let us delete also an unnecessary check for the variable "entry" there.

---
 net/netlabel/netlabel_mgmt.c | 46 ++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)
net/netlabel/netlabel_mgmt.c +23 -23
index f5807f5..17f1ed5 100644
@@ -99,17 +99,15 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 	u32 tmp_val;
 
 	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
-	if (entry = NULL) {
-		ret_val = -ENOMEM;
-		goto add_failure;
-	}
+	if (!entry)
+		return -ENOMEM;
 	entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]);
 	if (info->attrs[NLBL_MGMT_A_DOMAIN]) {
 		size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]);
 		entry->domain = kmalloc(tmp_size, GFP_KERNEL);
 		if (entry->domain = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto free_entry;
 		}
 		nla_strlcpy(entry->domain,
 			    info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size);
@@ -125,16 +123,16 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		break;
 	case NETLBL_NLTYPE_CIPSOV4:
 		if (!info->attrs[NLBL_MGMT_A_CV4DOI])
-			goto add_failure;
+			goto free_domain;
 
 		tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]);
 		cipsov4 = cipso_v4_doi_getdef(tmp_val);
 		if (cipsov4 = NULL)
-			goto add_failure;
+			goto free_domain;
 		entry->def.cipso = cipsov4;
 		break;
 	default:
-		goto add_failure;
+		goto free_domain;
 	}
 
 	if (info->attrs[NLBL_MGMT_A_IPV4ADDR]) {
@@ -145,7 +143,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
 		if (addrmap = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto doi_put_def;
 		}
 		INIT_LIST_HEAD(&addrmap->list4);
 		INIT_LIST_HEAD(&addrmap->list6);
@@ -153,12 +151,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV4ADDR]) ! 		    sizeof(struct in_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto free_address_map;
 		}
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV4MASK]) ! 		    sizeof(struct in_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto free_address_map;
 		}
 		addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]);
 		mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]);
@@ -166,7 +164,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		map = kzalloc(sizeof(*map), GFP_KERNEL);
 		if (map = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto free_address_map;
 		}
 		map->list.addr = addr->s_addr & mask->s_addr;
 		map->list.mask = mask->s_addr;
@@ -178,7 +176,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		ret_val = netlbl_af4list_add(&map->list, &addrmap->list4);
 		if (ret_val != 0) {
 			kfree(map);
-			goto add_failure;
+			goto free_address_map;
 		}
 
 		entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -192,7 +190,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
 		if (addrmap = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto doi_put_def;
 		}
 		INIT_LIST_HEAD(&addrmap->list4);
 		INIT_LIST_HEAD(&addrmap->list6);
@@ -200,12 +198,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV6ADDR]) ! 		    sizeof(struct in6_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto free_address_map;
 		}
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV6MASK]) ! 		    sizeof(struct in6_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto free_address_map;
 		}
 		addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]);
 		mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]);
@@ -213,7 +211,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		map = kzalloc(sizeof(*map), GFP_KERNEL);
 		if (map = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto free_address_map;
 		}
 		map->list.addr = *addr;
 		map->list.addr.s6_addr32[0] &= mask->s6_addr32[0];
@@ -227,7 +225,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		ret_val = netlbl_af6list_add(&map->list, &addrmap->list6);
 		if (ret_val != 0) {
 			kfree(map);
-			goto add_failure;
+			goto free_address_map;
 		}
 
 		entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -237,15 +235,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 
 	ret_val = netlbl_domhsh_add(entry, audit_info);
 	if (ret_val != 0)
-		goto add_failure;
+		goto free_address_map;
 
 	return 0;
 
-add_failure:
-	cipso_v4_doi_putdef(cipsov4);
-	if (entry)
-		kfree(entry->domain);
+free_address_map:
 	kfree(addrmap);
+doi_put_def:
+	cipso_v4_doi_putdef(cipsov4);
+free_domain:
+	kfree(entry->domain);
+free_entry:
 	kfree(entry);
 	return ret_val;
 }
Signature · 1 line
2.2.2
maintainer
#772 lore raw

Re: [PATCH 3/3] netlabel: Less function calls in netlbl_mgmt_add_common() after error detection

Quoted 23 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 31 Jan 2015 21:55:48 +0100

The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases by the netlbl_mgmt_add_common() function during error handling even if the passed variables contained still a null pointer.

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

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Let us delete also an unnecessary check for the variable "entry" there.

---
 net/netlabel/netlabel_mgmt.c | 46 ++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)
net/netlabel/netlabel_mgmt.c +0 -0
index f5807f5..17f1ed5 100644

...

Quoted 13 lines
net/netlabel/netlabel_mgmt.c +1 -5
@@ -237,15 +235,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 
        ret_val = netlbl_domhsh_add(entry, audit_info);
        if (ret_val != 0)
-               goto add_failure;
+               goto free_address_map;
 
        return 0;
 
-add_failure:
-       cipso_v4_doi_putdef(cipsov4);
-       if (entry)
-               kfree(entry->domain);

net/netlabel/netlabel_mgmt.c static int netlbl_mgmt_add_common(struct genl_info *info, · line 251

Quoted 10 lines
net/netlabel/netlabel_mgmt.c +6 -0
+free_address_map:
        kfree(addrmap);
+doi_put_def:
+       cipso_v4_doi_putdef(cipsov4);
+free_domain:
+       kfree(entry->domain);
+free_entry:
        kfree(entry);
        return ret_val;
 }

It would be nice if you could stick with the goto label naming style in the rest of the file, e.g. "add_free_addrmap"/"add_put_doi_def"/"add_free_domain"/"add_free_entry".

Signature · 2 lines
paul moore
www.paul-moore.com
#773 lore raw

PATCH v2 3/3 netlabel: Less function calls in netlbl_mgmt_add_common() after error detection

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 11:11:29 +0100

The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases by the netlbl_mgmt_add_common() function during error handling even if the passed variables contained still a null pointer.

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

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Let us delete also an unnecessary check for the variable "entry" there.

---
 net/netlabel/netlabel_mgmt.c | 49 ++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 25 deletions(-)
net/netlabel/netlabel_mgmt.c +24 -25
index f5807f5..7044074 100644
@@ -93,23 +93,20 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 				  struct netlbl_audit *audit_info)
 {
 	int ret_val = -EINVAL;
-	struct netlbl_dom_map *entry = NULL;
 	struct netlbl_domaddr_map *addrmap = NULL;
 	struct cipso_v4_doi *cipsov4 = NULL;
 	u32 tmp_val;
+	struct netlbl_dom_map *entry = kzalloc(sizeof(*entry), GFP_KERNEL);
 
-	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
-	if (entry = NULL) {
-		ret_val = -ENOMEM;
-		goto add_failure;
-	}
+	if (!entry)
+		return -ENOMEM;
 	entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]);
 	if (info->attrs[NLBL_MGMT_A_DOMAIN]) {
 		size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]);
 		entry->domain = kmalloc(tmp_size, GFP_KERNEL);
 		if (entry->domain = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_free_entry;
 		}
 		nla_strlcpy(entry->domain,
 			    info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size);
@@ -125,16 +122,16 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		break;
 	case NETLBL_NLTYPE_CIPSOV4:
 		if (!info->attrs[NLBL_MGMT_A_CV4DOI])
-			goto add_failure;
+			goto add_free_domain;
 
 		tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]);
 		cipsov4 = cipso_v4_doi_getdef(tmp_val);
 		if (cipsov4 = NULL)
-			goto add_failure;
+			goto add_free_domain;
 		entry->def.cipso = cipsov4;
 		break;
 	default:
-		goto add_failure;
+		goto add_free_domain;
 	}
 
 	if (info->attrs[NLBL_MGMT_A_IPV4ADDR]) {
@@ -145,7 +142,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
 		if (addrmap = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_doi_put_def;
 		}
 		INIT_LIST_HEAD(&addrmap->list4);
 		INIT_LIST_HEAD(&addrmap->list6);
@@ -153,12 +150,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV4ADDR]) ! 		    sizeof(struct in_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV4MASK]) ! 		    sizeof(struct in_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]);
 		mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]);
@@ -166,7 +163,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		map = kzalloc(sizeof(*map), GFP_KERNEL);
 		if (map = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		map->list.addr = addr->s_addr & mask->s_addr;
 		map->list.mask = mask->s_addr;
@@ -178,7 +175,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		ret_val = netlbl_af4list_add(&map->list, &addrmap->list4);
 		if (ret_val != 0) {
 			kfree(map);
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 
 		entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -192,7 +189,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
 		if (addrmap = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_doi_put_def;
 		}
 		INIT_LIST_HEAD(&addrmap->list4);
 		INIT_LIST_HEAD(&addrmap->list6);
@@ -200,12 +197,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV6ADDR]) ! 		    sizeof(struct in6_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV6MASK]) ! 		    sizeof(struct in6_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]);
 		mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]);
@@ -213,7 +210,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		map = kzalloc(sizeof(*map), GFP_KERNEL);
 		if (map = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		map->list.addr = *addr;
 		map->list.addr.s6_addr32[0] &= mask->s6_addr32[0];
@@ -227,7 +224,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		ret_val = netlbl_af6list_add(&map->list, &addrmap->list6);
 		if (ret_val != 0) {
 			kfree(map);
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 
 		entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -237,15 +234,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 
 	ret_val = netlbl_domhsh_add(entry, audit_info);
 	if (ret_val != 0)
-		goto add_failure;
+		goto add_free_addrmap;
 
 	return 0;
 
-add_failure:
-	cipso_v4_doi_putdef(cipsov4);
-	if (entry)
-		kfree(entry->domain);
+add_free_addrmap:
 	kfree(addrmap);
+add_doi_put_def:
+	cipso_v4_doi_putdef(cipsov4);
+add_free_domain:
+	kfree(entry->domain);
+add_free_entry:
 	kfree(entry);
 	return ret_val;
 }
Signature · 1 line
2.2.2
maintainer Acked-by on v2 3/3
#774 lore raw

Re: [PATCH v2 3/3] netlabel: Less function calls in netlbl_mgmt_add_common() after error detection

Quoted 12 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 11:11:29 +0100

The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases by the netlbl_mgmt_add_common() function during error handling even if the passed variables contained still a null pointer.

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

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

Quoted 6 lines

* Let us delete also an unnecessary check for the variable "entry" there.

---
 net/netlabel/netlabel_mgmt.c | 49 ++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 25 deletions(-)

Thanks for fixing the label names.

Quoted 158 lines
net/netlabel/netlabel_mgmt.c +24 -26
index f5807f5..7044074 100644
@@ -93,23 +93,20 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                                  struct netlbl_audit *audit_info)
 {
        int ret_val = -EINVAL;
-       struct netlbl_dom_map *entry = NULL;
        struct netlbl_domaddr_map *addrmap = NULL;
        struct cipso_v4_doi *cipsov4 = NULL;
        u32 tmp_val;
+       struct netlbl_dom_map *entry = kzalloc(sizeof(*entry), GFP_KERNEL);
 
-       entry = kzalloc(sizeof(*entry), GFP_KERNEL);
-       if (entry = NULL) {
-               ret_val = -ENOMEM;
-               goto add_failure;
-       }
+       if (!entry)
+               return -ENOMEM;
        entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]);
        if (info->attrs[NLBL_MGMT_A_DOMAIN]) {
                size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]);
                entry->domain = kmalloc(tmp_size, GFP_KERNEL);
                if (entry->domain = NULL) {
                        ret_val = -ENOMEM;
-                       goto add_failure;
+                       goto add_free_entry;
                }
                nla_strlcpy(entry->domain,
                            info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size);
@@ -125,16 +122,16 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                break;
        case NETLBL_NLTYPE_CIPSOV4:
                if (!info->attrs[NLBL_MGMT_A_CV4DOI])
-                       goto add_failure;
+                       goto add_free_domain;
 
                tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]);
                cipsov4 = cipso_v4_doi_getdef(tmp_val);
                if (cipsov4 = NULL)
-                       goto add_failure;
+                       goto add_free_domain;
                entry->def.cipso = cipsov4;
                break;
        default:
-               goto add_failure;
+               goto add_free_domain;
        }
 
        if (info->attrs[NLBL_MGMT_A_IPV4ADDR]) {
@@ -145,7 +142,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
                if (addrmap = NULL) {
                        ret_val = -ENOMEM;
-                       goto add_failure;
+                       goto add_doi_put_def;
                }
                INIT_LIST_HEAD(&addrmap->list4);
                INIT_LIST_HEAD(&addrmap->list6);
@@ -153,12 +150,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                if (nla_len(info->attrs[NLBL_MGMT_A_IPV4ADDR]) !>                     sizeof(struct in_addr)) {
                        ret_val = -EINVAL;
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
                if (nla_len(info->attrs[NLBL_MGMT_A_IPV4MASK]) !>                     sizeof(struct in_addr)) {
                        ret_val = -EINVAL;
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
                addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]);
                mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]);
@@ -166,7 +163,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                map = kzalloc(sizeof(*map), GFP_KERNEL);
                if (map = NULL) {
                        ret_val = -ENOMEM;
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
                map->list.addr = addr->s_addr & mask->s_addr;
                map->list.mask = mask->s_addr;
@@ -178,7 +175,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                ret_val = netlbl_af4list_add(&map->list, &addrmap->list4);
                if (ret_val != 0) {
                        kfree(map);
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
 
                entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -192,7 +189,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
                if (addrmap = NULL) {
                        ret_val = -ENOMEM;
-                       goto add_failure;
+                       goto add_doi_put_def;
                }
                INIT_LIST_HEAD(&addrmap->list4);
                INIT_LIST_HEAD(&addrmap->list6);
@@ -200,12 +197,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                if (nla_len(info->attrs[NLBL_MGMT_A_IPV6ADDR]) !>                     sizeof(struct in6_addr)) {
                        ret_val = -EINVAL;
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
                if (nla_len(info->attrs[NLBL_MGMT_A_IPV6MASK]) !>                     sizeof(struct in6_addr)) {
                        ret_val = -EINVAL;
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
                addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]);
                mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]);
@@ -213,7 +210,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                map = kzalloc(sizeof(*map), GFP_KERNEL);
                if (map = NULL) {
                        ret_val = -ENOMEM;
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
                map->list.addr = *addr;
                map->list.addr.s6_addr32[0] &= mask->s6_addr32[0];
@@ -227,7 +224,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
                ret_val = netlbl_af6list_add(&map->list, &addrmap->list6);
                if (ret_val != 0) {
                        kfree(map);
-                       goto add_failure;
+                       goto add_free_addrmap;
                }
 
                entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -237,15 +234,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 
        ret_val = netlbl_domhsh_add(entry, audit_info);
        if (ret_val != 0)
-               goto add_failure;
+               goto add_free_addrmap;
 
        return 0;
 
-add_failure:
-       cipso_v4_doi_putdef(cipsov4);
-       if (entry)
-               kfree(entry->domain);
+add_free_addrmap:
        kfree(addrmap);
+add_doi_put_def:
+       cipso_v4_doi_putdef(cipsov4);
+add_free_domain:
+       kfree(entry->domain);
+add_free_entry:
        kfree(entry);
        return ret_val;
 }
--

2.2.2

Signature · 2 lines
paul moore
www.paul-moore.com
maintainer
#775 lore raw

Re: [PATCH v2 3/3] netlabel: Less function calls in netlbl_mgmt_add_common() after error detection

In reply to SF Markus Elfring

When you post a new version of a patch within a series, you must repost the entire series, not just the patch which is changing.

Thanks.

#776 lore raw

v3 cover netlabel: Deletion of a few unnecessary checks

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 11:15:56 +0100

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

Markus Elfring (3):
Deletion of an unnecessary check before the function call "cipso_v4_doi_putdef" Deletion of an unnecessary check before the function call "cipso_v4_doi_free" Less function calls in netlbl_mgmt_add_common() after error detection

 net/netlabel/netlabel_cipso_v4.c |  3 +--
 net/netlabel/netlabel_mgmt.c     | 50 +++++++++++++++++++---------------------
 2 files changed, 25 insertions(+), 28 deletions(-)
Signature · 1 line
2.2.2
#777 lore raw

PATCH v3 1/3 netlabel: Deletion of an unnecessary check before the function call "cipso_v4_doi_putdef"

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 10:01:45 +0100

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

This issue was detected by using the Coccinelle software.

---
 net/netlabel/netlabel_mgmt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/netlabel/netlabel_mgmt.c +1 -2
index 8b3b789..f5807f5 100644
@@ -242,8 +242,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 	return 0;
 
 add_failure:
-	if (cipsov4)
-		cipso_v4_doi_putdef(cipsov4);
+	cipso_v4_doi_putdef(cipsov4);
 	if (entry)
 		kfree(entry->domain);
 	kfree(addrmap);
Signature · 1 line
2.2.2
#778 lore raw

PATCH v3 2/3 netlabel: Deletion of an unnecessary check before the function call "cipso_v4_doi_free"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 10:40:30 +0100

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

This issue was detected by using the Coccinelle software.

---
 net/netlabel/netlabel_cipso_v4.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/netlabel/netlabel_cipso_v4.c +1 -2
index 1796253..7fd1104 100644
@@ -324,8 +324,7 @@ static int netlbl_cipsov4_add_std(struct genl_info *info,
 	return 0;
 
 add_std_failure:
-	if (doi_def)
-		cipso_v4_doi_free(doi_def);
+	cipso_v4_doi_free(doi_def);
 	return ret_val;
 }
 
Signature · 1 line
2.2.2
#779 lore raw

PATCH v3 3/3 netlabel: Less function calls in netlbl_mgmt_add_common() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 11:00:24 +0100

The functions "cipso_v4_doi_putdef" and "kfree" could be called in some cases by the netlbl_mgmt_add_common() function during error handling even if the passed variables contained still a null pointer.

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

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Let us delete also an unnecessary check for the variable "entry" there.

---
 net/netlabel/netlabel_mgmt.c | 49 ++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 25 deletions(-)
net/netlabel/netlabel_mgmt.c +24 -25
index f5807f5..7044074 100644
@@ -93,23 +93,20 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 				  struct netlbl_audit *audit_info)
 {
 	int ret_val = -EINVAL;
-	struct netlbl_dom_map *entry = NULL;
 	struct netlbl_domaddr_map *addrmap = NULL;
 	struct cipso_v4_doi *cipsov4 = NULL;
 	u32 tmp_val;
+	struct netlbl_dom_map *entry = kzalloc(sizeof(*entry), GFP_KERNEL);
 
-	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
-	if (entry = NULL) {
-		ret_val = -ENOMEM;
-		goto add_failure;
-	}
+	if (!entry)
+		return -ENOMEM;
 	entry->def.type = nla_get_u32(info->attrs[NLBL_MGMT_A_PROTOCOL]);
 	if (info->attrs[NLBL_MGMT_A_DOMAIN]) {
 		size_t tmp_size = nla_len(info->attrs[NLBL_MGMT_A_DOMAIN]);
 		entry->domain = kmalloc(tmp_size, GFP_KERNEL);
 		if (entry->domain = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_free_entry;
 		}
 		nla_strlcpy(entry->domain,
 			    info->attrs[NLBL_MGMT_A_DOMAIN], tmp_size);
@@ -125,16 +122,16 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		break;
 	case NETLBL_NLTYPE_CIPSOV4:
 		if (!info->attrs[NLBL_MGMT_A_CV4DOI])
-			goto add_failure;
+			goto add_free_domain;
 
 		tmp_val = nla_get_u32(info->attrs[NLBL_MGMT_A_CV4DOI]);
 		cipsov4 = cipso_v4_doi_getdef(tmp_val);
 		if (cipsov4 = NULL)
-			goto add_failure;
+			goto add_free_domain;
 		entry->def.cipso = cipsov4;
 		break;
 	default:
-		goto add_failure;
+		goto add_free_domain;
 	}
 
 	if (info->attrs[NLBL_MGMT_A_IPV4ADDR]) {
@@ -145,7 +142,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
 		if (addrmap = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_doi_put_def;
 		}
 		INIT_LIST_HEAD(&addrmap->list4);
 		INIT_LIST_HEAD(&addrmap->list6);
@@ -153,12 +150,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV4ADDR]) ! 		    sizeof(struct in_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV4MASK]) ! 		    sizeof(struct in_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		addr = nla_data(info->attrs[NLBL_MGMT_A_IPV4ADDR]);
 		mask = nla_data(info->attrs[NLBL_MGMT_A_IPV4MASK]);
@@ -166,7 +163,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		map = kzalloc(sizeof(*map), GFP_KERNEL);
 		if (map = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		map->list.addr = addr->s_addr & mask->s_addr;
 		map->list.mask = mask->s_addr;
@@ -178,7 +175,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		ret_val = netlbl_af4list_add(&map->list, &addrmap->list4);
 		if (ret_val != 0) {
 			kfree(map);
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 
 		entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -192,7 +189,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		addrmap = kzalloc(sizeof(*addrmap), GFP_KERNEL);
 		if (addrmap = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_doi_put_def;
 		}
 		INIT_LIST_HEAD(&addrmap->list4);
 		INIT_LIST_HEAD(&addrmap->list6);
@@ -200,12 +197,12 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV6ADDR]) ! 		    sizeof(struct in6_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		if (nla_len(info->attrs[NLBL_MGMT_A_IPV6MASK]) ! 		    sizeof(struct in6_addr)) {
 			ret_val = -EINVAL;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		addr = nla_data(info->attrs[NLBL_MGMT_A_IPV6ADDR]);
 		mask = nla_data(info->attrs[NLBL_MGMT_A_IPV6MASK]);
@@ -213,7 +210,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		map = kzalloc(sizeof(*map), GFP_KERNEL);
 		if (map = NULL) {
 			ret_val = -ENOMEM;
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 		map->list.addr = *addr;
 		map->list.addr.s6_addr32[0] &= mask->s6_addr32[0];
@@ -227,7 +224,7 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 		ret_val = netlbl_af6list_add(&map->list, &addrmap->list6);
 		if (ret_val != 0) {
 			kfree(map);
-			goto add_failure;
+			goto add_free_addrmap;
 		}
 
 		entry->def.type = NETLBL_NLTYPE_ADDRSELECT;
@@ -237,15 +234,17 @@ static int netlbl_mgmt_add_common(struct genl_info *info,
 
 	ret_val = netlbl_domhsh_add(entry, audit_info);
 	if (ret_val != 0)
-		goto add_failure;
+		goto add_free_addrmap;
 
 	return 0;
 
-add_failure:
-	cipso_v4_doi_putdef(cipsov4);
-	if (entry)
-		kfree(entry->domain);
+add_free_addrmap:
 	kfree(addrmap);
+add_doi_put_def:
+	cipso_v4_doi_putdef(cipsov4);
+add_free_domain:
+	kfree(entry->domain);
+add_free_entry:
 	kfree(entry);
 	return ret_val;
 }
Signature · 1 line
2.2.2
#780 lore raw

PATCH 1/1 jfs: Deletion of an unnecessary check before the function call "unload_nls"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 17:00:24 +0100

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

This issue was detected by using the Coccinelle software.

---
 fs/jfs/super.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/jfs/super.c +1 -2
index 16c3a95..5d30c56 100644
@@ -619,8 +619,7 @@ out_mount_failed:
 	iput(sbi->direct_inode);
 	sbi->direct_inode = NULL;
 out_unload:
-	if (sbi->nls_tab)
-		unload_nls(sbi->nls_tab);
+	unload_nls(sbi->nls_tab);
 out_kfree:
 	kfree(sbi);
 	return ret;
Signature · 1 line
2.2.2
#781 lore raw

Re: [PATCH] jfs: Deletion of an unnecessary check before the function call "unload_nls"

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 17:00:24 +0100

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

This issue was detected by using the Coccinelle software.

Thanks! I'll push this upstream.

Dave

Quoted 19 lines
---
 fs/jfs/super.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/jfs/super.c +1 -2
index 16c3a95..5d30c56 100644
@@ -619,8 +619,7 @@ out_mount_failed:
 	iput(sbi->direct_inode);
 	sbi->direct_inode = NULL;
 out_unload:
-	if (sbi->nls_tab)
-		unload_nls(sbi->nls_tab);
+	unload_nls(sbi->nls_tab);
 out_kfree:
 	kfree(sbi);
 	return ret;
#782 lore raw

PATCH 1/1 staging: gdm72xx: Deletion of an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 18:28:33 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/staging/gdm72xx/gdm_wimax.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gdm72xx/gdm_wimax.c +1 -1
index 9cab54b..ac901e6 100644
@@ -362,7 +362,7 @@ static int gdm_wimax_close(struct net_device *dev)
 
 static void kdelete(void **buf)
 {
-	if (buf && *buf) {
+	if (buf) {
 		kfree(*buf);
 		*buf = NULL;
 	}
Signature · 1 line
2.2.2
#783 lore raw

Re: [PATCH] staging: gdm72xx: Deletion of an unnecessary check before the function call "kfree"

Quoted 18 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 18:28:33 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/staging/gdm72xx/gdm_wimax.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gdm72xx/gdm_wimax.c +0 -0
index 9cab54b..ac901e6 100644

drivers/staging/gdm72xx/gdm_wimax.c static int gdm_wimax_close(struct net_device *dev) · line 368

Quoted 8 lines
drivers/staging/gdm72xx/gdm_wimax.c +1 -1
@@ -362,7 +362,7 @@ static int gdm_wimax_close(struct net_device *dev)
 
 static void kdelete(void **buf)
 {
-	if (buf && *buf) {
+	if (buf) {
 		kfree(*buf);
 		*buf = NULL;
 	}

Instead we should delete this function and have the driver use the "correct" kfree calls instead, right? That extra setting the buffer to NULL is a waste for most of these calls.

thanks,

greg k-h

#784 lore raw

cover mn88472: Delete an unnecessary check

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 20:00:17 +0100

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

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

 drivers/staging/media/mn88472/mn88472.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
Signature · 1 line
2.2.2
#785 lore raw

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

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 19:12:56 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/staging/media/mn88472/mn88472.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/media/mn88472/mn88472.c +1 -2
index 52de8f8..e7874ae 100644
@@ -315,8 +315,7 @@ static int mn88472_init(struct dvb_frontend *fe)
 
 	return 0;
 err:
-	if (fw)
-		release_firmware(fw);
+	release_firmware(fw);
 
 	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
Signature · 1 line
2.2.2
#786 lore raw

PATCH 2/2 mn88472: One function call less in mn88472_init() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 1 Feb 2015 19:34:37 +0100

The release_firmware() function was called in three cases by the mn88472_init() function during error handling even if the passed variable "fw" contained still a null pointer.

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

---
 drivers/staging/media/mn88472/mn88472.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/staging/media/mn88472/mn88472.c +5 -5
index e7874ae..3975a57 100644
@@ -286,7 +286,7 @@ static int mn88472_init(struct dvb_frontend *fe)
 
 	ret = regmap_write(dev->regmap[0], 0xf5, 0x03);
 	if (ret)
-		goto err;
+		goto firmware_release;
 
 	for (remaining = fw->size; remaining > 0;
 			remaining -= (dev->i2c_wr_max - 1)) {
@@ -299,13 +299,13 @@ static int mn88472_init(struct dvb_frontend *fe)
 		if (ret) {
 			dev_err(&client->dev,
 					"firmware download failed=%d\n", ret);
-			goto err;
+			goto firmware_release;
 		}
 	}
 
 	ret = regmap_write(dev->regmap[0], 0xf5, 0x00);
 	if (ret)
-		goto err;
+		goto firmware_release;
 
 	release_firmware(fw);
 	fw = NULL;
@@ -314,9 +314,9 @@ static int mn88472_init(struct dvb_frontend *fe)
 	dev->warm = true;
 
 	return 0;
-err:
+firmware_release:
 	release_firmware(fw);
-
+err:
 	dev_dbg(&client->dev, "failed=%d\n", ret);
 	return ret;
 }
Signature · 1 line
2.2.2
#787 lore raw

[media] staging: bcm2048: Delete an unnecessary check before the function call "video_unregister_device"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 13:20:23 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/staging/media/bcm2048/radio-bcm2048.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/media/bcm2048/radio-bcm2048.c +1 -3
index 60a57b2..f308078 100644
@@ -2684,9 +2684,7 @@ static int __exit bcm2048_i2c_driver_remove(struct i2c_client *client)
 		vd = bdev->videodev;
 
 		bcm2048_sysfs_unregister_properties(bdev, ARRAY_SIZE(attrs));
-
-		if (vd)
-			video_unregister_device(vd);
+		video_unregister_device(vd);
 
 		if (bdev->power_state)
 			bcm2048_set_power_state(bdev, BCM2048_POWER_OFF);
Signature · 1 line
2.2.2
#788 lore raw

cover md: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:51:43 +0100

Further update suggestions were taken into account together with results from static source code analysis.

Markus Elfring (3):
dm snapshot: Deletion of unnecessary checks before the function call "vfree" md/bitmap: Delete an unnecessary check before the function call "kfree" dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy"

 drivers/md/bitmap.c             | 10 +++++-----
 drivers/md/dm-ioctl.c           |  3 +--
 drivers/md/dm-snap-persistent.c | 14 ++++----------
 3 files changed, 10 insertions(+), 17 deletions(-)
Signature · 1 line
2.2.2
#789 lore raw

PATCH 1/3 dm snapshot: Deletion of unnecessary checks before the function call "vfree"

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 14:38:29 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/md/dm-snap-persistent.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/md/dm-snap-persistent.c +4 -10
index d6e8817..808b841 100644
@@ -200,16 +200,11 @@ err_area:
 
 static void free_area(struct pstore *ps)
 {
-	if (ps->area)
-		vfree(ps->area);
+	vfree(ps->area);
 	ps->area = NULL;
-
-	if (ps->zero_area)
-		vfree(ps->zero_area);
+	vfree(ps->zero_area);
 	ps->zero_area = NULL;
-
-	if (ps->header_area)
-		vfree(ps->header_area);
+	vfree(ps->header_area);
 	ps->header_area = NULL;
 }
 
@@ -605,8 +600,7 @@ static void persistent_dtr(struct dm_exception_store *store)
 	free_area(ps);
 
 	/* Allocated in persistent_read_metadata */
-	if (ps->callbacks)
-		vfree(ps->callbacks);
+	vfree(ps->callbacks);
 
 	kfree(ps);
 }
Signature · 1 line
2.2.2
#790 lore raw

PATCH 2/3 md/bitmap: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:10:57 +0100

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

* This issue was detected by using the Coccinelle software.

* Let us also move an assignment for the variable "pages" to the place directly before it is really needed for a loop.

* Let us also move another kfree() call into a block which should belong to a previous check for the variable "bp".

---
 drivers/md/bitmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +5 -5
index da3604e..47d72df 100644
@@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
 	bitmap_file_unmap(&bitmap->storage);
 
 	bp = bitmap->counts.bp;
-	pages = bitmap->counts.pages;
 
 	/* free all allocated memory */
-
-	if (bp) /* deallocate the page memory */
+	if (bp) { /* deallocate the page memory */
+		pages = bitmap->counts.pages;
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
-	kfree(bp);
+		kfree(bp);
+	}
 	kfree(bitmap);
 }
 
Signature · 1 line
2.2.2
#791 lore raw

Re: [PATCH 2/3] md/bitmap: Delete an unnecessary check before the function call "kfree"

Quoted 34 lines · On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:10:57 +0100

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

* This issue was detected by using the Coccinelle software.

* Let us also move an assignment for the variable "pages" to the place directly before it is really needed for a loop.

* Let us also move another kfree() call into a block which should belong to a previous check for the variable "bp".

---
 drivers/md/bitmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +2 -3
index da3604e..47d72df 100644
@@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
 	bitmap_file_unmap(&bitmap->storage);
 
 	bp = bitmap->counts.bp;
-	pages = bitmap->counts.pages;
 
 	/* free all allocated memory */
-
-	if (bp) /* deallocate the page memory */
+	if (bp) { /* deallocate the page memory */
+		pages = bitmap->counts.pages;

drivers/md/bitmap.c static void bitmap_free(struct bitmap *bitmap) · line 1600

Quoted 10 lines
drivers/md/bitmap.c +3 -2
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
-	kfree(bp);
+		kfree(bp);
+	}
 	kfree(bitmap);
 }
 

Hi,
I'm somewhat amused that you removed a test for one kfree, but imposed a test on another. I realised the second test was already there, but why not just:

drivers/md/bitmap.c +1 -1
index da3604e73e8a..ad13b2e1bf1f 100644
@@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap)
 
 	if (bp) /* deallocate the page memory */
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
 	kfree(bp);
 	kfree(bitmap);

It makes the intention of the patch much clearer.

I'd probably prefer to leave the code as it is. I don't think either patch is really an improvement in readability, and readability trumps performance in places like this.

Thanks,
NeilBrown

#792 lore raw

Re: [PATCH 2/3] md/bitmap: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

Am 02.02.2015 20:46, schrieb NeilBrown:

Quoted 68 lines
Quoted 34 lines · On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:10:57 +0100

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

* This issue was detected by using the Coccinelle software.

* Let us also move an assignment for the variable "pages" to the place directly before it is really needed for a loop.

* Let us also move another kfree() call into a block which should belong to a previous check for the variable "bp".

---
 drivers/md/bitmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +2 -3
index da3604e..47d72df 100644
@@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
 	bitmap_file_unmap(&bitmap->storage);
 
 	bp = bitmap->counts.bp;
-	pages = bitmap->counts.pages;
 
 	/* free all allocated memory */
-
-	if (bp) /* deallocate the page memory */
+	if (bp) { /* deallocate the page memory */
+		pages = bitmap->counts.pages;

drivers/md/bitmap.c static void bitmap_free(struct bitmap *bitmap) · line 1600

Quoted 10 lines
drivers/md/bitmap.c +3 -2
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
-	kfree(bp);
+		kfree(bp);
+	}
 	kfree(bitmap);
 }
 

Hi,
I'm somewhat amused that you removed a test for one kfree, but imposed a test on another. I realised the second test was already there, but why not just:

drivers/md/bitmap.c +1 -1
index da3604e73e8a..ad13b2e1bf1f 100644
@@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap)
 
 	if (bp) /* deallocate the page memory */
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
 	kfree(bp);
 	kfree(bitmap);
Quoted 6 lines

It makes the intention of the patch much clearer.

I'd probably prefer to leave the code as it is. I don't think either patch is really an improvement in readability, and readability trumps performance in places like this.

hello Neil,
just for my curiosity.
is it possible that a bp[k] exists but bp[k].hijacked is 0 ? if that case: kfree(bp) would free an object in use. otherwise hijacked seems useless here as it is possible to free everything.

re,
wh

#793 lore raw

Re: [PATCH 2/3] md/bitmap: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring
Quoted 86 lines · On Tue, 03 Feb 2015 09:48:01 +0100 walter harms <[email protected]> wrote:

Am 02.02.2015 20:46, schrieb NeilBrown:

Quoted 68 lines
Quoted 34 lines · On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:10:57 +0100

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

* This issue was detected by using the Coccinelle software.

* Let us also move an assignment for the variable "pages" to the place directly before it is really needed for a loop.

* Let us also move another kfree() call into a block which should belong to a previous check for the variable "bp".

---
 drivers/md/bitmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +2 -3
index da3604e..47d72df 100644
@@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
 	bitmap_file_unmap(&bitmap->storage);
 
 	bp = bitmap->counts.bp;
-	pages = bitmap->counts.pages;
 
 	/* free all allocated memory */
-
-	if (bp) /* deallocate the page memory */
+	if (bp) { /* deallocate the page memory */
+		pages = bitmap->counts.pages;

drivers/md/bitmap.c static void bitmap_free(struct bitmap *bitmap) · line 1600

Quoted 10 lines
drivers/md/bitmap.c +3 -2
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
-	kfree(bp);
+		kfree(bp);
+	}
 	kfree(bitmap);
 }
 

Hi,
I'm somewhat amused that you removed a test for one kfree, but imposed a test on another. I realised the second test was already there, but why not just:

drivers/md/bitmap.c +1 -1
index da3604e73e8a..ad13b2e1bf1f 100644
@@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap)
 
 	if (bp) /* deallocate the page memory */
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
 	kfree(bp);
 	kfree(bitmap);
Quoted 6 lines

It makes the intention of the patch much clearer.

I'd probably prefer to leave the code as it is. I don't think either patch is really an improvement in readability, and readability trumps performance in places like this.

hello Neil,
just for my curiosity.
is it possible that a bp[k] exists but bp[k].hijacked is 0 ? if that case: kfree(bp) would free an object in use. otherwise hijacked seems useless here as it is possible to free everything.

Quoted 2 lines

re,
wh

If .hijacked is 0, the .map is a pointer (that would need to be freed) or is NULL.
If .hijacked is 1, then .map has been re-tasked as 2 16-bit counters. They are probably bother zero at this point, but I think it is safer to completely skip the 'free' if 'hijacked' is set as in that case 'map' isn't a pointer.

NeilBrown

#794 lore raw

Re: [PATCH 2/3] md/bitmap: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

Am 03.02.2015 10:07, schrieb NeilBrown:

Quoted 88 lines · On Tue, 03 Feb 2015 09:48:01 +0100 walter harms <[email protected]> wrote:
Quoted 87 lines

Am 02.02.2015 20:46, schrieb NeilBrown:

Quoted 68 lines
Quoted 34 lines · On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:10:57 +0100

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

* This issue was detected by using the Coccinelle software.

* Let us also move an assignment for the variable "pages" to the place directly before it is really needed for a loop.

* Let us also move another kfree() call into a block which should belong to a previous check for the variable "bp".

---
 drivers/md/bitmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +2 -3
index da3604e..47d72df 100644
@@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
 	bitmap_file_unmap(&bitmap->storage);
 
 	bp = bitmap->counts.bp;
-	pages = bitmap->counts.pages;
 
 	/* free all allocated memory */
-
-	if (bp) /* deallocate the page memory */
+	if (bp) { /* deallocate the page memory */
+		pages = bitmap->counts.pages;

drivers/md/bitmap.c static void bitmap_free(struct bitmap *bitmap) · line 1600

Quoted 10 lines
drivers/md/bitmap.c +3 -2
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
-	kfree(bp);
+		kfree(bp);
+	}
 	kfree(bitmap);
 }
 

Hi,
I'm somewhat amused that you removed a test for one kfree, but imposed a test on another. I realised the second test was already there, but why not just:

drivers/md/bitmap.c +1 -1
index da3604e73e8a..ad13b2e1bf1f 100644
@@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap)
 
 	if (bp) /* deallocate the page memory */
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
 	kfree(bp);
 	kfree(bitmap);
Quoted 6 lines

It makes the intention of the patch much clearer.

I'd probably prefer to leave the code as it is. I don't think either patch is really an improvement in readability, and readability trumps performance in places like this.

hello Neil,
just for my curiosity.
is it possible that a bp[k] exists but bp[k].hijacked is 0 ? if that case: kfree(bp) would free an object in use. otherwise hijacked seems useless here as it is possible to free everything.

Quoted 9 lines
Quoted 2 lines

re,
wh

If .hijacked is 0, the .map is a pointer (that would need to be freed) or is NULL.
If .hijacked is 1, then .map has been re-tasked as 2 16-bit counters. They are probably bother zero at this point, but I think it is safer to completely skip the 'free' if 'hijacked' is set as in that case 'map' isn't a pointer.

It seems i was not clear enough, sorry about that.

we have a loop to kfree(bp[k].map), thats fine how it is done.

I am wondering about the kfree(bp) after the loop.
if bp[k].map is not freed for what ever reason how can it be freed later after a kfree(bp) ?

what is what i am missing ? Is there a hidden copy ?

re,
wh

#795 lore raw

Re: [PATCH 2/3] md/bitmap: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring
Quoted 103 lines · On Tue, 03 Feb 2015 11:19:58 +0100 walter harms <[email protected]> wrote:

Am 03.02.2015 10:07, schrieb NeilBrown:

Quoted 88 lines · On Tue, 03 Feb 2015 09:48:01 +0100 walter harms <[email protected]> wrote:
Quoted 87 lines

Am 02.02.2015 20:46, schrieb NeilBrown:

Quoted 68 lines
Quoted 34 lines · On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:10:57 +0100

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

* This issue was detected by using the Coccinelle software.

* Let us also move an assignment for the variable "pages" to the place directly before it is really needed for a loop.

* Let us also move another kfree() call into a block which should belong to a previous check for the variable "bp".

---
 drivers/md/bitmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +2 -3
index da3604e..47d72df 100644
@@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
 	bitmap_file_unmap(&bitmap->storage);
 
 	bp = bitmap->counts.bp;
-	pages = bitmap->counts.pages;
 
 	/* free all allocated memory */
-
-	if (bp) /* deallocate the page memory */
+	if (bp) { /* deallocate the page memory */
+		pages = bitmap->counts.pages;

drivers/md/bitmap.c static void bitmap_free(struct bitmap *bitmap) · line 1600

Quoted 10 lines
drivers/md/bitmap.c +3 -2
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
-	kfree(bp);
+		kfree(bp);
+	}
 	kfree(bitmap);
 }
 

Hi,
I'm somewhat amused that you removed a test for one kfree, but imposed a test on another. I realised the second test was already there, but why not just:

drivers/md/bitmap.c +1 -1
index da3604e73e8a..ad13b2e1bf1f 100644
@@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap)
 
 	if (bp) /* deallocate the page memory */
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
 	kfree(bp);
 	kfree(bitmap);
Quoted 6 lines

It makes the intention of the patch much clearer.

I'd probably prefer to leave the code as it is. I don't think either patch is really an improvement in readability, and readability trumps performance in places like this.

hello Neil,
just for my curiosity.
is it possible that a bp[k] exists but bp[k].hijacked is 0 ? if that case: kfree(bp) would free an object in use. otherwise hijacked seems useless here as it is possible to free everything.

Quoted 9 lines
Quoted 2 lines

re,
wh

If .hijacked is 0, the .map is a pointer (that would need to be freed) or is NULL.
If .hijacked is 1, then .map has been re-tasked as 2 16-bit counters. They are probably bother zero at this point, but I think it is safer to completely skip the 'free' if 'hijacked' is set as in that case 'map' isn't a pointer.

It seems i was not clear enough, sorry about that.

Quoted 7 lines

we have a loop to kfree(bp[k].map), thats fine how it is done.

I am wondering about the kfree(bp) after the loop.
if bp[k].map is not freed for what ever reason how can it be freed later after a kfree(bp) ?

what is what i am missing ? Is there a hidden copy ?

If bp[k].map is a pointer, it will be freed.
If bp[k].map is not a pointer (because it has been hijacked), then there is nothing to free.

So after the loop, all bp[k].maps that were allocated will have been freed.

Does that help?

NeilBrown

Quoted 6 lines

re,
wh

#796 lore raw

Re: [PATCH 2/3] md/bitmap: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

Am 04.02.2015 07:48, schrieb NeilBrown:

Quoted 117 lines · On Tue, 03 Feb 2015 11:19:58 +0100 walter harms <[email protected]> wrote:
Quoted 104 lines

Am 03.02.2015 10:07, schrieb NeilBrown:

Quoted 88 lines · On Tue, 03 Feb 2015 09:48:01 +0100 walter harms <[email protected]> wrote:
Quoted 87 lines

Am 02.02.2015 20:46, schrieb NeilBrown:

Quoted 68 lines
Quoted 34 lines · On Mon, 02 Feb 2015 16:20:42 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:10:57 +0100

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

* This issue was detected by using the Coccinelle software.

* Let us also move an assignment for the variable "pages" to the place directly before it is really needed for a loop.

* Let us also move another kfree() call into a block which should belong to a previous check for the variable "bp".

---
 drivers/md/bitmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/md/bitmap.c +2 -3
index da3604e..47d72df 100644
@@ -1586,15 +1586,15 @@ static void bitmap_free(struct bitmap *bitmap)
 	bitmap_file_unmap(&bitmap->storage);
 
 	bp = bitmap->counts.bp;
-	pages = bitmap->counts.pages;
 
 	/* free all allocated memory */
-
-	if (bp) /* deallocate the page memory */
+	if (bp) { /* deallocate the page memory */
+		pages = bitmap->counts.pages;

drivers/md/bitmap.c static void bitmap_free(struct bitmap *bitmap) · line 1600

Quoted 10 lines
drivers/md/bitmap.c +3 -2
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
-	kfree(bp);
+		kfree(bp);
+	}
 	kfree(bitmap);
 }
 

Hi,
I'm somewhat amused that you removed a test for one kfree, but imposed a test on another. I realised the second test was already there, but why not just:

drivers/md/bitmap.c +1 -1
index da3604e73e8a..ad13b2e1bf1f 100644
@@ -1592,7 +1592,7 @@ static void bitmap_free(struct bitmap *bitmap)
 
 	if (bp) /* deallocate the page memory */
 		for (k = 0; k < pages; k++)
-			if (bp[k].map && !bp[k].hijacked)
+			if (!bp[k].hijacked)
 				kfree(bp[k].map);
 	kfree(bp);
 	kfree(bitmap);
Quoted 6 lines

It makes the intention of the patch much clearer.

I'd probably prefer to leave the code as it is. I don't think either patch is really an improvement in readability, and readability trumps performance in places like this.

hello Neil,
just for my curiosity.
is it possible that a bp[k] exists but bp[k].hijacked is 0 ? if that case: kfree(bp) would free an object in use. otherwise hijacked seems useless here as it is possible to free everything.

Quoted 9 lines
Quoted 2 lines

re,
wh

If .hijacked is 0, the .map is a pointer (that would need to be freed) or is NULL.
If .hijacked is 1, then .map has been re-tasked as 2 16-bit counters. They are probably bother zero at this point, but I think it is safer to completely skip the 'free' if 'hijacked' is set as in that case 'map' isn't a pointer.

It seems i was not clear enough, sorry about that.

Quoted 7 lines

we have a loop to kfree(bp[k].map), thats fine how it is done.

I am wondering about the kfree(bp) after the loop.
if bp[k].map is not freed for what ever reason how can it be freed later after a kfree(bp) ?

what is what i am missing ? Is there a hidden copy ?

If bp[k].map is a pointer, it will be freed.
If bp[k].map is not a pointer (because it has been hijacked), then there is nothing to free.

Quoted 6 lines

So after the loop, all bp[k].maps that were allocated will have been freed.

Does that help?

NeilBrown

thx for explanation,

i am happy now, no further questions.

re,
wh

#797 lore raw

PATCH 3/3 dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:30:37 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/md/dm-ioctl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/dm-ioctl.c +1 -2
index 73f791b..4fac6cf 100644
@@ -1053,8 +1053,7 @@ static int do_resume(struct dm_ioctl *param)
 	 * Since dm_swap_table synchronizes RCU, nobody should be in
 	 * read-side critical section already.
 	 */
-	if (old_map)
-		dm_table_destroy(old_map);
+	dm_table_destroy(old_map);
 
 	if (!r)
 		__dev_status(md, param);
Signature · 1 line
2.2.2
#798 lore raw

Re: [PATCH 3/3] dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy"

Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 15:30:37 +0100

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

This issue was detected by using the Coccinelle software.

Your proposed patch (while technically correct) hurts code clarity.

Nack.

#799 lore raw

Re: [PATCH 3/3] dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy"

Quoted 1 line

Your proposed patch (while technically correct) hurts code clarity.

How many source code readability and understanding challenges does each additional condition check cause?

Can the affected place become also a bit more efficient?

Regards,
Markus

#800 lore raw

Re: [PATCH 3/3] dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy"

Quoted 4 lines · SF Markus Elfring
Quoted 1 line

Your proposed patch (while technically correct) hurts code clarity.

How many source code readability and understanding challenges does each additional condition check cause?

Please don't make a mountain out of a mole hill in an attempt to defend your robotic patch (I'm quite tired of some of these static analyzer patch submissions).

FYI, I did stage your other patch for 3.20, see:
https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-for-3.20&id=d0ce7e911c97c7c6df1081dcedfefced82a0c6bf

Quoted 1 line

Can the affected place become also a bit more efficient?

Efficiency isn't a concern in this instance (it isn't a hot IO path). And even if it were, a branch (with current code) is more efficient vs a a jump + branch (your proposed patch) -- in the case that no active table exists. Now if it likely that old_map does exist then yes your patch is always a very slight win.

But given the duality of the calling function (deals with loading a new map and destroying the old map if it exists) I prefer to keep the code as is. Sorry.

#801 lore raw

Re: [PATCH 3/3] dm ioctl: Delete an unnecessary check before the function call "dm_table_destroy"

Quoted 2 lines

FYI, I did stage your other patch for 3.20, see:
https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-for-3.20&id=d0ce7e911c97c7c6df1081dcedfefced82a0c6bf

Thanks for your acceptance of the suggested clean-up around vfree() function calls at least.
Additional source code places can also be reconsidered at other times, can't they?

Regards,
Markus

#802 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 18:26:34 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/edac/i82443bxgx_edac.c | 4 +---
 drivers/edac/i82860_edac.c     | 9 ++-------
 drivers/edac/i82875p_edac.c    | 4 +---
 drivers/edac/i82975x_edac.c    | 4 +---
 4 files changed, 5 insertions(+), 16 deletions(-)
drivers/edac/i82443bxgx_edac.c +1 -3
index b4705d9..38d6406 100644
@@ -445,9 +445,7 @@ fail1:
 	pci_unregister_driver(&i82443bxgx_edacmc_driver);
 
 fail0:
-	if (mci_pdev != NULL)
-		pci_dev_put(mci_pdev);
-
+	pci_dev_put(mci_pdev);
 	return pci_rc;
 }
 
drivers/edac/i82860_edac.c +2 -7
index 4382343..ee1078c 100644
@@ -343,20 +343,15 @@ fail1:
 	pci_unregister_driver(&i82860_driver);
 
 fail0:
-	if (mci_pdev != NULL)
-		pci_dev_put(mci_pdev);
-
+	pci_dev_put(mci_pdev);
 	return pci_rc;
 }
 
 static void __exit i82860_exit(void)
 {
 	edac_dbg(3, "\n");
-
 	pci_unregister_driver(&i82860_driver);
-
-	if (mci_pdev != NULL)
-		pci_dev_put(mci_pdev);
+	pci_dev_put(mci_pdev);
 }
 
 module_init(i82860_init);
drivers/edac/i82875p_edac.c +1 -3
index 64b6832..c26a513 100644
@@ -576,9 +576,7 @@ fail1:
 	pci_unregister_driver(&i82875p_driver);
 
 fail0:
-	if (mci_pdev != NULL)
-		pci_dev_put(mci_pdev);
-
+	pci_dev_put(mci_pdev);
 	return pci_rc;
 }
 
drivers/edac/i82975x_edac.c +1 -3
index 10b1052..35ab66c 100644
@@ -685,9 +685,7 @@ fail1:
 	pci_unregister_driver(&i82975x_driver);
 
 fail0:
-	if (mci_pdev != NULL)
-		pci_dev_put(mci_pdev);
-
+	pci_dev_put(mci_pdev);
 	return pci_rc;
 }
 
Signature · 1 line
2.2.2
maintainer Applied
#803 lore raw

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

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 18:26:34 +0100

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

This issue was detected by using the Coccinelle software.

Queued for 3.21, thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#804 lore raw

PATCH 1/1 ata: Delete unnecessary checks before the function call "pci_dev_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 22:08:29 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/ata/pata_cs5530.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/ata/pata_cs5530.c +2 -4
index 48ae4b4..f9ca72e 100644
@@ -276,10 +276,8 @@ static int cs5530_init_chip(void)
 	pci_dev_put(cs5530_0);
 	return 0;
 fail_put:
-	if (master_0)
-		pci_dev_put(master_0);
-	if (cs5530_0)
-		pci_dev_put(cs5530_0);
+	pci_dev_put(master_0);
+	pci_dev_put(cs5530_0);
 	return -ENODEV;
 }
 
Signature · 1 line
2.2.2
Applied
#805 lore raw

Re: [PATCH] ata: Delete unnecessary checks before the function call "pci_dev_put"

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 22:08:29 +0100

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

This issue was detected by using the Coccinelle software.

Applied to libata/for-3.20.

Thanks.

Signature · 1 line
tejun
#806 lore raw

cover sata_mv: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 09:12:22 +0100

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

Markus Elfring (2):
Delete unnecessary checks before the function call "phy_power_off" More error handling for phy_power_off() in mv_platform_remove()

 drivers/ata/sata_mv.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.2.2
#807 lore raw

PATCH 1/2 sata_mv: Delete unnecessary checks before the function call "phy_power_off"

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 22:55:53 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/ata/sata_mv.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/ata/sata_mv.c +2 -4
index f9a0e34..f8c33e3 100644
@@ -4185,8 +4185,7 @@ err:
 			clk_disable_unprepare(hpriv->port_clks[port]);
 			clk_put(hpriv->port_clks[port]);
 		}
-		if (hpriv->port_phys[port])
-			phy_power_off(hpriv->port_phys[port]);
+		phy_power_off(hpriv->port_phys[port]);
 	}
 
 	return rc;
@@ -4216,8 +4215,7 @@ static int mv_platform_remove(struct platform_device *pdev)
 			clk_disable_unprepare(hpriv->port_clks[port]);
 			clk_put(hpriv->port_clks[port]);
 		}
-		if (hpriv->port_phys[port])
-			phy_power_off(hpriv->port_phys[port]);
+		phy_power_off(hpriv->port_phys[port]);
 	}
 	return 0;
 }
Signature · 1 line
2.2.2
Applied
#808 lore raw

Re: [PATCH 1/2] sata_mv: Delete unnecessary checks before the function call "phy_power_off"

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 22:55:53 +0100

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

This issue was detected by using the Coccinelle software.

Applied to libata/for-3.20.

Thanks.

Signature · 1 line
tejun
#809 lore raw

PATCH 2/2 sata_mv: More error handling for phy_power_off() in mv_platform_remove()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 2 Feb 2015 23:30:34 +0100

The return value from the phy_power_off() function was not used by the mv_platform_remove() function.

Let us improve error detection and eventually return a corresponding failure code.

---
 drivers/ata/sata_mv.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/ata/sata_mv.c +4 -2
index f8c33e3..4f9bc33 100644
@@ -4203,7 +4203,7 @@ static int mv_platform_remove(struct platform_device *pdev)
 {
 	struct ata_host *host = platform_get_drvdata(pdev);
 	struct mv_host_priv *hpriv = host->private_data;
-	int port;
+	int port, rc;
 	ata_host_detach(host);
 
 	if (!IS_ERR(hpriv->clk)) {
@@ -4215,7 +4215,9 @@ static int mv_platform_remove(struct platform_device *pdev)
 			clk_disable_unprepare(hpriv->port_clks[port]);
 			clk_put(hpriv->port_clks[port]);
 		}
-		phy_power_off(hpriv->port_phys[port]);
+		rc = phy_power_off(hpriv->port_phys[port]);
+		if (rc)
+			return rc;
 	}
 	return 0;
 }
Signature · 1 line
2.2.2
#810 lore raw

Re: [PATCH 2/2] sata_mv: More error handling for phy_power_off() in mv_platform_remove()

On Tue, Feb 03, 2015 at 09:36:01AM +0100, SF Markus Elfring wrote:
...

drivers/ata/sata_mv.c static int mv_platform_remove(struct platform_device *pdev) · line 4220

Quoted 8 lines
drivers/ata/sata_mv.c +3 -1
@@ -4215,7 +4215,9 @@ static int mv_platform_remove(struct platform_device *pdev)
 			clk_disable_unprepare(hpriv->port_clks[port]);
 			clk_put(hpriv->port_clks[port]);
 		}
-		phy_power_off(hpriv->port_phys[port]);
+		rc = phy_power_off(hpriv->port_phys[port]);
+		if (rc)
+			return rc;

So, this is a removal function which is ignoring failure from turning off phy, which seems like the right thing to do. The same thing with suspend routines. If something auxliary which isn't strictly necessary in reaching suspend state fails, the failure should be ignored.

Running static code analysis to locate trivial irregularities and performing identity transformations is fine, even great, but you're changing the behavior here without actually understanding what's going on. Please don't do these things automatically.

Thanks.

Signature · 1 line
tejun
#811 lore raw

Re: [PATCH 2/2] sata_mv: More error handling for phy_power_off() in mv_platform_remove()

In reply to SF Markus Elfring

Am 03.02.2015 13:10, schrieb Tejun Heo:

Quoted 17 lines · SF Markus Elfring

...

drivers/ata/sata_mv.c static int mv_platform_remove(struct platform_device *pdev) · line 4220

Quoted 8 lines
drivers/ata/sata_mv.c +3 -1
@@ -4215,7 +4215,9 @@ static int mv_platform_remove(struct platform_device *pdev)
 			clk_disable_unprepare(hpriv->port_clks[port]);
 			clk_put(hpriv->port_clks[port]);
 		}
-		phy_power_off(hpriv->port_phys[port]);
+		rc = phy_power_off(hpriv->port_phys[port]);
+		if (rc)
+			return rc;

So, this is a removal function which is ignoring failure from turning off phy, which seems like the right thing to do. The same thing with suspend routines. If something auxliary which isn't strictly necessary in reaching suspend state fails, the failure should be ignored.

Quoted 7 lines

Running static code analysis to locate trivial irregularities and performing identity transformations is fine, even great, but you're changing the behavior here without actually understanding what's going on. Please don't do these things automatically.

Thanks.

maybe this can be changed into
(void) phy_power_off(hpriv->port_phys[port]);

that would tell the compiler and other readers that this is intentional.

#812 lore raw

Re: [PATCH 2/2] sata_mv: More error handling for phy_power_off() in mv_platform_remove()

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

maybe this can be changed into
(void) phy_power_off(hpriv->port_phys[port]);

that would tell the compiler and other readers that this is intentional.

That's too anal to be helpful and too spurious to become even remotely consistent. Things like that are actualy harmful. Note that we have an annotation marking the other way - __must_check. Balance is to be found towards that direction, not this, so please stop.

Thanks.

Signature · 1 line
tejun
#813 lore raw

Re: [PATCH 2/2] sata_mv: More error handling for phy_power_off() in mv_platform_remove()

In reply to SF Markus Elfring
Quoted 1 line · Tejun Heo

That's too anal to be helpful and too spurious to become even remotely

Let me clarify the "too anal" part a bit. Let's say people push this like crazy and we successfully mark all places to either check the return value or have (void) in front. It's not difficult to realize that that would be the exact same situation as right now just with more visual clutter. That's the problem when these things become obsessive - they become indisciminate and thus meaningless. Annotate the exceptionals, not the other way around.

Thanks.

Signature · 1 line
tejun
#814 lore raw

PATCH 1/1 ti-soc-thermal: Delete an unnecessary check before the function call "cpufreq_cooling_unregister"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 11:15:14 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +1 -1
index 3fb054a..a38c175 100644
@@ -429,7 +429,7 @@ int ti_thermal_unregister_cpu_cooling(struct ti_bandgap *bgp, int id)
 
 	data = ti_bandgap_get_sensor_data(bgp, id);
 
-	if (data && data->cool_dev)
+	if (data)
 		cpufreq_cooling_unregister(data->cool_dev);
 
 	return 0;
Signature · 1 line
2.2.2
#815 lore raw

PATCH 1/1 pwm: Delete an unnecessary check before the function call "of_node_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 11:54:28 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/pwm/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pwm/core.c +1 -1
index 966497d..810aef3 100644
@@ -192,7 +192,7 @@ static void of_pwmchip_add(struct pwm_chip *chip)
 
 static void of_pwmchip_remove(struct pwm_chip *chip)
 {
-	if (chip->dev && chip->dev->of_node)
+	if (chip->dev)
 		of_node_put(chip->dev->of_node);
 }
 
Signature · 1 line
2.2.2
#816 lore raw

Re: [PATCH] pwm: Delete an unnecessary check before the function call "of_node_put"

Quoted 18 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 11:54:28 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/pwm/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pwm/core.c +0 -0
index 966497d..810aef3 100644

drivers/pwm/core.c static void of_pwmchip_add(struct pwm_chip *chip) · line 198

Quoted 8 lines
drivers/pwm/core.c +1 -1
@@ -192,7 +192,7 @@ static void of_pwmchip_add(struct pwm_chip *chip)
 
 static void of_pwmchip_remove(struct pwm_chip *chip)
 {
-	if (chip->dev && chip->dev->of_node)
+	if (chip->dev)
 		of_node_put(chip->dev->of_node);
 }
 

Applied, thanks.

Thierry

#817 lore raw

PATCH 1/1 x86: Intel-perf_event: Delete an unnecessary check before the function call "pci_dev_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 12:40:54 +0100

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

This issue was detected by using the Coccinelle software.

---
 arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c +1 -2
index 21af6149e..12d9548 100644
@@ -1132,8 +1132,7 @@ static int snbep_pci2phy_map_init(int devid)
 		}
 	}
 
-	if (ubox_dev)
-		pci_dev_put(ubox_dev);
+	pci_dev_put(ubox_dev);
 
 	return err ? pcibios_err_to_errno(err) : 0;
 }
Signature · 1 line
2.2.2
#818 lore raw

[tip:perf/core] perf/x86/intel/uncore: Delete an unnecessary check before pci_dev_put() call

perf/x86/intel/uncore: Delete an unnecessary check before pci_dev_put() call
Commit-ID:  8e57c586c6a8333c266a6cf76d50e110f2954558
Gitweb:     http://git.kernel.org/tip/8e57c586c6a8333c266a6cf76d50e110f2954558
Author:     Markus Elfring <[email protected]>
AuthorDate: Tue, 3 Feb 2015 12:40:54 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 18 Feb 2015 17:01:42 +0100

perf/x86/intel/uncore: Delete an unnecessary check before pci_dev_put() call

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

This issue was detected by using the Coccinelle software.

---
 arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c +1 -2
index 21af6149e..12d9548 100644
@@ -1132,8 +1132,7 @@ static int snbep_pci2phy_map_init(int devid)
 		}
 	}
 
-	if (ubox_dev)
-		pci_dev_put(ubox_dev);
+	pci_dev_put(ubox_dev);
 
 	return err ? pcibios_err_to_errno(err) : 0;
 }
#819 lore raw

PATCH 1/1 PowerPC-PCI: Delete unnecessary checks before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 13:55:53 +0100

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

This issue was detected by using the Coccinelle software.

---
 arch/powerpc/platforms/cell/celleb_pci.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/powerpc/platforms/cell/celleb_pci.c +2 -3
index 3ce70de..9b11b5d 100644
@@ -393,11 +393,10 @@ static int __init celleb_setup_fake_pci_device(struct device_node *node,
 
 error:
 	if (mem_init_done) {
-		if (config && *config)
+		if (config)
 			kfree(*config);
-		if (res && *res)
+		if (res)
 			kfree(*res);
-
 	} else {
 		if (config && *config) {
 			size = 256;
Signature · 1 line
2.2.2
#820 lore raw

PATCH 1/1 PowerPC-rheap: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 14:34:10 +0100

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

This issue was detected by using the Coccinelle software.

---
 arch/powerpc/lib/rheap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/lib/rheap.c +1 -1
index a1060a8..69abf84 100644
@@ -284,7 +284,7 @@ EXPORT_SYMBOL_GPL(rh_create);
  */
 void rh_destroy(rh_info_t * info)
 {
-	if ((info->flags & RHIF_STATIC_BLOCK) = 0 && info->block != NULL)
+	if ((info->flags & RHIF_STATIC_BLOCK) = 0)
 		kfree(info->block);
 
 	if ((info->flags & RHIF_STATIC_INFO) = 0)
Signature · 1 line
2.2.2
#821 lore raw

PATCH 1/1 sp2: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 15:05:26 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/media/dvb-frontends/sp2.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/media/dvb-frontends/sp2.c +1 -4
index cc1ef96..8fd4276 100644
@@ -413,11 +413,8 @@ static int sp2_remove(struct i2c_client *client)
 	struct sp2 *s = i2c_get_clientdata(client);
 
 	dev_dbg(&client->dev, "\n");
-
 	sp2_exit(client);
-	if (s != NULL)
-		kfree(s);
-
+	kfree(s);
 	return 0;
 }
 
Signature · 1 line
2.2.2
#822 lore raw

PATCH 1/1 V4L2: Delete an unnecessary check before the function call "media_entity_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 15:27:38 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/media/v4l2-core/v4l2-subdev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-subdev.c +1 -2
index 543631c..b9ff7fd 100644
@@ -93,8 +93,7 @@ static int subdev_open(struct file *file)
 
 err:
 #if defined(CONFIG_MEDIA_CONTROLLER)
-	if (entity)
-		media_entity_put(entity);
+	media_entity_put(entity);
 #endif
 	v4l2_fh_del(&subdev_fh->vfh);
 	v4l2_fh_exit(&subdev_fh->vfh);
Signature · 1 line
2.2.2
#823 lore raw

cover DVB: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 16:50:07 +0100

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

Markus Elfring (2):
Delete an unnecessary check before the function call "dvb_unregister_device" Less function calls in dvb_ca_en50221_init() after error detection

 drivers/media/dvb-core/dvb_ca_en50221.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
Signature · 1 line
2.2.2
#824 lore raw

PATCH 1/2 DVB: Delete an unnecessary check before the function call "dvb_unregister_device"

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 16:01:40 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/media/dvb-core/dvb_ca_en50221.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/dvb-core/dvb_ca_en50221.c +1 -2
index 0aac309..b999689 100644
@@ -1726,8 +1726,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
 
 error:
 	if (ca != NULL) {
-		if (ca->dvbdev != NULL)
-			dvb_unregister_device(ca->dvbdev);
+		dvb_unregister_device(ca->dvbdev);
 		kfree(ca->slot_info);
 		kfree(ca);
 	}
Signature · 1 line
2.2.2
#825 lore raw

PATCH 2/2 DVB: Less function calls in dvb_ca_en50221_init() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 16:47:48 +0100

The functions "dvb_unregister_device" and "kfree" could still be called by the dvb_ca_en50221_init() function in the case that a previous resource allocation failed.

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

* Let us delete also an unnecessary check for the variable "ca" there.

---
 drivers/media/dvb-core/dvb_ca_en50221.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
drivers/media/dvb-core/dvb_ca_en50221.c +12 -11
index b999689..9842fd1 100644
@@ -1676,14 +1676,14 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
 	/* initialise the system data */
 	if ((ca = kzalloc(sizeof(struct dvb_ca_private), GFP_KERNEL)) = NULL) {
 		ret = -ENOMEM;
-		goto error;
+		goto exit;
 	}
 	ca->pub = pubca;
 	ca->flags = flags;
 	ca->slot_count = slot_count;
 	if ((ca->slot_info = kcalloc(slot_count, sizeof(struct dvb_ca_slot), GFP_KERNEL)) = NULL) {
 		ret = -ENOMEM;
-		goto error;
+		goto free_ca;
 	}
 	init_waitqueue_head(&ca->wait_queue);
 	ca->open = 0;
@@ -1694,7 +1694,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
 	/* register the DVB device */
 	ret = dvb_register_device(dvb_adapter, &ca->dvbdev, &dvbdev_ca, ca, DVB_DEVICE_CA);
 	if (ret)
-		goto error;
+		goto free_slot_info;
 
 	/* now initialise each slot */
 	for (i = 0; i < slot_count; i++) {
@@ -1709,7 +1709,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
 
 	if (signal_pending(current)) {
 		ret = -EINTR;
-		goto error;
+		goto unregister_device;
 	}
 	mb();
 
@@ -1720,16 +1720,17 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
 		ret = PTR_ERR(ca->thread);
 		printk("dvb_ca_init: failed to start kernel_thread (%d)\n",
 			ret);
-		goto error;
+		goto unregister_device;
 	}
 	return 0;
 
-error:
-	if (ca != NULL) {
-		dvb_unregister_device(ca->dvbdev);
-		kfree(ca->slot_info);
-		kfree(ca);
-	}
+unregister_device:
+	dvb_unregister_device(ca->dvbdev);
+free_slot_info:
+	kfree(ca->slot_info);
+free_ca:
+	kfree(ca);
+exit:
 	pubca->private = NULL;
 	return ret;
 }
Signature · 1 line
2.2.2
#826 lore raw

PATCH 1/1 stk-webcam: Delete an unnecessary check before the function call "vfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 18:36:35 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/media/usb/stkwebcam/stk-webcam.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/usb/stkwebcam/stk-webcam.c +2 -4
index 3588dc3..3686c4e 100644
@@ -556,10 +556,8 @@ static int stk_free_sio_buffers(struct stk_camera *dev)
 	nbufs = dev->n_sbufs;
 	dev->n_sbufs = 0;
 	spin_unlock_irqrestore(&dev->spinlock, flags);
-	for (i = 0; i < nbufs; i++) {
-		if (dev->sio_bufs[i].buffer != NULL)
-			vfree(dev->sio_bufs[i].buffer);
-	}
+	for (i = 0; i < nbufs; i++)
+		vfree(dev->sio_bufs[i].buffer);
 	kfree(dev->sio_bufs);
 	dev->sio_bufs = NULL;
 	return 0;
Signature · 1 line
2.2.2
#827 lore raw

PATCH 1/1 au0828: Delete unnecessary checks before the function call "video_unregister_device"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 19:00:25 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/media/usb/au0828/au0828-video.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/media/usb/au0828/au0828-video.c +2 -6
index 5f337b1..e593fb5 100644
@@ -870,12 +870,8 @@ void au0828_analog_unregister(struct au0828_dev *dev)
 {
 	dprintk(1, "au0828_release_resources called\n");
 	mutex_lock(&au0828_sysfs_lock);
-
-	if (dev->vdev)
-		video_unregister_device(dev->vdev);
-	if (dev->vbi_dev)
-		video_unregister_device(dev->vbi_dev);
-
+	video_unregister_device(dev->vdev);
+	video_unregister_device(dev->vbi_dev);
 	mutex_unlock(&au0828_sysfs_lock);
 }
 
Signature · 1 line
2.2.2
#828 lore raw

PATCH 1/1 cpufreq-dt: Delete an unnecessary check before the function call "cpufreq_cooling_unregister"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 19:21:21 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/cpufreq/cpufreq-dt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cpufreq/cpufreq-dt.c +1 -2
index fde97d6..bab67db 100644
@@ -320,8 +320,7 @@ static int cpufreq_exit(struct cpufreq_policy *policy)
 {
 	struct private_data *priv = policy->driver_data;
 
-	if (priv->cdev)
-		cpufreq_cooling_unregister(priv->cdev);
+	cpufreq_cooling_unregister(priv->cdev);
 	dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table);
 	of_free_opp_table(priv->cpu_dev);
 	clk_put(policy->clk);
Signature · 1 line
2.2.2
#829 lore raw

Re: [PATCH] cpufreq-dt: Delete an unnecessary check before the function call "cpufreq_cooling_unregister"

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 19:21:21 +0100

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

This issue was detected by using the Coccinelle software.

Queued up for 3.20, thanks!

Quoted 19 lines
---
 drivers/cpufreq/cpufreq-dt.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cpufreq/cpufreq-dt.c +1 -2
index fde97d6..bab67db 100644
@@ -320,8 +320,7 @@ static int cpufreq_exit(struct cpufreq_policy *policy)
 {
 	struct private_data *priv = policy->driver_data;
 
-	if (priv->cdev)
-		cpufreq_cooling_unregister(priv->cdev);
+	cpufreq_cooling_unregister(priv->cdev);
 	dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table);
 	of_free_opp_table(priv->cpu_dev);
 	clk_put(policy->clk);
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#830 lore raw

PATCH 1/1 IBM-EMAC: Delete an unnecessary check before the function call "of_dev_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 19:47:33 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/ibm/emac/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/ibm/emac/core.c +1 -1
index 9388a83..162762d 100644
@@ -2367,7 +2367,7 @@ static int emac_wait_deps(struct emac_instance *dev)
 	err = emac_check_deps(dev, deps) ? 0 : -ENODEV;
 	for (i = 0; i < EMAC_DEP_COUNT; i++) {
 		of_node_put(deps[i].node);
-		if (err && deps[i].ofdev)
+		if (err)
 			of_dev_put(deps[i].ofdev);
 	}
 	if (err = 0) {
Signature · 1 line
2.2.2
maintainer Applied
#831 lore raw

Re: [PATCH] IBM-EMAC: Delete an unnecessary check before the function call "of_dev_put"

From: SF Markus Elfring <[email protected]>
Date: Tue, 03 Feb 2015 19:51:38 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 19:47:33 +0100

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

This issue was detected by using the Coccinelle software.

Applied.

#832 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 20:12:25 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/ti/netcp_ethss.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/ti/netcp_ethss.c +2 -4
index fa1041a..cbd6dde 100644
@@ -2010,12 +2010,10 @@ static int gbe_probe(struct netcp_device *netcp_device, struct device *dev,
 quit:
 	if (gbe_dev->hw_stats)
 		devm_kfree(dev, gbe_dev->hw_stats);
-	if (gbe_dev->ale)
-		cpsw_ale_destroy(gbe_dev->ale);
+	cpsw_ale_destroy(gbe_dev->ale);
 	if (gbe_dev->ss_regs)
 		devm_iounmap(dev, gbe_dev->ss_regs);
-	if (interfaces)
-		of_node_put(interfaces);
+	of_node_put(interfaces);
 	devm_kfree(dev, gbe_dev);
 	return ret;
 }
Signature · 1 line
2.2.2
maintainer Applied
#833 lore raw

Re: [PATCH] NetCP: Deletion of unnecessary checks before two function calls

From: SF Markus Elfring <[email protected]>
Date: Tue, 03 Feb 2015 20:22:23 +0100

Quoted 10 lines

From: Markus Elfring <[email protected]>
Date: Tue, 3 Feb 2015 20:12:25 +0100

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

This issue was detected by using the Coccinelle software.

Applied.

#834 lore raw

Re: [PATCH] NetCP: Deletion of unnecessary checks before two function calls

In reply to SF Markus Elfring

Hi Wingman,

There are some bugs in this error handling.

Quoted 6 lines · SF Markus Elfring
drivers/net/ethernet/ti/netcp_ethss.c +0 -0
index fa1041a..cbd6dde 100644
@@ -2010,12 +2010,10 @@ static int gbe_probe(struct netcp_device *netcp_device, struct device *dev,
 quit:

drivers/net/ethernet/ti/netcp_ethss.c static int gbe_probe(struct netcp_device *netcp_device, struct device *dev, · line 2016

Quoted 10 lines
drivers/net/ethernet/ti/netcp_ethss.c +2 -4
 	if (gbe_dev->hw_stats)
 		devm_kfree(dev, gbe_dev->hw_stats);
-	if (gbe_dev->ale)
-		cpsw_ale_destroy(gbe_dev->ale);
+	cpsw_ale_destroy(gbe_dev->ale);
 	if (gbe_dev->ss_regs)
 		devm_iounmap(dev, gbe_dev->ss_regs);
-	if (interfaces)
-		of_node_put(interfaces);
+	of_node_put(interfaces);
                    ^^^^^^^^^^

"interfaces" is sometimes unintialized in this code. I don't know why GCC doesn't catch this... :(

This is a "one rrr bug", which is caused because you just have one error label "quit" which handles all the error handling. Please read my Google+ comment on error handling.

https://plus.google.com/106378716002406849458/posts/dnanfhQ4mHQ

drivers/net/ethernet/ti/netcp_ethss.c static int gbe_probe(struct netcp_device *netcp_device, struct device *dev, · line 2017

Quoted 1 line
drivers/net/ethernet/ti/netcp_ethss.c +0 -0
 	devm_kfree(dev, gbe_dev);
        ^^^^^^^^^^^^^^^^^^^^^^^^

This is not the right way to use the devm_ interface. These things are freed automatically on error or when we are done with them. This driver is double freeing pretty much everything. Grep for devm_kfree() and fix everything.

I don't know why kbuild didn't catch this...

regards
dan carpenter

#835 lore raw

RE: [PATCH] NetCP: Deletion of unnecessary checks before two function calls

RGFuLA0KDQpUaGFua3MuICBXZSdsbCBsb29rIGludG8gaXQgYW5kIHNlbmQgYSBwYXRjaCBzb29u Lg0KDQpSZWdhcmRzLA0KV2luZ01hbg0KDQo+IC0tLS0tT3JpZ2luYWwgTWVzc2FnZS0tLS0tDQo+ IEZyb206IERhbiBDYXJwZW50ZXIgW21haWx0bzpkYW4uY2FycGVudGVyQG9yYWNsZS5jb21dDQo+ IFNlbnQ6IFRodXJzZGF5LCBGZWJydWFyeSAwNSwgMjAxNSA3OjAyIEFNDQo+IFRvOiBLd29rLCBX aW5nTWFuDQo+IENjOiBTRiBNYXJrdXMgRWxmcmluZzsgS2FyaWNoZXJpLCBNdXJhbGlkaGFyYW47 IEt3b2ssIFdpbmdNYW47DQo+IG5ldGRldkB2Z2VyLmtlcm5lbC5vcmc7IExLTUw7IGtlcm5lbC1q YW5pdG9yc0B2Z2VyLmtlcm5lbC5vcmc7IEp1bGlhIExhd2FsbA0KPiBTdWJqZWN0OiBSZTogW1BB VENIXSBOZXRDUDogRGVsZXRpb24gb2YgdW5uZWNlc3NhcnkgY2hlY2tzIGJlZm9yZSB0d28NCj4g ZnVuY3Rpb24gY2FsbHMNCj4gDQo+IEhpIFdpbmdtYW4sDQo+IA0KPiBUaGVyZSBhcmUgc29tZSBi dWdzIGluIHRoaXMgZXJyb3IgaGFuZGxpbmcuDQo+IA0KPiBPbiBUdWUsIEZlYiAwMywgMjAxNSBh dCAwODoyMjoyM1BNICswMTAwLCBTRiBNYXJrdXMgRWxmcmluZyB3cm90ZToNCj4gPiBkaWZmIC0t Z2l0IGEvZHJpdmVycy9uZXQvZXRoZXJuZXQvdGkvbmV0Y3BfZXRoc3MuYw0KPiBiL2RyaXZlcnMv bmV0L2V0aGVybmV0L3RpL25ldGNwX2V0aHNzLmMNCj4gPiBpbmRleCBmYTEwNDFhLi5jYmQ2ZGRl IDEwMDY0NA0KPiA+IC0tLSBhL2RyaXZlcnMvbmV0L2V0aGVybmV0L3RpL25ldGNwX2V0aHNzLmMN Cj4gPiArKysgYi9kcml2ZXJzL25ldC9ldGhlcm5ldC90aS9uZXRjcF9ldGhzcy5jDQo+ID4gQEAg LTIwMTAsMTIgKzIwMTAsMTAgQEAgc3RhdGljIGludCBnYmVfcHJvYmUoc3RydWN0IG5ldGNwX2Rl dmljZQ0KPiAqbmV0Y3BfZGV2aWNlLCBzdHJ1Y3QgZGV2aWNlICpkZXYsDQo+ID4gIHF1aXQ6DQo+ ID4gIAlpZiAoZ2JlX2Rldi0+aHdfc3RhdHMpDQo+ID4gIAkJZGV2bV9rZnJlZShkZXYsIGdiZV9k ZXYtPmh3X3N0YXRzKTsNCj4gPiAtCWlmIChnYmVfZGV2LT5hbGUpDQo+ID4gLQkJY3Bzd19hbGVf ZGVzdHJveShnYmVfZGV2LT5hbGUpOw0KPiA+ICsJY3Bzd19hbGVfZGVzdHJveShnYmVfZGV2LT5h bGUpOw0KPiA+ICAJaWYgKGdiZV9kZXYtPnNzX3JlZ3MpDQo+ID4gIAkJZGV2bV9pb3VubWFwKGRl diwgZ2JlX2Rldi0+c3NfcmVncyk7DQo+ID4gLQlpZiAoaW50ZXJmYWNlcykNCj4gPiAtCQlvZl9u b2RlX3B1dChpbnRlcmZhY2VzKTsNCj4gPiArCW9mX25vZGVfcHV0KGludGVyZmFjZXMpOw0KPiAg ICAgICAgICAgICAgICAgICAgIF5eXl5eXl5eXl4NCj4gImludGVyZmFjZXMiIGlzIHNvbWV0aW1l cyB1bmludGlhbGl6ZWQgaW4gdGhpcyBjb2RlLiAgSSBkb24ndCBrbm93IHdoeQ0KPiBHQ0MgZG9l c24ndCBjYXRjaCB0aGlzLi4uICA6KA0KPiANCj4gVGhpcyBpcyBhICJvbmUgcnJyIGJ1ZyIsIHdo aWNoIGlzIGNhdXNlZCBiZWNhdXNlIHlvdSBqdXN0IGhhdmUgb25lIGVycm9yDQo+IGxhYmVsICJx dWl0IiB3aGljaCBoYW5kbGVzIGFsbCB0aGUgZXJyb3IgaGFuZGxpbmcuICBQbGVhc2UgcmVhZCBt eQ0KPiBHb29nbGUrIGNvbW1lbnQgb24gZXJyb3IgaGFuZGxpbmcuDQo+IA0KPiBodHRwczovL3Bs dXMuZ29vZ2xlLmNvbS8xMDYzNzg3MTYwMDI0MDY4NDk0NTgvcG9zdHMvZG5hbmZoUTRtSFENCj4g DQo+ID4gIAlkZXZtX2tmcmVlKGRldiwgZ2JlX2Rldik7DQo+ICAgICAgICAgXl5eXl5eXl5eXl5e Xl5eXl5eXl5eXl5eDQo+IFRoaXMgaXMgbm90IHRoZSByaWdodCB3YXkgdG8gdXNlIHRoZSBkZXZt XyBpbnRlcmZhY2UuICBUaGVzZSB0aGluZ3MgYXJlDQo+IGZyZWVkIGF1dG9tYXRpY2FsbHkgb24g ZXJyb3Igb3Igd2hlbiB3ZSBhcmUgZG9uZSB3aXRoIHRoZW0uICBUaGlzIGRyaXZlcg0KPiBpcyBk b3VibGUgZnJlZWluZyBwcmV0dHkgbXVjaCBldmVyeXRoaW5nLiAgR3JlcCBmb3IgZGV2bV9rZnJl ZSgpIGFuZA0KPiBmaXggZXZlcnl0aGluZy4NCj4gDQo+IEkgZG9uJ3Qga25vdyB3aHkga2J1aWxk IGRpZG4ndCBjYXRjaCB0aGlzLi4uDQo+IA0KPiByZWdhcmRzDQo+IGRhbiBjYXJwZW50ZXINCg0K

#836 lore raw

PATCH 1/1 cxgb4: Delete an unnecessary check before the function call "release_firmware"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 11:28:43 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +1 -2
index 1147e1e..6d08b8c 100644
@@ -5129,8 +5129,7 @@ static int adap_init0(struct adapter *adap)
 				 state, &reset);
 
 		/* Cleaning up */
-		if (fw != NULL)
-			release_firmware(fw);
+		release_firmware(fw);
 		t4_free_mem(card_fw);
 
 		if (ret < 0)
Signature · 1 line
2.2.2
maintainer Applied
#837 lore raw

Re: [PATCH] cxgb4: Delete an unnecessary check before the function call "release_firmware"

From: SF Markus Elfring <[email protected]>
Date: Wed, 04 Feb 2015 11:38:39 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 11:28:43 +0100

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

This issue was detected by using the Coccinelle software.

Applied.

#838 lore raw

PATCH 1/1 myri10ge: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 12:32:14 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/myricom/myri10ge/myri10ge.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/myricom/myri10ge/myri10ge.c +1 -2
index 71af98b..1412f5a 100644
@@ -4226,8 +4226,7 @@ static void myri10ge_remove(struct pci_dev *pdev)
 		mtrr_del(mgp->mtrr, mgp->iomem_base, mgp->board_span);
 #endif
 	myri10ge_free_slices(mgp);
-	if (mgp->msix_vectors != NULL)
-		kfree(mgp->msix_vectors);
+	kfree(mgp->msix_vectors);
 	dma_free_coherent(&pdev->dev, sizeof(*mgp->cmd),
 			  mgp->cmd, mgp->cmd_bus);
 
Signature · 1 line
2.2.2
maintainer Applied
#839 lore raw

Re: [PATCH] myri10ge: Delete an unnecessary check before the function call "kfree"

From: SF Markus Elfring <[email protected]>
Date: Wed, 04 Feb 2015 12:36:02 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 12:32:14 +0100

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

This issue was detected by using the Coccinelle software.

Applied.

#840 lore raw

PATCH 1/1 net: fec: Delete unnecessary checks before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 12:56:42 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/freescale/fec_main.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +2 -5
index 1c7a7e4..29fd7e3 100644
@@ -2584,12 +2584,9 @@ static void fec_enet_free_queue(struct net_device *ndev)
 		}
 
 	for (i = 0; i < fep->num_rx_queues; i++)
-		if (fep->rx_queue[i])
-			kfree(fep->rx_queue[i]);
-
+		kfree(fep->rx_queue[i]);
 	for (i = 0; i < fep->num_tx_queues; i++)
-		if (fep->tx_queue[i])
-			kfree(fep->tx_queue[i]);
+		kfree(fep->tx_queue[i]);
 }
 
 static int fec_enet_alloc_queue(struct net_device *ndev)
Signature · 1 line
2.2.2
maintainer Applied
#841 lore raw

Re: [PATCH] net: fec: Delete unnecessary checks before the function call "kfree"

From: SF Markus Elfring <[email protected]>
Date: Wed, 04 Feb 2015 13:00:46 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 12:56:42 +0100

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

This issue was detected by using the Coccinelle software.

Applied.

#842 lore raw

PATCH 1/1 netxen: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 13:17:48 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c +1 -3
index a47fe67..7d1b524 100644
@@ -176,9 +176,7 @@ netxen_alloc_sds_rings(struct netxen_recv_context *recv_ctx, int count)
 static void
 netxen_free_sds_rings(struct netxen_recv_context *recv_ctx)
 {
-	if (recv_ctx->sds_rings != NULL)
-		kfree(recv_ctx->sds_rings);
-
+	kfree(recv_ctx->sds_rings);
 	recv_ctx->sds_rings = NULL;
 }
 
Signature · 1 line
2.2.2
maintainer Applied
#843 lore raw

Re: [PATCH] netxen: Delete an unnecessary check before the function call "kfree"

From: SF Markus Elfring <[email protected]>
Date: Wed, 04 Feb 2015 13:21:29 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 13:17:48 +0100

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

This issue was detected by using the Coccinelle software.

Applied.

#844 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 14:07:56 +0100

The functions kfree() and vfree() perform also input parameter validation. Thus the test around their calls is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c   | 24 ++++++++--------------
 .../net/ethernet/qlogic/qlcnic/qlcnic_minidump.c   |  3 +--
 2 files changed, 9 insertions(+), 18 deletions(-)
drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c +8 -16
index 2528c3f..a430a34a 100644
@@ -294,9 +294,7 @@ int qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
 
 void qlcnic_free_sds_rings(struct qlcnic_recv_context *recv_ctx)
 {
-	if (recv_ctx->sds_rings != NULL)
-		kfree(recv_ctx->sds_rings);
-
+	kfree(recv_ctx->sds_rings);
 	recv_ctx->sds_rings = NULL;
 }
 
@@ -1257,8 +1255,7 @@ qlcnic_check_options(struct qlcnic_adapter *adapter)
 	if (ahw->op_mode != QLCNIC_NON_PRIV_FUNC) {
 		if (fw_dump->tmpl_hdr = NULL ||
 				adapter->fw_version > prev_fw_version) {
-			if (fw_dump->tmpl_hdr)
-				vfree(fw_dump->tmpl_hdr);
+			vfree(fw_dump->tmpl_hdr);
 			if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
 				dev_info(&pdev->dev,
 					"Supports FW dump capability\n");
@@ -2374,13 +2371,12 @@ void qlcnic_free_tx_rings(struct qlcnic_adapter *adapter)
 
 	for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
 		tx_ring = &adapter->tx_ring[ring];
-		if (tx_ring && tx_ring->cmd_buf_arr != NULL) {
+		if (tx_ring) {
 			vfree(tx_ring->cmd_buf_arr);
 			tx_ring->cmd_buf_arr = NULL;
 		}
 	}
-	if (adapter->tx_ring != NULL)
-		kfree(adapter->tx_ring);
+	kfree(adapter->tx_ring);
 }
 
 int qlcnic_alloc_tx_rings(struct qlcnic_adapter *adapter,
@@ -2758,13 +2754,9 @@ static void qlcnic_remove(struct pci_dev *pdev)
 	}
 
 	qlcnic_dcb_free(adapter->dcb);
-
 	qlcnic_detach(adapter);
-
-	if (adapter->npars != NULL)
-		kfree(adapter->npars);
-	if (adapter->eswitch != NULL)
-		kfree(adapter->eswitch);
+	kfree(adapter->npars);
+	kfree(adapter->eswitch);
 
 	if (qlcnic_82xx_check(adapter))
 		qlcnic_clr_all_drv_state(adapter, 0);
@@ -2932,13 +2924,13 @@ void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
 
 static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
 {
-	if (adapter->fhash.fmax && adapter->fhash.fhead)
+	if (adapter->fhash.fmax)
 		kfree(adapter->fhash.fhead);
 
 	adapter->fhash.fhead = NULL;
 	adapter->fhash.fmax = 0;
 
-	if (adapter->rx_fhash.fmax && adapter->rx_fhash.fhead)
+	if (adapter->rx_fhash.fmax)
 		kfree(adapter->rx_fhash.fhead);
 
 	adapter->rx_fhash.fmax = 0;
drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c +1 -2
index c9f57fb..332bb8a 100644
@@ -1407,8 +1407,7 @@ void qlcnic_83xx_get_minidump_template(struct qlcnic_adapter *adapter)
 	current_version = qlcnic_83xx_get_fw_version(adapter);
 
 	if (fw_dump->tmpl_hdr = NULL || current_version > prev_version) {
-		if (fw_dump->tmpl_hdr)
-			vfree(fw_dump->tmpl_hdr);
+		vfree(fw_dump->tmpl_hdr);
 		if (!qlcnic_fw_cmd_get_minidump_temp(adapter))
 			dev_info(&pdev->dev, "Supports FW dump capability\n");
 	}
Signature · 1 line
2.2.2
maintainer Applied
#845 lore raw

Re: [PATCH] qlogic: Deletion of unnecessary checks before two function calls

From: SF Markus Elfring <[email protected]>
Date: Wed, 04 Feb 2015 14:13:37 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 14:07:56 +0100

The functions kfree() and vfree() perform also input parameter validation. Thus the test around their calls is not needed.

This issue was detected by using the Coccinelle software.

Applied.

#846 lore raw

PATCH 1/1 net: Mellanox: Delete unnecessary checks before the function call "vunmap"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 15:17:00 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/mellanox/mlx4/alloc.c      | 2 +-
 drivers/net/ethernet/mellanox/mlx5/core/alloc.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx4/alloc.c +1 -1
index 963dd7e..06faa51 100644
@@ -660,7 +660,7 @@ void mlx4_buf_free(struct mlx4_dev *dev, int size, struct mlx4_buf *buf)
 		dma_free_coherent(&dev->pdev->dev, size, buf->direct.buf,
 				  buf->direct.map);
 	else {
-		if (BITS_PER_LONG = 64 && buf->direct.buf)
+		if (BITS_PER_LONG = 64)
 			vunmap(buf->direct.buf);
 
 		for (i = 0; i < buf->nbufs; ++i)
drivers/net/ethernet/mellanox/mlx5/core/alloc.c +1 -1
index 56779c1..201ca6d 100644
@@ -121,7 +121,7 @@ void mlx5_buf_free(struct mlx5_core_dev *dev, struct mlx5_buf *buf)
 		dma_free_coherent(&dev->pdev->dev, buf->size, buf->direct.buf,
 				  buf->direct.map);
 	else {
-		if (BITS_PER_LONG = 64 && buf->direct.buf)
+		if (BITS_PER_LONG = 64)
 			vunmap(buf->direct.buf);
 
 		for (i = 0; i < buf->nbufs; i++)
Signature · 1 line
2.2.2
Acked-by on v1 1/1
#847 lore raw

Re: [PATCH] net: Mellanox: Delete unnecessary checks before the function call "vunmap"

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 15:17:00 +0100

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

This issue was detected by using the Coccinelle software.

maintainer
#848 lore raw

Re: [PATCH] net: Mellanox: Delete unnecessary checks before the function call "vunmap"

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Wed, 04 Feb 2015 15:22:33 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 15:17:00 +0100

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

This issue was detected by using the Coccinelle software.

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

#849 lore raw

PATCH v2 1/1 net: Mellanox: Delete unnecessary checks before the function call "vunmap"

From: Markus Elfring <[email protected]>
Date: Mon, 9 Feb 2015 11:10:41 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/mellanox/mlx4/alloc.c      | 2 +-
 drivers/net/ethernet/mellanox/mlx5/core/alloc.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx4/alloc.c +1 -1
index a716c26..0c51c69 100644
@@ -662,7 +662,7 @@ void mlx4_buf_free(struct mlx4_dev *dev, int size, struct mlx4_buf *buf)
 				  buf->direct.buf,
 				  buf->direct.map);
 	else {
-		if (BITS_PER_LONG = 64 && buf->direct.buf)
+		if (BITS_PER_LONG = 64)
 			vunmap(buf->direct.buf);
 
 		for (i = 0; i < buf->nbufs; ++i)
drivers/net/ethernet/mellanox/mlx5/core/alloc.c +1 -1
index 56779c1..201ca6d 100644
@@ -121,7 +121,7 @@ void mlx5_buf_free(struct mlx5_core_dev *dev, struct mlx5_buf *buf)
 		dma_free_coherent(&dev->pdev->dev, buf->size, buf->direct.buf,
 				  buf->direct.map);
 	else {
-		if (BITS_PER_LONG = 64 && buf->direct.buf)
+		if (BITS_PER_LONG = 64)
 			vunmap(buf->direct.buf);
 
 		for (i = 0; i < buf->nbufs; i++)
Signature · 1 line
2.2.2
Applied
#850 lore raw

Re: [PATCH v2] net: Mellanox: Delete unnecessary checks before the function call "vunmap"

From: SF Markus Elfring <[email protected]>
Date: Mon, 09 Feb 2015 11:21:26 +0100

Quoted 10 lines

From: Markus Elfring <[email protected]>
Date: Mon, 9 Feb 2015 11:10:41 +0100

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

This issue was detected by using the Coccinelle software.

Applied.

#851 lore raw

PATCH 1/1 net: ep93xx_eth: Delete unnecessary checks before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 15:56:58 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/cirrus/ep93xx_eth.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/cirrus/ep93xx_eth.c +2 -4
index 3a12c09..de9f7c9 100644
@@ -475,8 +475,7 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep)
 		if (d)
 			dma_unmap_single(dev, d, PKT_BUF_SIZE, DMA_FROM_DEVICE);
 
-		if (ep->rx_buf[i] != NULL)
-			kfree(ep->rx_buf[i]);
+		kfree(ep->rx_buf[i]);
 	}
 
 	for (i = 0; i < TX_QUEUE_ENTRIES; i++) {
@@ -486,8 +485,7 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep)
 		if (d)
 			dma_unmap_single(dev, d, PKT_BUF_SIZE, DMA_TO_DEVICE);
 
-		if (ep->tx_buf[i] != NULL)
-			kfree(ep->tx_buf[i]);
+		kfree(ep->tx_buf[i]);
 	}
 
 	dma_free_coherent(dev, sizeof(struct ep93xx_descs), ep->descs,
Signature · 1 line
2.2.2
#852 lore raw

RE: [PATCH] net: ep93xx_eth: Delete unnecessary checks before the function call "kfree"

Quoted 25 lines · Markus Elfring

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/ethernet/cirrus/ep93xx_eth.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/cirrus/ep93xx_eth.c +1 -2
index 3a12c09..de9f7c9 100644
@@ -475,8 +475,7 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep)
 		if (d)
 			dma_unmap_single(dev, d, PKT_BUF_SIZE, DMA_FROM_DEVICE);
 
-		if (ep->rx_buf[i] != NULL)
-			kfree(ep->rx_buf[i]);
+		kfree(ep->rx_buf[i]);
 	}
 
 	for (i = 0; i < TX_QUEUE_ENTRIES; i++) {

drivers/net/ethernet/cirrus/ep93xx_eth.c static void ep93xx_free_buffers(struct ep93xx_priv *ep) · line 491

Quoted 9 lines
drivers/net/ethernet/cirrus/ep93xx_eth.c +1 -2
@@ -486,8 +485,7 @@ static void ep93xx_free_buffers(struct ep93xx_priv *ep)
 		if (d)
 			dma_unmap_single(dev, d, PKT_BUF_SIZE, DMA_TO_DEVICE);
 
-		if (ep->tx_buf[i] != NULL)
-			kfree(ep->tx_buf[i]);
+		kfree(ep->tx_buf[i]);
 	}
 
 	dma_free_coherent(dev, sizeof(struct ep93xx_descs), ep->descs,

Thanks

maintainer Applied
#853 lore raw

Re: [PATCH] net: ep93xx_eth: Delete unnecessary checks before the function call "kfree"

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Wed, 04 Feb 2015 16:00:37 +0100

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 15:56:58 +0100

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

This issue was detected by using the Coccinelle software.

Applied.

#854 lore raw

cover CW1200: Deletion of an unnecessary check

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 17:31:00 +0100

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

Markus Elfring (2):
Delete an unnecessary check before the function call "release_firmware" Less function calls in cw1200_load_firmware_cw1200() after error detection

 drivers/net/wireless/cw1200/fwio.c | 40 +++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 16 deletions(-)
Signature · 1 line
2.2.2
#855 lore raw

PATCH 1/2 CW1200: Delete an unnecessary check before the function call "release_firmware"

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 16:32:15 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/wireless/cw1200/fwio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/wireless/cw1200/fwio.c +1 -2
index 6f1b9aa..581dfde 100644
@@ -246,8 +246,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 
 error:
 	kfree(buf);
-	if (firmware)
-		release_firmware(firmware);
+	release_firmware(firmware);
 	return ret;
 
 #undef APB_WRITE
Signature · 1 line
2.2.2
#856 lore raw

Re: [1/2] cw1200: Delete an unnecessary check before the function call "release_firmware"

Quoted 10 lines

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 16:32:15 +0100

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

This issue was detected by using the Coccinelle software.

Thanks, 2 patches applied to wireless-drivers-next.git:

df970d39b90e cw1200: Delete an unnecessary check before the function call "release_firmware" ee4ddad82356 cw1200: Less function calls in cw1200_load_firmware_cw1200() after error detection

Kalle Valo

#857 lore raw

PATCH 2/2 CW1200: Less function calls in cw1200_load_firmware_cw1200() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 17:28:41 +0100

The functions kfree() and release_firmware() were called in a few cases by the cw1200_load_firmware_cw1200() function during error handling even if the passed variables contained still a null pointer.

Corresponding implementation details could be improved by adjustments for jump targets.

---
 drivers/net/wireless/cw1200/fwio.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)
drivers/net/wireless/cw1200/fwio.c +23 -14
index 581dfde..30e7646 100644
@@ -66,25 +66,31 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 	do { \
 		ret = cw1200_apb_write_32(priv, CW1200_APB(reg), (val)); \
 		if (ret < 0) \
-			goto error; \
+			goto exit; \
+	} while (0)
+#define APB_WRITE2(reg, val) \
+	do { \
+		ret = cw1200_apb_write_32(priv, CW1200_APB(reg), (val)); \
+		if (ret < 0) \
+			goto free_buffer; \
 	} while (0)
 #define APB_READ(reg, val) \
 	do { \
 		ret = cw1200_apb_read_32(priv, CW1200_APB(reg), &(val)); \
 		if (ret < 0) \
-			goto error; \
+			goto free_buffer; \
 	} while (0)
 #define REG_WRITE(reg, val) \
 	do { \
 		ret = cw1200_reg_write_32(priv, (reg), (val)); \
 		if (ret < 0) \
-			goto error; \
+			goto exit; \
 	} while (0)
 #define REG_READ(reg, val) \
 	do { \
 		ret = cw1200_reg_read_32(priv, (reg), &(val)); \
 		if (ret < 0) \
-			goto error; \
+			goto exit; \
 	} while (0)
 
 	switch (priv->hw_revision) {
@@ -142,14 +148,14 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 	ret = request_firmware(&firmware, fw_path, priv->pdev);
 	if (ret) {
 		pr_err("Can't load firmware file %s.\n", fw_path);
-		goto error;
+		goto exit;
 	}
 
 	buf = kmalloc(DOWNLOAD_BLOCK_SIZE, GFP_KERNEL | GFP_DMA);
 	if (!buf) {
 		pr_err("Can't allocate firmware load buffer.\n");
 		ret = -ENOMEM;
-		goto error;
+		goto firmware_release;
 	}
 
 	/* Check if the bootloader is ready */
@@ -163,7 +169,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 	if (val32 != DOWNLOAD_I_AM_HERE) {
 		pr_err("Bootloader is not ready.\n");
 		ret = -ETIMEDOUT;
-		goto error;
+		goto free_buffer;
 	}
 
 	/* Calculcate number of download blocks */
@@ -171,7 +177,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 
 	/* Updating the length in Download Ctrl Area */
 	val32 = firmware->size; /* Explicit cast from size_t to u32 */
-	APB_WRITE(DOWNLOAD_IMAGE_SIZE_REG, val32);
+	APB_WRITE2(DOWNLOAD_IMAGE_SIZE_REG, val32);
 
 	/* Firmware downloading loop */
 	for (block = 0; block < num_blocks; block++) {
@@ -183,7 +189,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 		if (val32 != DOWNLOAD_PENDING) {
 			pr_err("Bootloader reported error %d.\n", val32);
 			ret = -EIO;
-			goto error;
+			goto free_buffer;
 		}
 
 		/* loop until put - get <= 24K */
@@ -198,7 +204,7 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 		if ((put - get) > (DOWNLOAD_FIFO_SIZE - DOWNLOAD_BLOCK_SIZE)) {
 			pr_err("Timeout waiting for FIFO.\n");
 			ret = -ETIMEDOUT;
-			goto error;
+			goto free_buffer;
 		}
 
 		/* calculate the block size */
@@ -220,12 +226,12 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 		if (ret < 0) {
 			pr_err("Can't write firmware block @ %d!\n",
 			       put & (DOWNLOAD_FIFO_SIZE - 1));
-			goto error;
+			goto free_buffer;
 		}
 
 		/* update the put register */
 		put += block_size;
-		APB_WRITE(DOWNLOAD_PUT_REG, put);
+		APB_WRITE2(DOWNLOAD_PUT_REG, put);
 	} /* End of firmware download loop */
 
 	/* Wait for the download completion */
@@ -238,18 +244,21 @@ static int cw1200_load_firmware_cw1200(struct cw1200_common *priv)
 	if (val32 != DOWNLOAD_SUCCESS) {
 		pr_err("Wait for download completion failed: 0x%.8X\n", val32);
 		ret = -ETIMEDOUT;
-		goto error;
+		goto free_buffer;
 	} else {
 		pr_info("Firmware download completed.\n");
 		ret = 0;
 	}
 
-error:
+free_buffer:
 	kfree(buf);
+firmware_release:
 	release_firmware(firmware);
+exit:
 	return ret;
 
 #undef APB_WRITE
+#undef APB_WRITE2
 #undef APB_READ
 #undef REG_WRITE
 #undef REG_READ
Signature · 1 line
2.2.2
#858 lore raw

PATCH 1/1 ath9k: Delete an unnecessary check before the function call "relay_close"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 18:48:28 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/wireless/ath/ath9k/common-spectral.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath9k/common-spectral.c +1 -1
index ec93ddf..5cee231 100644
@@ -582,7 +582,7 @@ static struct rchan_callbacks rfs_spec_scan_cb = {
 
 void ath9k_cmn_spectral_deinit_debug(struct ath_spec_scan_priv *spec_priv)
 {
-	if (config_enabled(CONFIG_ATH9K_DEBUGFS) && spec_priv->rfs_chan_spec_scan) {
+	if (config_enabled(CONFIG_ATH9K_DEBUGFS)) {
 		relay_close(spec_priv->rfs_chan_spec_scan);
 		spec_priv->rfs_chan_spec_scan = NULL;
 	}
Signature · 1 line
2.2.2
Applied
#859 lore raw

Re: ath9k: Delete an unnecessary check before the function call"relay_close"

Quoted 10 lines

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 18:48:28 +0100

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

This issue was detected by using the Coccinelle software.

Thanks, applied to wireless-drivers-next.git.

Kalle Valo

#860 lore raw

PATCH 1/1 ath10k: Delete unnecessary checks before the function call "release_firmware"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 19:30:23 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/wireless/ath/ath10k/core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/wireless/ath/ath10k/core.c +4 -4
index 2d0671e..45171ad 100644
@@ -393,16 +393,16 @@ static int ath10k_download_fw(struct ath10k *ar, enum ath10k_firmware_mode mode)
 
 static void ath10k_core_free_firmware_files(struct ath10k *ar)
 {
-	if (ar->board && !IS_ERR(ar->board))
+	if (!IS_ERR(ar->board))
 		release_firmware(ar->board);
 
-	if (ar->otp && !IS_ERR(ar->otp))
+	if (!IS_ERR(ar->otp))
 		release_firmware(ar->otp);
 
-	if (ar->firmware && !IS_ERR(ar->firmware))
+	if (!IS_ERR(ar->firmware))
 		release_firmware(ar->firmware);
 
-	if (ar->cal_file && !IS_ERR(ar->cal_file))
+	if (!IS_ERR(ar->cal_file))
 		release_firmware(ar->cal_file);
 
 	ar->board = NULL;
Signature · 1 line
2.2.2
Applied
#861 lore raw

Re: [PATCH] ath10k: Delete unnecessary checks before the function call "release_firmware"

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 19:30:23 +0100

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

This issue was detected by using the Coccinelle software.

Thanks, applied to ath.git.

Signature · 1 line
Kalle Valo
#862 lore raw

PATCH 1/1 orinoco: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 19:53:11 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/wireless/orinoco/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/orinoco/main.c +1 -1
index 38ec8d1..c410180 100644
@@ -2342,7 +2342,7 @@ void free_orinocodev(struct orinoco_private *priv)
 	list_for_each_entry_safe(sd, sdtemp, &priv->scan_list, list) {
 		list_del(&sd->list);
 
-		if ((sd->len > 0) && sd->buf)
+		if (sd->len > 0)
 			kfree(sd->buf);
 		kfree(sd);
 	}
Signature · 1 line
2.2.2
Applied
#863 lore raw

Re: orinoco: Delete an unnecessary check before the function call "kfree"

Quoted 10 lines

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 19:53:11 +0100

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

This issue was detected by using the Coccinelle software.

Thanks, applied to wireless-drivers-next.git.

Kalle Valo

#864 lore raw

PATCH 1/1 HostAP: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 20:06:39 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/net/wireless/hostap/hostap_ap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/hostap/hostap_ap.c +1 -1
index 5965255..fd8d83d 100644
@@ -145,7 +145,7 @@ static void ap_free_sta(struct ap_data *ap, struct sta_info *sta)
 	if (sta->aid > 0)
 		ap->sta_aid[sta->aid - 1] = NULL;
 
-	if (!sta->ap && sta->u.sta.challenge)
+	if (!sta->ap)
 		kfree(sta->u.sta.challenge);
 	del_timer_sync(&sta->timer);
 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
Signature · 1 line
2.2.2
Applied
#865 lore raw

Re: hostap: Delete an unnecessary check before the function call "kfree"

Quoted 10 lines

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 20:06:39 +0100

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

This issue was detected by using the Coccinelle software.

Thanks, applied to wireless-drivers-next.git.

Kalle Valo

#866 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 20:28:49 +0100

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

---
 drivers/net/wireless/brcm80211/brcmfmac/sdio.c | 3 +--
 drivers/net/wireless/brcm80211/brcmfmac/usb.c  | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/net/wireless/brcm80211/brcmfmac/sdio.c +1 -2
index 99a3776..5b5520b 100644
@@ -2543,8 +2543,7 @@ static void brcmf_sdio_bus_stop(struct device *dev)
 	brcmu_pktq_flush(&bus->txq, true, NULL, NULL);
 
 	/* Clear any held glomming stuff */
-	if (bus->glomd)
-		brcmu_pkt_buf_free_skb(bus->glomd);
+	brcmu_pkt_buf_free_skb(bus->glomd);
 	brcmf_sdio_free_glom(bus);
 
 	/* Clear rx control and wake any waiters */
drivers/net/wireless/brcm80211/brcmfmac/usb.c +1 -1
index 4572def..10c684c 100644
@@ -421,7 +421,7 @@ fail:
 	brcmf_err("fail!\n");
 	while (!list_empty(q)) {
 		req = list_entry(q->next, struct brcmf_usbreq, list);
-		if (req && req->urb)
+		if (req)
 			usb_free_urb(req->urb);
 		list_del(q->next);
 	}
Signature · 1 line
2.2.2
Applied
#867 lore raw

Re: brcm80211: Delete unnecessary checks before two function calls

Quoted 9 lines

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 20:28:49 +0100

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

Thanks, applied to wireless-drivers-next.git.

Kalle Valo

#868 lore raw

PATCH 1/1 SGI-XPC: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 20:50:31 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/misc/sgi-xp/xpc_partition.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/misc/sgi-xp/xpc_partition.c +1 -2
index 6956f7e..0e32431 100644
@@ -98,8 +98,7 @@ xpc_get_rsvd_page_pa(int nasid)
 			len = L1_CACHE_ALIGN(len);
 
 		if (len > buf_len) {
-			if (buf_base != NULL)
-				kfree(buf_base);
+			kfree(buf_base);
 			buf_len = L1_CACHE_ALIGN(len);
 			buf = xpc_kmalloc_cacheline_aligned(buf_len, GFP_KERNEL,
 							    &buf_base);
Signature · 1 line
2.2.2
#869 lore raw

PATCH 1/1 macintosh: Delete an unnecessary check before the function call "of_node_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 21:32:27 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/macintosh/smu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/macintosh/smu.c +1 -2
index 10ae69b..d531f80 100644
@@ -557,8 +557,7 @@ int __init smu_init (void)
 	return 0;
 
 fail_msg_node:
-	if (smu->msg_node)
-		of_node_put(smu->msg_node);
+	of_node_put(smu->msg_node);
 fail_db_node:
 	of_node_put(smu->db_node);
 fail_bootmem:
Signature · 1 line
2.2.2
#870 lore raw

Re: [PATCH] macintosh: Delete an unnecessary check before the function call "of_node_put"

Am 04.02.2015 um 21:36 schrieb SF Markus Elfring:

Quoted 19 lines

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 21:32:27 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/macintosh/smu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/macintosh/smu.c +0 -0
index 10ae69b..d531f80 100644

drivers/macintosh/smu.c int __init smu_init (void) · line 563

Quoted 9 lines
drivers/macintosh/smu.c +1 -2
@@ -557,8 +557,7 @@ int __init smu_init (void)
 	return 0;
 
 fail_msg_node:
-	if (smu->msg_node)
-		of_node_put(smu->msg_node);
+	of_node_put(smu->msg_node);
 fail_db_node:
 	of_node_put(smu->db_node);
 fail_bootmem:

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

Regards,
Markus

#871 lore raw

PATCH 1/1 GPU-DRM-Exynos: Delete unnecessary checks before two function calls

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 21:54:45 +0100

The functions phy_power_on() and vunmap() perform also input parameter validation. Thus the test around their calls is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/exynos/exynos_dp_core.c   | 6 ++----
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/drm/exynos/exynos_dp_core.c +2 -4
index 34d46aa..306cf1d 100644
@@ -1057,14 +1057,12 @@ static int exynos_dp_create_connector(struct exynos_drm_display *display,
 
 static void exynos_dp_phy_init(struct exynos_dp_device *dp)
 {
-	if (dp->phy)
-		phy_power_on(dp->phy);
+	phy_power_on(dp->phy);
 }
 
 static void exynos_dp_phy_exit(struct exynos_dp_device *dp)
 {
-	if (dp->phy)
-		phy_power_off(dp->phy);
+	phy_power_off(dp->phy);
 }
 
 static void exynos_dp_poweron(struct exynos_drm_display *display)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +1 -1
index e12ea90..0dd448a 100644
@@ -313,7 +313,7 @@ static void exynos_drm_fbdev_destroy(struct drm_device *dev,
 	struct exynos_drm_gem_obj *exynos_gem_obj = exynos_fbd->exynos_gem_obj;
 	struct drm_framebuffer *fb;
 
-	if (is_drm_iommu_supported(dev) && exynos_gem_obj->buffer->kvaddr)
+	if (is_drm_iommu_supported(dev))
 		vunmap(exynos_gem_obj->buffer->kvaddr);
 
 	/* release drm framebuffer and real buffer */
Signature · 1 line
2.2.2
Acked-by on v1 1/1
#872 lore raw

Re: [PATCH] GPU-DRM-Exynos: Delete unnecessary checks before two function calls

Hi,

Quoted 41 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 21:54:45 +0100

The functions phy_power_on() and vunmap() perform also input parameter validation. Thus the test around their calls is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/exynos/exynos_dp_core.c   | 6 ++----
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/drm/exynos/exynos_dp_core.c +2 -4
index 34d46aa..306cf1d 100644
@@ -1057,14 +1057,12 @@ static int exynos_dp_create_connector(struct exynos_drm_display *display,
 
 static void exynos_dp_phy_init(struct exynos_dp_device *dp)
 {
-	if (dp->phy)
-		phy_power_on(dp->phy);
+	phy_power_on(dp->phy);
 }
 
 static void exynos_dp_phy_exit(struct exynos_dp_device *dp)
 {
-	if (dp->phy)
-		phy_power_off(dp->phy);
+	phy_power_off(dp->phy);
 }
 
 static void exynos_dp_poweron(struct exynos_drm_display *display)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +0 -0
index e12ea90..0dd448a 100644

drivers/gpu/drm/exynos/exynos_drm_fbdev.c static void exynos_drm_fbdev_destroy(struct drm_device *dev, · line 319

Quoted 8 lines
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +1 -1
@@ -313,7 +313,7 @@ static void exynos_drm_fbdev_destroy(struct drm_device *dev,
 	struct exynos_drm_gem_obj *exynos_gem_obj = exynos_fbd->exynos_gem_obj;
 	struct drm_framebuffer *fb;
 
-	if (is_drm_iommu_supported(dev) && exynos_gem_obj->buffer->kvaddr)
+	if (is_drm_iommu_supported(dev))
 		vunmap(exynos_gem_obj->buffer->kvaddr);
 
 	/* release drm framebuffer and real buffer */

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

#873 lore raw

Re: [PATCH] GPU-DRM-Exynos: Delete unnecessary checks before two function calls

Quoted 43 lines
Quoted 43 lines

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 21:54:45 +0100

The functions phy_power_on() and vunmap() perform also input parameter validation. Thus the test around their calls is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/exynos/exynos_dp_core.c   | 6 ++----
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/drm/exynos/exynos_dp_core.c +2 -4
index 34d46aa..306cf1d 100644
@@ -1057,14 +1057,12 @@ static int exynos_dp_create_connector(struct exynos_drm_display *display,
 
 static void exynos_dp_phy_init(struct exynos_dp_device *dp)
 {
-	if (dp->phy)
-		phy_power_on(dp->phy);
+	phy_power_on(dp->phy);
 }
 
 static void exynos_dp_phy_exit(struct exynos_dp_device *dp)
 {
-	if (dp->phy)
-		phy_power_off(dp->phy);
+	phy_power_off(dp->phy);
 }
 
 static void exynos_dp_poweron(struct exynos_drm_display *display)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +0 -0
index e12ea90..0dd448a 100644
@@ -313,7 +313,7 @@ static void exynos_drm_fbdev_destroy(struct drm_device *dev,
 	struct exynos_drm_gem_obj *exynos_gem_obj = exynos_fbd->exynos_gem_obj;
 	struct drm_framebuffer *fb;
 
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_fbdev.c static void exynos_drm_fbdev_destroy(struct drm_device *dev, · line 319

Quoted 6 lines
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +1 -1
-	if (is_drm_iommu_supported(dev) && exynos_gem_obj->buffer->kvaddr)
+	if (is_drm_iommu_supported(dev))
 		vunmap(exynos_gem_obj->buffer->kvaddr);
 
 	/* release drm framebuffer and real buffer */

Do the chances increase to integrate this update suggestion into another source code repository?

Regards,
Markus

#874 lore raw

PATCH 1/1 GPU-DRM-Exynos: Delete an unnecessary check before the function call "vunmap"

In reply to Joonyoung Shim

From: Markus Elfring <[email protected]>
Date: Thu, 21 Jul 2016 19:23:25 +0200

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

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +1 -2
index dd09117..4cfb39d 100644
@@ -269,8 +269,7 @@ static void exynos_drm_fbdev_destroy(struct drm_device *dev,
 	struct exynos_drm_gem *exynos_gem = exynos_fbd->exynos_gem;
 	struct drm_framebuffer *fb;
 
-	if (exynos_gem->kvaddr)
-		vunmap(exynos_gem->kvaddr);
+	vunmap(exynos_gem->kvaddr);
 
 	/* release drm framebuffer and real buffer */
 	if (fb_helper->fb && fb_helper->fb->funcs) {
Signature · 1 line
2.9.2
Applied
#875 lore raw

Re: [PATCH] GPU-DRM-Exynos: Delete an unnecessary check before the function call "vunmap"

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 21 Jul 2016 19:23:25 +0200

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

This issue was detected by using the Coccinelle software.

Applied to drm-misc

Quoted 25 lines
---
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +1 -3
index dd09117..4cfb39d 100644
@@ -269,8 +269,7 @@ static void exynos_drm_fbdev_destroy(struct drm_device *dev,
        struct exynos_drm_gem *exynos_gem = exynos_fbd->exynos_gem;
        struct drm_framebuffer *fb;
 
-       if (exynos_gem->kvaddr)
-               vunmap(exynos_gem->kvaddr);
+       vunmap(exynos_gem->kvaddr);
 
        /* release drm framebuffer and real buffer */
        if (fb_helper->fb && fb_helper->fb->funcs) {
--

2.9.2

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

#876 lore raw

PATCH 1/1 GPU-DRM-OMAP: Delete unnecessary checks before two function calls

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 4 Feb 2015 22:22:36 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/omapdrm/omap_fbdev.c | 3 +--
 drivers/gpu/drm/omapdrm/omap_gem.c   | 5 ++---
 2 files changed, 3 insertions(+), 5 deletions(-)
drivers/gpu/drm/omapdrm/omap_fbdev.c +1 -2
index d292d24..fcc02b0 100644
@@ -270,8 +270,7 @@ fail_unlock:
 fail:
 
 	if (ret) {
-		if (fbi)
-			framebuffer_release(fbi);
+		framebuffer_release(fbi);
 		if (fb) {
 			drm_framebuffer_unregister_private(fb);
 			drm_framebuffer_remove(fb);
drivers/gpu/drm/omapdrm/omap_gem.c +2 -3
index aeb91ed..18a4137 100644
@@ -1292,12 +1292,11 @@ void omap_gem_free_object(struct drm_gem_object *obj)
 		if (omap_obj->pages)
 			omap_gem_detach_pages(obj);
 
-		if (!is_shmem(obj)) {
+		if (!is_shmem(obj))
 			dma_free_writecombine(dev->dev, obj->size,
 					omap_obj->vaddr, omap_obj->paddr);
-		} else if (omap_obj->vaddr) {
+		else
 			vunmap(omap_obj->vaddr);
-		}
 	}
 
 	/* don't free externally allocated syncobj */
Signature · 1 line
2.2.2
#877 lore raw

PATCH 1/1 GPU-DRM-OMAP: Delete unnecessary checks before two function calls

From: Markus Elfring <[email protected]>
Date: Fri, 22 Jul 2016 08:28:31 +0200

The following functions test whether their argument is NULL and then return immediately.
* backlight_device_unregister
* drm_gem_object_unreference_unlocked

Thus the test around the calls is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c | 3 +--
 drivers/gpu/drm/omapdrm/omap_fb.c               | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/omapdrm/displays/panel-dsi-cm.c +1 -2
index 1b0cf2d..0eae8af 100644
@@ -1284,8 +1284,7 @@ static int dsicm_probe(struct platform_device *pdev)
 	return 0;
 
 err_sysfs_create:
-	if (bldev != NULL)
-		backlight_device_unregister(bldev);
+	backlight_device_unregister(bldev);
 err_bl:
 	destroy_workqueue(ddata->workqueue);
 err_reg:
drivers/gpu/drm/omapdrm/omap_fb.c +2 -2
index 983c8cf..31f5178 100644
@@ -115,8 +115,8 @@ static void omap_framebuffer_destroy(struct drm_framebuffer *fb)
 
 	for (i = 0; i < n; i++) {
 		struct plane *plane = &omap_fb->planes[i];
-		if (plane->bo)
-			drm_gem_object_unreference_unlocked(plane->bo);
+
+		drm_gem_object_unreference_unlocked(plane->bo);
 	}
 
 	kfree(omap_fb);
Signature · 1 line
2.9.2
#878 lore raw

PATCH 1/1 GPU-DRM-Tegra: Delete an unnecessary check before the function call "vunmap"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 10:12:51 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/tegra/fb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/tegra/fb.c +1 -1
index e9c715d..803598e 100644
@@ -66,7 +66,7 @@ static void tegra_fb_destroy(struct drm_framebuffer *framebuffer)
 		struct tegra_bo *bo = fb->planes[i];
 
 		if (bo) {
-			if (bo->pages && bo->vaddr)
+			if (bo->pages)
 				vunmap(bo->vaddr);
 
 			drm_gem_object_unreference_unlocked(&bo->gem);
Signature · 1 line
2.2.2
#879 lore raw

Re: [PATCH] GPU-DRM-Tegra: Delete an unnecessary check before the function call "vunmap"

Quoted 19 lines

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 10:12:51 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/tegra/fb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/tegra/fb.c +0 -0
index e9c715d..803598e 100644

drivers/gpu/drm/tegra/fb.c static void tegra_fb_destroy(struct drm_framebuffer *framebuffer) · line 72

Quoted 8 lines
drivers/gpu/drm/tegra/fb.c +1 -1
@@ -66,7 +66,7 @@ static void tegra_fb_destroy(struct drm_framebuffer *framebuffer)
 		struct tegra_bo *bo = fb->planes[i];
 
 		if (bo) {
-			if (bo->pages && bo->vaddr)
+			if (bo->pages)
 				vunmap(bo->vaddr);
 
 			drm_gem_object_unreference_unlocked(&bo->gem);

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

Regards,
Markus

#880 lore raw

Re: [PATCH] GPU-DRM-Tegra: Delete an unnecessary check before the function call "vunmap"

Quoted 7 lines · SF Markus Elfring
Quoted 7 lines

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 10:12:51 +0100

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

This issue was detected by using the Coccinelle software.

The fix is correct, but the subject looks weird.
"GPU-DRM-Tegra:"should be "drm/tegra:".

Otherwise,

Maybe Thierry can take it through his tree once this issue is addressed?

#881 lore raw

PATCH 1/1 drm/tegra: Delete an unnecessary check before the function call "vunmap"

From: Markus Elfring <[email protected]>
Date: Sat, 16 Jul 2016 07:23:42 +0200

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

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/tegra/fb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/tegra/fb.c +1 -1
index 1b12aa7..e6d71fa 100644
@@ -68,7 +68,7 @@ static void tegra_fb_destroy(struct drm_framebuffer *framebuffer)
 		struct tegra_bo *bo = fb->planes[i];
 
 		if (bo) {
-			if (bo->pages && bo->vaddr)
+			if (bo->pages)
 				vunmap(bo->vaddr);
 
 			drm_gem_object_unreference_unlocked(&bo->gem);
Signature · 1 line
2.9.1
#882 lore raw

PATCH 1/1 driver core: Delete an unnecessary check before the function call "put_device"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 11:48:26 +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/base/core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/base/core.c +1 -2
index 97e2baf..9c6536f 100644
@@ -1095,8 +1095,7 @@ done:
 	kobject_del(&dev->kobj);
  Error:
 	cleanup_device_parent(dev);
-	if (parent)
-		put_device(parent);
+	put_device(parent);
 name_error:
 	kfree(dev->p);
 	dev->p = NULL;
Signature · 1 line
2.2.2
#883 lore raw

PATCH 1/1 InfiniBand: Delete unnecessary checks before the function, call "srp_destroy_fr_pool"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 13:20:42 +0100

The srp_destroy_fr_pool() 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/infiniband/ulp/srp/ib_srp.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/infiniband/ulp/srp/ib_srp.c +5 -7
index 0747c05..6f5dfa1 100644
@@ -549,8 +549,7 @@ static int srp_create_ch_ib(struct srp_rdma_ch *ch)
 				     "FR pool allocation failed (%d)\n", ret);
 			goto err_qp;
 		}
-		if (ch->fr_pool)
-			srp_destroy_fr_pool(ch->fr_pool);
+		srp_destroy_fr_pool(ch->fr_pool);
 		ch->fr_pool = fr_pool;
 	} else if (!dev->use_fast_reg && dev->has_fmr) {
 		fmr_pool = srp_alloc_fmr_pool(target);
@@ -615,13 +614,12 @@ static void srp_free_ch_ib(struct srp_target_port *target,
 	if (!ch->qp)
 		return;
 
-	if (dev->use_fast_reg) {
-		if (ch->fr_pool)
-			srp_destroy_fr_pool(ch->fr_pool);
-	} else {
+	if (dev->use_fast_reg)
+		srp_destroy_fr_pool(ch->fr_pool);
+	else
 		if (ch->fmr_pool)
 			ib_destroy_fmr_pool(ch->fmr_pool);
-	}
+
 	srp_destroy_qp(ch);
 	ib_destroy_cq(ch->send_cq);
 	ib_destroy_cq(ch->recv_cq);
Signature · 1 line
2.2.2
#884 lore raw

Re: [PATCH] InfiniBand: Delete unnecessary checks before the function, call "srp_destroy_fr_pool"

Quoted 35 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 13:20:42 +0100

The srp_destroy_fr_pool() 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/infiniband/ulp/srp/ib_srp.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/infiniband/ulp/srp/ib_srp.c +1 -6
index 0747c05..6f5dfa1 100644
@@ -549,8 +549,7 @@ static int srp_create_ch_ib(struct srp_rdma_ch *ch)
 				     "FR pool allocation failed (%d)\n", ret);
 			goto err_qp;
 		}
-		if (ch->fr_pool)
-			srp_destroy_fr_pool(ch->fr_pool);
+		srp_destroy_fr_pool(ch->fr_pool);
 		ch->fr_pool = fr_pool;
 	} else if (!dev->use_fast_reg && dev->has_fmr) {
 		fmr_pool = srp_alloc_fmr_pool(target);
@@ -615,13 +614,12 @@ static void srp_free_ch_ib(struct srp_target_port *target,
 	if (!ch->qp)
 		return;
 
-	if (dev->use_fast_reg) {
-		if (ch->fr_pool)
-			srp_destroy_fr_pool(ch->fr_pool);
-	} else {

drivers/infiniband/ulp/srp/ib_srp.c static void srp_free_ch_ib(struct srp_target_port *target, · line 625

Quoted 10 lines
drivers/infiniband/ulp/srp/ib_srp.c +4 -1
+	if (dev->use_fast_reg)
+		srp_destroy_fr_pool(ch->fr_pool);
+	else
 		if (ch->fmr_pool)
 			ib_destroy_fmr_pool(ch->fmr_pool);
-	}
+
 	srp_destroy_qp(ch);
 	ib_destroy_cq(ch->send_cq);
 	ib_destroy_cq(ch->recv_cq);

This patch makes the code in srp_free_ch_ib() asymmetric which is unfortunate. Please add a test in ib_destroy_fmr_pool() such that the check before ib_destroy_fmr_pool() can also be eliminated.

Bart.

#885 lore raw

PATCH 1/1 au1100fb: Delete unnecessary checks before two function calls

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 14:10:21 +0100

The functions clk_enable() and clk_disable() test whether their argument is NULL and then return immediately. Thus the test around the calls is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/video/fbdev/au1100fb.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/video/fbdev/au1100fb.c +2 -8
index 5956018..47ee023 100644
@@ -605,11 +605,8 @@ int au1100fb_drv_suspend(struct platform_device *dev, pm_message_t state)
 	/* Blank the LCD */
 	au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
 
-	if (fbdev->lcdclk)
-		clk_disable(fbdev->lcdclk);
-
+	clk_disable(fbdev->lcdclk);
 	memcpy(&fbregs, fbdev->regs, sizeof(struct au1100fb_regs));
-
 	return 0;
 }
 
@@ -621,13 +618,10 @@ int au1100fb_drv_resume(struct platform_device *dev)
 		return 0;
 
 	memcpy(fbdev->regs, &fbregs, sizeof(struct au1100fb_regs));
-
-	if (fbdev->lcdclk)
-		clk_enable(fbdev->lcdclk);
+	clk_enable(fbdev->lcdclk);
 
 	/* Unblank the LCD */
 	au1100fb_fb_blank(VESA_NO_BLANKING, &fbdev->info);
-
 	return 0;
 }
 #else
Signature · 1 line
2.2.2
#886 lore raw

Re: [PATCH] au1100fb: Delete unnecessary checks before two function calls

Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 14:10:21 +0100

The functions clk_enable() and clk_disable() test whether their argument is NULL and then return immediately.

This isn't true for clk_enable().

"I find it acceptable that some of my update suggestions do not fit to your quality expectations at the moment." --
https://lkml.org/lkml/2015/1/22/446

It's frustrating that you make the same mistake over and over and you are fine with doing that. If you make a mistake and you are fixing a bug, then hopefully you fix more bugs than you introduce. If you make a mistake and you are doing a cleanup then you are really just introducing bugs and that's not helpful. I wish you would find something useful to do instead of sending these patches. :(

regards,
dan carpenter

#887 lore raw

Re: [PATCH] au1100fb: Delete unnecessary checks before two function calls

Quoted 4 lines
Quoted 2 lines

The functions clk_enable() and clk_disable() test whether their argument is NULL and then return immediately.

This isn't true for clk_enable().

I stumble on an interesting name space issue once more.

Quoted 2 lines

It's frustrating that you make the same mistake over and over and you are fine with doing that.

I admit that there can be also risks with my update suggestions in similar ways to contributions from other software developers.

A specific function implementation exists which performs also input parameter validation.
http://lxr.free-electrons.com/source/drivers/sh/clk/core.c#L291

Such variants might not fit to the functions au1100fb_drv_suspend() and au1100fb_drv_resume().

Do you want that I send a reduced patch?

Regards,
Markus

#888 lore raw

Re: [PATCH] au1100fb: Delete unnecessary checks before two function calls

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

The functions clk_enable() and clk_disable() test whether their argument is NULL and then return immediately.

This isn't true for clk_enable().

I stumble on an interesting name space issue once more.

The "once more" is the problem in this statement. Other people would have stopped making the mistake by now. I am able to see your bugs so you should be able to see your bugs as well.

Quoted 7 lines
Quoted 3 lines

It's frustrating that you make the same mistake over and over and you are fine with doing that.

I admit that there can be also risks with my update suggestions in similar ways to contributions from other software developers.

At times, I have told other people to stop sending cleanups until they can at least fix a bugs to balance out the bugs they have introduced. It's unacceptable to only introduce bugs and never fix any.

regards,
dan carpenter

#889 lore raw

Re: [PATCH] au1100fb: Delete unnecessary checks before two function calls

Quoted 1 line

It's unacceptable to only introduce bugs

Such a view is generally fine.

Would you like to point any more update candidates out from my suggestion collection?

Quoted 1 line

and never fix any.

Would you like to clarify any statistics around my update suggestions?

Regards,
Markus

#890 lore raw

PATCH 1/1 USB: appledisplay: Deletion of a check before backlight_device_unregister()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 16:07:43 +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/usb/misc/appledisplay.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/misc/appledisplay.c +1 -1
index b3d245e..a0a3827 100644
@@ -329,7 +329,7 @@ error:
 					pdata->urbdata, pdata->urb->transfer_dma);
 			usb_free_urb(pdata->urb);
 		}
-		if (pdata->bd && !IS_ERR(pdata->bd))
+		if (!IS_ERR(pdata->bd))
 			backlight_device_unregister(pdata->bd);
 		kfree(pdata->msgdata);
 	}
Signature · 1 line
2.2.2
#891 lore raw

PATCH 1/1 ueagle-atm: Delete unnecessary checks before the function call "release_firmware"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 16:33:09 +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/atm/ueagle-atm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/atm/ueagle-atm.c +2 -2
index 5a45937..888998a 100644
@@ -952,7 +952,7 @@ static void uea_load_page_e1(struct work_struct *work)
 	int i;
 
 	/* reload firmware when reboot start and it's loaded already */
-	if (ovl = 0 && pageno = 0 && sc->dsp_firm) {
+	if (ovl = 0 && pageno = 0) {
 		release_firmware(sc->dsp_firm);
 		sc->dsp_firm = NULL;
 	}
@@ -1074,7 +1074,7 @@ static void uea_load_page_e4(struct work_struct *work)
 	uea_dbg(INS_TO_USBDEV(sc), "sending DSP page %u\n", pageno);
 
 	/* reload firmware when reboot start and it's loaded already */
-	if (pageno = 0 && sc->dsp_firm) {
+	if (pageno = 0) {
 		release_firmware(sc->dsp_firm);
 		sc->dsp_firm = NULL;
 	}
Signature · 1 line
2.2.2
#892 lore raw

PATCH 1/1 USB: whci-hcd: Delete an unnecessary check before the function call "usb_put_hcd"

In reply to SF Markus Elfring

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

The usb_put_hcd() 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/whci/hcd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/host/whci/hcd.c +1 -2
index d7b363a..43626c4 100644
@@ -313,8 +313,7 @@ error_wusbhc_create:
 	uwb_rc_put(wusbhc->uwb_rc);
 error:
 	whc_clean_up(whc);
-	if (usb_hcd)
-		usb_put_hcd(usb_hcd);
+	usb_put_hcd(usb_hcd);
 	return ret;
 }
 
Signature · 1 line
2.2.2
#893 lore raw

PATCH 1/1 Input: Delete an unnecessary check before the function call "input_free_device"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 17:35:35 +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/input/joystick/adi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/input/joystick/adi.c +1 -2
index b784257..d09cefa 100644
@@ -535,8 +535,7 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
 		}
 	}
  fail2:	for (i = 0; i < 2; i++)
-		if (port->adi[i].dev)
-			input_free_device(port->adi[i].dev);
+		input_free_device(port->adi[i].dev);
 	gameport_close(gameport);
  fail1:	gameport_set_drvdata(gameport, NULL);
 	kfree(port);
Signature · 1 line
2.2.2
maintainer Applied
#894 lore raw

Re: [PATCH] Input: Delete an unnecessary check before the function call "input_free_device"

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 17:35:35 +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.

Applied, thank you.

Quoted 21 lines
---
 drivers/input/joystick/adi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/input/joystick/adi.c +1 -2
index b784257..d09cefa 100644
@@ -535,8 +535,7 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
 		}
 	}
  fail2:	for (i = 0; i < 2; i++)
-		if (port->adi[i].dev)
-			input_free_device(port->adi[i].dev);
+		input_free_device(port->adi[i].dev);
 	gameport_close(gameport);
  fail1:	gameport_set_drvdata(gameport, NULL);
 	kfree(port);
Signature · 1 line
2.2.2
Signature · 1 line
Dmitry
#895 lore raw

PATCH 1/1 uwb/whci: Delete an unnecessary check before the function call "umc_device_unregister"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 21:40:29 +0100

The umc_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/uwb/whci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/uwb/whci.c +1 -2
index 46b7cfc..c3ee39a 100644
@@ -133,8 +133,7 @@ static void whci_del_cap(struct whci_card *card, int n)
 {
 	struct umc_dev *umc = card->devs[n];
 
-	if (umc != NULL)
-		umc_device_unregister(umc);
+	umc_device_unregister(umc);
 }
 
 static int whci_n_caps(struct pci_dev *pci)
Signature · 1 line
2.2.2
#896 lore raw

PATCH 1/1 SCSI-bfa: Delete more unnecessary checks before the function call "vfree"

In reply to SF Markus Elfring

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

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

This issue was detected by using the Coccinelle software.

---
 drivers/scsi/bfa/bfad.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/bfa/bfad.c +3 -3
index e90a374..05c8ca0 100644
@@ -1810,11 +1810,11 @@ bfad_load_fwimg(struct pci_dev *pdev)
 static void
 bfad_free_fwimg(void)
 {
-	if (bfi_image_ct2_size && bfi_image_ct2)
+	if (bfi_image_ct2_size)
 		vfree(bfi_image_ct2);
-	if (bfi_image_ct_size && bfi_image_ct)
+	if (bfi_image_ct_size)
 		vfree(bfi_image_ct);
-	if (bfi_image_cb_size && bfi_image_cb)
+	if (bfi_image_cb_size)
 		vfree(bfi_image_cb);
 }
 
Signature · 1 line
2.2.2
#897 lore raw

PATCH 1/1 SCSI-aic7...: Delete unnecessary checks before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 22:23:48 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/scsi/aic7xxx/aic7xxx_core.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/scsi/aic7xxx/aic7xxx_core.c +5 -10
index 10172a3..98a5ed1 100644
@@ -2200,8 +2200,7 @@ ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel, int force)
 	if (channel = 'B')
 		scsi_id += 8;
 	tstate = ahc->enabled_targets[scsi_id];
-	if (tstate != NULL)
-		kfree(tstate);
+	kfree(tstate);
 	ahc->enabled_targets[scsi_id] = NULL;
 }
 #endif
@@ -4482,8 +4481,7 @@ ahc_set_unit(struct ahc_softc *ahc, int unit)
 void
 ahc_set_name(struct ahc_softc *ahc, char *name)
 {
-	if (ahc->name != NULL)
-		kfree(ahc->name);
+	kfree(ahc->name);
 	ahc->name = name;
 }
 
@@ -4550,10 +4548,8 @@ ahc_free(struct ahc_softc *ahc)
 		kfree(ahc->black_hole);
 	}
 #endif
-	if (ahc->name != NULL)
-		kfree(ahc->name);
-	if (ahc->seep_config != NULL)
-		kfree(ahc->seep_config);
+	kfree(ahc->name);
+	kfree(ahc->seep_config);
 #ifndef __FreeBSD__
 	kfree(ahc);
 #endif
@@ -4958,8 +4954,7 @@ ahc_fini_scbdata(struct ahc_softc *ahc)
 	case 0:
 		break;
 	}
-	if (scb_data->scbarray != NULL)
-		kfree(scb_data->scbarray);
+	kfree(scb_data->scbarray);
 }
 
 static void
Signature · 1 line
2.2.2
#898 lore raw

Re: [PATCH] SCSI-aic7...: Delete unnecessary checks before the function call "kfree"

Am 05.02.2015 um 22:27 schrieb SF Markus Elfring:

Quoted 52 lines

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 22:23:48 +0100

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

This issue was detected by using the Coccinelle software.

---
 drivers/scsi/aic7xxx/aic7xxx_core.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/scsi/aic7xxx/aic7xxx_core.c +4 -8
index 10172a3..98a5ed1 100644
@@ -2200,8 +2200,7 @@ ahc_free_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel, int force)
 	if (channel = 'B')
 		scsi_id += 8;
 	tstate = ahc->enabled_targets[scsi_id];
-	if (tstate != NULL)
-		kfree(tstate);
+	kfree(tstate);
 	ahc->enabled_targets[scsi_id] = NULL;
 }
 #endif
@@ -4482,8 +4481,7 @@ ahc_set_unit(struct ahc_softc *ahc, int unit)
 void
 ahc_set_name(struct ahc_softc *ahc, char *name)
 {
-	if (ahc->name != NULL)
-		kfree(ahc->name);
+	kfree(ahc->name);
 	ahc->name = name;
 }
 
@@ -4550,10 +4548,8 @@ ahc_free(struct ahc_softc *ahc)
 		kfree(ahc->black_hole);
 	}
 #endif
-	if (ahc->name != NULL)
-		kfree(ahc->name);
-	if (ahc->seep_config != NULL)
-		kfree(ahc->seep_config);
+	kfree(ahc->name);
+	kfree(ahc->seep_config);
 #ifndef __FreeBSD__
 	kfree(ahc);
 #endif

drivers/scsi/aic7xxx/aic7xxx_core.c ahc_fini_scbdata(struct ahc_softc *ahc) · line 4960

Quoted 9 lines
drivers/scsi/aic7xxx/aic7xxx_core.c +1 -2
@@ -4958,8 +4954,7 @@ ahc_fini_scbdata(struct ahc_softc *ahc)
 	case 0:
 		break;
 	}
-	if (scb_data->scbarray != NULL)
-		kfree(scb_data->scbarray);
+	kfree(scb_data->scbarray);
 }
 
 static void

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

Regards,
Markus

#899 lore raw

cover SCSI-lpfc: Deletion of an unnecessary check

In reply to SF Markus Elfring

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

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

Markus Elfring (2):
Delete an unnecessary check before the function call "kfree" One function call less in lpfc_bsg_hba_set_event() after error detection

 drivers/scsi/lpfc/lpfc_bsg.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
Signature · 1 line
2.2.2
#900 lore raw

PATCH 1/2 SCSI-lpfc: Delete an unnecessary check before the function call "kfree"

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 22:45:02 +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/lpfc/lpfc_bsg.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/scsi/lpfc/lpfc_bsg.c +1 -3
index a7bf359..1af783a 100644
@@ -1261,9 +1261,7 @@ lpfc_bsg_hba_set_event(struct fc_bsg_job *job)
 	return 0; /* call job done later */
 
 job_error:
-	if (dd_data != NULL)
-		kfree(dd_data);
-
+	kfree(dd_data);
 	job->dd_data = NULL;
 	return rc;
 }
Signature · 1 line
2.2.2
#901 lore raw

PATCH 2/2 SCSI-lpfc: One function call less in lpfc_bsg_hba_set_event() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 5 Feb 2015 23:03:52 +0100

The kfree() function was called in two cases by the lpfc_bsg_hba_set_event() function during error handling even if the passed variable "dd_data" contained still a null pointer.

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

---
 drivers/scsi/lpfc/lpfc_bsg.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/scsi/lpfc/lpfc_bsg.c +3 -2
index 1af783a..b8074cf 100644
@@ -1240,7 +1240,7 @@ lpfc_bsg_hba_set_event(struct fc_bsg_job *job)
 					"2617 Failed allocation of event "
 					"waiter\n");
 			rc = -ENOMEM;
-			goto job_error;
+			goto free_data;
 		}
 		dd_data->type = TYPE_EVT;
 		dd_data->set_job = NULL;
@@ -1260,8 +1260,9 @@ lpfc_bsg_hba_set_event(struct fc_bsg_job *job)
 	spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
 	return 0; /* call job done later */
 
-job_error:
+free_data:
 	kfree(dd_data);
+job_error:
 	job->dd_data = NULL;
 	return rc;
 }
Signature · 1 line
2.2.2
Acked-by on the v1 series
#902 lore raw

Re: [PATCH 0/2] SCSI-lpfc: Deletion of an unnecessary check

In reply to SF Markus Elfring

Markus,

Suggestions noted. If not merged, I'll pull them into the next patch set.

-- james

Quoted 13 lines · SF Markus Elfring

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

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

Markus Elfring (2):
Delete an unnecessary check before the function call "kfree" One function call less in lpfc_bsg_hba_set_event() after error detection

  drivers/scsi/lpfc/lpfc_bsg.c | 7 +++----
  1 file changed, 3 insertions(+), 4 deletions(-)
#903 lore raw

cover SCSI-debug: Deletion of a few unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 6 Feb 2015 18:08:53 +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 "vfree" Less function calls in scsi_debug_init() after error detection Fix exception handling for an alignment/granularity mismatch
in scsi_debug_init()

 drivers/scsi/scsi_debug.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
Signature · 1 line
2.2.2
#904 lore raw

PATCH 1/3 SCSI-debug: Deletion of unnecessary checks before the function call "vfree"

From: Markus Elfring <[email protected]>
Date: Fri, 6 Feb 2015 16:56:57 +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/scsi_debug.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/scsi/scsi_debug.c +3 -9
index 1132321..9e4add7 100644
@@ -4969,12 +4969,9 @@ bus_unreg:
 dev_unreg:
 	root_device_unregister(pseudo_primary);
 free_vm:
-	if (map_storep)
-		vfree(map_storep);
-	if (dif_storep)
-		vfree(dif_storep);
+	vfree(map_storep);
+	vfree(dif_storep);
 	vfree(fake_storep);
-
 	return ret;
 }
 
@@ -4989,10 +4986,7 @@ static void __exit scsi_debug_exit(void)
 	driver_unregister(&sdebug_driverfs_driver);
 	bus_unregister(&pseudo_lld_bus);
 	root_device_unregister(pseudo_primary);
-
-	if (dif_storep)
-		vfree(dif_storep);
-
+	vfree(dif_storep);
 	vfree(fake_storep);
 }
 
Signature · 1 line
2.2.2
Acked-by on v1 1/3
#905 lore raw

Re: [PATCH 1/3] SCSI-debug: Deletion of unnecessary checks before the function call "vfree"

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 6 Feb 2015 16:56:57 +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.

Quoted 36 lines
---
  drivers/scsi/scsi_debug.c | 12 +++---------
  1 file changed, 3 insertions(+), 9 deletions(-)
drivers/scsi/scsi_debug.c +3 -9
index 1132321..9e4add7 100644
@@ -4969,12 +4969,9 @@ bus_unreg:
  dev_unreg:
  	root_device_unregister(pseudo_primary);
  free_vm:
-	if (map_storep)
-		vfree(map_storep);
-	if (dif_storep)
-		vfree(dif_storep);
+	vfree(map_storep);
+	vfree(dif_storep);
  	vfree(fake_storep);
-
  	return ret;
  }
 
@@ -4989,10 +4986,7 @@ static void __exit scsi_debug_exit(void)
  	driver_unregister(&sdebug_driverfs_driver);
  	bus_unregister(&pseudo_lld_bus);
  	root_device_unregister(pseudo_primary);
-
-	if (dif_storep)
-		vfree(dif_storep);
-
+	vfree(dif_storep);
  	vfree(fake_storep);
  }
 
#906 lore raw

PATCH 2/3 SCSI-debug: Less function calls in scsi_debug_init() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 6 Feb 2015 17:48:34 +0100

The vfree() function was called in two cases by the scsi_debug_init() function during error handling even if the passed variables "dif_storep" and "map_storep" contained null pointers eventually.

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

---
 drivers/scsi/scsi_debug.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/scsi/scsi_debug.c +6 -4
index 9e4add7..756b7be 100644
@@ -4887,7 +4887,7 @@ static int __init scsi_debug_init(void)
 		if (dif_storep = NULL) {
 			pr_err("%s: out of mem. (DIX)\n", __func__);
 			ret = -ENOMEM;
-			goto free_vm;
+			goto free_fake;
 		}
 
 		memset(dif_storep, 0xff, dif_size);
@@ -4920,7 +4920,7 @@ static int __init scsi_debug_init(void)
 		if (map_storep = NULL) {
 			pr_err("%s: out of mem. (MAP)\n", __func__);
 			ret = -ENOMEM;
-			goto free_vm;
+			goto free_dif;
 		}
 
 		bitmap_zero(map_storep, map_size);
@@ -4934,7 +4934,7 @@ static int __init scsi_debug_init(void)
 	if (IS_ERR(pseudo_primary)) {
 		pr_warn("%s: root_device_register() error\n", __func__);
 		ret = PTR_ERR(pseudo_primary);
-		goto free_vm;
+		goto free_map;
 	}
 	ret = bus_register(&pseudo_lld_bus);
 	if (ret < 0) {
@@ -4968,9 +4968,11 @@ bus_unreg:
 	bus_unregister(&pseudo_lld_bus);
 dev_unreg:
 	root_device_unregister(pseudo_primary);
-free_vm:
+free_map:
 	vfree(map_storep);
+free_dif:
 	vfree(dif_storep);
+free_fake:
 	vfree(fake_storep);
 	return ret;
 }
Signature · 1 line
2.2.2
Acked-by on v1 2/3
#907 lore raw

Re: [PATCH 2/3] SCSI-debug: Less function calls in scsi_debug_init() after error detection

Quoted 11 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 6 Feb 2015 17:48:34 +0100

The vfree() function was called in two cases by the scsi_debug_init() function during error handling even if the passed variables "dif_storep" and "map_storep" contained null pointers eventually.

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

Quoted 49 lines
---
  drivers/scsi/scsi_debug.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/scsi/scsi_debug.c +6 -4
index 9e4add7..756b7be 100644
@@ -4887,7 +4887,7 @@ static int __init scsi_debug_init(void)
  		if (dif_storep = NULL) {
  			pr_err("%s: out of mem. (DIX)\n", __func__);
  			ret = -ENOMEM;
-			goto free_vm;
+			goto free_fake;
  		}
 
  		memset(dif_storep, 0xff, dif_size);
@@ -4920,7 +4920,7 @@ static int __init scsi_debug_init(void)
  		if (map_storep = NULL) {
  			pr_err("%s: out of mem. (MAP)\n", __func__);
  			ret = -ENOMEM;
-			goto free_vm;
+			goto free_dif;
  		}
 
  		bitmap_zero(map_storep, map_size);
@@ -4934,7 +4934,7 @@ static int __init scsi_debug_init(void)
  	if (IS_ERR(pseudo_primary)) {
  		pr_warn("%s: root_device_register() error\n", __func__);
  		ret = PTR_ERR(pseudo_primary);
-		goto free_vm;
+		goto free_map;
  	}
  	ret = bus_register(&pseudo_lld_bus);
  	if (ret < 0) {
@@ -4968,9 +4968,11 @@ bus_unreg:
  	bus_unregister(&pseudo_lld_bus);
  dev_unreg:
  	root_device_unregister(pseudo_primary);
-free_vm:
+free_map:
  	vfree(map_storep);
+free_dif:
  	vfree(dif_storep);
+free_fake:
  	vfree(fake_storep);
  	return ret;
  }
#908 lore raw

PATCH 3/3 SCSI-debug: Fix exception handling for an alignment/granularity mismatch in scsi_debug_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 6 Feb 2015 17:57:32 +0100

The scsi_debug_init() function returned directly if the data items "alignment" and "granularity" did not fit together.

Let us improve the affected exception handling by replacing the return statement by a goto statement so that previously allocated resources will also be appropriately released.

---
 drivers/scsi/scsi_debug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/scsi_debug.c +2 -1
index 756b7be..2c78663 100644
@@ -4909,7 +4909,8 @@ static int __init scsi_debug_init(void)
 		    scsi_debug_unmap_alignment) {
 			pr_err("%s: ERR: unmap_granularity <= unmap_alignment\n",
 			       __func__);
-			return -EINVAL;
+			ret = -EINVAL;
+			goto free_dif;
 		}
 
 		map_size = lba_to_map_index(sdebug_store_sectors - 1) + 1;
Signature · 1 line
2.2.2
Acked-by on v1 3/3
#909 lore raw

Re: [PATCH 3/3] SCSI-debug: Fix exception handling for an alignment/granularity mismatch in scsi_debug_init()

Quoted 11 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 6 Feb 2015 17:57:32 +0100

The scsi_debug_init() function returned directly if the data items "alignment" and "granularity" did not fit together.

Let us improve the affected exception handling by replacing the return statement by a goto statement so that previously allocated resources will also be appropriately released.

Quoted 19 lines
---
  drivers/scsi/scsi_debug.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/scsi_debug.c +2 -1
index 756b7be..2c78663 100644
@@ -4909,7 +4909,8 @@ static int __init scsi_debug_init(void)
  		    scsi_debug_unmap_alignment) {
  			pr_err("%s: ERR: unmap_granularity <= unmap_alignment\n",
  			       __func__);
-			return -EINVAL;
+			ret = -EINVAL;
+			goto free_dif;
  		}
 
  		map_size = lba_to_map_index(sdebug_store_sectors - 1) + 1;
#910 lore raw

PATCH 1/1 SCSI-csiostor: Delete an unnecessary check before the function call "release_firmware"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 6 Feb 2015 19:10:25 +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/scsi/csiostor/csio_hw.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/csiostor/csio_hw.c +1 -2
index 35c5f83..37fa8bf 100644
@@ -2117,8 +2117,7 @@ csio_hw_flash_fw(struct csio_hw *hw, int *reset)
 			 hw->fw_state, reset);
 
 	/* Cleaning up */
-	if (fw != NULL)
-		release_firmware(fw);
+	release_firmware(fw);
 	kfree(card_fw);
 	return ret;
 }
Signature · 1 line
2.2.2
#911 lore raw

cover SCSI-QLA4...: Deletion of some unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 6 Feb 2015 23:03:41 +0100

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

Markus Elfring (4):
Deletion of unnecessary checks before three function calls Less function calls in qla4xxx_is_session_exists() after error detection Less function calls in qla4xxx_is_flash_ddb_exists() after error detection Less function calls in qla4xxx_sysfs_ddb_logout() after error detection

 drivers/scsi/qla4xxx/ql4_mbx.c |  2 +-
 drivers/scsi/qla4xxx/ql4_os.c  | 96 ++++++++++++++++++------------------------
 2 files changed, 42 insertions(+), 56 deletions(-)
Signature · 1 line
2.2.2
#912 lore raw

PATCH 1/4 SCSI-QLA4...: Deletion of unnecessary checks before three function calls

From: Markus Elfring <[email protected]>
Date: Fri, 6 Feb 2015 20:38:23 +0100

The following functions perform also input parameter validation.
* iscsi_boot_destroy_kset
* kfree
* vfree

Thus the test around their calls is not needed.

This issue was detected by using the Coccinelle software.

---
 drivers/scsi/qla4xxx/ql4_mbx.c |  2 +-
 drivers/scsi/qla4xxx/ql4_os.c  | 31 ++++++++++---------------------
 2 files changed, 11 insertions(+), 22 deletions(-)
drivers/scsi/qla4xxx/ql4_mbx.c +1 -1
index c291fdf..2343c0f 100644
@@ -2410,7 +2410,7 @@ exit_free_acb:
 	dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk), acb,
 			  acb_dma);
 exit_config_acb:
-	if ((acb_config = ACB_CONFIG_SET) && ha->saved_acb) {
+	if (acb_config = ACB_CONFIG_SET) {
 		kfree(ha->saved_acb);
 		ha->saved_acb = NULL;
 	}
drivers/scsi/qla4xxx/ql4_os.c +10 -21
index 6d25879..2a00fd3 100644
@@ -4131,9 +4131,7 @@ static void qla4xxx_mem_free(struct scsi_qla_host *ha)
 		dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
 				  ha->queues_dma);
 
-	 if (ha->fw_dump)
-		vfree(ha->fw_dump);
-
+	vfree(ha->fw_dump);
 	ha->queues_len = 0;
 	ha->queues = NULL;
 	ha->queues_dma = 0;
@@ -4155,8 +4153,7 @@ static void qla4xxx_mem_free(struct scsi_qla_host *ha)
 	if (ha->chap_dma_pool)
 		dma_pool_destroy(ha->chap_dma_pool);
 
-	if (ha->chap_list)
-		vfree(ha->chap_list);
+	vfree(ha->chap_list);
 	ha->chap_list = NULL;
 
 	if (ha->fw_ddb_dma_pool)
@@ -4175,9 +4172,7 @@ static void qla4xxx_mem_free(struct scsi_qla_host *ha)
 		iounmap(ha->reg);
 	}
 
-	if (ha->reset_tmplt.buff)
-		vfree(ha->reset_tmplt.buff);
-
+	vfree(ha->reset_tmplt.buff);
 	pci_release_regions(ha->pdev);
 }
 
@@ -6370,10 +6365,8 @@ static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
 	}
 
 exit_check:
-	if (fw_tddb)
-		vfree(fw_tddb);
-	if (tmp_tddb)
-		vfree(tmp_tddb);
+	vfree(fw_tddb);
+	vfree(tmp_tddb);
 	return ret;
 }
 
@@ -6525,10 +6518,8 @@ static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
 	}
 
 exit_check:
-	if (fw_tddb)
-		vfree(fw_tddb);
-	if (tmp_tddb)
-		vfree(tmp_tddb);
+	vfree(fw_tddb);
+	vfree(tmp_tddb);
 	return ret;
 }
 
@@ -7806,10 +7797,8 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
 		ret = -ESRCH;
 
 exit_ddb_logout:
-	if (flash_tddb)
-		vfree(flash_tddb);
-	if (tmp_tddb)
-		vfree(tmp_tddb);
+	vfree(flash_tddb);
+	vfree(tmp_tddb);
 	if (fw_ddb_entry)
 		dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
 
@@ -9002,7 +8991,7 @@ static void qla4xxx_remove_adapter(struct pci_dev *pdev)
 	/* destroy iface from sysfs */
 	qla4xxx_destroy_ifaces(ha);
 
-	if ((!ql4xdisablesysfsboot) && ha->boot_kset)
+	if (!ql4xdisablesysfsboot)
 		iscsi_boot_destroy_kset(ha->boot_kset);
 
 	qla4xxx_destroy_fw_ddb_session(ha);
Signature · 1 line
2.2.2
#913 lore raw

PATCH 2/4 SCSI-QLA4...: Less function calls in qla4xxx_is_session_exists() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 6 Feb 2015 21:14:40 +0100

The vfree() function was called in two cases by the qla4xxx_is_session_exists() function during error handling even if the passed variables "fw_tddb" and "tmp_tddb" contained still a null pointer.

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

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

---
 drivers/scsi/qla4xxx/ql4_os.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/scsi/qla4xxx/ql4_os.c +8 -9
index 2a00fd3..a7ca479 100644
@@ -6327,17 +6327,15 @@ static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
 				     uint32_t *index)
 {
 	struct ddb_entry *ddb_entry;
-	struct ql4_tuple_ddb *fw_tddb = NULL;
-	struct ql4_tuple_ddb *tmp_tddb = NULL;
 	int idx;
 	int ret = QLA_ERROR;
+	struct ql4_tuple_ddb *tmp_tddb;
+	struct ql4_tuple_ddb *fw_tddb = vzalloc(sizeof(*fw_tddb));
 
-	fw_tddb = vzalloc(sizeof(*fw_tddb));
 	if (!fw_tddb) {
 		DEBUG2(ql4_printk(KERN_WARNING, ha,
 				  "Memory Allocation failed.\n"));
-		ret = QLA_SUCCESS;
-		goto exit_check;
+		return QLA_SUCCESS;
 	}
 
 	tmp_tddb = vzalloc(sizeof(*tmp_tddb));
@@ -6345,7 +6343,7 @@ static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
 		DEBUG2(ql4_printk(KERN_WARNING, ha,
 				  "Memory Allocation failed.\n"));
 		ret = QLA_SUCCESS;
-		goto exit_check;
+		goto free_fw;
 	}
 
 	qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
@@ -6360,13 +6358,14 @@ static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
 			ret = QLA_SUCCESS; /* found */
 			if (index != NULL)
 				*index = idx;
-			goto exit_check;
+			goto free_tmp;
 		}
 	}
 
-exit_check:
-	vfree(fw_tddb);
+free_tmp:
 	vfree(tmp_tddb);
+free_fw:
+	vfree(fw_tddb);
 	return ret;
 }
 
Signature · 1 line
2.2.2
#914 lore raw

Re: [PATCH 2/4] SCSI-QLA4...: Less function calls in qla4xxx_is_session_exists() after error detection

Quoted 5 lines · SF Markus Elfring
drivers/scsi/qla4xxx/ql4_os.c +0 -0
index 2a00fd3..a7ca479 100644

drivers/scsi/qla4xxx/ql4_os.c static int qla4xxx_is_session_exists(struct scsi_qla_host *ha, · line 6334

Quoted 10 lines
drivers/scsi/qla4xxx/ql4_os.c +2 -2
@@ -6327,17 +6327,15 @@ static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
 				     uint32_t *index)
 {
 	struct ddb_entry *ddb_entry;
-	struct ql4_tuple_ddb *fw_tddb = NULL;
-	struct ql4_tuple_ddb *tmp_tddb = NULL;
 	int idx;
 	int ret = QLA_ERROR;
+	struct ql4_tuple_ddb *tmp_tddb;
+	struct ql4_tuple_ddb *fw_tddb = vzalloc(sizeof(*fw_tddb));
 

Don't do allocations in the initializers. Same for patches 3 and 4 as well.

regards,
dan carpenter

#915 lore raw

Re: [PATCH 2/4] SCSI-QLA4...: Less function calls in qla4xxx_is_session_exists() after error detection

Quoted 11 lines · Dan Carpenter
Quoted 10 lines · SF Markus Elfring
drivers/scsi/qla4xxx/ql4_os.c +0 -2
index 2a00fd3..a7ca479 100644
@@ -6327,17 +6327,15 @@ static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
 				     uint32_t *index)
 {
 	struct ddb_entry *ddb_entry;
-	struct ql4_tuple_ddb *fw_tddb = NULL;
-	struct ql4_tuple_ddb *tmp_tddb = NULL;
Quoted 8 lines

drivers/scsi/qla4xxx/ql4_os.c static int qla4xxx_is_session_exists(struct scsi_qla_host *ha, · line 6334

Quoted 5 lines
drivers/scsi/qla4xxx/ql4_os.c +2 -0
 	int idx;
 	int ret = QLA_ERROR;
+	struct ql4_tuple_ddb *tmp_tddb;
+	struct ql4_tuple_ddb *fw_tddb = vzalloc(sizeof(*fw_tddb));
 

Don't do allocations in the initializers. Same for patches 3 and 4 as well.

Why not? I can think of some reasons, but I am wondering what is the precise one.

thanks,
julia

#916 lore raw

Re: [PATCH 2/4] SCSI-QLA4...: Less function calls in qla4xxx_is_session_exists() after error detection

Quoted 22 lines · Julia Lawall
Quoted 11 lines · Dan Carpenter
Quoted 10 lines · SF Markus Elfring
drivers/scsi/qla4xxx/ql4_os.c +0 -2
index 2a00fd3..a7ca479 100644
@@ -6327,17 +6327,15 @@ static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
 				     uint32_t *index)
 {
 	struct ddb_entry *ddb_entry;
-	struct ql4_tuple_ddb *fw_tddb = NULL;
-	struct ql4_tuple_ddb *tmp_tddb = NULL;
Quoted 8 lines

drivers/scsi/qla4xxx/ql4_os.c static int qla4xxx_is_session_exists(struct scsi_qla_host *ha, · line 6334

Quoted 5 lines
drivers/scsi/qla4xxx/ql4_os.c +2 -0
 	int idx;
 	int ret = QLA_ERROR;
+	struct ql4_tuple_ddb *tmp_tddb;
+	struct ql4_tuple_ddb *fw_tddb = vzalloc(sizeof(*fw_tddb));
 

Don't do allocations in the initializers. Same for patches 3 and 4 as well.

Quoted 2 lines

Why not? I can think of some reasons, but I am wondering what is the precise one.

1) People gloss over initializers without reading them. You shouldn't put complicated code in initializers. Sarah Sharp is more strict on this than I am. http://www.spinics.net/lists/linux-usb/msg44389.html

2) It means you have to put a line of separation between the allocation and the NULL check, but they should be next to each other.

regards,
dan carpenter

#917 lore raw

Re: [PATCH 2/4] SCSI-QLA4...: Less function calls in qla4xxx_is_session_exists() after error detection

Quoted 1 line

1) People gloss over initializers without reading them.

I would find such a habit strange.

Quoted 1 line

You shouldn't put complicated code in initializers.

Does the affected memory allocation fall into such a category?

Quoted 2 lines

2) It means you have to put a line of separation between the allocation and the NULL check, but they should be next to each other.

Would you like to extend the Linux coding style documentation?

Regards,
Markus

#918 lore raw

PATCH 3/4 SCSI-QLA4...: Less function calls in qla4xxx_is_flash_ddb_exists() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 6 Feb 2015 21:55:55 +0100

The vfree() function was called in two cases by the qla4xxx_is_flash_ddb_exists() function during error handling even if the passed variables "fw_tddb" and "tmp_tddb" contained still a null pointer.

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

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

---
 drivers/scsi/qla4xxx/ql4_os.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/scsi/qla4xxx/ql4_os.c +9 -10
index a7ca479..e508bc9 100644
@@ -6470,16 +6470,14 @@ static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
 				       struct dev_db_entry *fw_ddb_entry)
 {
 	struct qla_ddb_index  *nt_ddb_idx, *nt_ddb_idx_tmp;
-	struct ql4_tuple_ddb *fw_tddb = NULL;
-	struct ql4_tuple_ddb *tmp_tddb = NULL;
 	int rval, ret = QLA_ERROR;
+	struct ql4_tuple_ddb *tmp_tddb;
+	struct ql4_tuple_ddb *fw_tddb = vzalloc(sizeof(*fw_tddb));
 
-	fw_tddb = vzalloc(sizeof(*fw_tddb));
 	if (!fw_tddb) {
 		DEBUG2(ql4_printk(KERN_WARNING, ha,
 				  "Memory Allocation failed.\n"));
-		ret = QLA_SUCCESS;
-		goto exit_check;
+		return QLA_SUCCESS;
 	}
 
 	tmp_tddb = vzalloc(sizeof(*tmp_tddb));
@@ -6487,7 +6485,7 @@ static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
 		DEBUG2(ql4_printk(KERN_WARNING, ha,
 				  "Memory Allocation failed.\n"));
 		ret = QLA_SUCCESS;
-		goto exit_check;
+		goto vfree_fw;
 	}
 
 	qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb, NULL);
@@ -6498,7 +6496,7 @@ static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
 		ret = qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb, true);
 		/* found duplicate ddb */
 		if (ret = QLA_SUCCESS)
-			goto exit_check;
+			goto vfree_tmp;
 	}
 
 	list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
@@ -6512,13 +6510,14 @@ static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
 			else
 				ret = QLA_SUCCESS;
 
-			goto exit_check;
+			goto vfree_tmp;
 		}
 	}
 
-exit_check:
-	vfree(fw_tddb);
+vfree_tmp:
 	vfree(tmp_tddb);
+vfree_fw:
+	vfree(fw_tddb);
 	return ret;
 }
 
Signature · 1 line
2.2.2
#919 lore raw

PATCH 4/4 SCSI-QLA4...: Less function calls in qla4xxx_sysfs_ddb_logout() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 6 Feb 2015 22:44:23 +0100

The vfree() function was called in three cases by the qla4xxx_sysfs_ddb_logout() function during error handling even if the passed variables "flash_tddb" and "tmp_tddb" contained still a null pointer.

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

* Let us return immediately after the first failed function call according to the current Linux coding style convention.

* Delete also an unnecessary check for the variable "fw_ddb_entry" there.

---
 drivers/scsi/qla4xxx/ql4_os.c | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)
drivers/scsi/qla4xxx/ql4_os.c +17 -18
index e508bc9..802390b 100644
@@ -7699,23 +7699,22 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
 {
 	struct Scsi_Host *shost = iscsi_flash_session_to_shost(fnode_sess);
 	struct scsi_qla_host *ha = to_qla_host(shost);
-	struct ql4_tuple_ddb *flash_tddb = NULL;
-	struct ql4_tuple_ddb *tmp_tddb = NULL;
-	struct dev_db_entry *fw_ddb_entry = NULL;
-	struct ddb_entry *ddb_entry = NULL;
 	dma_addr_t fw_ddb_dma;
 	uint32_t next_idx = 0;
 	uint32_t state = 0, conn_err = 0;
 	uint16_t conn_id = 0;
 	int idx, index;
 	int status, ret = 0;
+	struct ql4_tuple_ddb *flash_tddb;
+	struct ql4_tuple_ddb *tmp_tddb;
+	struct ddb_entry *ddb_entry;
+	struct dev_db_entry *fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool,
+								GFP_KERNEL,
+								&fw_ddb_dma);
 
-	fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
-				      &fw_ddb_dma);
-	if (fw_ddb_entry = NULL) {
+	if (!fw_ddb_entry) {
 		ql4_printk(KERN_ERR, ha, "%s:Out of memory\n", __func__);
-		ret = -ENOMEM;
-		goto exit_ddb_logout;
+		return -ENOMEM;
 	}
 
 	flash_tddb = vzalloc(sizeof(*flash_tddb));
@@ -7723,7 +7722,7 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
 		ql4_printk(KERN_WARNING, ha,
 			   "%s:Memory Allocation failed.\n", __func__);
 		ret = -ENOMEM;
-		goto exit_ddb_logout;
+		goto free_pool;
 	}
 
 	tmp_tddb = vzalloc(sizeof(*tmp_tddb));
@@ -7731,7 +7730,7 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
 		ql4_printk(KERN_WARNING, ha,
 			   "%s:Memory Allocation failed.\n", __func__);
 		ret = -ENOMEM;
-		goto exit_ddb_logout;
+		goto free_flash;
 	}
 
 	if (!fnode_sess->targetname) {
@@ -7739,7 +7738,7 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
 			   "%s:Cannot logout from SendTarget entry\n",
 			   __func__);
 		ret = -EPERM;
-		goto exit_ddb_logout;
+		goto free_tmp;
 	}
 
 	if (fnode_sess->is_boot_target) {
@@ -7747,7 +7746,7 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
 			   "%s: Logout from boot target entry is not permitted.\n",
 			   __func__);
 		ret = -EPERM;
-		goto exit_ddb_logout;
+		goto free_tmp;
 	}
 
 	strlcpy(flash_tddb->iscsi_name, fnode_sess->targetname,
@@ -7794,12 +7793,12 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess,
 	if (idx = MAX_DDB_ENTRIES)
 		ret = -ESRCH;
 
-exit_ddb_logout:
-	vfree(flash_tddb);
+free_tmp:
 	vfree(tmp_tddb);
-	if (fw_ddb_entry)
-		dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
-
+free_flash:
+	vfree(flash_tddb);
+free_pool:
+	dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
 	return ret;
 }
 
Signature · 1 line
2.2.2
#920 lore raw

PATCH 1/1 video: fbdev-SIS: Deletion of unnecessary checks before three function calls

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 21 Feb 2015 14:14:56 +0100

The functions sisfb_search_crt2type(), sisfb_search_specialtiming() and sisfb_search_tvstd() 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/video/fbdev/sis/sis_main.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/video/fbdev/sis/sis_main.c +3 -8
index fcf610e..20ca80f 100644
@@ -6605,12 +6605,9 @@ static int __init sisfb_init_module(void)
 		sisfb_scalelcd = scalelcd ^ 1;
 
 	/* Need to check crt2 type first for fstn/dstn */
+	sisfb_search_crt2type(forcecrt2type);
 
-	if(forcecrt2type)
-		sisfb_search_crt2type(forcecrt2type);
-
-	if(tvstandard)
-		sisfb_search_tvstd(tvstandard);
+	sisfb_search_tvstd(tvstandard);
 
 	if(mode)
 		sisfb_search_mode(mode, false);
@@ -6656,9 +6653,7 @@ static int __init sisfb_init_module(void)
 		sisfb_pdca = (pdc1 & 0x1f);
 
 	sisfb_nocrt2rate = nocrt2rate;
-
-	if(specialtiming)
-		sisfb_search_specialtiming(specialtiming);
+	sisfb_search_specialtiming(specialtiming);
 
 	if((lvdshl >= 0) && (lvdshl <= 3))
 		sisfb_lvdshl = lvdshl;
Signature · 1 line
2.3.0
#921 lore raw

PATCH 1/1 crypto-jitterentropy: Delete unnecessary checks before the function call "kzfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 23 Jun 2015 22:30:21 +0200

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.

---
 crypto/jitterentropy.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
crypto/jitterentropy.c +2 -4
index d3c3045..22ded3e 100644
@@ -698,11 +698,9 @@ static struct rand_data *jent_entropy_collector_alloc(unsigned int osr,
 
 static void jent_entropy_collector_free(struct rand_data *entropy_collector)
 {
-	if (entropy_collector->mem)
-		kzfree(entropy_collector->mem);
+	kzfree(entropy_collector->mem);
 	entropy_collector->mem = NULL;
-	if (entropy_collector)
-		kzfree(entropy_collector);
+	kzfree(entropy_collector);
 	entropy_collector = NULL;
 }
 
Signature · 1 line
2.4.4
#922 lore raw

Re: [PATCH] crypto-jitterentropy: Delete unnecessary checks before the function call "kzfree"

Am Dienstag, 23. Juni 2015, 23:20:21 schrieb SF Markus Elfring:

Hi Markus,

Quoted 7 lines

From: Markus Elfring <[email protected]>
Date: Tue, 23 Jun 2015 22:30:21 +0200

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.

Ack: the patch is correct and I was overzealous.

Nack: I just proposed a patch earlier today to avoid compiler warnings [1]. That patch clashes with yours. May I ask you to wait briefly to see whether that patch will be accepted? If yes, it would be great if you could repost the patch that applies to the changed code.

PS: when you are at it, maybe even the last line in the function can be
removed: setting the entropy_collector to NULL at that the end of the function is moot as well.

Thanks.

[1] http://lkml.iu.edu/hypermail/linux/kernel/1506.2/05196.html

Quoted 24 lines
---
 crypto/jitterentropy.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
crypto/jitterentropy.c +2 -4
index d3c3045..22ded3e 100644
@@ -698,11 +698,9 @@ static struct rand_data
 *jent_entropy_collector_alloc(unsigned int osr,
 
 static void jent_entropy_collector_free(struct rand_data
 *entropy_collector) {
-	if (entropy_collector->mem)
-		kzfree(entropy_collector->mem);
+	kzfree(entropy_collector->mem);
 	entropy_collector->mem = NULL;
-	if (entropy_collector)
-		kzfree(entropy_collector);
+	kzfree(entropy_collector);
 	entropy_collector = NULL;
 }
Signature · 2 lines
Ciao
Stephan
#923 lore raw

Re: [PATCH] crypto-jitterentropy: Delete unnecessary checks before the function call "kzfree"

The other NULL assignment isn't useful either. Also If "entropy_collector" is NULL then we would oops calling

kzfree(entropy_collector->mem);
       ^^^^^^^^^^^^^^^^^^^^^^

Dereference.

I don't understand the patch that you sent. We shouldn't be introducing jent_zalloc() or jent_zfree(). Why are you adding abstractions there? Quite bad ones as well.

regards,
dan carpenter

#924 lore raw

Re: [PATCH] crypto-jitterentropy: Delete unnecessary checks before the function call "kzfree"

Am Mittwoch, 24. Juni 2015, 10:48:19 schrieb Dan Carpenter:

Hi Dan,

Quoted 8 lines

The other NULL assignment isn't useful either. Also If "entropy_collector" is NULL then we would oops calling

kzfree(entropy_collector->mem);
      ^^^^^^^^^^^^^^^^^^^^^^

Dereference.

I don't understand the patch that you sent. We shouldn't be introducing jent_zalloc() or jent_zfree(). Why are you adding abstractions there?

The one C file should have no dependencies on any kernel header files. Thus, all links to kernel functions are wrapped.

Quoted 1 line

Quite bad ones as well.

What would you suggest to change?

Thanks.

Ciao
Stephan

#925 lore raw

Re: [PATCH] crypto-jitterentropy: Delete unnecessary checks before the function call "kzfree"

Ah. I should have read the whole thread. I sort of assumed we were just adding abstractions for the fun of it (because I have worked in staging for too long).

regards,
dan carpenter

maintainer Applied
#926 lore raw

Re: [PATCH] crypto-jitterentropy: Delete 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: Tue, 23 Jun 2015 22:30:21 +0200

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.

Applied.

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

ACPI-APEI: Make exception handling a bit more efficient in __einj_error_trigger()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 24 Jun 2015 11:41:46 +0200

Return from the __einj_error_trigger() function directly after a failed call for the request_mem_region() function according to the current Linux coding style convention.

Drop an unnecessary initialisation for the variable "trigger_tab" then.

---
 drivers/acpi/apei/einj.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/acpi/apei/einj.c +3 -3
index a095d4f..c3a2c06 100644
@@ -299,7 +299,7 @@ static struct acpi_generic_address *einj_get_trigger_parameter_region(
 static int __einj_error_trigger(u64 trigger_paddr, u32 type,
 				u64 param1, u64 param2)
 {
-	struct acpi_einj_trigger *trigger_tab = NULL;
+	struct acpi_einj_trigger *trigger_tab;
 	struct apei_exec_context trigger_ctx;
 	struct apei_resources trigger_resources;
 	struct acpi_whea_header *trigger_entry;
@@ -316,7 +316,7 @@ static int __einj_error_trigger(u64 trigger_paddr, u32 type,
 		       (unsigned long long)trigger_paddr,
 		       (unsigned long long)trigger_paddr +
 			    sizeof(*trigger_tab) - 1);
-		goto out;
+		return rc;
 	}
 	trigger_tab = ioremap_cache(trigger_paddr, sizeof(*trigger_tab));
 	if (!trigger_tab) {
@@ -407,7 +407,7 @@ out_rel_entry:
 			   table_size - sizeof(*trigger_tab));
 out_rel_header:
 	release_mem_region(trigger_paddr, sizeof(*trigger_tab));
-out:
+
 	if (trigger_tab)
 		iounmap(trigger_tab);
 
Signature · 1 line
2.4.4
#928 lore raw

PATCH 1/1 ACPICA: Delete an unnecessary check before the function call "acpi_ds_delete_walk_state"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 24 Jun 2015 13:33:47 +0200

The acpi_ds_delete_walk_state() 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/acpica/dsmethod.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/acpi/acpica/dsmethod.c +1 -4
index 85bb951..188b254 100644
@@ -574,10 +574,7 @@ cleanup:
 	/* On error, we must terminate the method properly */
 
 	acpi_ds_terminate_control_method(obj_desc, next_walk_state);
-	if (next_walk_state) {
-		acpi_ds_delete_walk_state(next_walk_state);
-	}
-
+	acpi_ds_delete_walk_state(next_walk_state);
 	return_ACPI_STATUS(status);
 }
 
Signature · 1 line
2.4.4
#929 lore raw

RE: [PATCH] ACPICA: Delete an unnecessary check before the function call "acpi_ds_delete_walk_state"

Got it, thanks.

Quoted 41 lines

-----Original Message-----
From: SF Markus Elfring [mailto:elfring(a)users.sourceforge.net]
Sent: Wednesday, June 24, 2015 4:46 AM
To: Len Brown; Zheng, Lv; Wysocki, Rafael J; Moore, Robert; linux- acpi(a)vger.kernel.org; devel(a)acpica.org
Cc: LKML; kernel-janitors(a)vger.kernel.org; Julia Lawall
Subject: [PATCH] ACPICA: Delete an unnecessary check before the function call "acpi_ds_delete_walk_state"

From: Markus Elfring <elfring(a)users.sourceforge.net>
Date: Wed, 24 Jun 2015 13:33:47 +0200

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

Signed-off-by Markus Elfring <elfring(a)users.sourceforge.net>
---
 drivers/acpi/acpica/dsmethod.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/acpi/acpica/dsmethod.c index 85bb951..188b254 100644

drivers/acpi/acpica/dsmethod.c +1 -5
@@ -574,10 +574,7 @@ cleanup:
 	/* On error, we must terminate the method properly */
 
 	acpi_ds_terminate_control_method(obj_desc, next_walk_state);
-	if (next_walk_state) {
-		acpi_ds_delete_walk_state(next_walk_state);
-	}
-
+	acpi_ds_delete_walk_state(next_walk_state);
 	return_ACPI_STATUS(status);
 }
 
--

2.4.4

#930 lore raw

PATCH 1/1 kdbus: Delete an unnecessary check before the function call "kdbus_domain_unref"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 24 Jun 2015 14:30:17 +0200

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

---
 ipc/kdbus/fs.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
ipc/kdbus/fs.c +1 -3
index d01f33b..205a3ad 100644
@@ -325,9 +325,7 @@ static void fs_super_kill(struct super_block *sb)
 	}
 
 	kill_anon_super(sb);
-
-	if (domain)
-		kdbus_domain_unref(domain);
+	kdbus_domain_unref(domain);
 }
 
 static int fs_super_set(struct super_block *sb, void *data)
Signature · 1 line
2.4.4
Reviewed-by on v1 1/1
#931 lore raw

Re: [PATCH] kdbus: Delete an unnecessary check before the function call "kdbus_domain_unref"

Hi

Quoted 18 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 24 Jun 2015 14:30:17 +0200

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

---
 ipc/kdbus/fs.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
ipc/kdbus/fs.c +0 -0
index d01f33b..205a3ad 100644

ipc/kdbus/fs.c static void fs_super_kill(struct super_block *sb) · line 328

Quoted 7 lines
ipc/kdbus/fs.c +1 -3
@@ -325,9 +325,7 @@ static void fs_super_kill(struct super_block *sb)
        }
 
        kill_anon_super(sb);
-
-       if (domain)
-               kdbus_domain_unref(domain);
+       kdbus_domain_unref(domain);

Yeah, your patch is correct. The condition was kinda nice as it shows the connection to the tear-down before the call to kill_anon_super(). But the function is simple enough for a reader to figure out themselves.

Thanks
David

Quoted 6 lines
ipc/kdbus/fs.c +0 -1
 }
 
 static int fs_super_set(struct super_block *sb, void *data)
--

2.4.4

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

Re: [PATCH] kdbus: Delete an unnecessary check before the function call "kdbus_domain_unref"

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

From: Markus Elfring <[email protected]>
Date: Wed, 24 Jun 2015 14:30:17 +0200

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

---
 ipc/kdbus/fs.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
ipc/kdbus/fs.c +1 -3
index d01f33b..205a3ad 100644
@@ -325,9 +325,7 @@ static void fs_super_kill(struct super_block *sb)
 	}
 
 	kill_anon_super(sb);
-
-	if (domain)
-		kdbus_domain_unref(domain);
+	kdbus_domain_unref(domain);
 }
 
 static int fs_super_set(struct super_block *sb, void *data)
Signature · 1 line
2.4.4
Signature · 2 lines
Djalal Harouni
http://opendz.org
#933 lore raw

Re: [PATCH] kdbus: Delete an unnecessary check before the function call "kdbus_domain_unref"

In reply to SF Markus Elfring

Hi

Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 24 Jun 2015 14:30:17 +0200

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

Quoted 6 lines

This issue was detected by using the Coccinelle software.

---
 ipc/kdbus/fs.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Applied!

Thanks
David

Quoted 18 lines
ipc/kdbus/fs.c +1 -4
index d01f33b..205a3ad 100644
@@ -325,9 +325,7 @@ static void fs_super_kill(struct super_block *sb)
        }
 
        kill_anon_super(sb);
-
-       if (domain)
-               kdbus_domain_unref(domain);
+       kdbus_domain_unref(domain);
 }
 
 static int fs_super_set(struct super_block *sb, void *data)
--

2.4.4

#934 lore raw

PATCH 1/1 SCSI-wd33c93: Deletion of a check before the function call "wd33c93_setup"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 24 Jun 2015 17:15:17 +0200

The wd33c93_setup() 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/wd33c93.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/wd33c93.c +1 -1
index 9e09da4..e5ed956 100644
@@ -1939,7 +1939,7 @@ wd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs,
 	int val;
 	char buf[32];
 
-	if (!done_setup && setup_strings)
+	if (!done_setup)
 		wd33c93_setup(setup_strings);
 
 	hostdata = (struct WD33C93_hostdata *) instance->hostdata;
Signature · 1 line
2.4.4
#935 lore raw

Re: [PATCH] SCSI-wd33c93: Deletion of a check before the function call "wd33c93_setup"

Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 24 Jun 2015 17:15:17 +0200

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

Guys, you should be aware that Markus auto generates his patches and he doesn't even do a cursory review.

"I find it acceptable that some of my update suggestions do not fit to your quality expectations at the moment." -- Markus Elfring
(https://lkml.org/lkml/2015/1/22/446)

regards,
dan carpenter

#936 lore raw

PATCH 1/1 s390/process: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 24 Jun 2015 22:40:30 +0200

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

This issue was detected by using the Coccinelle software.

---
 arch/s390/kernel/process.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/s390/kernel/process.c +1 -2
index dc5edc2..22e6448 100644
@@ -81,8 +81,7 @@ void release_thread(struct task_struct *dead_task)
 
 void arch_release_task_struct(struct task_struct *tsk)
 {
-	if (tsk->thread.vxrs)
-		kfree(tsk->thread.vxrs);
+	kfree(tsk->thread.vxrs);
 }
 
 int copy_thread(unsigned long clone_flags, unsigned long new_stackp,
Signature · 1 line
2.4.4
#937 lore raw

Re: [PATCH] s390/process: Delete an unnecessary check before the function call "kfree"

Am 24.06.2015 22:48, schrieb SF Markus Elfring:

Quoted 18 lines

From: Markus Elfring <[email protected]>
Date: Wed, 24 Jun 2015 22:40:30 +0200

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

This issue was detected by using the Coccinelle software.

---
 arch/s390/kernel/process.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/s390/kernel/process.c +0 -0
index dc5edc2..22e6448 100644

arch/s390/kernel/process.c void release_thread(struct task_struct *dead_task) · line 87

Quoted 9 lines
arch/s390/kernel/process.c +1 -2
@@ -81,8 +81,7 @@ void release_thread(struct task_struct *dead_task)
 
 void arch_release_task_struct(struct task_struct *tsk)
 {
-	if (tsk->thread.vxrs)
-		kfree(tsk->thread.vxrs);
+	kfree(tsk->thread.vxrs);
 }
 
 int copy_thread(unsigned long clone_flags, unsigned long new_stackp,

maybe the intention was to check tsk != NULL ?

re,
wh

#938 lore raw

Re: [PATCH] s390/process: Delete an unnecessary check before the function call "kfree"

Quoted 21 lines · walter harms

Am 24.06.2015 22:48, schrieb SF Markus Elfring:

Quoted 19 lines

From: Markus Elfring <[email protected]>
Date: Wed, 24 Jun 2015 22:40:30 +0200

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

This issue was detected by using the Coccinelle software.

---
 arch/s390/kernel/process.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/s390/kernel/process.c +0 -0
index dc5edc2..22e6448 100644
@@ -81,8 +81,7 @@ void release_thread(struct task_struct *dead_task)
 
Quoted 6 lines

arch/s390/kernel/process.c void release_thread(struct task_struct *dead_task) · line 85

Quoted 6 lines
arch/s390/kernel/process.c +1 -2
 void arch_release_task_struct(struct task_struct *tsk)
 {
-	if (tsk->thread.vxrs)
-		kfree(tsk->thread.vxrs);
+	kfree(tsk->thread.vxrs);
 }

This code will be changed soon anyway. So it would be rather pointless to apply your patch now. Thanks anyway!

Quoted 2 lines

arch/s390/kernel/process.c void release_thread(struct task_struct *dead_task) · line 87

Quoted 1 line
arch/s390/kernel/process.c +0 -0
 int copy_thread(unsigned long clone_flags, unsigned long new_stackp,

maybe the intention was to check tsk != NULL ?

No.

#939 lore raw

cover ARM-OMAP2+: Deletion of unnecessary checks before two function calls

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 25 Jun 2015 13:24:35 +0200

Some functions which release a system resource tolerate the passing of a null pointer. I do not see a need because of this fact that a function caller repeats a corresponding check.

Markus Elfring (2):
Delete a check before the function call "omap_device_delete" Delete a check before the function call "of_node_put"

 arch/arm/mach-omap2/omap_device.c | 3 +--
 arch/arm/mach-omap2/timer.c       | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
Signature · 1 line
2.4.4
#940 lore raw

PATCH 1/2 ARM-OMAP2+: Delete an unnecessary check before the function call "omap_device_delete"

From: Markus Elfring <[email protected]>
Date: Thu, 25 Jun 2015 13:00:11 +0200

The omap_device_delete() 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-omap2/omap_device.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm/mach-omap2/omap_device.c +1 -2
index 4cb8fd9..196366e 100644
@@ -193,8 +193,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)
Signature · 1 line
2.4.4
#941 lore raw

PATCH 2/2 ARM-OMAP2+: Delete an unnecessary check before the function call "of_node_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 25 Jun 2015 13:05:28 +0200

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/arm/mach-omap2/timer.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm/mach-omap2/timer.c +1 -2
index cac46d8..15448221 100644
@@ -208,8 +208,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.4.4
maintainer
#942 lore raw

Re: [PATCH 0/2] ARM-OMAP2+: Deletion of unnecessary checks before two function calls

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

From: Markus Elfring <[email protected]>
Date: Thu, 25 Jun 2015 13:24:35 +0200

Some functions which release a system resource tolerate the passing of a null pointer. I do not see a need because of this fact that a function caller repeats a corresponding check.

Quoted 7 lines

Markus Elfring (2):
Delete a check before the function call "omap_device_delete" Delete a check before the function call "of_node_put"

 arch/arm/mach-omap2/omap_device.c | 3 +--
 arch/arm/mach-omap2/timer.c       | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

Applying both into omap-for-v4.3/soc thanks.

Tony

#943 lore raw

cover ARM-kernel: Deletion of unnecessary checks before two function calls

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>

Some functions tolerate the passing of a null pointer. I do not see a need because of this fact that a function caller repeats a corresponding check.

Markus Elfring (2):
Delete a check before the function call "smp_set_ops" Delete a check before the function call "unwind_table_del"

 arch/arm/kernel/module.c | 3 +--
 arch/arm/kernel/setup.c  | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)
Signature · 1 line
2.4.4
#944 lore raw

PATCH 1/2 ARM-kernel: Delete an unnecessary check before the function call "smp_set_ops"

From: Markus Elfring <[email protected]>
Date: Thu, 25 Jun 2015 15:00:17 +0200

The smp_set_ops() 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/kernel/setup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/kernel/setup.c +1 -1
index e6d8c76..9ac786d 100644
@@ -977,7 +977,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.4.4
#945 lore raw

PATCH 2/2 ARM-kernel: Delete an unnecessary check before the function call "unwind_table_del"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 25 Jun 2015 15:05:21 +0200

The unwind_table_del() 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/kernel/module.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm/kernel/module.c +1 -2
index efdddcb..0cc1afa 100644
@@ -390,7 +390,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
 }
Signature · 1 line
2.4.4
#946 lore raw

cover perf header: Deletion of an unnecessary check

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>

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

Markus Elfring (2):
Delete an unnecessary check before the function call "free_event_desc" Less function calls in read_event_desc() after error detection

 tools/perf/util/header.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
Signature · 1 line
2.4.4
#947 lore raw

PATCH 1/2 perf header: Delete an unnecessary check before the function call "free_event_desc"

From: Markus Elfring <[email protected]>
Date: Thu, 25 Jun 2015 17:12:32 +0200

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

---
 tools/perf/util/header.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/util/header.c +1 -2
index 21a77e7..03ace57 100644
@@ -1063,8 +1063,7 @@ out:
 	free(buf);
 	return events;
 error:
-	if (events)
-		free_event_desc(events);
+	free_event_desc(events);
 	events = NULL;
 	goto out;
 }
Signature · 1 line
2.4.4
#948 lore raw

Re: [PATCH 1/2] perf header: Delete an unnecessary check before the function call "free_event_desc"

Em Thu, Jun 25, 2015 at 06:22:18PM +0200, SF Markus Elfring escreveu:

Quoted 7 lines

From: Markus Elfring <[email protected]>
Date: Thu, 25 Jun 2015 17:12:32 +0200

The free_event_desc() 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, applying.

- Arnaldo

Quoted 21 lines
---
 tools/perf/util/header.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/util/header.c +1 -2
index 21a77e7..03ace57 100644
@@ -1063,8 +1063,7 @@ out:
 	free(buf);
 	return events;
 error:
-	if (events)
-		free_event_desc(events);
+	free_event_desc(events);
 	events = NULL;
 	goto out;
 }
Signature · 1 line
2.4.4
#949 lore raw

[tip:perf/urgent] perf header: Delete an unnecessary check before the calling free_event_desc()

In reply to SF Markus Elfring
perf header: Delete an unnecessary check before the calling free_event_desc()
Commit-ID:  4cc97614812e96c135e369f3d723fcda07d33437
Gitweb:     http://git.kernel.org/tip/4cc97614812e96c135e369f3d723fcda07d33437
Author:     Markus Elfring <[email protected]>
AuthorDate: Thu, 25 Jun 2015 17:12:32 +0200
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 25 Jun 2015 15:15:49 -0300

perf header: Delete an unnecessary check before the calling free_event_desc()

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

---
 tools/perf/util/header.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/perf/util/header.c +1 -2
index 21a77e7..03ace57 100644
@@ -1063,8 +1063,7 @@ out:
 	free(buf);
 	return events;
 error:
-	if (events)
-		free_event_desc(events);
+	free_event_desc(events);
 	events = NULL;
 	goto out;
 }
#950 lore raw

PATCH 2/2 perf header: Less function calls in read_event_desc() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 25 Jun 2015 17:50:37 +0200

The functions "free" and "free_event_desc" were called in a few cases by the function "read_event_desc" during error handling even if the passed variable contained a null pointer.

This implementation detail could be improved by the adjustment of jump targets. Drop unnecessary initialisations for the variables "buf" and "events" then.

---
 tools/perf/util/header.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
tools/perf/util/header.c +15 -14
index 03ace57..8071163 100644
@@ -978,9 +978,9 @@ static void free_event_desc(struct perf_evsel *events)
 static struct perf_evsel *
 read_event_desc(struct perf_header *ph, int fd)
 {
-	struct perf_evsel *evsel, *events = NULL;
+	struct perf_evsel *evsel, *events;
 	u64 *id;
-	void *buf = NULL;
+	void *buf;
 	u32 nre, sz, nr, i, j;
 	ssize_t ret;
 	size_t msz;
@@ -988,14 +988,14 @@ read_event_desc(struct perf_header *ph, int fd)
 	/* number of events */
 	ret = readn(fd, &nre, sizeof(nre));
 	if (ret != (ssize_t)sizeof(nre))
-		goto error;
+		return NULL;
 
 	if (ph->needs_swap)
 		nre = bswap_32(nre);
 
 	ret = readn(fd, &sz, sizeof(sz));
 	if (ret != (ssize_t)sizeof(sz))
-		goto error;
+		return NULL;
 
 	if (ph->needs_swap)
 		sz = bswap_32(sz);
@@ -1003,12 +1003,12 @@ read_event_desc(struct perf_header *ph, int fd)
 	/* buffer to hold on file attr struct */
 	buf = malloc(sz);
 	if (!buf)
-		goto error;
+		return NULL;
 
 	/* the last event terminates with evsel->attr.size = 0: */
 	events = calloc(nre + 1, sizeof(*events));
 	if (!events)
-		goto error;
+		goto free_buffer;
 
 	msz = sizeof(evsel->attr);
 	if (sz < msz)
@@ -1023,7 +1023,7 @@ read_event_desc(struct perf_header *ph, int fd)
 		 */
 		ret = readn(fd, buf, sz);
 		if (ret != (ssize_t)sz)
-			goto error;
+			goto free_events;
 
 		if (ph->needs_swap)
 			perf_event__attr_swap(buf);
@@ -1032,7 +1032,7 @@ read_event_desc(struct perf_header *ph, int fd)
 
 		ret = readn(fd, &nr, sizeof(nr));
 		if (ret != (ssize_t)sizeof(nr))
-			goto error;
+			goto free_events;
 
 		if (ph->needs_swap) {
 			nr = bswap_32(nr);
@@ -1046,26 +1046,27 @@ read_event_desc(struct perf_header *ph, int fd)
 
 		id = calloc(nr, sizeof(*id));
 		if (!id)
-			goto error;
+			goto free_events;
 		evsel->ids = nr;
 		evsel->id = id;
 
 		for (j = 0 ; j < nr; j++) {
 			ret = readn(fd, id, sizeof(*id));
 			if (ret != (ssize_t)sizeof(*id))
-				goto error;
+				goto free_events;
 			if (ph->needs_swap)
 				*id = bswap_64(*id);
 			id++;
 		}
 	}
-out:
+
 	free(buf);
 	return events;
-error:
+free_events:
 	free_event_desc(events);
-	events = NULL;
-	goto out;
+free_buffer:
+	free(buf);
+	return NULL;
 }
 
 static int __desc_attr__fprintf(FILE *fp, const char *name, const char *val,
Signature · 1 line
2.4.4
#951 lore raw

Re: [PATCH 2/2] perf header: Less function calls in read_event_desc() after error detection

Em Thu, Jun 25, 2015 at 06:24:09PM +0200, SF Markus Elfring escreveu:

Quoted 6 lines

From: Markus Elfring <[email protected]>
Date: Thu, 25 Jun 2015 17:50:37 +0200

The functions "free" and "free_event_desc" were called in a few cases by the function "read_event_desc" during error handling even if the passed variable contained a null pointer.

And that is not a problem, free(NULL) is perfectly valid, as is valid to call free_event_desc(NULL).

But if you want to avoid those extra NULL checks done at those functions, then add a new out: label that just do 'return events;' that is NULL, etc.

- Arnaldo

Quoted 25 lines

This implementation detail could be improved by the adjustment of jump targets. Drop unnecessary initialisations for the variables "buf" and "events" then.

---
 tools/perf/util/header.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
tools/perf/util/header.c +2 -2
index 03ace57..8071163 100644
@@ -978,9 +978,9 @@ static void free_event_desc(struct perf_evsel *events)
 static struct perf_evsel *
 read_event_desc(struct perf_header *ph, int fd)
 {
-	struct perf_evsel *evsel, *events = NULL;
+	struct perf_evsel *evsel, *events;
 	u64 *id;
-	void *buf = NULL;
+	void *buf;
 	u32 nre, sz, nr, i, j;
 	ssize_t ret;
 	size_t msz;

tools/perf/util/header.c read_event_desc(struct perf_header *ph, int fd) · line 991

Quoted 5 lines
tools/perf/util/header.c +1 -1
@@ -988,14 +988,14 @@ read_event_desc(struct perf_header *ph, int fd)
 	/* number of events */
 	ret = readn(fd, &nre, sizeof(nre));
 	if (ret != (ssize_t)sizeof(nre))
-		goto error;
+		return NULL;

Please leave the single point of exit, i.e. this should 'goto out:' and the out: label will return events, that is set to NULL

Quoted 80 lines
tools/perf/util/header.c +12 -11
 	if (ph->needs_swap)
 		nre = bswap_32(nre);
 
 	ret = readn(fd, &sz, sizeof(sz));
 	if (ret != (ssize_t)sizeof(sz))
-		goto error;
+		return NULL;
 
 	if (ph->needs_swap)
 		sz = bswap_32(sz);
@@ -1003,12 +1003,12 @@ read_event_desc(struct perf_header *ph, int fd)
 	/* buffer to hold on file attr struct */
 	buf = malloc(sz);
 	if (!buf)
-		goto error;
+		return NULL;
 
 	/* the last event terminates with evsel->attr.size = 0: */
 	events = calloc(nre + 1, sizeof(*events));
 	if (!events)
-		goto error;
+		goto free_buffer;
 
 	msz = sizeof(evsel->attr);
 	if (sz < msz)
@@ -1023,7 +1023,7 @@ read_event_desc(struct perf_header *ph, int fd)
 		 */
 		ret = readn(fd, buf, sz);
 		if (ret != (ssize_t)sz)
-			goto error;
+			goto free_events;
 
 		if (ph->needs_swap)
 			perf_event__attr_swap(buf);
@@ -1032,7 +1032,7 @@ read_event_desc(struct perf_header *ph, int fd)
 
 		ret = readn(fd, &nr, sizeof(nr));
 		if (ret != (ssize_t)sizeof(nr))
-			goto error;
+			goto free_events;
 
 		if (ph->needs_swap) {
 			nr = bswap_32(nr);
@@ -1046,26 +1046,27 @@ read_event_desc(struct perf_header *ph, int fd)
 
 		id = calloc(nr, sizeof(*id));
 		if (!id)
-			goto error;
+			goto free_events;
 		evsel->ids = nr;
 		evsel->id = id;
 
 		for (j = 0 ; j < nr; j++) {
 			ret = readn(fd, id, sizeof(*id));
 			if (ret != (ssize_t)sizeof(*id))
-				goto error;
+				goto free_events;
 			if (ph->needs_swap)
 				*id = bswap_64(*id);
 			id++;
 		}
 	}
-out:
+
 	free(buf);
 	return events;
-error:
+free_events:
 	free_event_desc(events);
-	events = NULL;
-	goto out;
+free_buffer:
+	free(buf);
+	return NULL;
 }
 
 static int __desc_attr__fprintf(FILE *fp, const char *name, const char *val,
Signature · 1 line
2.4.4
#952 lore raw

Re: [PATCH 2/2] perf header: Less function calls in read_event_desc() after error detection

Quoted 6 lines
Quoted 3 lines

The functions "free" and "free_event_desc" were called in a few cases by the function "read_event_desc" during error handling even if the passed variable contained a null pointer.

And that is not a problem, free(NULL) is perfectly valid, as is valid to call free_event_desc(NULL).

I hope that inefficient exception handling can be fixed.

Quoted 2 lines

But if you want to avoid those extra NULL checks done at those functions, then add a new out: label that just do 'return events;' that is NULL, etc.

I adjusted the jump labels in the affected function already.

Quoted 25 lines
Quoted 25 lines

This implementation detail could be improved by the adjustment of jump targets. Drop unnecessary initialisations for the variables "buf" and "events" then.

---
 tools/perf/util/header.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
tools/perf/util/header.c +2 -2
index 03ace57..8071163 100644
@@ -978,9 +978,9 @@ static void free_event_desc(struct perf_evsel *events)
 static struct perf_evsel *
 read_event_desc(struct perf_header *ph, int fd)
 {
-	struct perf_evsel *evsel, *events = NULL;
+	struct perf_evsel *evsel, *events;
 	u64 *id;
-	void *buf = NULL;
+	void *buf;
 	u32 nre, sz, nr, i, j;
 	ssize_t ret;
 	size_t msz;
@@ -988,14 +988,14 @@ read_event_desc(struct perf_header *ph, int fd)
Quoted 8 lines

tools/perf/util/header.c read_event_desc(struct perf_header *ph, int fd) · line 991

Quoted 5 lines
tools/perf/util/header.c +1 -1
 	/* number of events */
 	ret = readn(fd, &nre, sizeof(nre));
 	if (ret != (ssize_t)sizeof(nre))
-		goto error;
+		return NULL;

Please leave the single point of exit, i.e. this should 'goto out:' and the out: label will return events, that is set to NULL

Does my update suggestion fit to the wording "If there is no cleanup needed then just return directly." from the Linux coding style documentation?

Quoted 79 lines
Quoted 79 lines
tools/perf/util/header.c +12 -11
 	if (ph->needs_swap)
 		nre = bswap_32(nre);
 
 	ret = readn(fd, &sz, sizeof(sz));
 	if (ret != (ssize_t)sizeof(sz))
-		goto error;
+		return NULL;
 
 	if (ph->needs_swap)
 		sz = bswap_32(sz);
@@ -1003,12 +1003,12 @@ read_event_desc(struct perf_header *ph, int fd)
 	/* buffer to hold on file attr struct */
 	buf = malloc(sz);
 	if (!buf)
-		goto error;
+		return NULL;
 
 	/* the last event terminates with evsel->attr.size = 0: */
 	events = calloc(nre + 1, sizeof(*events));
 	if (!events)
-		goto error;
+		goto free_buffer;
 
 	msz = sizeof(evsel->attr);
 	if (sz < msz)
@@ -1023,7 +1023,7 @@ read_event_desc(struct perf_header *ph, int fd)
 		 */
 		ret = readn(fd, buf, sz);
 		if (ret != (ssize_t)sz)
-			goto error;
+			goto free_events;
 
 		if (ph->needs_swap)
 			perf_event__attr_swap(buf);
@@ -1032,7 +1032,7 @@ read_event_desc(struct perf_header *ph, int fd)
 
 		ret = readn(fd, &nr, sizeof(nr));
 		if (ret != (ssize_t)sizeof(nr))
-			goto error;
+			goto free_events;
 
 		if (ph->needs_swap) {
 			nr = bswap_32(nr);
@@ -1046,26 +1046,27 @@ read_event_desc(struct perf_header *ph, int fd)
 
 		id = calloc(nr, sizeof(*id));
 		if (!id)
-			goto error;
+			goto free_events;
 		evsel->ids = nr;
 		evsel->id = id;
 
 		for (j = 0 ; j < nr; j++) {
 			ret = readn(fd, id, sizeof(*id));
 			if (ret != (ssize_t)sizeof(*id))
-				goto error;
+				goto free_events;
 			if (ph->needs_swap)
 				*id = bswap_64(*id);
 			id++;
 		}
 	}
-out:
+
 	free(buf);
 	return events;
-error:
+free_events:
 	free_event_desc(events);
-	events = NULL;
-	goto out;
+free_buffer:
+	free(buf);
+	return NULL;
 }
 
 static int __desc_attr__fprintf(FILE *fp, const char *name, const char *val,
Signature · 1 line
2.4.4
#953 lore raw

PATCH 1/1 keys: Delete an unnecessary check before the function call "key_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Jun 2015 16:10:54 +0200

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

---
 fs/ext4/crypto_key.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ext4/crypto_key.c +1 -2
index 442d24e..f8d15ae 100644
@@ -89,8 +89,7 @@ void ext4_free_crypt_info(struct ext4_crypt_info *ci)
 	if (!ci)
 		return;
 
-	if (ci->ci_keyring_key)
-		key_put(ci->ci_keyring_key);
+	key_put(ci->ci_keyring_key);
 	crypto_free_ablkcipher(ci->ci_ctfm);
 	kmem_cache_free(ext4_crypt_info_cachep, ci);
 }
Signature · 1 line
2.4.4
#954 lore raw

PATCH 1/1 fs-ext4 crypto: Delete an unnecessary check before the function call "key_put"

From: Markus Elfring <[email protected]>
Date: Fri, 26 Jun 2015 16:10:54 +0200
Subject: [PATCH] fs-ext4 crypto: Delete an unnecessary check before the
function call "key_put"

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

---
 fs/ext4/crypto_key.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ext4/crypto_key.c +1 -2
index 442d24e..f8d15ae 100644
@@ -89,8 +89,7 @@ void ext4_free_crypt_info(struct ext4_crypt_info *ci)
 	if (!ci)
 		return;
 
-	if (ci->ci_keyring_key)
-		key_put(ci->ci_keyring_key);
+	key_put(ci->ci_keyring_key);
 	crypto_free_ablkcipher(ci->ci_ctfm);
 	kmem_cache_free(ext4_crypt_info_cachep, ci);
 }
Signature · 1 line
2.4.4
#955 lore raw

PATCH 1/1 f2fs crypto: Delete an unnecessary check before the function call "key_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Jun 2015 17:28:55 +0200

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

---
 fs/f2fs/crypto_key.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/f2fs/crypto_key.c +1 -2
index 95b8f93..9f77de2 100644
@@ -92,8 +92,7 @@ static void f2fs_free_crypt_info(struct f2fs_crypt_info *ci)
 	if (!ci)
 		return;
 
-	if (ci->ci_keyring_key)
-		key_put(ci->ci_keyring_key);
+	key_put(ci->ci_keyring_key);
 	crypto_free_ablkcipher(ci->ci_ctfm);
 	kmem_cache_free(f2fs_crypt_info_cachep, ci);
 }
Signature · 1 line
2.4.4
#956 lore raw

PATCH 1/1 eCryptfs: Delete a check before the function call "key_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Jun 2015 18:18:54 +0200

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

This issue was detected by using the Coccinelle software.

---
 fs/ecryptfs/crypto.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ecryptfs/crypto.c +1 -2
index 97315f2..80d6901 100644
@@ -258,8 +258,7 @@ void ecryptfs_destroy_mount_crypt_stat(
 				 &mount_crypt_stat->global_auth_tok_list,
 				 mount_crypt_stat_list) {
 		list_del(&auth_tok->mount_crypt_stat_list);
-		if (auth_tok->global_auth_tok_key
-		    && !(auth_tok->flags & ECRYPTFS_AUTH_TOK_INVALID))
+		if (!(auth_tok->flags & ECRYPTFS_AUTH_TOK_INVALID))
 			key_put(auth_tok->global_auth_tok_key);
 		kmem_cache_free(ecryptfs_global_auth_tok_cache, auth_tok);
 	}
Signature · 1 line
2.4.4
#957 lore raw

Re: [PATCH] eCryptfs: Delete a check before the function call "key_put"

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Jun 2015 18:18:54 +0200

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

This issue was detected by using the Coccinelle software.

Thanks for the cleanup. I'll include it in an upcoming eCryptfs pull request.

Tyler

Quoted 21 lines
---
 fs/ecryptfs/crypto.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/ecryptfs/crypto.c +1 -2
index 97315f2..80d6901 100644
@@ -258,8 +258,7 @@ void ecryptfs_destroy_mount_crypt_stat(
 				 &mount_crypt_stat->global_auth_tok_list,
 				 mount_crypt_stat_list) {
 		list_del(&auth_tok->mount_crypt_stat_list);
-		if (auth_tok->global_auth_tok_key
-		    && !(auth_tok->flags & ECRYPTFS_AUTH_TOK_INVALID))
+		if (!(auth_tok->flags & ECRYPTFS_AUTH_TOK_INVALID))
 			key_put(auth_tok->global_auth_tok_key);
 		kmem_cache_free(ecryptfs_global_auth_tok_cache, auth_tok);
 	}
Signature · 1 line
2.4.4
#958 lore raw

PATCH 1/1 crypto-qat: Deletion of unnecessary checks before two function calls

In reply to SF Markus Elfring

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

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

This issue was detected by using the Coccinelle software.

---
 drivers/crypto/qat/qat_common/adf_accel_engine.c | 5 +----
 drivers/crypto/qat/qat_common/adf_transport.c    | 2 +-
 2 files changed, 2 insertions(+), 5 deletions(-)
drivers/crypto/qat/qat_common/adf_accel_engine.c +1 -4
index 7f8b66c..fdda8e7 100644
@@ -88,10 +88,7 @@ void adf_ae_fw_release(struct adf_accel_dev *accel_dev)
 
 	qat_uclo_del_uof_obj(loader_data->fw_loader);
 	qat_hal_deinit(loader_data->fw_loader);
-
-	if (loader_data->uof_fw)
-		release_firmware(loader_data->uof_fw);
-
+	release_firmware(loader_data->uof_fw);
 	loader_data->uof_fw = NULL;
 	loader_data->fw_loader = NULL;
 }
drivers/crypto/qat/qat_common/adf_transport.c +1 -1
index ccec3274..db2926b 100644
@@ -449,7 +449,7 @@ static int adf_init_bank(struct adf_accel_dev *accel_dev,
 err:
 	for (i = 0; i < ADF_ETR_MAX_RINGS_PER_BANK; i++) {
 		ring = &bank->rings[i];
-		if (hw_data->tx_rings_mask & (1 << i) && ring->inflights)
+		if (hw_data->tx_rings_mask & (1 << i))
 			kfree(ring->inflights);
 	}
 	return -ENOMEM;
Signature · 1 line
2.4.4
maintainer Applied
#959 lore raw

Re: [PATCH] crypto-qat: Deletion of unnecessary checks before two function calls

Quoted 10 lines · SF Markus Elfring

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

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

This issue was detected by using the Coccinelle software.

Applied.

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

PATCH 1/1 tc1100-wmi: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Jun 2015 21:21:16 +0200

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

This issue was detected by using the Coccinelle software.

---
 drivers/platform/x86/tc1100-wmi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/tc1100-wmi.c +1 -1
index e365425..89aa976 100644
@@ -82,7 +82,7 @@ static int get_state(u32 *out, u8 instance)
 		tmp = 0;
 	}
 
-	if (result.length > 0 && result.pointer)
+	if (result.length > 0)
 		kfree(result.pointer);
 
 	switch (instance) {
Signature · 1 line
2.4.4
Applied
#961 lore raw

Re: [PATCH] tc1100-wmi: Delete an unnecessary check before the function call "kfree"

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Jun 2015 21:21:16 +0200

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

This issue was detected by using the Coccinelle software.

Queued, thanks.

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

PATCH 1/1 staging: xgifb: Delete an unnecessary check before the function call "XGIfb_search_crt2type"

In reply to SF Markus Elfring

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

The XGIfb_search_crt2type() 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/xgifb/XGI_main_26.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/xgifb/XGI_main_26.c +1 -2
index 943d463..ee0906e 100644
@@ -2090,8 +2090,7 @@ static int __init xgifb_init(void)
 {
 	char *option = NULL;
 
-	if (forcecrt2type != NULL)
-		XGIfb_search_crt2type(forcecrt2type);
+	XGIfb_search_crt2type(forcecrt2type);
 	if (fb_get_options("xgifb", &option))
 		return -ENODEV;
 	XGIfb_setup(option);
Signature · 1 line
2.4.4
#963 lore raw

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

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Jun 2015 23:10:42 +0200

The following functions test whether their argument is NULL and then return immediately.
* kfree
* ll_file_data_put
* ptlrpc_connection_put

Thus the test around such calls is not needed.

This issue was detected by using the Coccinelle software.

See also a previous update suggestion:
"remove unneeded null test before free" by Julia Lawall
https://lkml.org/lkml/2015/5/1/498
https://www.mail-archive.com/[email protected]/msg878600.html

---
 drivers/staging/lustre/lustre/llite/file.c      | 3 +--
 drivers/staging/lustre/lustre/llite/llite_lib.c | 2 +-
 drivers/staging/lustre/lustre/ptlrpc/import.c   | 6 ++----
 drivers/staging/lustre/lustre/ptlrpc/service.c  | 4 +---
 4 files changed, 5 insertions(+), 10 deletions(-)
drivers/staging/lustre/lustre/llite/file.c +1 -2
index 3075db2..1a85c41 100644
@@ -702,8 +702,7 @@ out_och_free:
 out_openerr:
 		if (opendir_set != 0)
 			ll_stop_statahead(inode, lli->lli_opendir_key);
-		if (fd != NULL)
-			ll_file_data_put(fd);
+		ll_file_data_put(fd);
 	} else {
 		ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_OPEN, 1);
 	}
drivers/staging/lustre/lustre/llite/llite_lib.c +1 -1
index 2513988..ab4839c 100644
@@ -1114,7 +1114,7 @@ void ll_clear_inode(struct inode *inode)
 	if (lli->lli_mds_read_och)
 		ll_md_real_close(inode, FMODE_READ);
 
-	if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
+	if (S_ISLNK(inode->i_mode)) {
 		kfree(lli->lli_symlink_name);
 		lli->lli_symlink_name = NULL;
 	}
drivers/staging/lustre/lustre/ptlrpc/import.c +2 -4
index c9b8481..1eae389 100644
@@ -555,14 +555,12 @@ static int import_select_connection(struct obd_import *imp)
 	imp_conn->oic_last_attempt = cfs_time_current_64();
 
 	/* switch connection, don't mind if it's same as the current one */
-	if (imp->imp_connection)
-		ptlrpc_connection_put(imp->imp_connection);
+	ptlrpc_connection_put(imp->imp_connection);
 	imp->imp_connection = ptlrpc_connection_addref(imp_conn->oic_conn);
 
 	dlmexp = class_conn2export(&imp->imp_dlm_handle);
 	LASSERT(dlmexp != NULL);
-	if (dlmexp->exp_connection)
-		ptlrpc_connection_put(dlmexp->exp_connection);
+	ptlrpc_connection_put(dlmexp->exp_connection);
 	dlmexp->exp_connection = ptlrpc_connection_addref(imp_conn->oic_conn);
 	class_export_put(dlmexp);
 
drivers/staging/lustre/lustre/ptlrpc/service.c +1 -3
index 9117f1c..b9ae0b7 100644
@@ -2826,9 +2826,7 @@ void ptlrpc_hr_fini(void)
 	ptlrpc_stop_hr_threads();
 
 	cfs_percpt_for_each(hrp, i, ptlrpc_hr.hr_partitions) {
-		if (hrp->hrp_thrs != NULL) {
-			kfree(hrp->hrp_thrs);
-		}
+		kfree(hrp->hrp_thrs);
 	}
 
 	cfs_percpt_free(ptlrpc_hr.hr_partitions);
Signature · 1 line
2.4.4
#964 lore raw

Re: [PATCH] staging: lustre: Deletion of unnecessary checks before three function calls

Quoted 2 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Jun 2015 23:10:42 +0200

Sorry, I'm not taking any of your patches until you fix this all up.

greg k-h

#965 lore raw

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

From: Markus Elfring <[email protected]>

The following functions test whether their argument is NULL and then return immediately.
* kfree
* ll_file_data_put
* ptlrpc_connection_put

Thus the test around such calls is not needed.

This issue was detected by using the Coccinelle software.

See also a previous update suggestion:
"remove unneeded null test before free" by Julia Lawall
https://lkml.org/lkml/2015/5/1/498
https://www.mail-archive.com/[email protected]/msg878600.html

---
 drivers/staging/lustre/lustre/llite/file.c      | 3 +--
 drivers/staging/lustre/lustre/llite/llite_lib.c | 2 +-
 drivers/staging/lustre/lustre/ptlrpc/import.c   | 6 ++----
 drivers/staging/lustre/lustre/ptlrpc/service.c  | 4 +---
 4 files changed, 5 insertions(+), 10 deletions(-)
drivers/staging/lustre/lustre/llite/file.c +1 -2
index 3075db2..1a85c41 100644
@@ -702,8 +702,7 @@ out_och_free:
 out_openerr:
 		if (opendir_set != 0)
 			ll_stop_statahead(inode, lli->lli_opendir_key);
-		if (fd != NULL)
-			ll_file_data_put(fd);
+		ll_file_data_put(fd);
 	} else {
 		ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_OPEN, 1);
 	}
drivers/staging/lustre/lustre/llite/llite_lib.c +1 -1
index 2513988..ab4839c 100644
@@ -1114,7 +1114,7 @@ void ll_clear_inode(struct inode *inode)
 	if (lli->lli_mds_read_och)
 		ll_md_real_close(inode, FMODE_READ);
 
-	if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
+	if (S_ISLNK(inode->i_mode)) {
 		kfree(lli->lli_symlink_name);
 		lli->lli_symlink_name = NULL;
 	}
drivers/staging/lustre/lustre/ptlrpc/import.c +2 -4
index c9b8481..1eae389 100644
@@ -555,14 +555,12 @@ static int import_select_connection(struct obd_import *imp)
 	imp_conn->oic_last_attempt = cfs_time_current_64();
 
 	/* switch connection, don't mind if it's same as the current one */
-	if (imp->imp_connection)
-		ptlrpc_connection_put(imp->imp_connection);
+	ptlrpc_connection_put(imp->imp_connection);
 	imp->imp_connection = ptlrpc_connection_addref(imp_conn->oic_conn);
 
 	dlmexp = class_conn2export(&imp->imp_dlm_handle);
 	LASSERT(dlmexp != NULL);
-	if (dlmexp->exp_connection)
-		ptlrpc_connection_put(dlmexp->exp_connection);
+	ptlrpc_connection_put(dlmexp->exp_connection);
 	dlmexp->exp_connection = ptlrpc_connection_addref(imp_conn->oic_conn);
 	class_export_put(dlmexp);
 
drivers/staging/lustre/lustre/ptlrpc/service.c +1 -3
index 9117f1c..b9ae0b7 100644
@@ -2826,9 +2826,7 @@ void ptlrpc_hr_fini(void)
 	ptlrpc_stop_hr_threads();
 
 	cfs_percpt_for_each(hrp, i, ptlrpc_hr.hr_partitions) {
-		if (hrp->hrp_thrs != NULL) {
-			kfree(hrp->hrp_thrs);
-		}
+		kfree(hrp->hrp_thrs);
 	}
 
 	cfs_percpt_free(ptlrpc_hr.hr_partitions);
Signature · 1 line
2.4.4
#966 lore raw

PATCH 1/1 staging: comedi: adl_pci9118: Delete an unnecessary check before the function call "pci_dev_put"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 27 Jun 2015 13:50:43 +0200

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/staging/comedi/drivers/adl_pci9118.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/comedi/drivers/adl_pci9118.c +1 -2
index fb3043d..19b5806 100644
@@ -1717,8 +1717,7 @@ static void pci9118_detach(struct comedi_device *dev)
 		pci9118_reset(dev);
 	comedi_pci_detach(dev);
 	pci9118_free_dma(dev);
-	if (pcidev)
-		pci_dev_put(pcidev);
+	pci_dev_put(pcidev);
 }
 
 static struct comedi_driver adl_pci9118_driver = {
Signature · 1 line
2.4.4
#967 lore raw

Re: [PATCH] staging: comedi: adl_pci9118: Delete an unnecessary check before the function call "pci_dev_put"

Quoted 19 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 27 Jun 2015 13:50:43 +0200

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/staging/comedi/drivers/adl_pci9118.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/comedi/drivers/adl_pci9118.c +0 -0
index fb3043d..19b5806 100644

drivers/staging/comedi/drivers/adl_pci9118.c static void pci9118_detach(struct comedi_device *dev) · line 1723

Quoted 9 lines
drivers/staging/comedi/drivers/adl_pci9118.c +1 -2
@@ -1717,8 +1717,7 @@ static void pci9118_detach(struct comedi_device *dev)
  		pci9118_reset(dev);
  	comedi_pci_detach(dev);
  	pci9118_free_dma(dev);
-	if (pcidev)
-		pci_dev_put(pcidev);
+	pci_dev_put(pcidev);
  }
 
  static struct comedi_driver adl_pci9118_driver = {

The same patch was posted independently (and earlier) by Maninder Singh, but I think we concluded that the code was more understandable without this change, as the test within pci_dev_put() is more of a safety net.

Signature · 2 lines
-=( Ian Abbott @ MEV Ltd.    E-mail: <[email protected]> )=-
-=(                          Web: http://www.mev.co.uk/  )=-
#968 lore raw

cover staging: wilc1000: Deletion of two unnecessary checks

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>

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

Markus Elfring (2):
Delete unnecessary checks before two function calls One function call less in mac_ioctl() after error detection

 drivers/staging/wilc1000/linux_wlan.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
Signature · 1 line
2.4.4
#969 lore raw

PATCH 1/2 staging: wilc1000: Delete unnecessary checks before two function calls

From: Markus Elfring <[email protected]>
Date: Sat, 27 Jun 2015 15:56:57 +0200

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

This issue was detected by using the Coccinelle software.

---
 drivers/staging/wilc1000/linux_wlan.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/staging/wilc1000/linux_wlan.c +2 -7
index b352c50..2aa8d9b 100644
@@ -2421,11 +2421,7 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 	}
 
 done:
-
-	if (buff != NULL) {
-		kfree(buff);
-	}
-
+	kfree(buff);
 	return s32Error;
 }
 
@@ -2707,8 +2703,7 @@ static void __exit exit_wilc_driver(void)
 		}
 	}
 
-
-	if ((g_linux_wlan != NULL) && g_linux_wlan->wilc_firmware != NULL) {
+	if (g_linux_wlan) {
 		release_firmware(g_linux_wlan->wilc_firmware);
 		g_linux_wlan->wilc_firmware = NULL;
 	}
Signature · 1 line
2.4.4
#970 lore raw

Re: [PATCH 1/2] staging: wilc1000: Delete unnecessary checks before two function calls

Quoted 2 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 27 Jun 2015 15:56:57 +0200

Why is this in the body of the email? Please fix your email client or just use git send-email properly.

#971 lore raw

Re: Clarification for the use of additional fields in the message body

Quoted 4 lines
Quoted 2 lines

From: Markus Elfring <[email protected]>
Date: Sat, 27 Jun 2015 15:56:57 +0200

Why is this in the body of the email?

Does the canonical patch format support to preserve specific details about a shown commit by specification of fields like "Date" and "From" in the message body?

Regards,
Markus

#972 lore raw

Re: Clarification for the use of additional fields in the message body

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

From: Markus Elfring <[email protected]>
Date: Sat, 27 Jun 2015 15:56:57 +0200

Why is this in the body of the email?

Does the canonical patch format support to preserve specific details about a shown commit by specification of fields like "Date" and "From" in the message body?

Using "From:" in the body can be used to provide your properly spelled name, or the name/e-mail of the actual author, if that happens not to be the sender. git-send-email will do that automagically for you. If "From:" is not specified in the message body, the e-mails sender will be used as author.

The date, as far as I know, is ignored. It is the commit date, not the authoring date, and once your patch is applied by a maintainer (i.e. committed), the date gets reset anyway. No need to try and preserve it.

Frans

#973 lore raw

Re: Clarification for the use of additional fields in the message body

Quoted 3 lines

The date, as far as I know, is ignored. It is the commit date, not the authoring date, and once your patch is applied by a maintainer (i.e. committed), the date gets reset anyway.

Thanks for your feedback.

Quoted 1 line

No need to try and preserve it.

I find that it might occasionally help to share and keep the record on timestamps about the evolution for an original update suggestion.

Regards,
Markus

#974 lore raw

Re: Clarification for the use of additional fields in the message body

Quoted 4 lines · SF Markus Elfring
Quoted 1 line

No need to try and preserve it.

I find that it might occasionally help to share and keep the record on timestamps about the evolution for an original update suggestion.

I think that as far as these kernel mailing lists are concerned, the date of the update suggestion is the date on which you submitted the patch, rather than the date you originally committed it to your local tree. If you wish to keep track of this evolution for yourself, or wish to share it, you're better off stashing it somewhere in a (public) git repo that you control. If you wish, you can always make mention of that repo below the ---, just above the diffstat. If you insist on placing the date somewhere, you can also put the date there if you wish. It'll be ignored by git when applied.

Cheers,
Frans

#975 lore raw

Re: Clarification for the use of additional fields in the message body

Quoted 3 lines

I think that as far as these kernel mailing lists are concerned, the date of the update suggestion is the date on which you submitted the patch, rather than the date you originally committed it to your local tree.

I imagine that there are committers who would like to keep corresponding software development history a bit more accurate.

Quoted 3 lines

If you wish to keep track of this evolution for yourself, or wish to share it, you're better off stashing it somewhere in a (public) git repo that you control.

Would it be nicer to preserve such data directly also by the usual mail interface?

Quoted 2 lines

If you insist on placing the date somewhere, you can also put the date there if you wish. It'll be ignored by git when applied.

This content management tool provides the capability to store the discussed information by the parameters "--author=" and "--date=", doesn't it?
Is the environment variable "GIT_AUTHOR_DATE" also interesting occasionally?

How often do you take extra care for passing appropriate data there?

Regards,
Markus

#976 lore raw

Re: Clarification for the use of additional fields in the message body

Quoted 6 lines · SF Markus Elfring
Quoted 3 lines

I think that as far as these kernel mailing lists are concerned, the date of the update suggestion is the date on which you submitted the patch, rather than the date you originally committed it to your local tree.

I imagine that there are committers who would like to keep corresponding software development history a bit more accurate.

I guess it depends on what your view on accurate is.

Quoted 11 lines
Quoted 3 lines

If you wish to keep track of this evolution for yourself, or wish to share it, you're better off stashing it somewhere in a (public) git repo that you control.

Would it be nicer to preserve such data directly also by the usual mail interface?

Quoted 2 lines

If you insist on placing the date somewhere, you can also put the date there if you wish. It'll be ignored by git when applied.

Quoted 6 lines

This content management tool provides the capability to store the discussed information by the parameters "--author=" and "--date=", doesn't it?
Is the environment variable "GIT_AUTHOR_DATE" also interesting occasionally?

How often do you take extra care for passing appropriate data there?

I can't remember ever changing or explicitly preserving the commit date. I don't think I care enough. I did change the author on botched patches, but that's an exception. Remembering the author separately from the committer is something git does by design anyway.

Frans

#977 lore raw

Re: Clarification for the use of additional fields in the message body

Quoted 2 lines

I can't remember ever changing or explicitly preserving the commit date. I don't think I care enough.

Would any more software developers and maintainers like to share their experiences around such details?

When do commit timestamps become relevant as a documentation item for contribution authorship?

Quoted 2 lines

Remembering the author separately from the committer is something git does by design anyway.

Do you usually just reuse a procedure from a well-known command for which a description is provided like the following?
http://git-scm.com/docs/git-am
'…
"From: " and "Subject: " lines starting the body override the respective commit author name and title values taken from the headers.
…'

Will further fields be eventually mentioned there?

Regards,
Markus

#978 lore raw

Re: Clarification for the use of additional fields in the message body

Hi Markus,

Quoted 8 lines · SF Markus Elfring
Quoted 2 lines

I can't remember ever changing or explicitly preserving the commit date. I don't think I care enough.

Would any more software developers and maintainers like to share their experiences around such details?

When do commit timestamps become relevant as a documentation item for contribution authorship?

They are never relevant.

"When" a commit happened is never relevant except in relation to other things, at which point the actual date and time is almost completely irrelevant.

Just submit your patches using git-format-patch or git-send-email and friends. There's a file in the documentation directory of the kernel tree describing submitting patches and email client setup. Read them both, do what they say without anything extra.

Quoted 12 lines
Quoted 2 lines

Remembering the author separately from the committer is something git does by design anyway.

Do you usually just reuse a procedure from a well-known command for which a description is provided like the following?
http://git-scm.com/docs/git-am
'…
"From: " and "Subject: " lines starting the body override the respective commit author name and title values taken from the headers.
…'

Quoted 1 line

Will further fields be eventually mentioned there?

Why? Just do what is described in SubmittingPatches. Your attempts to "improve" on the system are unnecessary and annoying people. The instructions there are the recommended way to do things for a reason.

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
#979 lore raw

Re: Clarification for the use of additional fields in the message body

Quoted 3 lines

There's a file in the documentation directory of the kernel tree describing submitting patches and email client setup. Read them both,

I read this information several times.

Quoted 1 line

do what they say without anything extra.

Do you see any special consequences if a bit of "extra" functionality is already provided by the Git software for a while?

Quoted 1 line

Your attempts to "improve" on the system are unnecessary

It seems that my approach does not need improvements for the current command "git am".
Would a few extensions for the available documentation help to clarify the situation?

Do items like "commit mail address" and "commit timestamp" belong together for the data structure "author" by design in this content management system?

Quoted 1 line

and annoying people.

I understand that various update suggestions can be surprising. It is also usual that corresponding acceptance might take a bit longer than what some contributors would prefer.

Regards,
Markus

#980 lore raw

Re: Clarification for the use of additional fields in the message body

Hi Markus,

Quoted 11 lines · SF Markus Elfring
Quoted 3 lines

There's a file in the documentation directory of the kernel tree describing submitting patches and email client setup. Read them both,

I read this information several times.

Quoted 1 line

do what they say without anything extra.

Do you see any special consequences if a bit of "extra" functionality is already provided by the Git software for a while?

If it's harmless, then no, but in this case, people are questioning why you're adding it as it adds no value to anyone and makes it look like you don't know what you're doing.

Quoted 6 lines
Quoted 1 line

Your attempts to "improve" on the system are unnecessary

It seems that my approach does not need improvements for the current command "git am".
Would a few extensions for the available documentation help to clarify the situation?

The issue is that the headers you're adding, From: and Date: are unnecessary.

The From: header you add is unnecessary as your email's From: header has the exact same information. The reason it's there is because sometimes people forward patches on from other people, e.g. if I were to resend one of your patches, I'd add a From: header to the body of the email so it'd be credited to you.

The Date: header you add is unnecessary as git-format-patch sets the date header in the email it produces to the author date stored in the commit. (see below) So if you're sending your patches in emails produced by git-format-patch, there's absolutely no reason to include it.

Quoted 3 lines

Do items like "commit mail address" and "commit timestamp" belong together for the data structure "author" by design in this content management system?

The information stored for a commit is:

= = = = =
tree 09496defc9eb793c665a7b80aa22f24c7bd5f204
parent 63c07589832bfe5ec49f2523ddb0e94a20af0f31
author Julian Calaby <[email protected]> 1435196810 +1000 committer Julian Calaby <[email protected]> 1436322540 +1000

= = = = =
Then the subject and commit message.

The numbers after the email addresses are the timestamps. They are both almost completely irrelevant for most workflows as people are less interested in when a commit was made and more interested in what release it's in, how it was merged, etc. All of which should be determined without using the timestamp.

To be honest, I've only ever used that timestamp for reporting purposes at work, and I'd be surprised if anyone was doing anything other than that with them.

In short, nobody cares, and nobody's going to be upset if the actual time you authored a patch is different to the time recorded upstream.

Quoted 5 lines
Quoted 1 line

and annoying people.

I understand that various update suggestions can be surprising. It is also usual that corresponding acceptance might take a bit longer than what some contributors would prefer.

How would you feel if someone came in to your place of work and told you to change how you do the job you've been doing for years without a good reason?

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
#981 lore raw

Re: Clarification for the use of additional fields in the message body

Quoted 2 lines

If it's harmless, then no, but in this case, people are questioning why you're adding it as it adds no value

Some Git software developers care to keep the information complete for the author commit.

Quoted 1 line

to anyone and makes it look like you don't know what you're doing.

I specify message field overrides in my update suggestions intentionally.

Quoted 1 line

The issue is that the headers you're adding, From: and Date: are unnecessary.

We have got different opinions about the purpose.

Quoted 2 lines

The From: header you add is unnecessary as your email's From: header has the exact same information.

I would like to point out that there is a slight difference in my use case.

Quoted 3 lines

The reason it's there is because sometimes people forward patches on from other people, e.g. if I were to resend one of your patches, I'd add a From: header to the body of the email so it'd be credited to you.

I am also interested in such an use case.

Quoted 2 lines

The Date: header you add is unnecessary as git-format-patch sets the date header in the email it produces to the author date stored in the commit.

How do you think about my extra patch preparation for the mentioned mail forwarding?

Quoted 2 lines

So if you're sending your patches in emails produced by git-format-patch, there's absolutely no reason to include it.

I disagree here to some degree.

The difference in suggested commit timestamps of a few minutes might look negligible for some patches. There are few occasions where the delay between a concrete commit and its publishing by an interface like email can become days.

Quoted 4 lines

They are both almost completely irrelevant for most workflows as people are less interested in when a commit was made and more interested in what release it's in, how it was merged, etc. All of which should be determined without using the timestamp.

How often will it matter who made and published a change first?

Quoted 3 lines

To be honest, I've only ever used that timestamp for reporting purposes at work, and I'd be surprised if anyone was doing anything other than that with them.

Thanks for your detailed feedback.

Quoted 3 lines

How would you feel if someone came in to your place of work and told you to change how you do the job you've been doing for years without a good reason?

You might feel uncomfortable for a moment if you would interpret such a suggestion as a personal attack.

I guess that I point only a few technical details out which can change the popularity of existing functionality from the Git software.

Regards,
Markus

#982 lore raw

Re: Clarification for the use of additional fields in the message body

Hi Markus,

Quoted 7 lines · SF Markus Elfring
Quoted 2 lines

If it's harmless, then no, but in this case, people are questioning why you're adding it as it adds no value

Some Git software developers care to keep the information complete for the author commit.

Quoted 8 lines
Quoted 1 line

to anyone and makes it look like you don't know what you're doing.

I specify message field overrides in my update suggestions intentionally.

Quoted 1 line

The issue is that the headers you're adding, From: and Date: are unnecessary.

We have got different opinions about the purpose.

Let me rephrase that: they _should_ be unnecessary.

Quoted 4 lines
Quoted 2 lines

The From: header you add is unnecessary as your email's From: header has the exact same information.

I would like to point out that there is a slight difference in my use case.

Then fix your email client or patch submission process.

Quoted 5 lines
Quoted 3 lines

The reason it's there is because sometimes people forward patches on from other people, e.g. if I were to resend one of your patches, I'd add a From: header to the body of the email so it'd be credited to you.

I am also interested in such an use case.

This happens automatically if you use git-format-patch on a commit you didn't author. Nobody is adding this manually.

Quoted 5 lines
Quoted 2 lines

The Date: header you add is unnecessary as git-format-patch sets the date header in the email it produces to the author date stored in the commit.

How do you think about my extra patch preparation for the mentioned mail forwarding?

It sounds like you're using what could only be described as a Rube-Goldberg process to send email. Is there truly no way to simplify that process? (Also, are the servers you send it through re-writing the original headers?)

You should be sending the patches directly with SMTP using git-send-email, if you're not, then you're making things overly complicated for yourself.

Quoted 9 lines
Quoted 2 lines

So if you're sending your patches in emails produced by git-format-patch, there's absolutely no reason to include it.

I disagree here to some degree.

The difference in suggested commit timestamps of a few minutes might look negligible for some patches. There are few occasions where the delay between a concrete commit and its publishing by an interface like email can become days.

I made a commit a month ago, it got rebased today, in fact, I sent it's metadata in my previous email. When I ran git-format-patch on it, the timestamp in the headers of the email produced was the date from a month ago.

If I then sent that email, I believe it'd make it to the list here with that date intact. If it hadn't, I'd be trying to figure out why and either fix it or find a different path to get my patch here.

Quoted 6 lines
Quoted 4 lines

They are both almost completely irrelevant for most workflows as people are less interested in when a commit was made and more interested in what release it's in, how it was merged, etc. All of which should be determined without using the timestamp.

How often will it matter who made and published a change first?

If multiple people are submitting identical changes, then the one that is applied is the one the maintainer sees first, which will most likely be determined by which one hit their inbox / list first. Nobody is going to look at timestamps in emails to determine which one will be applied.

If you're worried about which one of several versions of a patch will be applied, change the subject to [PATCH v2] ..... instead of [PATCH] .... for the second version.

Quoted 7 lines
Quoted 3 lines

To be honest, I've only ever used that timestamp for reporting purposes at work, and I'd be surprised if anyone was doing anything other than that with them.

Thanks for your detailed feedback.

Quoted 6 lines
Quoted 3 lines

How would you feel if someone came in to your place of work and told you to change how you do the job you've been doing for years without a good reason?

You might feel uncomfortable for a moment if you would interpret such a suggestion as a personal attack.

I'm not interpreting this as a personal attack.

Quoted 2 lines

I guess that I point only a few technical details out which can change the popularity of existing functionality from the Git software.

Git was originally written to manage the Linux kernel. This feature was probably added by either Linus himself or one of the original developers who I believe were kernel developers. The patch submission process has been around for a long time, if this feature isn't used, it's for a good reason.

Having a feature doesn't mean that it should be used.

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
#983 lore raw

Re: Clarification for the use of additional fields in the message body

Quoted 1 line

Is there truly no way to simplify that process?

I see some software development possibilities which could improve the communication with high volume mailing lists.

Quoted 1 line

You should be sending the patches directly with SMTP using git-send-email,

This tool is also fine for the publishing of a lot of patches.

Quoted 1 line

if you're not, then you're making things overly complicated for yourself.

But I prefer a graphical user interface for my mail handling so far.

Quoted 1 line

Having a feature doesn't mean that it should be used.

Does any of the "questionable functionality" get occasionally overlooked a bit too often?

Regards,
Markus

#984 lore raw

Re: Clarification for the use of additional fields in the message body

Hi Markus,

Quoted 4 lines · SF Markus Elfring
Quoted 1 line

Is there truly no way to simplify that process?

I see some software development possibilities which could improve the communication with high volume mailing lists.

You shouldn't need any software development, most people's processes are:

1. Make changes
2. git add <files>
3. git commit
4. Repeat 1-3 for all changes they want to make
5. git-format-patch
6. git-send-email through some SMTP server to the list and appropriate other people

From what I've read, you appear to have some semi-automatic tool for steps 1 through 4. I'd strongly recommend changing your patch submission process to use git-format-patch and git-send-email. If Sourceforge's email system doesn't let you send emails with SMTP directly, then you might want to try sending emails through your ISP's mail server.

Maintainers use a very similar process, however they collect and review patches in some personal repository in addition to making changes and committing them. Tools like patchwork are simply fancy methods of accumulating patches into git trees. Most people are using git-format-patch and git-send-email, possibly with some scripting around them, to format and send patches.

Quoted 3 lines
Quoted 1 line

You should be sending the patches directly with SMTP using git-send-email,

This tool is also fine for the publishing of a lot of patches.

git-send-email or some other tool?

Quoted 3 lines
Quoted 1 line

if you're not, then you're making things overly complicated for yourself.

But I prefer a graphical user interface for my mail handling so far.

I send my patches using git-send-email through gmail's servers then deal with literally everything else through gmail's web interface or Android app. Using git-send-email doesn't mean you can't use a graphical mail interface.

I used to send patches through a carefully configured instance of Thunderbird, however this required too many steps and it loved to mangle patches in ways that annoyed people.

Quoted 4 lines
Quoted 1 line

Having a feature doesn't mean that it should be used.

Does any of the "questionable functionality" get occasionally overlooked a bit too often?

It's not "questionable functionality", it's functionality we don't see a need for.

If I wanted to, I could insert a patch at any point in the history of Linux in my own repository, however any attempt to push that upstream would cause enormous amounts of pain and annoyance, to everyone who attempted to deal with it, so I don't.

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
maintainer
#985 lore raw

Re: Clarification for the use of additional fields in the message body

In reply to Julian Calaby
Quoted 5 lines · Julian Calaby

If multiple people are submitting identical changes, then the one that is applied is the one the maintainer sees first, which will most likely be determined by which one hit their inbox / list first. Nobody is going to look at timestamps in emails to determine which one will be applied.

And some maintainers may choose *not* to act on a patch first, even if they see it first. They might be focused on bug fix patches, and not act on cleanup or feature patches until -rc3 or rc4. Or maybe they will use separate branches for "urgent_for_linus" patches, so two different patchs may end up in completely different git flows.

Quoted 3 lines

If you're worried about which one of several versions of a patch will be applied, change the subject to [PATCH v2] ..... instead of [PATCH] .... for the second version.

*Please* do this. In fact, this is the one thing I wish git send-email would do automatically, along with having a place to edit and track the 0/N summary patch.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

To be honest, I've only ever used that timestamp for reporting purposes at work, and I'd be surprised if anyone was doing anything other than that with them.

Thanks for your detailed feedback.

Note also that some maintainers have work flow that deliberately smash the date (i.e., because they are using a system such as guilt), so if you are depending on the submitted timestamp, it's going to break on you.

- Ted

#986 lore raw

Re: Clarification for the use of additional fields in the message body

Quoted 4 lines

Note also that some maintainers have work flow that deliberately smash the date (i.e., because they are using a system such as guilt), so if you are depending on the submitted timestamp, it's going to break on you.

Thanks for your hint.

I am just trying to offer the possibility for the reuse of a more precise commit timestamp together with an appropriate author mail address for my update suggestions.
Do you reject any more such message field overrides?

Regards,
Markus

maintainer
#987 lore raw

Re: Clarification for the use of additional fields in the message body

Quoted 11 lines · SF Markus Elfring
Quoted 4 lines

Note also that some maintainers have work flow that deliberately smash the date (i.e., because they are using a system such as guilt), so if you are depending on the submitted timestamp, it's going to break on you.

Thanks for your hint.

I am just trying to offer the possibility for the reuse of a more precise commit timestamp together with an appropriate author mail address for my update suggestions.
Do you reject any more such message field overrides?

Well, I won't hold it against you, since I also often need to fix patches or git commit descriptions anyway. But at the same time, my workflow (which you have no right to dictate) **will** destroy your timestamp. Given that you haven't explained why you want to do this, I'm not going have much sympathy if you complain.

Personally, given that you're going through some extremely baroque e-mail/patchsubmission scheme, I don't understand why you can't also arrange to override the Date field in the e-mail header. But I don't really care all that much, because I can ignore your timestamp no matter where you put it.

Regards,

- Ted

#988 lore raw

PATCH 2/2 staging: wilc1000: One function call less in mac_ioctl() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 27 Jun 2015 16:00:59 +0200

The kfree() function was called in two cases by the mac_ioctl() function during error handling even if the passed variable did not contain a pointer for a valid data item.

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

* Drop an unnecessary initialisation for the variable "buff" then.

---
 drivers/staging/wilc1000/linux_wlan.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/staging/wilc1000/linux_wlan.c +4 -6
index 2aa8d9b..f492310 100644
@@ -2351,16 +2351,13 @@ int mac_close(struct net_device *ndev)
 
 int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 {
-
-	u8 *buff = NULL;
+	u8 *buff;
 	s8 rssi;
 	u32 size = 0, length = 0;
 	perInterface_wlan_t *nic;
 	struct WILC_WFI_priv *priv;
 	s32 s32Error = WILC_SUCCESS;
 
-
-
 	/* struct iwreq *wrq = (struct iwreq *) req;	// tony moved to case SIOCSIWPRIV */
 	#ifdef USE_WIRELESS
 	nic = netdev_priv(ndev);
@@ -2405,7 +2402,7 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 				if (copy_to_user(wrq->u.data.pointer, buff, size)) {
 					PRINT_ER("%s: failed to copy data to user buffer\n", __func__);
 					s32Error = -EFAULT;
-					goto done;
+					goto free_buffer;
 				}
 			}
 		}
@@ -2420,8 +2417,9 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 	}
 	}
 
-done:
+free_buffer:
 	kfree(buff);
+done:
 	return s32Error;
 }
 
Signature · 1 line
2.4.4
#989 lore raw

Re: [PATCH 2/2] staging: wilc1000: One function call less in mac_ioctl() after error detection

Quoted 26 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 27 Jun 2015 16:00:59 +0200

The kfree() function was called in two cases by the mac_ioctl() function during error handling even if the passed variable did not contain a pointer for a valid data item.

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

* Drop an unnecessary initialisation for the variable "buff" then.

---
 drivers/staging/wilc1000/linux_wlan.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/staging/wilc1000/linux_wlan.c +0 -1
index 2aa8d9b..f492310 100644
@@ -2351,16 +2351,13 @@ int mac_close(struct net_device *ndev)
 
 int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 {
-

drivers/staging/wilc1000/linux_wlan.c int mac_close(struct net_device *ndev) · line 2363

Quoted 10 lines
drivers/staging/wilc1000/linux_wlan.c +1 -3
-	u8 *buff = NULL;
+	u8 *buff;
 	s8 rssi;
 	u32 size = 0, length = 0;
 	perInterface_wlan_t *nic;
 	struct WILC_WFI_priv *priv;
 	s32 s32Error = WILC_SUCCESS;
 
-
-

Removing these blank lines seems to have nothing to do with the topic of the patch.

julia

Quoted 31 lines
drivers/staging/wilc1000/linux_wlan.c +3 -3
 	/* struct iwreq *wrq = (struct iwreq *) req;	// tony moved to case SIOCSIWPRIV */
 	#ifdef USE_WIRELESS
 	nic = netdev_priv(ndev);
@@ -2405,7 +2402,7 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 				if (copy_to_user(wrq->u.data.pointer, buff, size)) {
 					PRINT_ER("%s: failed to copy data to user buffer\n", __func__);
 					s32Error = -EFAULT;
-					goto done;
+					goto free_buffer;
 				}
 			}
 		}
@@ -2420,8 +2417,9 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 	}
 	}
 
-done:
+free_buffer:
 	kfree(buff);
+done:
 	return s32Error;
 }
 
--

2.4.4

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

#990 lore raw

Re: [PATCH 2/2] staging: wilc1000: One function call less in mac_ioctl() after error detection

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

From: Markus Elfring <[email protected]>
Date: Sat, 27 Jun 2015 16:00:59 +0200

Again, please fix.

Quoted 9 lines

The kfree() function was called in two cases by the mac_ioctl() function during error handling even if the passed variable did not contain a pointer for a valid data item.

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

* Drop an unnecessary initialisation for the variable "buff" then.

That's a different issue, please fix it in a separate patch.

thanks,

greg k-h

#991 lore raw

Re: staging: wilc1000: One function call less in mac_ioctl() after error detection

Quoted 10 lines
Quoted 8 lines

The kfree() function was called in two cases by the mac_ioctl() function during error handling even if the passed variable did not contain a pointer for a valid data item.

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

* Drop an unnecessary initialisation for the variable "buff" then.

That's a different issue, please fix it in a separate patch.

I have got an other opinion here.
This update suggestion depends on a small source code clean-up from the previous patch, doesn't it?

Do you want that I split the second suggestion from this series into more steps?

Regards,
Markus

#992 lore raw

cover staging: wilc1000: Fine-tuning for two function implementations

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>

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

Markus Elfring (3):
Delete an unnecessary check before the function call "release_firmware" One function call less in mac_ioctl() after error detection Reduce scope for a few variables in mac_ioctl()

 drivers/staging/wilc1000/linux_wlan.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
Signature · 1 line
2.9.2
#993 lore raw

PATCH 1/3 staging: wilc1000: Delete an unnecessary check before the function call "release_firmware"

From: Markus Elfring <[email protected]>
Date: Sun, 24 Jul 2016 21:00:20 +0200

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/wilc1000/linux_wlan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/wilc1000/linux_wlan.c +1 -1
index 3a66255..cdef645 100644
@@ -1223,7 +1223,7 @@ void wilc_netdev_cleanup(struct wilc *wilc)
 			vif[i] = netdev_priv(wilc->vif[i]->ndev);
 	}
 
-	if (wilc && wilc->firmware) {
+	if (wilc) {
 		release_firmware(wilc->firmware);
 		wilc->firmware = NULL;
 	}
Signature · 1 line
2.9.2
#994 lore raw

PATCH 2/3 staging: wilc1000: One function call less in mac_ioctl() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 24 Jul 2016 21:15:23 +0200

The kfree() function was called in two cases by the mac_ioctl() function during error handling even if the passed variable did not contain a pointer for a valid data item.

Improve this implementation detail by the introduction of another jump label.

---
 drivers/staging/wilc1000/linux_wlan.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/staging/wilc1000/linux_wlan.c +3 -5
index cdef645..7b1ebcc 100644
@@ -1130,7 +1130,7 @@ static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 				if (copy_to_user(wrq->u.data.pointer, buff, size)) {
 					netdev_err(ndev, "failed to copy\n");
 					ret = -EFAULT;
-					goto done;
+					goto free_buffer;
 				}
 			}
 		}
@@ -1144,11 +1144,9 @@ static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 		goto done;
 	}
 	}
-
-done:
-
+free_buffer:
 	kfree(buff);
-
+done:
 	return ret;
 }
 
Signature · 1 line
2.9.2
#995 lore raw

Re: [PATCH 2/3] staging: wilc1000: One function call less in mac_ioctl() after error detection

Hi Marcus,

Quoted 11 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 24 Jul 2016 21:15:23 +0200

The kfree() function was called in two cases by the mac_ioctl() function during error handling even if the passed variable did not contain a pointer for a valid data item.

Improve this implementation detail by the introduction of another jump label.

This is pointless micro-optimisation: kfree(NULL) is perfectly valid and buff is either malloc'd memory or NULL when it's called.

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
#996 lore raw

PATCH 3/3 staging: wilc1000: Reduce scope for a few variables in mac_ioctl()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 24 Jul 2016 21:45:37 +0200

Three local variables were used only within a single case branch.

* Thus move the data type definition for "rssi" and "size" into the corresponding code block.

* The variable "length" was not modified after its initialisation. Thus pass a constant value in the affected function call instead.

---
 drivers/staging/wilc1000/linux_wlan.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/staging/wilc1000/linux_wlan.c +4 -5
index 7b1ebcc..173be16 100644
@@ -1094,8 +1094,6 @@ int wilc_mac_close(struct net_device *ndev)
 static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 {
 	u8 *buff = NULL;
-	s8 rssi;
-	u32 size = 0, length = 0;
 	struct wilc_vif *vif;
 	s32 ret = 0;
 	struct wilc *wilc;
@@ -1110,8 +1108,7 @@ static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 	case SIOCSIWPRIV:
 	{
 		struct iwreq *wrq = (struct iwreq *)req;
-
-		size = wrq->u.data.length;
+		u32 size = wrq->u.data.length;
 
 		if (size && wrq->u.data.pointer) {
 			buff = memdup_user(wrq->u.data.pointer,
@@ -1119,7 +1116,9 @@ static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
 			if (IS_ERR(buff))
 				return PTR_ERR(buff);
 
-			if (strncasecmp(buff, "RSSI", length) = 0) {
+			if (strncasecmp(buff, "RSSI", 0) = 0) {
+				s8 rssi;
+
 				ret = wilc_get_rssi(vif, &rssi);
 				netdev_info(ndev, "RSSI :%d\n", rssi);
 
Signature · 1 line
2.9.2
#997 lore raw

Re: [PATCH 3/3] staging: wilc1000: Reduce scope for a few variables in mac_ioctl()

drivers/staging/wilc1000/linux_wlan.c static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) · line 1121

Quoted 5 lines
drivers/staging/wilc1000/linux_wlan.c +3 -1
-			if (strncasecmp(buff, "RSSI", length) = 0) {
+			if (strncasecmp(buff, "RSSI", 0) = 0) {
+				s8 rssi;
+

Um, please think a second about if it makes any sense at all to compare zero chars of two strings.

Lino

#998 lore raw

Re: [PATCH 3/3] staging: wilc1000: Reduce scope for a few variables in mac_ioctl()

Am 25.07.2016 21:17, schrieb Lino Sanfilippo:

Quoted 10 lines

drivers/staging/wilc1000/linux_wlan.c static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) · line 1121

Quoted 5 lines
drivers/staging/wilc1000/linux_wlan.c +3 -1
-			if (strncasecmp(buff, "RSSI", length) = 0) {
+			if (strncasecmp(buff, "RSSI", 0) = 0) {
+				s8 rssi;
+

Um, please think a second about if it makes any sense at all to compare zero chars of two strings.

Lino

also:
the switch has only one case and default.

re,
wh

#999 lore raw

Re: staging: wilc1000: Reduce scope for a few variables in mac_ioctl()

In reply to Lino Sanfilippo
Quoted 7 lines

drivers/staging/wilc1000/linux_wlan.c static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) · line 1121

Quoted 4 lines
drivers/staging/wilc1000/linux_wlan.c +3 -1
-			if (strncasecmp(buff, "RSSI", length) = 0) {
+			if (strncasecmp(buff, "RSSI", 0) = 0) {
+				s8 rssi;
+

Um, please think a second about if it makes any sense at all to compare zero chars of two strings.

Under which circumstances should the variable "length" contain an other value than zero?

How can this open issue be fixed better?

Regards,
Markus

#1000 lore raw

Aw: Re: staging: wilc1000: Reduce scope for a few variables in mac_ioctl()

Quoted 14 lines

Gesendet: Dienstag, 26. Juli 2016 um 08:25 Uhr
Von: "SF Markus Elfring" <[email protected]>

Quoted 7 lines

drivers/staging/wilc1000/linux_wlan.c static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd) · line 1121

Quoted 4 lines
drivers/staging/wilc1000/linux_wlan.c +3 -1
-			if (strncasecmp(buff, "RSSI", length) = 0) {
+			if (strncasecmp(buff, "RSSI", 0) = 0) {
+				s8 rssi;
+

Um, please think a second about if it makes any sense at all to compare zero chars of two strings.

Quoted 2 lines

Under which circumstances should the variable "length" contain an other value than zero?

Which circumstances do "not any sense at all" imply?

Quoted 2 lines

How can this open issue be fixed better?

The code is not too complicated and I think it is very obvious which value/variable should be passed instead of 0. I suggest to fix this since it is indeed a bug, instead of doing "micro optimizations" - which is the last thing that code in the staging area needs (as IIRC you have already been told by others, including the staging maintainer).

Regards,
Lino

#1001 lore raw

Re: staging: wilc1000: Reduce scope for a few variables in mac_ioctl()

Quoted 1 line

Which circumstances do "not any sense at all" imply?

Should the expression 'strlen("RSSI")' be passed for the parameter 'length' instead?

Quoted 1 line

I suggest to fix this since it is indeed a bug,

We can agree that this function implementation was broken for a while there.

Quoted 2 lines

instead of doing "micro optimizations" - which is the last thing that code in the staging area needs (as IIRC you have already been told by others, including the staging maintainer).

The acceptance might grow a bit more for such software fine-tuning (like refactoring around variable usage).

Regards,
Markus

#1002 lore raw

PATCH 1/1 ipmi: Delete an unnecessary check before the function call "cleanup_one_si"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 27 Jun 2015 18:12:14 +0200

The cleanup_one_si() 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/ipmi/ipmi_si_intf.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/char/ipmi/ipmi_si_intf.c +1 -3
index cb90f76..fbfed36 100644
@@ -2778,9 +2778,7 @@ static int ipmi_remove(struct platform_device *dev)
 {
 	struct smi_info *info = dev_get_drvdata(&dev->dev);
 
-	if (info)
-		cleanup_one_si(info);
-
+	cleanup_one_si(info);
 	return 0;
 }
 
Signature · 1 line
2.4.4
#1003 lore raw

PATCH 1/1 drm/bridge: ps8622: Delete a check before backlight_device_unregister()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 27 Jun 2015 20:44:49 +0200

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

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/bridge/ps8622.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/bridge/ps8622.c +1 -3
index 1a6607b..70dacb8 100644
@@ -646,9 +646,7 @@ static int ps8622_remove(struct i2c_client *client)
 {
 	struct ps8622_bridge *ps8622 = i2c_get_clientdata(client);
 
-	if (ps8622->bl)
-		backlight_device_unregister(ps8622->bl);
-
+	backlight_device_unregister(ps8622->bl);
 	drm_bridge_remove(&ps8622->bridge);
 
 	return 0;
Signature · 1 line
2.4.4
#1004 lore raw

PATCH 1/1 drm/bridge: ps8622: Delete an unnecessary check before backlight_device_unregister()

From: Markus Elfring <[email protected]>
Date: Fri, 22 Jul 2016 14:45:51 +0200

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

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/bridge/parade-ps8622.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/bridge/parade-ps8622.c +1 -3
index 5cd8dd7..583b8ce 100644
@@ -636,9 +636,7 @@ static int ps8622_remove(struct i2c_client *client)
 {
 	struct ps8622_bridge *ps8622 = i2c_get_clientdata(client);
 
-	if (ps8622->bl)
-		backlight_device_unregister(ps8622->bl);
-
+	backlight_device_unregister(ps8622->bl);
 	drm_bridge_remove(&ps8622->bridge);
 
 	return 0;
Signature · 1 line
2.9.2
Applied
#1005 lore raw

Re: [PATCH] drm/bridge: ps8622: Delete an unnecessary check before backlight_device_unregister()

Quoted 10 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 22 Jul 2016 14:45:51 +0200

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

This issue was detected by using the Coccinelle software.

Applied to drm-misc

Quoted 26 lines
---
 drivers/gpu/drm/bridge/parade-ps8622.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/bridge/parade-ps8622.c +1 -4
index 5cd8dd7..583b8ce 100644
@@ -636,9 +636,7 @@ static int ps8622_remove(struct i2c_client *client)
 {
        struct ps8622_bridge *ps8622 = i2c_get_clientdata(client);
 
-       if (ps8622->bl)
-               backlight_device_unregister(ps8622->bl);
-
+       backlight_device_unregister(ps8622->bl);
        drm_bridge_remove(&ps8622->bridge);
 
        return 0;
--

2.9.2

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

#1006 lore raw

cover drm/msm/dsi: Deletion of an unnecessary check

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>

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

Markus Elfring (2):
Delete an unnecessary check before the function call "dsi_destroy" One function call less in dsi_init() after error detection

 drivers/gpu/drm/msm/dsi/dsi.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)
Signature · 1 line
2.4.4
#1007 lore raw

PATCH 1/2 drm/msm/dsi: Delete an unnecessary check before the function call "dsi_destroy"

From: Markus Elfring <[email protected]>
Date: Sat, 27 Jun 2015 22:05:31 +0200

The dsi_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/gpu/drm/msm/dsi/dsi.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/msm/dsi/dsi.c +1 -3
index 1f2561e..dc4f38f 100644
@@ -110,9 +110,7 @@ static struct msm_dsi *dsi_init(struct platform_device *pdev)
 	return msm_dsi;
 
 fail:
-	if (msm_dsi)
-		dsi_destroy(msm_dsi);
-
+	dsi_destroy(msm_dsi);
 	return ERR_PTR(ret);
 }
 
Signature · 1 line
2.4.4
#1008 lore raw

PATCH 2/2 drm/msm/dsi: One function call less in dsi_init() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 27 Jun 2015 22:23:28 +0200

The dsi_destroy() function was called in two cases by the dsi_init() function during error handling even if the passed variable contained a null pointer.

* This implementation detail could be improved by adjustments for jump targets according to the Linux coding style convention.

* Drop an unnecessary initialisation for the variable "msm_dsi" then.

---
 drivers/gpu/drm/msm/dsi/dsi.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
drivers/gpu/drm/msm/dsi/dsi.c +9 -13
index dc4f38f..971f000 100644
@@ -74,19 +74,15 @@ static void dsi_destroy(struct msm_dsi *msm_dsi)
 
 static struct msm_dsi *dsi_init(struct platform_device *pdev)
 {
-	struct msm_dsi *msm_dsi = NULL;
+	struct msm_dsi *msm_dsi;
 	int ret;
 
-	if (!pdev) {
-		ret = -ENXIO;
-		goto fail;
-	}
+	if (!pdev)
+		return -ENXIO;
 
 	msm_dsi = devm_kzalloc(&pdev->dev, sizeof(*msm_dsi), GFP_KERNEL);
-	if (!msm_dsi) {
-		ret = -ENOMEM;
-		goto fail;
-	}
+	if (!msm_dsi)
+		return -ENOMEM;
 	DBG("dsi probed=%p", msm_dsi);
 
 	msm_dsi->pdev = pdev;
@@ -95,21 +91,21 @@ static struct msm_dsi *dsi_init(struct platform_device *pdev)
 	/* Init dsi host */
 	ret = msm_dsi_host_init(msm_dsi);
 	if (ret)
-		goto fail;
+		goto destroy_dsi;
 
 	/* GET dsi PHY */
 	ret = dsi_get_phy(msm_dsi);
 	if (ret)
-		goto fail;
+		goto destroy_dsi;
 
 	/* Register to dsi manager */
 	ret = msm_dsi_manager_register(msm_dsi);
 	if (ret)
-		goto fail;
+		goto destroy_dsi;
 
 	return msm_dsi;
 
-fail:
+destroy_dsi:
 	dsi_destroy(msm_dsi);
 	return ERR_PTR(ret);
 }
Signature · 1 line
2.4.4
#1009 lore raw

PATCH 1/1 drm/amdgpu: Delete an unnecessary check before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Jun 2015 10:27:35 +0200

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

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -2
index fec487d..a85cd08 100644
@@ -1575,8 +1575,7 @@ void amdgpu_device_fini(struct amdgpu_device *adev)
 	amdgpu_fence_driver_fini(adev);
 	amdgpu_fbdev_fini(adev);
 	r = amdgpu_fini(adev);
-	if (adev->ip_block_enabled)
-		kfree(adev->ip_block_enabled);
+	kfree(adev->ip_block_enabled);
 	adev->ip_block_enabled = NULL;
 	adev->accel_working = false;
 	/* free i2c buses */
Signature · 1 line
2.4.4
#1010 lore raw

Re: [PATCH] drm/amdgpu: Delete an unnecessary check before the function call "kfree"

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Jun 2015 10:27:35 +0200

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

This issue was detected by using the Coccinelle software.

I already have the same patch from Maninder Singh.

Thanks!

Alex

Quoted 25 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -3
index fec487d..a85cd08 100644
@@ -1575,8 +1575,7 @@ void amdgpu_device_fini(struct amdgpu_device *adev)
        amdgpu_fence_driver_fini(adev);
        amdgpu_fbdev_fini(adev);
        r = amdgpu_fini(adev);
-       if (adev->ip_block_enabled)
-               kfree(adev->ip_block_enabled);
+       kfree(adev->ip_block_enabled);
        adev->ip_block_enabled = NULL;
        adev->accel_working = false;
        /* free i2c buses */
--

2.4.4

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

#1011 lore raw

cover drm/amdgpu: Fine-tuning for three function implementations

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 16 Jul 2016 16:23:21 +0200

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

Markus Elfring (8):
Delete an unnecessary check before drm_gem_object_unreference_unlocked() Delete unnecessary checks before the function call "kfree"
One function call less in amdgpu_cgs_acpi_eval_object() after error detection Delete a variable in amdgpu_cgs_acpi_eval_object()
Delete an unnecessary variable initialisation in amdgpu_cgs_acpi_eval_object() Change assignment for a variable in amdgpu_cgs_acpi_eval_object() Change assignment for a buffer variable in phm_dispatch_table() Delete an unnecessary variable initialisation in phm_dispatch_table()

 drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c            | 28 ++++++++++------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c        |  4 +---
 .../gpu/drm/amd/powerplay/hwmgr/functiontables.c   | 12 ++++------
 3 files changed, 19 insertions(+), 25 deletions(-)
Signature · 1 line
2.9.1
#1012 lore raw

PATCH 1/8 drm/amdgpu: Delete an unnecessary check before drm_gem_object_unreference_unlocked()

From: Markus Elfring <[email protected]>
Date: Sat, 16 Jul 2016 11:28:36 +0200

The drm_gem_object_unreference_unlocked() 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/amd/amdgpu/amdgpu_display.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +1 -3
index a6eecf6..2a07b15 100644
@@ -516,9 +516,7 @@ static void amdgpu_user_framebuffer_destroy(struct drm_framebuffer *fb)
 {
 	struct amdgpu_framebuffer *amdgpu_fb = to_amdgpu_framebuffer(fb);
 
-	if (amdgpu_fb->obj) {
-		drm_gem_object_unreference_unlocked(amdgpu_fb->obj);
-	}
+	drm_gem_object_unreference_unlocked(amdgpu_fb->obj);
 	drm_framebuffer_cleanup(fb);
 	kfree(amdgpu_fb);
 }
Signature · 1 line
2.9.1
#1013 lore raw

PATCH 2/8 drm/amdgpu/powerplay: Delete unnecessary checks before the function call "kfree"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 16 Jul 2016 12:38:12 +0200

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

This issue was detected by using the Coccinelle software.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c              | 3 +--
 drivers/gpu/drm/amd/powerplay/hwmgr/functiontables.c | 5 +----
 2 files changed, 2 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c +1 -2
index cf6f49f..6f11bc1 100644
@@ -1053,8 +1053,7 @@ static int amdgpu_cgs_acpi_eval_object(struct cgs_device *cgs_device,
 	}
 
 error:
-	if (obj != NULL)
-		kfree(obj);
+	kfree(obj);
 	kfree((void *)input.pointer);
 	return result;
 }
drivers/gpu/drm/amd/powerplay/hwmgr/functiontables.c +1 -4
index 7a705ce..024e22e 100644
@@ -76,10 +76,7 @@ int phm_dispatch_table(struct pp_hwmgr *hwmgr,
 	}
 
 	result = phm_run_table(hwmgr, rt_table, input, output, temp_storage);
-
-	if (NULL != temp_storage)
-		kfree(temp_storage);
-
+	kfree(temp_storage);
 	return result;
 }
 
Signature · 1 line
2.9.1