Skip to contentSkip to conversation

Source code review around jump label usage

PATCH In review SF Markus Elfring 114 participants 1,410 messages Dec 11, 2015 – Jan 5, 2024 2 messages not in the archive Page 3 of 6

Subsystems (101)
lore
Share & tools
lore
#499 lore raw

PATCH 3/3 hostap: Delete unnecessary initialisations for the variable "ret"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 20 Aug 2016 18:23:14 +0200

The local variable "ret" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning of four functions.

---
 drivers/net/wireless/intersil/hostap/hostap_ioctl.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/wireless/intersil/hostap/hostap_ioctl.c +4 -4
index 5942917..c37b0bb 100644
@@ -2895,7 +2895,7 @@ static int prism2_ioctl_priv_monitor(struct net_device *dev, int *i)
 {
 	struct hostap_interface *iface;
 	local_info_t *local;
-	int ret = 0;
+	int ret;
 	u32 mode;
 
 	iface = netdev_priv(dev);
@@ -3035,7 +3035,7 @@ static int ap_mac_cmd_ioctl(local_info_t *local, int *cmd)
 static int prism2_ioctl_priv_download(local_info_t *local, struct iw_point *p)
 {
 	struct prism2_download_param *param;
-	int ret = 0;
+	int ret;
 
 	if (p->length < sizeof(struct prism2_download_param) ||
 	    p->length > 1024 || !p->pointer)
@@ -3791,7 +3791,7 @@ static int prism2_ioctl_scan_req(local_info_t *local,
 static int prism2_ioctl_priv_hostapd(local_info_t *local, struct iw_point *p)
 {
 	struct prism2_hostapd_param *param;
-	int ret = 0;
+	int ret;
 	int ap_ioctl = 0;
 
 	if (p->length < sizeof(struct prism2_hostapd_param) ||
@@ -3954,7 +3954,7 @@ int hostap_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 	struct iwreq *wrq = (struct iwreq *) ifr;
 	struct hostap_interface *iface;
 	local_info_t *local;
-	int ret = 0;
+	int ret;
 
 	iface = netdev_priv(dev);
 	local = iface->local;
Signature · 1 line
2.9.3
maintainer
#500 lore raw

Re: [PATCH 0/3] hostap: Fine-tuning for a few functions

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

From: Markus Elfring <[email protected]>
Date: Sat, 20 Aug 2016 18:35:43 +0200

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

Is it worth touching this old stuff especially when you are not making any functional changes.

Regards,
Arend

Quoted 8 lines

Markus Elfring (3):
Use memdup_user()
Delete an unnecessary jump label
Delete unnecessary variable initialisations

 .../net/wireless/intersil/hostap/hostap_ioctl.c    | 36 ++++++++--------------
 1 file changed, 12 insertions(+), 24 deletions(-)
#501 lore raw

Re: [PATCH 0/3] hostap: Fine-tuning for a few functions

Quoted 9 lines · Arend van Spriel
Quoted 5 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 20 Aug 2016 18:35:43 +0200

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

Is it worth touching this old stuff especially when you are not making any functional changes.

On the other hand if these patches break something this might be a good way to get feedback if someone is really using this driver ;)

But yeah, not really sure what to do with these obsolete drivers like hostap, ray_cs and wl3501.

Signature · 1 line
Kalle Valo
maintainer
#502 lore raw

Re: [PATCH 0/3] hostap: Fine-tuning for a few functions

Quoted 1 line · Kalle Valo

Arend van Spriel <[email protected]> writes:

[]

Quoted 2 lines

But yeah, not really sure what to do with these obsolete drivers like hostap, ray_cs and wl3501.

Maybe marking sections obsolete in MAINTAINERS could flag some "shouldn't touch this" warning for old code in checkpatch.pl and/or get_maintainer.pl

maintainer
#503 lore raw

PATCH 1/1 checkpatch: See if modified files are marked obsolete in MAINTAINERS

In reply to Kalle Valo

Use get_maintainer to check the status of individual files. If "obsolete", suggest leaving the files alone.

---
 scripts/checkpatch.pl | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
scripts/checkpatch.pl +14 -0
index 4de3cc4..df5e9d9 100755
@@ -704,6 +704,16 @@ sub seed_camelcase_file {
 	}
 }
 
+sub is_maintained_obsolete {
+	my ($filename) = @_;
+
+	return 0 if (!(-e "$root/scripts/get_maintainer.pl"));
+
+	my $status = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback $filename 2>&1`;
+
+	return $status =~ /obsolete/i;
+}
+
 my $camelcase_seeded = 0;
 sub seed_camelcase_includes {
 	return if ($camelcase_seeded);
@@ -2289,6 +2299,10 @@ sub process {
 		}
 
 		if ($found_file) {
+			if (is_maintained_obsolete($realfile)) {
+				WARN("OBSOLETE",
+				     "$realfile is marked as 'obsolete' in the MAINTAINERS hierarchy.  No unnecessary modifications please.\n");
+			}
 			if ($realfile =~ m@^(?:drivers/net/|net/|drivers/staging/)@) {
 				$check = 1;
 			} else {
Signature · 1 line
2.8.0.rc4.16.g56331f8
#504 lore raw

Re: [PATCH] checkpatch: See if modified files are marked obsolete in MAINTAINERS

scripts/checkpatch.pl sub process { · line 2305

Quoted 8 lines
scripts/checkpatch.pl +4 -0
@@ -2289,6 +2299,10 @@ sub process {
 		}
 
 		if ($found_file) {
+			if (is_maintained_obsolete($realfile)) {
+				WARN("OBSOLETE",
+				     "$realfile is marked as 'obsolete' in the MAINTAINERS hierarchy.  No unnecessary modifications please.\n");
+			}

How do you think about to avoid a double negation in such a warning message?

Would a wording like "… Only really necessary modifications please.\n" be more useful here?

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

maintainer
#505 lore raw

Re: [PATCH] checkpatch: See if modified files are marked obsolete in MAINTAINERS

Quoted 10 lines · SF Markus Elfring

scripts/checkpatch.pl sub process { · line 2305

Quoted 8 lines
(quoted diff) +0 -0
@@ -2289,6 +2299,10 @@ sub process {
  		}


  if ($found_file) {

scripts/checkpatch.pl +4 -0
+			if (is_maintained_obsolete($realfile)) {
+				WARN("OBSOLETE",
+				     "$realfile is marked as 'obsolete' in the MAINTAINERS hierarchy.  No unnecessary modifications please.\n");
+			}

How do you think about to avoid a double negation in such a warning message?

Quoted 2 lines

Would a wording like "… Only really necessary modifications please.\n" be more useful here?

No, probably not.

#506 lore raw

Re: checkpatch: See if modified files are marked obsolete in MAINTAINERS

In reply to Joe Perches
Quoted 2 lines

Use get_maintainer to check the status of individual files. If "obsolete", suggest leaving the files alone.

Will another software system like the "kbuild test robot" need any more fine-tuning for this change?

Regards,
Markus

#507 lore raw

Re: checkpatch: See if modified files are marked obsolete in MAINTAINERS

Quoted 5 lines · SF Markus Elfring
Quoted 2 lines

Use get_maintainer to check the status of individual files. If "obsolete", suggest leaving the files alone.

Will another software system like the "kbuild test robot" need any more fine-tuning for this change?

It only works on files in which there have been commits, thus by definition not obsolete.

julia

Quoted 8 lines

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

#508 lore raw

PATCH 1/1 s390/tape: Use memdup_user() rather than duplicating its implementation

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 20 Aug 2016 19:25:34 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
 drivers/s390/char/tape_3590.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/s390/char/tape_3590.c +3 -8
index d3d1936..e352047 100644
@@ -312,15 +312,10 @@ static int tape_3592_ioctl_kekl_set(struct tape_device *device,
 		return -ENOSYS;
 	if (!crypt_enabled(device))
 		return -EUNATCH;
-	ext_kekls = kmalloc(sizeof(*ext_kekls), GFP_KERNEL);
-	if (!ext_kekls)
-		return -ENOMEM;
-	if (copy_from_user(ext_kekls, (char __user *)arg, sizeof(*ext_kekls))) {
-		rc = -EFAULT;
-		goto out;
-	}
+	ext_kekls = memdup_user((char __user *)arg, sizeof(*ext_kekls));
+	if (IS_ERR(ext_kekls))
+		return PTR_ERR(ext_kekls);
 	rc = tape_3592_kekl_set(device, ext_kekls);
-out:
 	kfree(ext_kekls);
 	return rc;
 }
Signature · 1 line
2.9.3
#509 lore raw

Re: [PATCH] s390/tape: Use memdup_user() rather than duplicating its implementation

Quoted 9 lines · On Sat, 20 Aug 2016 19:32:03 +0200 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Sat, 20 Aug 2016 19:25:34 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

Applied to linux-s390. Thanks.

Signature · 4 lines
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.
#510 lore raw

cover aacraid: Fine-tuning for a few functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 09:03:21 +0200

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

Markus Elfring (7):
Use memdup_user() rather than duplicating its implementation One function call less in aac_send_raw_srb() after error detection Delete unnecessary initialisations in aac_send_raw_srb() Delete unnecessary braces
Add spaces after control flow keywords
Improve determination of a few sizes
Apply another recommendation from "checkpatch.pl"

 drivers/scsi/aacraid/commctrl.c | 140 +++++++++++++++++++---------------------
 1 file changed, 67 insertions(+), 73 deletions(-)
Signature · 1 line
2.9.3
#511 lore raw

PATCH 1/7 aacraid: Use memdup_user() rather than duplicating its implementation

From: Markus Elfring <[email protected]>
Date: Sat, 20 Aug 2016 20:05:24 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
 drivers/scsi/aacraid/commctrl.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/scsi/aacraid/commctrl.c +3 -9
index 5648b71..1af3084 100644
@@ -526,15 +526,9 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 		goto cleanup;
 	}
 
-	user_srbcmd = kmalloc(fibsize, GFP_KERNEL);
-	if (!user_srbcmd) {
-		dprintk((KERN_DEBUG"aacraid: Could not make a copy of the srb\n"));
-		rcode = -ENOMEM;
-		goto cleanup;
-	}
-	if(copy_from_user(user_srbcmd, user_srb,fibsize)){
-		dprintk((KERN_DEBUG"aacraid: Could not copy srb from user\n"));
-		rcode = -EFAULT;
+	user_srbcmd = memdup_user(user_srb, fibsize);
+	if (IS_ERR(user_srbcmd)) {
+		rcode = PTR_ERR(user_srbcmd);
 		goto cleanup;
 	}
 
Signature · 1 line
2.9.3
#512 lore raw

RE: [PATCH 1/7] aacraid: Use memdup_user() rather than duplicating its implementation

PiBGcm9tOiBNYXJrdXMgRWxmcmluZyA8ZWxmcmluZ0B1c2Vycy5zb3VyY2Vmb3JnZS5uZXQ+DQo+ IERhdGU6IFNhdCwgMjAgQXVnIDIwMTYgMjA6MDU6MjQgKzAyMDANCj4gDQo+IFJldXNlIGV4aXN0 aW5nIGZ1bmN0aW9uYWxpdHkgZnJvbSBtZW1kdXBfdXNlcigpIGluc3RlYWQgb2Yga2VlcGluZyBk dXBsaWNhdGUNCj4gc291cmNlIGNvZGUuDQo+IA0KPiBUaGlzIGlzc3VlIHdhcyBkZXRlY3RlZCBi eSB1c2luZyB0aGUgQ29jY2luZWxsZSBzb2Z0d2FyZS4NCj4gDQo+IFNpZ25lZC1vZmYtYnk6IE1h cmt1cyBFbGZyaW5nIDxlbGZyaW5nQHVzZXJzLnNvdXJjZWZvcmdlLm5ldD4NCj4gLS0tDQo+ICBk cml2ZXJzL3Njc2kvYWFjcmFpZC9jb21tY3RybC5jIHwgMTIgKysrLS0tLS0tLS0tDQo+ICAxIGZp bGUgY2hhbmdlZCwgMyBpbnNlcnRpb25zKCspLCA5IGRlbGV0aW9ucygtKQ0KPiANCj4gZGlmZiAt LWdpdCBhL2RyaXZlcnMvc2NzaS9hYWNyYWlkL2NvbW1jdHJsLmMgYi9kcml2ZXJzL3Njc2kvYWFj cmFpZC9jb21tY3RybC5jDQo+IGluZGV4IDU2NDhiNzEuLjFhZjMwODQgMTAwNjQ0DQo+IC0tLSBh L2RyaXZlcnMvc2NzaS9hYWNyYWlkL2NvbW1jdHJsLmMNCj4gKysrIGIvZHJpdmVycy9zY3NpL2Fh Y3JhaWQvY29tbWN0cmwuYw0KPiBAQCAtNTI2LDE1ICs1MjYsOSBAQCBzdGF0aWMgaW50IGFhY19z ZW5kX3Jhd19zcmIoc3RydWN0IGFhY19kZXYqIGRldiwgdm9pZA0KPiBfX3VzZXIgKiBhcmcpDQo+ ICAgICAgICAgICAgICAgICBnb3RvIGNsZWFudXA7DQo+ICAgICAgICAgfQ0KPiANCj4gLSAgICAg ICB1c2VyX3NyYmNtZCA9IGttYWxsb2MoZmlic2l6ZSwgR0ZQX0tFUk5FTCk7DQo+IC0gICAgICAg aWYgKCF1c2VyX3NyYmNtZCkgew0KPiAtICAgICAgICAgICAgICAgZHByaW50aygoS0VSTl9ERUJV RyJhYWNyYWlkOiBDb3VsZCBub3QgbWFrZSBhIGNvcHkgb2YgdGhlIHNyYlxuIikpOw0KPiAtICAg ICAgICAgICAgICAgcmNvZGUgPSAtRU5PTUVNOw0KPiAtICAgICAgICAgICAgICAgZ290byBjbGVh bnVwOw0KPiAtICAgICAgIH0NCj4gLSAgICAgICBpZihjb3B5X2Zyb21fdXNlcih1c2VyX3NyYmNt ZCwgdXNlcl9zcmIsZmlic2l6ZSkpew0KPiAtICAgICAgICAgICAgICAgZHByaW50aygoS0VSTl9E RUJVRyJhYWNyYWlkOiBDb3VsZCBub3QgY29weSBzcmIgZnJvbSB1c2VyXG4iKSk7DQo+IC0gICAg ICAgICAgICAgICByY29kZSA9IC1FRkFVTFQ7DQo+ICsgICAgICAgdXNlcl9zcmJjbWQgPSBtZW1k dXBfdXNlcih1c2VyX3NyYiwgZmlic2l6ZSk7DQo+ICsgICAgICAgaWYgKElTX0VSUih1c2VyX3Ny YmNtZCkpIHsNCj4gKyAgICAgICAgICAgICAgIHJjb2RlID0gUFRSX0VSUih1c2VyX3NyYmNtZCk7 DQo+ICAgICAgICAgICAgICAgICBnb3RvIGNsZWFudXA7DQo+ICAgICAgICAgfQ0KPiANCj4gLS0N Cg0KSGkgTWFya3VzLA0KDQpQYXRjaCAyLzcgc2hvdWxkIHByZWNlZGUgUGF0Y2ggMS83LCBhcyBm YWxsaW5nIGludG8ga2ZyZWUoKSB3b3VsZCBub3QgbG9vayBwcmV0dHkuDQoNClRoYW5rcywgLURh dmUNCg=

#513 lore raw

Re: [PATCH 1/7] aacraid: Use memdup_user() rather than duplicating its implementation

Quoted 20 lines
Quoted 20 lines
drivers/scsi/aacraid/commctrl.c +3 -9
@@ -526,15 +526,9 @@ static int aac_send_raw_srb(struct aac_dev* dev, void
 __user * arg)
                goto cleanup;
        }
 
-       user_srbcmd = kmalloc(fibsize, GFP_KERNEL);
-       if (!user_srbcmd) {
-               dprintk((KERN_DEBUG"aacraid: Could not make a copy of the srb\n"));
-               rcode = -ENOMEM;
-               goto cleanup;
-       }
-       if(copy_from_user(user_srbcmd, user_srb,fibsize)){
-               dprintk((KERN_DEBUG"aacraid: Could not copy srb from user\n"));
-               rcode = -EFAULT;
+       user_srbcmd = memdup_user(user_srb, fibsize);
+       if (IS_ERR(user_srbcmd)) {
+               rcode = PTR_ERR(user_srbcmd);
                goto cleanup;
        }
Quoted 5 lines
Quoted 1 line

--

Hi Markus,

Patch 2/7 should precede Patch 1/7, as falling into kfree() would not look pretty.

Do you eventually prefer that this source code adjustment should be combined with the update suggestion "[2/7] aacraid: One function call less in aac_send_raw_srb() after error detection" in a single update step?

Regards,
Markus

#514 lore raw

RE: [PATCH 1/7] aacraid: Use memdup_user() rather than duplicating its implementation

PiA+DQo+ID4gSGkgTWFya3VzLA0KPiA+DQo+ID4gUGF0Y2ggMi83IHNob3VsZCBwcmVjZWRlIFBh dGNoIDEvNywgYXMgZmFsbGluZyBpbnRvIGtmcmVlKCkgd291bGQgbm90IGxvb2sNCj4gcHJldHR5 Lg0KPiANCj4gRG8geW91IGV2ZW50dWFsbHkgcHJlZmVyIHRoYXQgdGhpcyBzb3VyY2UgY29kZSBh ZGp1c3RtZW50IHNob3VsZCBiZSBjb21iaW5lZA0KPiB3aXRoIHRoZSB1cGRhdGUgc3VnZ2VzdGlv biAiWzIvN10gYWFjcmFpZDogT25lIGZ1bmN0aW9uIGNhbGwgbGVzcyBpbg0KPiBhYWNfc2VuZF9y YXdfc3JiKCkgYWZ0ZXIgZXJyb3IgZGV0ZWN0aW9uIiBpbiBhIHNpbmdsZSB1cGRhdGUgc3RlcD8N Cj4gDQoNCkhpIE1hcmt1cywNCg0KTXkgcHJpbWFyeSBvYmplY3RpdmUgaW4gdGhpcyB3b3VsZCBi ZSB0aGUgYWJpbGl0eSB0byBiaXNlY3QgLi4uIFRoZSBzZWNvbmRhcnkgd291bGQgYmUgb25lIGlz c3VlL3BhdGNoLiBJIHRoaW5rIG15IHByZWZlcmVuY2Ugd291bGQgYmUgdG8gc3dhcCBwYXRjaGVz IDEgYW5kIDIuDQoNClRoYW5rcywgLURhdmUNCg=

#515 lore raw

PATCH 2/7 aacraid: One function call less in aac_send_raw_srb() after error detection

In reply to SF Markus Elfring

From e8187662ee30aab709a260c72fb86c51673f8e0d Mon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Sat, 20 Aug 2016 20:40:47 +0200
Subject: [PATCH 2/7] aacraid: One function call less in aac_send_raw_srb()
after error detection

The kfree() function was called in a few cases by the aac_send_raw_srb() function during error handling even if the variable "user_srbcmd" contained eventually an inappropriate pointer value.

---
 drivers/scsi/aacraid/commctrl.c | 49 ++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 25 deletions(-)
drivers/scsi/aacraid/commctrl.c +24 -25
index 1af3084..6dcdf91 100644
@@ -517,19 +517,19 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 	if(copy_from_user(&fibsize, &user_srb->count,sizeof(u32))){
 		dprintk((KERN_DEBUG"aacraid: Could not copy data size from user\n"));
 		rcode = -EFAULT;
-		goto cleanup;
+		goto free_sg_list;
 	}
 
 	if ((fibsize < (sizeof(struct user_aac_srb) - sizeof(struct user_sgentry))) ||
 	    (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))) {
 		rcode = -EINVAL;
-		goto cleanup;
+		goto free_sg_list;
 	}
 
 	user_srbcmd = memdup_user(user_srb, fibsize);
 	if (IS_ERR(user_srbcmd)) {
 		rcode = PTR_ERR(user_srbcmd);
-		goto cleanup;
+		goto free_sg_list;
 	}
 
 	user_reply = arg+fibsize;
@@ -564,7 +564,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 		dprintk((KERN_DEBUG"aacraid: too many sg entries %d\n",
 		  le32_to_cpu(srbcmd->sg.count)));
 		rcode = -EINVAL;
-		goto cleanup;
+		goto free_user_srbcmd;
 	}
 	actual_fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) +
 		((user_srbcmd->sg.count & 0xff) * sizeof(struct sgentry));
@@ -580,12 +580,12 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 		  sizeof(struct aac_srb), sizeof(struct sgentry),
 		  sizeof(struct sgentry64), fibsize));
 		rcode = -EINVAL;
-		goto cleanup;
+		goto free_user_srbcmd;
 	}
 	if ((data_dir = DMA_NONE) && user_srbcmd->sg.count) {
 		dprintk((KERN_DEBUG"aacraid: SG with no direction specified in Raw SRB command\n"));
 		rcode = -EINVAL;
-		goto cleanup;
+		goto free_user_srbcmd;
 	}
 	byte_count = 0;
 	if (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64) {
@@ -606,7 +606,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 				      (dev->scsi_host_ptr->max_sectors << 9) :
 				      65536)) {
 					rcode = -EINVAL;
-					goto cleanup;
+					goto free_user_srbcmd;
 				}
 				/* Does this really need to be GFP_DMA? */
 				p = kmalloc(upsg->sg[i].count,GFP_KERNEL|__GFP_DMA);
@@ -614,7 +614,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 					dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
 					  upsg->sg[i].count,i,upsg->count));
 					rcode = -ENOMEM;
-					goto cleanup;
+					goto free_user_srbcmd;
 				}
 				addr = (u64)upsg->sg[i].addr[0];
 				addr += ((u64)upsg->sg[i].addr[1]) << 32;
@@ -626,7 +626,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 					if(copy_from_user(p,sg_user[i],upsg->sg[i].count)){
 						dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
 						rcode = -EFAULT;
-						goto cleanup;
+						goto free_user_srbcmd;
 					}
 				}
 				addr = pci_map_single(dev->pdev, p, upsg->sg[i].count, data_dir);
@@ -644,7 +644,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 			if (!usg) {
 				dprintk((KERN_DEBUG"aacraid: Allocation error in Raw SRB command\n"));
 				rcode = -ENOMEM;
-				goto cleanup;
+				goto free_user_srbcmd;
 			}
 			actual_fibsize = actual_fibsize64;
 
@@ -658,7 +658,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 				      65536)) {
 					kfree(usg);
 					rcode = -EINVAL;
-					goto cleanup;
+					goto free_user_srbcmd;
 				}
 				/* Does this really need to be GFP_DMA? */
 				p = kmalloc(usg->sg[i].count,GFP_KERNEL|__GFP_DMA);
@@ -667,7 +667,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 					  usg->sg[i].count,i,usg->count));
 					kfree(usg);
 					rcode = -ENOMEM;
-					goto cleanup;
+					goto free_user_srbcmd;
 				}
 				sg_user[i] = (void __user *)(uintptr_t)usg->sg[i].addr;
 				sg_list[i] = p; // save so we can clean up later
@@ -678,7 +678,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 						kfree (usg);
 						dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
 						rcode = -EFAULT;
-						goto cleanup;
+						goto free_user_srbcmd;
 					}
 				}
 				addr = pci_map_single(dev->pdev, p, usg->sg[i].count, data_dir);
@@ -711,7 +711,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 				      (dev->scsi_host_ptr->max_sectors << 9) :
 				      65536)) {
 					rcode = -EINVAL;
-					goto cleanup;
+					goto free_user_srbcmd;
 				}
 				/* Does this really need to be GFP_DMA? */
 				p = kmalloc(usg->sg[i].count,GFP_KERNEL|__GFP_DMA);
@@ -719,7 +719,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 					dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
 					  usg->sg[i].count,i,usg->count));
 					rcode = -ENOMEM;
-					goto cleanup;
+					goto free_user_srbcmd;
 				}
 				addr = (u64)usg->sg[i].addr[0];
 				addr += ((u64)usg->sg[i].addr[1]) << 32;
@@ -731,7 +731,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 					if(copy_from_user(p,sg_user[i],usg->sg[i].count)){
 						dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
 						rcode = -EFAULT;
-						goto cleanup;
+						goto free_user_srbcmd;
 					}
 				}
 				addr = pci_map_single(dev->pdev, p, usg->sg[i].count, data_dir);
@@ -750,14 +750,14 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 				      (dev->scsi_host_ptr->max_sectors << 9) :
 				      65536)) {
 					rcode = -EINVAL;
-					goto cleanup;
+					goto free_user_srbcmd;
 				}
 				p = kmalloc(upsg->sg[i].count, GFP_KERNEL);
 				if (!p) {
 					dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
 					  upsg->sg[i].count, i, upsg->count));
 					rcode = -ENOMEM;
-					goto cleanup;
+					goto free_user_srbcmd;
 				}
 				sg_user[i] = (void __user *)(uintptr_t)upsg->sg[i].addr;
 				sg_list[i] = p; // save so we can clean up later
@@ -768,7 +768,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 							upsg->sg[i].count)) {
 						dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
 						rcode = -EFAULT;
-						goto cleanup;
+						goto free_user_srbcmd;
 					}
 				}
 				addr = pci_map_single(dev->pdev, p,
@@ -788,13 +788,13 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 	}
 	if (status = -ERESTARTSYS) {
 		rcode = -ERESTARTSYS;
-		goto cleanup;
+		goto free_user_srbcmd;
 	}
 
 	if (status != 0){
 		dprintk((KERN_DEBUG"aacraid: Could not send raw srb fib to hba\n"));
 		rcode = -ENXIO;
-		goto cleanup;
+		goto free_user_srbcmd;
 	}
 
 	if (flags & SRB_DataIn) {
@@ -806,7 +806,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 			if(copy_to_user(sg_user[i], sg_list[i], byte_count)){
 				dprintk((KERN_DEBUG"aacraid: Could not copy sg data to user\n"));
 				rcode = -EFAULT;
-				goto cleanup;
+				goto free_user_srbcmd;
 
 			}
 		}
@@ -816,11 +816,10 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 	if(copy_to_user(user_reply,reply,sizeof(struct aac_srb_reply))){
 		dprintk((KERN_DEBUG"aacraid: Could not copy reply to user\n"));
 		rcode = -EFAULT;
-		goto cleanup;
 	}
-
-cleanup:
+free_user_srbcmd:
 	kfree(user_srbcmd);
+free_sg_list:
 	for(i=0; i <= sg_indx; i++){
 		kfree(sg_list[i]);
 	}
Signature · 1 line
2.9.3
#516 lore raw

PATCH 3/7 aacraid: Delete unnecessary initialisations in aac_send_raw_srb()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 20 Aug 2016 21:25:20 +0200

Six local variables will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

---
 drivers/scsi/aacraid/commctrl.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/scsi/aacraid/commctrl.c +6 -6
index 6dcdf91..49a664f 100644
@@ -476,20 +476,20 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 {
 	struct fib* srbfib;
 	int status;
-	struct aac_srb *srbcmd = NULL;
-	struct user_aac_srb *user_srbcmd = NULL;
+	struct aac_srb *srbcmd;
+	struct user_aac_srb *user_srbcmd;
 	struct user_aac_srb __user *user_srb = arg;
 	struct aac_srb_reply __user *user_reply;
 	struct aac_srb_reply* reply;
-	u32 fibsize = 0;
-	u32 flags = 0;
+	u32 fibsize;
+	u32 flags;
 	s32 rcode = 0;
 	u32 data_dir;
 	void __user *sg_user[32];
 	void *sg_list[32];
 	u32 sg_indx = 0;
-	u32 byte_count = 0;
-	u32 actual_fibsize64, actual_fibsize = 0;
+	u32 byte_count;
+	u32 actual_fibsize64, actual_fibsize;
 	int i;
 
 
Signature · 1 line
2.9.3
#517 lore raw

PATCH 4/7 aacraid: Delete unnecessary braces

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 07:07:08 +0200

Do not use curly brackets at some source code places where a single statement should be sufficient.

---
 drivers/scsi/aacraid/commctrl.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/scsi/aacraid/commctrl.c +6 -12
index 49a664f..9f4ddb0 100644
@@ -66,13 +66,11 @@ static int ioctl_send_fib(struct aac_dev * dev, void __user *arg)
 	unsigned int size, osize;
 	int retval;
 
-	if (dev->in_reset) {
+	if (dev->in_reset)
 		return -EBUSY;
-	}
 	fibptr = aac_fib_alloc(dev);
-	if(fibptr = NULL) {
+	if (!fibptr)
 		return -ENOMEM;
-	}
 
 	kfib = fibptr->hw_fib_va;
 	/*
@@ -138,9 +136,8 @@ static int ioctl_send_fib(struct aac_dev * dev, void __user *arg)
 		retval = aac_fib_send(le16_to_cpu(kfib->header.Command), fibptr,
 				le16_to_cpu(kfib->header.Size) , FsaNormal,
 				1, 1, NULL, NULL);
-		if (retval) {
+		if (retval)
 			goto cleanup;
-		}
 		if (aac_fib_complete(fibptr) != 0) {
 			retval = -EINVAL;
 			goto cleanup;
@@ -228,12 +225,10 @@ static int open_getadapter_fib(struct aac_dev * dev, void __user *arg)
 		}
 		list_add_tail(&fibctx->next, &dev->fib_list);
 		spin_unlock_irqrestore(&dev->fib_lock, flags);
-		if (copy_to_user(arg, &fibctx->unique,
-						sizeof(fibctx->unique))) {
+		if (copy_to_user(arg, &fibctx->unique, sizeof(fibctx->unique)))
 			status = -EFAULT;
-		} else {
+		else
 			status = 0;
-		}
 	}
 	return status;
 }
@@ -820,9 +815,8 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 free_user_srbcmd:
 	kfree(user_srbcmd);
 free_sg_list:
-	for(i=0; i <= sg_indx; i++){
+	for (i = 0; i <= sg_indx; i++)
 		kfree(sg_list[i]);
-	}
 	if (rcode != -ERESTARTSYS) {
 		aac_fib_complete(srbfib);
 		aac_fib_free(srbfib);
Signature · 1 line
2.9.3
#518 lore raw

PATCH 5/7 aacraid: Add spaces after control flow keywords

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 07:10:43 +0200

Keywords which belong to the category "control flow" in the C programming language should be followed by a space character according to the Linux coding style convention.

---
 drivers/scsi/aacraid/commctrl.c | 41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)
drivers/scsi/aacraid/commctrl.c +24 -17
index 9f4ddb0..cda03f0 100644
@@ -251,7 +251,7 @@ static int next_getadapter_fib(struct aac_dev * dev, void __user *arg)
 	struct list_head * entry;
 	unsigned long flags;
 
-	if(copy_from_user((void *)&f, arg, sizeof(struct fib_ioctl)))
+	if (copy_from_user((void *)&f, arg, sizeof(struct fib_ioctl)))
 		return -EFAULT;
 	/*
 	 *	Verify that the HANDLE passed in was a valid AdapterFibContext
@@ -280,7 +280,7 @@ static int next_getadapter_fib(struct aac_dev * dev, void __user *arg)
 		return -EINVAL;
 	}
 
-	if((fibctx->type != FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT) ||
+	if ((fibctx->type != FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT) ||
 		 (fibctx->size != sizeof(struct aac_fib_context))) {
 		spin_unlock_irqrestore(&dev->fib_lock, flags);
 		dprintk ((KERN_INFO "Fib Context corrupt?\n"));
@@ -327,7 +327,7 @@ return_fib:
 			ssleep(1);
 		}
 		if (f.wait) {
-			if(down_interruptible(&fibctx->wait_sem) < 0) {
+			if (down_interruptible(&fibctx->wait_sem) < 0) {
 				status = -ERESTARTSYS;
 			} else {
 				/* Lock again and retry */
@@ -404,7 +404,7 @@ static int close_getadapter_fib(struct aac_dev * dev, void __user *arg)
 	entry = dev->fib_list.next;
 	fibctx = NULL;
 
-	while(entry != &dev->fib_list) {
+	while (entry != &dev->fib_list) {
 		fibctx = list_entry(entry, struct aac_fib_context, next);
 		/*
 		 *	Extract the fibctx from the input parameters
@@ -418,7 +418,7 @@ static int close_getadapter_fib(struct aac_dev * dev, void __user *arg)
 	if (!fibctx)
 		return 0; /* Already gone */
 
-	if((fibctx->type != FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT) ||
+	if ((fibctx->type != FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT) ||
 		 (fibctx->size != sizeof(struct aac_fib_context)))
 		return -EINVAL;
 	spin_lock_irqsave(&dev->fib_lock, flags);
@@ -509,7 +509,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 	srbcmd = (struct aac_srb*) fib_data(srbfib);
 
 	memset(sg_list, 0, sizeof(sg_list)); /* cleanup may take issue */
-	if(copy_from_user(&fibsize, &user_srb->count,sizeof(u32))){
+	if (copy_from_user(&fibsize, &user_srb->count, sizeof(u32))) {
 		dprintk((KERN_DEBUG"aacraid: Could not copy data size from user\n"));
 		rcode = -EFAULT;
 		goto free_sg_list;
@@ -605,7 +605,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 				}
 				/* Does this really need to be GFP_DMA? */
 				p = kmalloc(upsg->sg[i].count,GFP_KERNEL|__GFP_DMA);
-				if(!p) {
+				if (!p) {
 					dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
 					  upsg->sg[i].count,i,upsg->count));
 					rcode = -ENOMEM;
@@ -618,7 +618,9 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 				sg_indx = i;
 
 				if (flags & SRB_DataOut) {
-					if(copy_from_user(p,sg_user[i],upsg->sg[i].count)){
+					if (copy_from_user(p,
+							   sg_user[i],
+							   upsg->sg[i].count)) {
 						dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
 						rcode = -EFAULT;
 						goto free_user_srbcmd;
@@ -657,7 +659,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 				}
 				/* Does this really need to be GFP_DMA? */
 				p = kmalloc(usg->sg[i].count,GFP_KERNEL|__GFP_DMA);
-				if(!p) {
+				if (!p) {
 					dprintk((KERN_DEBUG "aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
 					  usg->sg[i].count,i,usg->count));
 					kfree(usg);
@@ -669,7 +671,9 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 				sg_indx = i;
 
 				if (flags & SRB_DataOut) {
-					if(copy_from_user(p,sg_user[i],upsg->sg[i].count)){
+					if (copy_from_user(p,
+							   sg_user[i],
+							   upsg->sg[i].count)) {
 						kfree (usg);
 						dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
 						rcode = -EFAULT;
@@ -710,7 +714,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 				}
 				/* Does this really need to be GFP_DMA? */
 				p = kmalloc(usg->sg[i].count,GFP_KERNEL|__GFP_DMA);
-				if(!p) {
+				if (!p) {
 					dprintk((KERN_DEBUG"aacraid: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
 					  usg->sg[i].count,i,usg->count));
 					rcode = -ENOMEM;
@@ -723,7 +727,9 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 				sg_indx = i;
 
 				if (flags & SRB_DataOut) {
-					if(copy_from_user(p,sg_user[i],usg->sg[i].count)){
+					if (copy_from_user(p,
+							   sg_user[i],
+							   usg->sg[i].count)) {
 						dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
 						rcode = -EFAULT;
 						goto free_user_srbcmd;
@@ -759,8 +765,9 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 				sg_indx = i;
 
 				if (flags & SRB_DataOut) {
-					if(copy_from_user(p, sg_user[i],
-							upsg->sg[i].count)) {
+					if (copy_from_user(p,
+							   sg_user[i],
+							   upsg->sg[i].count)) {
 						dprintk((KERN_DEBUG"aacraid: Could not copy sg data from user\n"));
 						rcode = -EFAULT;
 						goto free_user_srbcmd;
@@ -793,12 +800,12 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 	}
 
 	if (flags & SRB_DataIn) {
-		for(i = 0 ; i <= sg_indx; i++){
+		for (i = 0 ; i <= sg_indx; i++) {
 			byte_count = le32_to_cpu(
 			  (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)
 			      ? ((struct sgmap64*)&srbcmd->sg)->sg[i].count
 			      : srbcmd->sg.sg[i].count);
-			if(copy_to_user(sg_user[i], sg_list[i], byte_count)){
+			if (copy_to_user(sg_user[i], sg_list[i], byte_count)) {
 				dprintk((KERN_DEBUG"aacraid: Could not copy sg data to user\n"));
 				rcode = -EFAULT;
 				goto free_user_srbcmd;
@@ -808,7 +815,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 	}
 
 	reply = (struct aac_srb_reply *) fib_data(srbfib);
-	if(copy_to_user(user_reply,reply,sizeof(struct aac_srb_reply))){
+	if (copy_to_user(user_reply, reply, sizeof(struct aac_srb_reply))) {
 		dprintk((KERN_DEBUG"aacraid: Could not copy reply to user\n"));
 		rcode = -EFAULT;
 	}
Signature · 1 line
2.9.3
#519 lore raw

PATCH 6/7 aacraid: Improve determination of a few sizes

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 08:04:48 +0200

Replace the specification of data structures by references for variables as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/scsi/aacraid/commctrl.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/aacraid/commctrl.c +4 -4
index cda03f0..d2029db 100644
@@ -177,7 +177,7 @@ static int open_getadapter_fib(struct aac_dev * dev, void __user *arg)
 	struct aac_fib_context * fibctx;
 	int status;
 
-	fibctx = kmalloc(sizeof(struct aac_fib_context), GFP_KERNEL);
+	fibctx = kmalloc(sizeof(*fibctx), GFP_KERNEL);
 	if (fibctx = NULL) {
 		status = -ENOMEM;
 	} else {
@@ -186,7 +186,7 @@ static int open_getadapter_fib(struct aac_dev * dev, void __user *arg)
 		struct aac_fib_context * context;
 
 		fibctx->type = FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT;
-		fibctx->size = sizeof(struct aac_fib_context);
+		fibctx->size = sizeof(*fibctx);
 		/*
 		 *	Yes yes, I know this could be an index, but we have a
 		 * better guarantee of uniqueness for the locked loop below.
@@ -251,7 +251,7 @@ static int next_getadapter_fib(struct aac_dev * dev, void __user *arg)
 	struct list_head * entry;
 	unsigned long flags;
 
-	if (copy_from_user((void *)&f, arg, sizeof(struct fib_ioctl)))
+	if (copy_from_user(&f, arg, sizeof(f)))
 		return -EFAULT;
 	/*
 	 *	Verify that the HANDLE passed in was a valid AdapterFibContext
@@ -509,7 +509,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 	srbcmd = (struct aac_srb*) fib_data(srbfib);
 
 	memset(sg_list, 0, sizeof(sg_list)); /* cleanup may take issue */
-	if (copy_from_user(&fibsize, &user_srb->count, sizeof(u32))) {
+	if (copy_from_user(&fibsize, &user_srb->count, sizeof(fibsize))) {
 		dprintk((KERN_DEBUG"aacraid: Could not copy data size from user\n"));
 		rcode = -EFAULT;
 		goto free_sg_list;
Signature · 1 line
2.9.3
#520 lore raw

PATCH 7/7 aacraid: Apply another recommendation from "checkpatch.pl"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 08:23:25 +0200

The script "checkpatch.pl" can point out that assignments should usually not be performed within condition checks.
Thus move the assignment for the variable "srbfib" to a separate statement.

---
 drivers/scsi/aacraid/commctrl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/aacraid/commctrl.c +2 -2
index d2029db..7e6c76d 100644
@@ -499,9 +499,9 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 	/*
 	 *	Allocate and initialize a Fib then setup a SRB command
 	 */
-	if (!(srbfib = aac_fib_alloc(dev))) {
+	srbfib = aac_fib_alloc(dev);
+	if (!srbfib)
 		return -ENOMEM;
-	}
 	aac_fib_init(srbfib);
 	/* raw_srb FIB is not FastResponseCapable */
 	srbfib->hw_fib_va->header.XferState &= ~cpu_to_le32(FastResponseCapable);
Signature · 1 line
2.9.3
#521 lore raw

PATCH 1/1 megaraid_sas: Use memdup_user() rather than duplicating its implementation

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 10:39:04 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
 drivers/scsi/megaraid/megaraid_sas_base.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/scsi/megaraid/megaraid_sas_base.c +3 -8
index c1ed25a..9a2fe4e 100644
@@ -6711,14 +6711,9 @@ static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg)
 	unsigned long flags;
 	u32 wait_time = MEGASAS_RESET_WAIT_TIME;
 
-	ioc = kmalloc(sizeof(*ioc), GFP_KERNEL);
-	if (!ioc)
-		return -ENOMEM;
-
-	if (copy_from_user(ioc, user_ioc, sizeof(*ioc))) {
-		error = -EFAULT;
-		goto out_kfree_ioc;
-	}
+	ioc = memdup_user(user_ioc, sizeof(*ioc));
+	if (IS_ERR(ioc))
+		return PTR_ERR(ioc);
 
 	instance = megasas_lookup_instance(ioc->host_no);
 	if (!instance) {
Signature · 1 line
2.9.3
maintainer
#522 lore raw

RE: [PATCH] megaraid_sas: Use memdup_user() rather than duplicating its implementation

Quoted 48 lines

-----Original Message-----
From: SF Markus Elfring [mailto:[email protected]]
Sent: Sunday, August 21, 2016 2:19 PM
To: [email protected]; [email protected]; James E. J.
Bottomley; Kashyap Desai; Martin K. Petersen; Sumit Saxena; Uday Lingala
Cc: LKML; [email protected]; Julia Lawall
Subject: [PATCH] megaraid_sas: Use memdup_user() rather than duplicating its
implementation

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 10:39:04 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate
source code.

This issue was detected by using the Coccinelle software.

---
drivers/scsi/megaraid/megaraid_sas_base.c | 11 +++--------

1 file changed, 3 insertions(+), 8 deletions(-)
drivers/scsi/megaraid/megaraid_sas_base.c +3 -8
index c1ed25a..9a2fe4e 100644
@@ -6711,14 +6711,9 @@ static int megasas_mgmt_ioctl_fw(struct file *file,
 unsigned long arg)
 	unsigned long flags;
 	u32 wait_time = MEGASAS_RESET_WAIT_TIME;
 
-	ioc = kmalloc(sizeof(*ioc), GFP_KERNEL);
-	if (!ioc)
-		return -ENOMEM;
-
-	if (copy_from_user(ioc, user_ioc, sizeof(*ioc))) {
-		error = -EFAULT;
-		goto out_kfree_ioc;
-	}
+	ioc = memdup_user(user_ioc, sizeof(*ioc));
+	if (IS_ERR(ioc))
+		return PTR_ERR(ioc);
 
 	instance = megasas_lookup_instance(ioc->host_no);
Quoted 1 line
	if (!instance) {

Acked by: Sumit Saxena <[email protected]>

Quoted 2 lines

--
2.9.3

#523 lore raw

Re: [PATCH] megaraid_sas: Use memdup_user() rather than duplicating its implementation

In reply to SF Markus Elfring
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"SF" = SF Markus Elfring <[email protected]> writes:

SF> Reuse existing functionality from memdup_user() instead of keeping SF> duplicate source code.

Applied to 4.9/scsi-queue.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#524 lore raw

PATCH 1/1 staging/lustre/llite: Use memdup_user() rather than duplicating its implementation

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 11:30:57 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
 drivers/staging/lustre/lustre/llite/dir.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/staging/lustre/lustre/llite/dir.c +3 -9
index 031c9e4..8b70e42 100644
@@ -1676,14 +1676,9 @@ out_poll:
 	case LL_IOC_QUOTACTL: {
 		struct if_quotactl *qctl;
 
-		qctl = kzalloc(sizeof(*qctl), GFP_NOFS);
-		if (!qctl)
-			return -ENOMEM;
-
-		if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl))) {
-			rc = -EFAULT;
-			goto out_quotactl;
-		}
+		qctl = memdup_user((void __user *)arg, sizeof(*qctl));
+		if (IS_ERR(qctl))
+			return PTR_ERR(qctl);
 
 		rc = quotactl_ioctl(sbi, qctl);
 
@@ -1691,7 +1686,6 @@ out_poll:
 					    sizeof(*qctl)))
 			rc = -EFAULT;
 
-out_quotactl:
 		kfree(qctl);
 		return rc;
 	}
Signature · 1 line
2.9.3
#525 lore raw

Re: [PATCH] staging/lustre/llite: Use memdup_user() rather than duplicating its implementation

Quoted 18 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 11:30:57 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
  drivers/staging/lustre/lustre/llite/dir.c | 12 +++---------
  1 file changed, 3 insertions(+), 9 deletions(-)
drivers/staging/lustre/lustre/llite/dir.c +0 -0
index 031c9e4..8b70e42 100644

drivers/staging/lustre/lustre/llite/dir.c out_poll: · line 1679

Quoted 4 lines
drivers/staging/lustre/lustre/llite/dir.c +0 -1
@@ -1676,14 +1676,9 @@ out_poll:
  	case LL_IOC_QUOTACTL: {
  		struct if_quotactl *qctl;
 
-		qctl = kzalloc(sizeof(*qctl), GFP_NOFS);

Same as previously reported in another patch, GFP_NOFS has not the same meaning than GPF_KERNEL.
So your proposed clean-up is not 100% equivalent.

Are your sure that GPF_KERNEL instead of GFP_NOFS is right in this code?

Maybe, the coccinelle check should be tweak to only spot "kzalloc(..., GFP_KERNEL)" allocation?

Quoted 14 lines
drivers/staging/lustre/lustre/llite/dir.c +3 -7
-		if (!qctl)
-			return -ENOMEM;
-
-		if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl))) {
-			rc = -EFAULT;
-			goto out_quotactl;
-		}
+		qctl = memdup_user((void __user *)arg, sizeof(*qctl));
+		if (IS_ERR(qctl))
+			return PTR_ERR(qctl);
 
  		rc = quotactl_ioctl(sbi, qctl);
 

drivers/staging/lustre/lustre/llite/dir.c out_poll: · line 1691

Quoted 7 lines
drivers/staging/lustre/lustre/llite/dir.c +0 -1
@@ -1691,7 +1686,6 @@ out_poll:
  					    sizeof(*qctl)))
  			rc = -EFAULT;
 
-out_quotactl:
  		kfree(qctl);
  		return rc;
  	}

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus

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

#526 lore raw

Re: [PATCH] staging/lustre/llite: Use memdup_user() rather than duplicating its implementation

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

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 11:30:57 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
  drivers/staging/lustre/lustre/llite/dir.c | 12 +++---------
  1 file changed, 3 insertions(+), 9 deletions(-)
drivers/staging/lustre/lustre/llite/dir.c +0 -0
index 031c9e4..8b70e42 100644

drivers/staging/lustre/lustre/llite/dir.c out_poll: · line 1679

Quoted 4 lines
drivers/staging/lustre/lustre/llite/dir.c +0 -1
@@ -1676,14 +1676,9 @@ out_poll:
  	case LL_IOC_QUOTACTL: {
  		struct if_quotactl *qctl;
 
-		qctl = kzalloc(sizeof(*qctl), GFP_NOFS);

Same as previously reported in another patch, GFP_NOFS has not the same meaning than GPF_KERNEL.
So your proposed clean-up is not 100% equivalent.

Are your sure that GPF_KERNEL instead of GFP_NOFS is right in this code?

Maybe, the coccinelle check should be tweak to only spot "kzalloc(..., GFP_KERNEL)" allocation?

Quoted 14 lines
drivers/staging/lustre/lustre/llite/dir.c +3 -7
-		if (!qctl)
-			return -ENOMEM;
-
-		if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl))) {
-			rc = -EFAULT;
-			goto out_quotactl;
-		}
+		qctl = memdup_user((void __user *)arg, sizeof(*qctl));
+		if (IS_ERR(qctl))
+			return PTR_ERR(qctl);
 
  		rc = quotactl_ioctl(sbi, qctl);
 

drivers/staging/lustre/lustre/llite/dir.c out_poll: · line 1691

Quoted 7 lines
drivers/staging/lustre/lustre/llite/dir.c +0 -1
@@ -1691,7 +1686,6 @@ out_poll:
  					    sizeof(*qctl)))
  			rc = -EFAULT;
 
-out_quotactl:
  		kfree(qctl);
  		return rc;
  	}

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus

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

#527 lore raw

Re: [PATCH] staging/lustre/llite: Use memdup_user() rather than duplicating its implementation

Quoted 27 lines · Christophe JAILLET
Quoted 19 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 11:30:57 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
  drivers/staging/lustre/lustre/llite/dir.c | 12 +++---------
  1 file changed, 3 insertions(+), 9 deletions(-)
drivers/staging/lustre/lustre/llite/dir.c +0 -0
index 031c9e4..8b70e42 100644

drivers/staging/lustre/lustre/llite/dir.c out_poll: · line 1678

Quoted 3 lines
drivers/staging/lustre/lustre/llite/dir.c +0 -0
@@ -1676,14 +1676,9 @@ out_poll:
  	case LL_IOC_QUOTACTL: {
  		struct if_quotactl *qctl;
  -		qctl = kzalloc(sizeof(*qctl), GFP_NOFS);

Same as previously reported in another patch, GFP_NOFS has not the same meaning than GPF_KERNEL.
So your proposed clean-up is not 100% equivalent.

Quoted 4 lines

Are your sure that GPF_KERNEL instead of GFP_NOFS is right in this code?

Maybe, the coccinelle check should be tweak to only spot "kzalloc(..., GFP_KERNEL)" allocation?

To my dim recollection, GFP_NOFS is not actually allowed in a place where copy_from_user is being used. copy_from_user can block due to page faults, and GFP_NOFS is used when a certain kind of blocking is not allowed. So if the code really needs GFP_NOFS, then something else is wrong.

The semantic patch intentionally does not specify GFP_KERNEL for this reason, ie so that these issues will come up and be discussed. On the ther hand I agree about the GFP_DMA case, since that doesn't relate to blocking, as far as I know. The semantic patch should be updated to not make/propose the change in that case.

julia

Quoted 33 lines
Quoted 9 lines
drivers/staging/lustre/lustre/llite/dir.c +1 -7
-		if (!qctl)
-			return -ENOMEM;
-
-		if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl))) {
-			rc = -EFAULT;
-			goto out_quotactl;
-		}
+		qctl = memdup_user((void __user *)arg, sizeof(*qctl));

drivers/staging/lustre/lustre/llite/dir.c out_poll:

Quoted 10 lines
drivers/staging/lustre/lustre/llite/dir.c +2 -0
+		if (IS_ERR(qctl))
+			return PTR_ERR(qctl);
    		rc = quotactl_ioctl(sbi, qctl);
  @@ -1691,7 +1686,6 @@ out_poll:
  					    sizeof(*qctl)))
  			rc = -EFAULT;
  -out_quotactl:
  		kfree(qctl);
  		return rc;
  	}

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus

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

#528 lore raw

Re: [PATCH] staging/lustre/llite: Use memdup_user() rather than duplicating its implementation

Quoted 42 lines · Julia Lawall
Quoted 27 lines · Christophe JAILLET
Quoted 19 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 11:30:57 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
  drivers/staging/lustre/lustre/llite/dir.c | 12 +++---------
  1 file changed, 3 insertions(+), 9 deletions(-)
drivers/staging/lustre/lustre/llite/dir.c +0 -0
index 031c9e4..8b70e42 100644

drivers/staging/lustre/lustre/llite/dir.c out_poll: · line 1678

Quoted 3 lines
drivers/staging/lustre/lustre/llite/dir.c +0 -0
@@ -1676,14 +1676,9 @@ out_poll:
  	case LL_IOC_QUOTACTL: {
  		struct if_quotactl *qctl;
  -		qctl = kzalloc(sizeof(*qctl), GFP_NOFS);

Same as previously reported in another patch, GFP_NOFS has not the same meaning than GPF_KERNEL.
So your proposed clean-up is not 100% equivalent.

Quoted 4 lines

Are your sure that GPF_KERNEL instead of GFP_NOFS is right in this code?

Maybe, the coccinelle check should be tweak to only spot "kzalloc(..., GFP_KERNEL)" allocation?

To my dim recollection, GFP_NOFS is not actually allowed in a place where copy_from_user is being used. copy_from_user can block due to page faults, and GFP_NOFS is used when a certain kind of blocking is not allowed. So if the code really needs GFP_NOFS, then something else is wrong.

Quoted 5 lines

The semantic patch intentionally does not specify GFP_KERNEL for this reason, ie so that these issues will come up and be discussed. On the ther hand I agree about the GFP_DMA case, since that doesn't relate to blocking, as far as I know. The semantic patch should be updated to not make/propose the change in that case.

I think semantic patch should be updated for all possible flags except GFP_NOFS and GFP_ATOMIC. Because only using these 2 flags with copy_from_user can cause blocking.

Quoted 36 lines

julia

Quoted 33 lines
Quoted 9 lines
drivers/staging/lustre/lustre/llite/dir.c +1 -7
-		if (!qctl)
-			return -ENOMEM;
-
-		if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl))) {
-			rc = -EFAULT;
-			goto out_quotactl;
-		}
+		qctl = memdup_user((void __user *)arg, sizeof(*qctl));

drivers/staging/lustre/lustre/llite/dir.c out_poll:

Quoted 10 lines
drivers/staging/lustre/lustre/llite/dir.c +2 -0
+		if (IS_ERR(qctl))
+			return PTR_ERR(qctl);
    		rc = quotactl_ioctl(sbi, qctl);
  @@ -1691,7 +1686,6 @@ out_poll:
  					    sizeof(*qctl)))
  			rc = -EFAULT;
  -out_quotactl:
  		kfree(qctl);
  		return rc;
  	}

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus

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

Signature · 1 line
Vaishali
#529 lore raw

Re: [PATCH] staging/lustre/llite: Use memdup_user() rather than duplicating its implementation

Quoted 51 lines · Vaishali Thakkar
Quoted 42 lines · Julia Lawall
Quoted 27 lines · Christophe JAILLET
Quoted 19 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 11:30:57 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
  drivers/staging/lustre/lustre/llite/dir.c | 12 +++---------
  1 file changed, 3 insertions(+), 9 deletions(-)
drivers/staging/lustre/lustre/llite/dir.c +0 -0
index 031c9e4..8b70e42 100644

drivers/staging/lustre/lustre/llite/dir.c out_poll: · line 1678

Quoted 3 lines
drivers/staging/lustre/lustre/llite/dir.c +0 -0
@@ -1676,14 +1676,9 @@ out_poll:
  	case LL_IOC_QUOTACTL: {
  		struct if_quotactl *qctl;
  -		qctl = kzalloc(sizeof(*qctl), GFP_NOFS);

Same as previously reported in another patch, GFP_NOFS has not the same meaning than GPF_KERNEL.
So your proposed clean-up is not 100% equivalent.

Quoted 4 lines

Are your sure that GPF_KERNEL instead of GFP_NOFS is right in this code?

Maybe, the coccinelle check should be tweak to only spot "kzalloc(..., GFP_KERNEL)" allocation?

To my dim recollection, GFP_NOFS is not actually allowed in a place where copy_from_user is being used. copy_from_user can block due to page faults, and GFP_NOFS is used when a certain kind of blocking is not allowed. So if the code really needs GFP_NOFS, then something else is wrong.

Quoted 5 lines

The semantic patch intentionally does not specify GFP_KERNEL for this reason, ie so that these issues will come up and be discussed. On the ther hand I agree about the GFP_DMA case, since that doesn't relate to blocking, as far as I know. The semantic patch should be updated to not make/propose the change in that case.

Quoted 3 lines

I think semantic patch should be updated for all possible flags except GFP_NOFS and GFP_ATOMIC. Because only using these 2 flags with copy_from_user can cause blocking.

They don't cause blocking, but rather prevent it.

But people could use variables as well. Since other things are rare, it seems like it could be better to only block reports on what is known to be safe, and not to block reports on unknown things. A warning could be given in some cases.

julia

Quoted 41 lines
Quoted 37 lines

julia

Quoted 33 lines
Quoted 9 lines
drivers/staging/lustre/lustre/llite/dir.c +1 -7
-		if (!qctl)
-			return -ENOMEM;
-
-		if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl))) {
-			rc = -EFAULT;
-			goto out_quotactl;
-		}
+		qctl = memdup_user((void __user *)arg, sizeof(*qctl));

drivers/staging/lustre/lustre/llite/dir.c out_poll:

Quoted 10 lines
drivers/staging/lustre/lustre/llite/dir.c +2 -0
+		if (IS_ERR(qctl))
+			return PTR_ERR(qctl);
    		rc = quotactl_ioctl(sbi, qctl);
  @@ -1691,7 +1686,6 @@ out_poll:
  					    sizeof(*qctl)))
  			rc = -EFAULT;
  -out_quotactl:
  		kfree(qctl);
  		return rc;
  	}

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus

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

--
Vaishali

#530 lore raw

Re: [PATCH] staging/lustre/llite: Use memdup_user() rather than duplicating its implementation

Quoted 55 lines · Julia Lawall
Quoted 51 lines · Vaishali Thakkar
Quoted 47 lines · Julia Lawall
Quoted 27 lines · Christophe JAILLET
Quoted 19 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 11:30:57 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
  drivers/staging/lustre/lustre/llite/dir.c | 12 +++---------
  1 file changed, 3 insertions(+), 9 deletions(-)
drivers/staging/lustre/lustre/llite/dir.c +0 -0
index 031c9e4..8b70e42 100644

drivers/staging/lustre/lustre/llite/dir.c out_poll: · line 1678

Quoted 3 lines
drivers/staging/lustre/lustre/llite/dir.c +0 -0
@@ -1676,14 +1676,9 @@ out_poll:
  	case LL_IOC_QUOTACTL: {
  		struct if_quotactl *qctl;
  -		qctl = kzalloc(sizeof(*qctl), GFP_NOFS);

Same as previously reported in another patch, GFP_NOFS has not the same meaning than GPF_KERNEL.
So your proposed clean-up is not 100% equivalent.

Quoted 4 lines

Are your sure that GPF_KERNEL instead of GFP_NOFS is right in this code?

Maybe, the coccinelle check should be tweak to only spot "kzalloc(..., GFP_KERNEL)" allocation?

To my dim recollection, GFP_NOFS is not actually allowed in a place where copy_from_user is being used. copy_from_user can block due to page faults, and GFP_NOFS is used when a certain kind of blocking is not allowed. So if the code really needs GFP_NOFS, then something else is wrong.

The semantic patch intentionally does not specify GFP_KERNEL for this reason, ie so that these issues will come up and be discussed. On the ther hand I agree about the GFP_DMA case, since that doesn't relate to blocking, as far as I know. The semantic patch should be updated to not make/propose the change in that case.

Quoted 5 lines
Quoted 3 lines

I think semantic patch should be updated for all possible flags except GFP_NOFS and GFP_ATOMIC. Because only using these 2 flags with copy_from_user can cause blocking.

They don't cause blocking, but rather prevent it.

Yes, sorry. I meant blocking functions which may sleep in between.

Quoted 4 lines

But people could use variables as well. Since other things are rare, it seems like it could be better to only block reports on what is known to be safe, and not to block reports on unknown things. A warning could be given in some cases.

Sounds reasonable. Warning will work I guess.

Quoted 44 lines

julia

Quoted 41 lines
Quoted 37 lines

julia

Quoted 33 lines
Quoted 9 lines
drivers/staging/lustre/lustre/llite/dir.c +1 -7
-		if (!qctl)
-			return -ENOMEM;
-
-		if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl))) {
-			rc = -EFAULT;
-			goto out_quotactl;
-		}
+		qctl = memdup_user((void __user *)arg, sizeof(*qctl));

drivers/staging/lustre/lustre/llite/dir.c out_poll:

Quoted 10 lines
drivers/staging/lustre/lustre/llite/dir.c +2 -0
+		if (IS_ERR(qctl))
+			return PTR_ERR(qctl);
    		rc = quotactl_ioctl(sbi, qctl);
  @@ -1691,7 +1686,6 @@ out_poll:
  					    sizeof(*qctl)))
  			rc = -EFAULT;
  -out_quotactl:
  		kfree(qctl);
  		return rc;
  	}

---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus

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

--
Vaishali

Signature · 1 line
Vaishali
#531 lore raw

cover USB-iowarrior: Fine-tuning for some function implementations

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 15:41:23 +0200

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

Markus Elfring (7):
Use memdup_user() rather than duplicating its implementation Delete unnecessary initialisations for the variable "dev" Delete an unnecessary initialisation in iowarrior_release() Delete unnecessary initialisations in iowarrior_open() Delete unnecessary initialisations in iowarrior_write() Delete unnecessary braces
Apply another recommendation from "checkpatch.pl"

 drivers/usb/misc/iowarrior.c | 53 ++++++++++++++++++--------------------------
 1 file changed, 22 insertions(+), 31 deletions(-)
Signature · 1 line
2.9.3
#532 lore raw

PATCH 1/7 USB-iowarrior: Use memdup_user() rather than duplicating its implementation

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 12:48:27 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
 drivers/usb/misc/iowarrior.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/usb/misc/iowarrior.c +3 -8
index 7defa34..8ae01b0 100644
@@ -368,14 +368,9 @@ static ssize_t iowarrior_write(struct file *file,
 	case USB_DEVICE_ID_CODEMERCS_IOWPV2:
 	case USB_DEVICE_ID_CODEMERCS_IOW40:
 		/* IOW24 and IOW40 use a synchronous call */
-		buf = kmalloc(count, GFP_KERNEL);
-		if (!buf) {
-			retval = -ENOMEM;
-			goto exit;
-		}
-		if (copy_from_user(buf, user_buffer, count)) {
-			retval = -EFAULT;
-			kfree(buf);
+		buf = memdup_user(user_buffer, count);
+		if (IS_ERR(buf)) {
+			retval = PTR_ERR(buf);
 			goto exit;
 		}
 		retval = usb_set_report(dev->interface, 2, 0, buf, count);
Signature · 1 line
2.9.3
#533 lore raw

PATCH 2/7 USB-iowarrior: Delete unnecessary initialisations for the variable "dev"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 13:26:09 +0200

The local variable "dev" was initialised despite of the detail that it was immediately reassigned by the following statement. Thus remove such unnecessary specifications.

---
 drivers/usb/misc/iowarrior.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/misc/iowarrior.c +2 -2
index 8ae01b0..6048f97 100644
@@ -468,7 +468,7 @@ exit:
 static long iowarrior_ioctl(struct file *file, unsigned int cmd,
 							unsigned long arg)
 {
-	struct iowarrior *dev = NULL;
+	struct iowarrior *dev;
 	__u8 *buffer;
 	__u8 __user *user_buffer;
 	int retval;
@@ -751,7 +751,7 @@ static int iowarrior_probe(struct usb_interface *interface,
 			   const struct usb_device_id *id)
 {
 	struct usb_device *udev = interface_to_usbdev(interface);
-	struct iowarrior *dev = NULL;
+	struct iowarrior *dev;
 	struct usb_host_interface *iface_desc;
 	struct usb_endpoint_descriptor *endpoint;
 	int i;
Signature · 1 line
2.9.3
#534 lore raw

PATCH 3/7 USB-iowarrior: Delete an unnecessary initialisation in iowarrior_release()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 13:45:09 +0200

The local variable "retval" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

---
 drivers/usb/misc/iowarrior.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/misc/iowarrior.c +1 -1
index 6048f97..449bf64 100644
@@ -644,7 +644,7 @@ out:
 static int iowarrior_release(struct inode *inode, struct file *file)
 {
 	struct iowarrior *dev;
-	int retval = 0;
+	int retval;
 
 	dev = file->private_data;
 	if (dev = NULL) {
Signature · 1 line
2.9.3
#535 lore raw

PATCH 4/7 USB-iowarrior: Delete unnecessary initialisations in iowarrior_open()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 15:15:03 +0200

Two local variables will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

---
 drivers/usb/misc/iowarrior.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/misc/iowarrior.c +2 -2
index 449bf64..e3564d8 100644
@@ -587,10 +587,10 @@ error_out:
  */
 static int iowarrior_open(struct inode *inode, struct file *file)
 {
-	struct iowarrior *dev = NULL;
+	struct iowarrior *dev;
 	struct usb_interface *interface;
 	int subminor;
-	int retval = 0;
+	int retval;
 
 	mutex_lock(&iowarrior_mutex);
 	subminor = iminor(inode);
Signature · 1 line
2.9.3
#536 lore raw

PATCH 5/7 USB-iowarrior: Delete unnecessary initialisations in iowarrior_write()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 15:17:22 +0200

Two local variables will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

---
 drivers/usb/misc/iowarrior.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/misc/iowarrior.c +2 -2
index e3564d8..ffbbb74 100644
@@ -338,8 +338,8 @@ static ssize_t iowarrior_write(struct file *file,
 			       size_t count, loff_t *ppos)
 {
 	struct iowarrior *dev;
-	int retval = 0;
-	char *buf = NULL;	/* for IOW24 and IOW56 we need a buffer */
+	int retval;
+	char *buf;	/* for IOW24 and IOW56 we need a buffer */
 	struct urb *int_out_urb = NULL;
 
 	dev = file->private_data;
Signature · 1 line
2.9.3
#537 lore raw

PATCH 6/7 USB-iowarrior: Delete unnecessary braces

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 15:25:30 +0200

Do not use curly brackets at a few source code places where a single statement should be sufficient.

---
 drivers/usb/misc/iowarrior.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)
drivers/usb/misc/iowarrior.c +8 -14
index ffbbb74..132c8cf 100644
@@ -227,10 +227,10 @@ static void iowarrior_write_callback(struct urb *urb)
 	/* sync/async unlink faults aren't errors */
 	if (status &&
 	    !(status = -ENOENT ||
-	      status = -ECONNRESET || status = -ESHUTDOWN)) {
+	      status = -ECONNRESET || status = -ESHUTDOWN))
 		dev_dbg(&dev->interface->dev,
 			"nonzero write bulk status received: %d\n", status);
-	}
+
 	/* free up our allocated buffer */
 	usb_free_coherent(urb->dev, urb->transfer_buffer_length,
 			  urb->transfer_buffer, urb->transfer_dma);
@@ -304,25 +304,21 @@ static ssize_t iowarrior_read(struct file *file, char __user *buffer,
 								      read_index
 								      (dev)) ! 								  -1));
-				if (r) {
+				if (r)
 					//we were interrupted by a signal
 					return -ERESTART;
-				}
-				if (!dev->present) {
+				if (!dev->present)
 					//The device was unplugged
 					return -ENODEV;
-				}
-				if (read_idx = -1) {
+				if (read_idx = -1)
 					// Can this happen ???
 					return 0;
-				}
 			}
 		}
 
 		offset = read_idx * (dev->report_size + 1);
-		if (copy_to_user(buffer, dev->read_queue + offset, count)) {
+		if (copy_to_user(buffer, dev->read_queue + offset, count))
 			return -EFAULT;
-		}
 	} while (atomic_read(&dev->overflow_flag));
 
 	read_idx = ++read_idx = MAX_INTERRUPT_BUFFER ? 0 : read_idx;
@@ -475,9 +471,8 @@ static long iowarrior_ioctl(struct file *file, unsigned int cmd,
 	int io_res;		/* checks for bytes read/written and copy_to/from_user results */
 
 	dev = file->private_data;
-	if (dev = NULL) {
+	if (!dev)
 		return -ENODEV;
-	}
 
 	buffer = kzalloc(dev->report_size, GFP_KERNEL);
 	if (!buffer)
@@ -647,9 +642,8 @@ static int iowarrior_release(struct inode *inode, struct file *file)
 	int retval;
 
 	dev = file->private_data;
-	if (dev = NULL) {
+	if (!dev)
 		return -ENODEV;
-	}
 
 	dev_dbg(&dev->interface->dev, "minor %d\n", dev->minor);
 
Signature · 1 line
2.9.3
#538 lore raw

PATCH 7/7 USB-iowarrior: Apply another recommendation from "checkpatch.pl"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 15:30:11 +0200

The script "checkpatch.pl" can point out that assignments should usually not be performed within condition checks.
Thus move the assignments for two local variables to separate statements.

---
 drivers/usb/misc/iowarrior.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/misc/iowarrior.c +4 -2
index 132c8cf..78b5d65 100644
@@ -292,7 +292,8 @@ static ssize_t iowarrior_read(struct file *file, char __user *buffer,
 	/* repeat until no buffer overrun in callback handler occur */
 	do {
 		atomic_set(&dev->overflow_flag, 0);
-		if ((read_idx = read_index(dev)) = -1) {
+		read_idx = read_index(dev);
+		if (read_idx = -1) {
 			/* queue empty */
 			if (file->f_flags & O_NONBLOCK)
 				return -EAGAIN;
@@ -616,7 +617,8 @@ static int iowarrior_open(struct inode *inode, struct file *file)
 	}
 
 	/* setup interrupt handler for receiving values */
-	if ((retval = usb_submit_urb(dev->int_in_urb, GFP_KERNEL)) < 0) {
+	retval = usb_submit_urb(dev->int_in_urb, GFP_KERNEL);
+	if (retval < 0) {
 		dev_err(&interface->dev, "Error %d while submitting URB\n", retval);
 		retval = -EFAULT;
 		goto out;
Signature · 1 line
2.9.3
#539 lore raw

cover IB/core: Fine-tuning for ib_is_udata_cleared()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 19:34:12 +0200

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

Markus Elfring (2):
Use memdup_user()
Delete an unnecessary initialisation

 include/rdma/ib_verbs.h | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
Signature · 1 line
2.9.3
#540 lore raw

PATCH 1/2 IB/core: Use memdup_user() rather than duplicating its implementation

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 18:45:22 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
 include/rdma/ib_verbs.h | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
include/rdma/ib_verbs.h +2 -7
index 6f667dd..033610b 100644
@@ -2205,16 +2205,11 @@ static inline bool ib_is_udata_cleared(struct ib_udata *udata,
 	if (len > USHRT_MAX)
 		return false;
 
-	buf = kmalloc(len, GFP_KERNEL);
-	if (!buf)
+	buf = memdup_user(p, len);
+	if (IS_ERR(buf))
 		return false;
 
-	if (copy_from_user(buf, p, len))
-		goto free;
-
 	ret = !memchr_inv(buf, 0, len);
-
-free:
 	kfree(buf);
 	return ret;
 }
Signature · 1 line
2.9.3
#541 lore raw

PATCH 2/2 IB/core: Delete an unnecessary initialisation in ib_is_udata_cleared()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 19:23:12 +0200

The local variable "ret" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

---
 include/rdma/ib_verbs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/rdma/ib_verbs.h +1 -1
index 033610b..0d8100f 100644
@@ -2199,7 +2199,7 @@ static inline bool ib_is_udata_cleared(struct ib_udata *udata,
 				       size_t len)
 {
 	const void __user *p = udata->inbuf + offset;
-	bool ret = false;
+	bool ret;
 	u8 *buf;
 
 	if (len > USHRT_MAX)
Signature · 1 line
2.9.3
maintainer
#542 lore raw

Re: [PATCH 0/2] IB/core: Fine-tuning for ib_is_udata_cleared()

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

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 19:34:12 +0200

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

Don't introduce a defect in patch 1 and correct
that introduced defect in patch 2.

This should be a single patch.

#543 lore raw

Re: IB/core: Fine-tuning for ib_is_udata_cleared()

Quoted 5 lines
Quoted 2 lines

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

Don't introduce a defect in patch 1 and correct
that introduced defect in patch 2.

Which detail do you not like here?

Quoted 1 line

This should be a single patch.

Do any more software software developers would like to get the proposed changes in a single update step?

Regards,
Markus

maintainer
#544 lore raw

Re: IB/core: Fine-tuning for ib_is_udata_cleared()

Quoted 3 lines · SF Markus Elfring
Quoted 2 lines

Don't introduce a defect in patch 1 and correct
that introduced defect in patch 2.

Which detail do you not like here?

See above.

#545 lore raw

Re: IB/core: Fine-tuning for ib_is_udata_cleared()

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

Don't introduce a defect in patch 1 and correct
that introduced defect in patch 2.

Which detail do you not like here?

See above.

This feedback is not clearer.

I find that the two update steps should work in principle, shouldn't they?

I guess that we have got different preferences for the shown patch granularity. Another update variant can follow a bit later with the changes squashed together.

Regards,
Markus

#546 lore raw

Re: IB/core: Fine-tuning for ib_is_udata_cleared()

Hi,

Le dimanche 21 août 2016 à 22:15 +0200, SF Markus Elfring a écrit :

Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

Don't introduce a defect in patch 1 and correct
that introduced defect in patch 2.

Which detail do you not like here?

See above.

This feedback is not clearer.

It's clear enough: your second patch fixes an issue you introduced in your first patch by removing the code which made use of the ret initialization value:

-       if (copy_from_user(buf, p, len))
-               goto free;

Quoted 3 lines

I find that the two update steps should work in principle, shouldn't they?

It would be better to squash them here.

Regards.

--
Yann Droneaud
OPTEYA

#547 lore raw

PATCH v2 1/1 IB/core: Use memdup_user() rather than duplicating its implementation

From: Markus Elfring <[email protected]>
Date: Mon, 22 Aug 2016 18:23:24 +0200

* Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

* The local variable "ret" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

---

v2: The desired changes were put into a single patch instead of
distributing them over two update steps.

 include/rdma/ib_verbs.h | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
include/rdma/ib_verbs.h +3 -8
index 6f667dd..0d8100f 100644
@@ -2199,22 +2199,17 @@ static inline bool ib_is_udata_cleared(struct ib_udata *udata,
 				       size_t len)
 {
 	const void __user *p = udata->inbuf + offset;
-	bool ret = false;
+	bool ret;
 	u8 *buf;
 
 	if (len > USHRT_MAX)
 		return false;
 
-	buf = kmalloc(len, GFP_KERNEL);
-	if (!buf)
+	buf = memdup_user(p, len);
+	if (IS_ERR(buf))
 		return false;
 
-	if (copy_from_user(buf, p, len))
-		goto free;
-
 	ret = !memchr_inv(buf, 0, len);
-
-free:
 	kfree(buf);
 	return ret;
 }
Signature · 1 line
2.9.3
Applied
#548 lore raw

Re: [PATCH v2] IB/core: Use memdup_user() rather than duplicating its implementation

Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 22 Aug 2016 18:23:24 +0200

* Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

Quoted 6 lines

This issue was detected by using the Coccinelle software.

* The local variable "ret" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

Applied, thanks.

Signature · 2 lines
Doug Ledford <[email protected]>
    GPG Key ID: 0E572FDD
#549 lore raw

PATCH 1/1 Smack: Use memdup_user() rather than duplicating its implementation

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 20:17:36 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
 security/smack/smackfs.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
security/smack/smackfs.c +3 -8
index e249a66..6492fe9 100644
@@ -2523,14 +2523,9 @@ static ssize_t smk_write_revoke_subj(struct file *file, const char __user *buf,
 	if (count = 0 || count > SMK_LONGLABEL)
 		return -EINVAL;
 
-	data = kzalloc(count, GFP_KERNEL);
-	if (data = NULL)
-		return -ENOMEM;
-
-	if (copy_from_user(data, buf, count) != 0) {
-		rc = -EFAULT;
-		goto out_data;
-	}
+	data = memdup_user(buf, count);
+	if (IS_ERR(data))
+		return PTR_ERR(data);
 
 	cp = smk_parse_smack(data, count);
 	if (IS_ERR(cp)) {
Signature · 1 line
2.9.3
maintainer Acked-by on v1 1/1 Applied
#550 lore raw

Re: [PATCH] Smack: Use memdup_user() rather than duplicating its implementation

Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 20:17:36 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

Applied to git://github.com/cschaufler/smack-next.git#smack-for-4.9

Quoted 26 lines
---
 security/smack/smackfs.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
security/smack/smackfs.c +3 -8
index e249a66..6492fe9 100644
@@ -2523,14 +2523,9 @@ static ssize_t smk_write_revoke_subj(struct file *file, const char __user *buf,
 	if (count = 0 || count > SMK_LONGLABEL)
 		return -EINVAL;
 
-	data = kzalloc(count, GFP_KERNEL);
-	if (data = NULL)
-		return -ENOMEM;
-
-	if (copy_from_user(data, buf, count) != 0) {
-		rc = -EFAULT;
-		goto out_data;
-	}
+	data = memdup_user(buf, count);
+	if (IS_ERR(data))
+		return PTR_ERR(data);
 
 	cp = smk_parse_smack(data, count);
 	if (IS_ERR(cp)) {
#551 lore raw

cover ALSA: compress: Fine-tuning for snd_compr_set_params()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 21:35:43 +0200

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

Markus Elfring (2):
Use memdup_user()
Reduce the scope for two variables

 sound/core/compress_offload.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
Signature · 1 line
2.9.3
#552 lore raw

PATCH 1/2 ALSA: compress: Use memdup_user() rather than duplicating its implementation

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 21:02:06 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
 sound/core/compress_offload.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
sound/core/compress_offload.c +3 -7
index 2c49848..583d407 100644
@@ -553,13 +553,9 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 		 * we should allow parameter change only when stream has been
 		 * opened not in other cases
 		 */
-		params = kmalloc(sizeof(*params), GFP_KERNEL);
-		if (!params)
-			return -ENOMEM;
-		if (copy_from_user(params, (void __user *)arg, sizeof(*params))) {
-			retval = -EFAULT;
-			goto out;
-		}
+		params = memdup_user((void __user *)arg, sizeof(*params));
+		if (IS_ERR(params))
+			return PTR_ERR(params);
 
 		retval = snd_compress_check_input(params);
 		if (retval)
Signature · 1 line
2.9.3
Acked-by on v1 1/2
#553 lore raw

Re: [PATCH 1/2] ALSA: compress: Use memdup_user() rather than duplicating its implementation

Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 21:02:06 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

It usually helps to have Coccinelle script in changelog.

But nevertheless

Quoted 30 lines
---
 sound/core/compress_offload.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
sound/core/compress_offload.c +3 -7
index 2c49848..583d407 100644
@@ -553,13 +553,9 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 		 * we should allow parameter change only when stream has been
 		 * opened not in other cases
 		 */
-		params = kmalloc(sizeof(*params), GFP_KERNEL);
-		if (!params)
-			return -ENOMEM;
-		if (copy_from_user(params, (void __user *)arg, sizeof(*params))) {
-			retval = -EFAULT;
-			goto out;
-		}
+		params = memdup_user((void __user *)arg, sizeof(*params));
+		if (IS_ERR(params))
+			return PTR_ERR(params);
 
 		retval = snd_compress_check_input(params);
 		if (retval)
Signature · 1 line
2.9.3
Signature · 1 line
~Vinod
#554 lore raw

Re: [alsa-devel] [PATCH 1/2] ALSA: compress: Use memdup_user() rather than duplicating its implementation

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

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 21:02:06 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

Applied this one, but the second patch won't be, since other people seem to disagree with the usefulness.

thanks,

Takashi

#555 lore raw

Re: [alsa-devel] [PATCH 1/2] ALSA: compress: Use memdup_user() rather than duplicating its implementation

Quoted 9 lines · Takashi Iwai
Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 21:02:06 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

Quoted 6 lines
Quoted 3 lines

This issue was detected by using the Coccinelle software.

Applied this one, but the second patch won't be, since other people seem to disagree with the usefulness.

I see a v2 as well discarding patch 2 here and some other changes

Signature · 1 line
~Vinod
#556 lore raw

PATCH 2/2 ALSA: compress: Reduce the scope for two variables in snd_compr_set_params()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 21:26:18 +0200

Reduce the scope for the local variables to an if branch.

---
 sound/core/compress_offload.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
sound/core/compress_offload.c +6 -6
index 583d407..b43aec5 100644
@@ -545,14 +545,14 @@ static int snd_compress_check_input(struct snd_compr_params *params)
 static int
 snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 {
-	struct snd_compr_params *params;
-	int retval;
-
 	if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
 		/*
 		 * we should allow parameter change only when stream has been
 		 * opened not in other cases
 		 */
+		int retval;
+		struct snd_compr_params *params;
+
 		params = memdup_user((void __user *)arg, sizeof(*params));
 		if (IS_ERR(params))
 			return PTR_ERR(params);
@@ -578,12 +578,12 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 			stream->runtime->state = SNDRV_PCM_STATE_SETUP;
 		else
 			stream->runtime->state = SNDRV_PCM_STATE_PREPARED;
+out:
+		kfree(params);
+		return retval;
 	} else {
 		return -EPERM;
 	}
-out:
-	kfree(params);
-	return retval;
 }
 
 static int
Signature · 1 line
2.9.3
maintainer
#557 lore raw

Re: [PATCH 2/2] ALSA: compress: Reduce the scope for two variables in snd_compr_set_params()

Quoted 1 line · SF Markus Elfring

Reduce the scope for the local variables to an if branch.

[]

sound/core/compress_offload.c

Quoted 1 line
sound/core/compress_offload.c +0 -0

[]

Quoted 8 lines
sound/core/compress_offload.c +0 -0
@@ -545,14 +545,14 @@ static int snd_compress_check_input(struct snd_compr_params *params)

 static int
 snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) {

sound/core/compress_offload.c +0 -3
-	struct snd_compr_params *params;
-	int retval;
-

  if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) {

Likely better not reducing variable scope but changing:

  if (stream->runtime->state == SNDRV_PCM_STATE_OPEN)

to

	if (stream->runtime->state != SNDRV_PCM_STATE_OPEN)
		return -EPERM;

and unindenting the remainder of the code one level instead.

#558 lore raw

v2 cover ALSA: compress: Fine-tuning for snd_compr_set_params()

From: Markus Elfring <[email protected]>
Date: Mon, 22 Aug 2016 10:27:01 +0200

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

Markus Elfring (2):
Restructure source code around an if statement
Use memdup_user()

 sound/core/compress_offload.c | 58 +++++++++++++++++++------------------------
 1 file changed, 26 insertions(+), 32 deletions(-)
Signature · 1 line
2.9.3
#559 lore raw

PATCH v2 1/2 ALSA: compress: Restructure source code around an if statement in snd_compr_set_params()

From: Markus Elfring <[email protected]>
Date: Mon, 22 Aug 2016 10:01:52 +0200

* Reverse a condition check.

* Reduce the indentation one level then for some source code from a previous if branch.

---
 sound/core/compress_offload.c | 62 +++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 32 deletions(-)
sound/core/compress_offload.c +30 -32
index 2c49848..a10d139 100644
@@ -548,43 +548,41 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 	struct snd_compr_params *params;
 	int retval;
 
-	if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
-		/*
-		 * we should allow parameter change only when stream has been
-		 * opened not in other cases
-		 */
-		params = kmalloc(sizeof(*params), GFP_KERNEL);
-		if (!params)
-			return -ENOMEM;
-		if (copy_from_user(params, (void __user *)arg, sizeof(*params))) {
-			retval = -EFAULT;
-			goto out;
-		}
+	if (stream->runtime->state != SNDRV_PCM_STATE_OPEN)
+		return -EPERM;
+	/*
+	 * we should allow parameter change only when stream has been
+	 * opened not in other cases
+	 */
+	params = kmalloc(sizeof(*params), GFP_KERNEL);
+	if (!params)
+		return -ENOMEM;
+	if (copy_from_user(params, (void __user *)arg, sizeof(*params))) {
+		retval = -EFAULT;
+		goto out;
+	}
 
-		retval = snd_compress_check_input(params);
-		if (retval)
-			goto out;
+	retval = snd_compress_check_input(params);
+	if (retval)
+		goto out;
 
-		retval = snd_compr_allocate_buffer(stream, params);
-		if (retval) {
-			retval = -ENOMEM;
-			goto out;
-		}
+	retval = snd_compr_allocate_buffer(stream, params);
+	if (retval) {
+		retval = -ENOMEM;
+		goto out;
+	}
 
-		retval = stream->ops->set_params(stream, params);
-		if (retval)
-			goto out;
+	retval = stream->ops->set_params(stream, params);
+	if (retval)
+		goto out;
 
-		stream->metadata_set = false;
-		stream->next_track = false;
+	stream->metadata_set = false;
+	stream->next_track = false;
 
-		if (stream->direction == SND_COMPRESS_PLAYBACK)
-			stream->runtime->state = SNDRV_PCM_STATE_SETUP;
-		else
-			stream->runtime->state = SNDRV_PCM_STATE_PREPARED;
-	} else {
-		return -EPERM;
-	}
+	if (stream->direction == SND_COMPRESS_PLAYBACK)
+		stream->runtime->state = SNDRV_PCM_STATE_SETUP;
+	else
+		stream->runtime->state = SNDRV_PCM_STATE_PREPARED;
 out:
 	kfree(params);
 	return retval;
Signature · 1 line
2.9.3
#560 lore raw

PATCH v2 2/2 ALSA: compress: Use memdup_user() rather than duplicating its implementation

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 22 Aug 2016 10:12:37 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

This issue was detected by using the Coccinelle software.

---
 sound/core/compress_offload.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
sound/core/compress_offload.c +3 -7
index a10d139..786989b 100644
@@ -554,13 +554,9 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 	 * we should allow parameter change only when stream has been
 	 * opened not in other cases
 	 */
-	params = kmalloc(sizeof(*params), GFP_KERNEL);
-	if (!params)
-		return -ENOMEM;
-	if (copy_from_user(params, (void __user *)arg, sizeof(*params))) {
-		retval = -EFAULT;
-		goto out;
-	}
+	params = memdup_user((void __user *)arg, sizeof(*params));
+	if (IS_ERR(params))
+		return PTR_ERR(params);
 
 	retval = snd_compress_check_input(params);
 	if (retval)
Signature · 1 line
2.9.3
#562 lore raw

Re: [PATCH 2/2] ALSA: compress: Reduce the scope for two variables in snd_compr_set_params()

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

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 21:26:18 +0200

Reduce the scope for the local variables to an if branch.

---
 sound/core/compress_offload.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
sound/core/compress_offload.c +0 -0
index 583d407..b43aec5 100644
@@ -545,14 +545,14 @@ static int snd_compress_check_input(struct snd_compr_params *params)
 static int
 snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 {

sound/core/compress_offload.c static int snd_compress_check_input(struct snd_compr_params *params) · line 554

Quoted 10 lines
sound/core/compress_offload.c +2 -3
-	struct snd_compr_params *params;
-	int retval;
-
 	if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
 		/*
 		 * we should allow parameter change only when stream has been
 		 * opened not in other cases
 		 */
+		int retval;
+		struct snd_compr_params *params;

I don't like this at all. Local variables should be at the top of the function, not hiding under 4 lines of comments in the middle of the code.

julia

Quoted 24 lines
sound/core/compress_offload.c +4 -4
+
 		params = memdup_user((void __user *)arg, sizeof(*params));
 		if (IS_ERR(params))
 			return PTR_ERR(params);
@@ -578,12 +578,12 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 			stream->runtime->state = SNDRV_PCM_STATE_SETUP;
 		else
 			stream->runtime->state = SNDRV_PCM_STATE_PREPARED;
+out:
+		kfree(params);
+		return retval;
 	} else {
 		return -EPERM;
 	}
-out:
-	kfree(params);
-	return retval;
 }
 
 static int
--

2.9.3

#563 lore raw

Re: [PATCH 2/2] ALSA: compress: Reduce the scope for two variables in snd_compr_set_params()

Quoted 27 lines · Julia Lawall
Quoted 23 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 21:26:18 +0200

Reduce the scope for the local variables to an if branch.

---
 sound/core/compress_offload.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
sound/core/compress_offload.c +0 -3
index 583d407..b43aec5 100644
@@ -545,14 +545,14 @@ static int snd_compress_check_input(struct snd_compr_params *params)
 static int
 snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 {
-	struct snd_compr_params *params;
-	int retval;
-
 	if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
 		/*
Quoted 8 lines

sound/core/compress_offload.c static int snd_compress_check_input(struct snd_compr_params *params) · line 554

Quoted 5 lines
sound/core/compress_offload.c +2 -0
 		 * we should allow parameter change only when stream has been
 		 * opened not in other cases
 		 */
+		int retval;
+		struct snd_compr_params *params;

I don't like this at all. Local variables should be at the top of the function, not hiding under 4 lines of comments in the middle of the code.

I agree with you this, it doesn't help IMO as well

Signature · 1 line
~Vinod
#564 lore raw

Re: [PATCH 2/2] ALSA: compress: Reduce the scope for two variables in snd_compr_set_params()

In reply to SF Markus Elfring

Am 21.08.2016 21:45, schrieb SF Markus Elfring:

Quoted 38 lines

From: Markus Elfring <[email protected]>
Date: Sun, 21 Aug 2016 21:26:18 +0200

Reduce the scope for the local variables to an if branch.

---
 sound/core/compress_offload.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
sound/core/compress_offload.c +5 -3
index 583d407..b43aec5 100644
@@ -545,14 +545,14 @@ static int snd_compress_check_input(struct snd_compr_params *params)
 static int
 snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 {
-	struct snd_compr_params *params;
-	int retval;
-
 	if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
 		/*
 		 * we should allow parameter change only when stream has been
 		 * opened not in other cases
 		 */
+		int retval;
+		struct snd_compr_params *params;
+
 		params = memdup_user((void __user *)arg, sizeof(*params));
 		if (IS_ERR(params))
 			return PTR_ERR(params);
@@ -578,12 +578,12 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 			stream->runtime->state = SNDRV_PCM_STATE_SETUP;
 		else
 			stream->runtime->state = SNDRV_PCM_STATE_PREPARED;
+out:
+		kfree(params);

sound/core/compress_offload.c snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) · line 589

Quoted 10 lines
sound/core/compress_offload.c +1 -3
+		return retval;
 	} else {
 		return -EPERM;
 	}
-out:
-	kfree(params);
-	return retval;
 }
 
 static int

if would make sense to have

if (stream->runtime->state != SNDRV_PCM_STATE_OPEN)

	return -EPERM;

and read adjust the indent.

just my 2 cents
re,
wh

#565 lore raw

cover cris-cryptocop: Fine-tuning for some function implementations

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Aug 2016 14:34:34 +0200

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

Markus Elfring (8):
Use kmalloc_array() in two functions Improve determination of sizes in five functions Delete unnecessary braces
Less function calls after error detection Move an assignment for the variable "nooutpages" Delete two variables
Delete unnecessary variable initialisations Apply another recommendation from "checkpatch.pl"

 arch/cris/arch-v32/drivers/cryptocop.c | 299 +++++++++++++++------------------
 1 file changed, 140 insertions(+), 159 deletions(-)
Signature · 1 line
2.9.3
#566 lore raw

PATCH 1/8 cris-cryptocop: Use kmalloc_array() in two functions

From: Markus Elfring <[email protected]>
Date: Thu, 25 Aug 2016 22:11:44 +0200

* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

* Replace the specifications of data structures by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 arch/cris/arch-v32/drivers/cryptocop.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
arch/cris/arch-v32/drivers/cryptocop.c +13 -5
index 2081d8b..1632abc 100644
@@ -1532,7 +1532,9 @@ int cryptocop_new_session(cryptocop_session_id *sid, struct cryptocop_transform_
 		return -ENOMEM;
 	}
 
-	sess->tfrm_ctx = kmalloc(no_tfrms * sizeof(struct cryptocop_transform_ctx), alloc_flag);
+	sess->tfrm_ctx = kmalloc_array(no_tfrms,
+				       sizeof(*sess->tfrm_ctx),
+				       alloc_flag);
 	if (!sess->tfrm_ctx) {
 		DEBUG_API(printk("cryptocop_new_session, kmalloc cryptocop_transform_ctx\n"));
 		kfree(sess);
@@ -2697,7 +2699,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 	/* Map user pages for in and out data of the operation. */
 	noinpages = (((unsigned long int)(oper.indata + prev_ix) & ~PAGE_MASK) + oper.inlen - 1 - prev_ix + ~PAGE_MASK) >> PAGE_SHIFT;
 	DEBUG(printk("cryptocop_ioctl_process: noinpages=%d\n", noinpages));
-	inpages = kmalloc(noinpages * sizeof(struct page*), GFP_KERNEL);
+	inpages = kmalloc_array(noinpages, sizeof(*inpages), GFP_KERNEL);
 	if (!inpages){
 		DEBUG_API(printk("cryptocop_ioctl_process: kmalloc inpages\n"));
 		nooutpages = noinpages = 0;
@@ -2707,7 +2709,9 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 	if (oper.do_cipher){
 		nooutpages = (((unsigned long int)oper.cipher_outdata & ~PAGE_MASK) + oper.cipher_outlen - 1 + ~PAGE_MASK) >> PAGE_SHIFT;
 		DEBUG(printk("cryptocop_ioctl_process: nooutpages=%d\n", nooutpages));
-		outpages = kmalloc(nooutpages * sizeof(struct page*), GFP_KERNEL);
+		outpages = kmalloc_array(nooutpages,
+					 sizeof(*outpages),
+					 GFP_KERNEL);
 		if (!outpages){
 			DEBUG_API(printk("cryptocop_ioctl_process: kmalloc outpages\n"));
 			nooutpages = noinpages = 0;
@@ -2753,8 +2757,12 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 
 	/* Add 6 to nooutpages to make room for possibly inserted buffers for storing digest and
 	 * csum output and splits when units are (dis-)connected. */
-	cop->tfrm_op.indata = kmalloc((noinpages) * sizeof(struct iovec), GFP_KERNEL);
-	cop->tfrm_op.outdata = kmalloc((6 + nooutpages) * sizeof(struct iovec), GFP_KERNEL);
+	cop->tfrm_op.indata = kmalloc_array(noinpages,
+					    sizeof(*cop->tfrm_op.indata),
+					    GFP_KERNEL);
+	cop->tfrm_op.outdata = kmalloc_array(6 + nooutpages,
+					     sizeof(*cop->tfrm_op.outdata),
+					     GFP_KERNEL);
 	if (!cop->tfrm_op.indata || !cop->tfrm_op.outdata) {
 		DEBUG_API(printk("cryptocop_ioctl_process: kmalloc iovecs\n"));
 		err = -ENOMEM;
Signature · 1 line
2.9.3
#567 lore raw

PATCH 2/8 cris-cryptocop: Improve determination of sizes in five functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 25 Aug 2016 22:32:27 +0200

Replace the specification of data structures by references for variables as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 arch/cris/arch-v32/drivers/cryptocop.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
arch/cris/arch-v32/drivers/cryptocop.c +6 -6
index 1632abc..8e04b92 100644
@@ -323,7 +323,7 @@ static struct cryptocop_dma_desc *alloc_cdesc(int alloc_flag)
 		spin_unlock_irqrestore(&descr_pool_lock, flags);
 		cdesc->from_pool = 1;
 	} else {
-		cdesc = kmalloc(sizeof(struct cryptocop_dma_desc), alloc_flag);
+		cdesc = kmalloc(sizeof(*cdesc), alloc_flag);
 		if (!cdesc) {
 			DEBUG_API(printk("alloc_cdesc: kmalloc\n"));
 			return NULL;
@@ -1526,7 +1526,7 @@ int cryptocop_new_session(cryptocop_session_id *sid, struct cryptocop_transform_
 		return -EINVAL;
 	}
 
-	sess = kmalloc(sizeof(struct cryptocop_session), alloc_flag);
+	sess = kmalloc(sizeof(*sess), alloc_flag);
 	if (!sess){
 		DEBUG_API(printk("cryptocop_new_session, kmalloc cryptocop_session\n"));
 		return -ENOMEM;
@@ -2247,7 +2247,7 @@ static int cryptocop_job_setup(struct cryptocop_prio_job **pj, struct cryptocop_
 	int  alloc_flag = operation->in_interrupt ? GFP_ATOMIC : GFP_KERNEL;
 	void *iop_alloc_ptr = NULL;
 
-	*pj = kmalloc(sizeof (struct cryptocop_prio_job), alloc_flag);
+	*pj = kmalloc(sizeof(**pj), alloc_flag);
 	if (!*pj) return -ENOMEM;
 
 	DEBUG(printk("cryptocop_job_setup: operation=0x%p\n", operation));
@@ -2552,12 +2552,12 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 		return -EFAULT;
 	}
 
-	cop = kmalloc(sizeof(struct cryptocop_operation), GFP_KERNEL);
+	cop = kmalloc(sizeof(*cop), GFP_KERNEL);
 	if (!cop) {
 		DEBUG_API(printk("cryptocop_ioctl_process: kmalloc\n"));
 		return -ENOMEM;
 	}
-	jc = kmalloc(sizeof(struct ioctl_job_cb_ctx), GFP_KERNEL);
+	jc = kmalloc(sizeof(*jc), GFP_KERNEL);
 	if (!jc) {
 		DEBUG_API(printk("cryptocop_ioctl_process: kmalloc\n"));
 		err = -ENOMEM;
@@ -3082,7 +3082,7 @@ static int cryptocop_ioctl_create_session(struct inode *inode, struct file *filp
 		ti_csum.next = tis;
 		tis = &ti_csum;
 	} /* (sop.csum != cryptocop_csum_none) */
-	dev = kmalloc(sizeof(struct cryptocop_private), GFP_KERNEL);
+	dev = kmalloc(sizeof(*dev), GFP_KERNEL);
 	if (!dev){
 		DEBUG_API(printk("create session, alloc dev\n"));
 		return -ENOMEM;
Signature · 1 line
2.9.3
#568 lore raw

PATCH 3/8 cris-cryptocop: Delete unnecessary braces

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Aug 2016 08:15:38 +0200

Do not use curly brackets at some source code places where a single statement should be sufficient.

---
 arch/cris/arch-v32/drivers/cryptocop.c | 140 +++++++++++++--------------------
 1 file changed, 56 insertions(+), 84 deletions(-)
arch/cris/arch-v32/drivers/cryptocop.c +56 -84
index 8e04b92..1165639 100644
@@ -352,11 +352,10 @@ static void setup_descr_chain(struct cryptocop_dma_desc *cd)
 {
 	DEBUG(printk("setup_descr_chain: entering\n"));
 	while (cd) {
-		if (cd->next) {
+		if (cd->next)
 			cd->dma_descr->next = (dma_descr_data*)virt_to_phys(cd->next->dma_descr);
-		} else {
+		else
 			cd->dma_descr->next = NULL;
-		}
 		cd = cd->next;
 	}
 	DEBUG(printk("setup_descr_chain: exit\n"));
@@ -996,13 +995,15 @@ static int cryptocop_setup_dma_list(struct cryptocop_operation *operation, struc
 
 			DEBUG(printk("cryptocop_setup_dma_list: parsing an operation descriptor configuration.\n"));
 			/* Get the local context for the transform and mark it as the output unit if it produces output. */
-			if (digest_ctx.tcfg && (digest_ctx.tcfg->tid = dcfg->tid)){
+			if (digest_ctx.tcfg &&
+			   (digest_ctx.tcfg->tid = dcfg->tid))
 				tc = &digest_ctx;
-			} else if (cipher_ctx.tcfg && (cipher_ctx.tcfg->tid = dcfg->tid)){
+			else if (cipher_ctx.tcfg &&
+				(cipher_ctx.tcfg->tid = dcfg->tid))
 				tc = &cipher_ctx;
-			} else if (csum_ctx.tcfg && (csum_ctx.tcfg->tid = dcfg->tid)){
+			else if (csum_ctx.tcfg &&
+				(csum_ctx.tcfg->tid = dcfg->tid))
 				tc = &csum_ctx;
-			}
 			if (!tc) {
 				DEBUG_API(printk("cryptocop_setup_dma_list: invalid transform %d specified in descriptor.\n", dcfg->tid));
 				failed = -EINVAL;
@@ -1047,13 +1048,12 @@ static int cryptocop_setup_dma_list(struct cryptocop_operation *operation, struc
 			}
 			if (tc->current_src != src_dma) {
 				/* Find the unit we are sourcing from. */
-				if (digest_ctx.unit_no = tc->current_src){
+				if (digest_ctx.unit_no = tc->current_src)
 					tc->curr_src = &digest_ctx;
-				} else if (cipher_ctx.unit_no = tc->current_src){
+				else if (cipher_ctx.unit_no = tc->current_src)
 					tc->curr_src = &cipher_ctx;
-				} else if (csum_ctx.unit_no = tc->current_src){
+				else if (csum_ctx.unit_no = tc->current_src)
 					tc->curr_src = &csum_ctx;
-				}
 				if ((tc->curr_src = tc) && (tc->unit_no != src_dma)){
 					DEBUG_API(printk("cryptocop_setup_dma_list: unit %d configured to source from itself.\n", tc->unit_no));
 					failed = -EINVAL;
@@ -1065,7 +1065,7 @@ static int cryptocop_setup_dma_list(struct cryptocop_operation *operation, struc
 
 			/* Detect source switch. */
 			DEBUG(printk("cryptocop_setup_dma_list: tc->active=%d tc->unit_no=%d tc->current_src=%d tc->previous_src=%d, tc->curr_src=0x%p, tc->prev_srv=0x%p\n", tc->active, tc->unit_no, tc->current_src, tc->previous_src, tc->curr_src, tc->prev_src));
-			if (tc->active && (tc->current_src != tc->previous_src)) {
+			if (tc->active && (tc->current_src != tc->previous_src))
 				/* Only allow source switch when both the old source unit and the new one have
 				 * no pending data to process (i.e. the consumed length must be a multiple of the
 				 * transform blocklength). */
@@ -1077,12 +1077,10 @@ static int cryptocop_setup_dma_list(struct cryptocop_operation *operation, struc
 					failed = -EINVAL;
 					goto error_cleanup;
 				}
-			}
 			/* Detect unit deactivation. */
-			if (dcfg->last) {
+			if (dcfg->last)
 				/* Length check of this is handled below. */
 				tc->done = 1;
-			}
 			dcfg = dcfg->next;
 		} /* while (dcfg) */
 		DEBUG(printk("cryptocop_setup_dma_list: parsing operation descriptor configuration complete.\n"));
@@ -1116,20 +1114,17 @@ static int cryptocop_setup_dma_list(struct cryptocop_operation *operation, struc
 
 		if (csum_ctx.active) {
 			csum_ctx.consumed += desc_len;
-			if (csum_ctx.done) {
+			if (csum_ctx.done)
 				csum_ctx.produced = 2;
-			}
 			DEBUG(printk("cryptocop_setup_dma_list: csum_ctx producing: consumed=%d, produced=%d, blocklength=%d.\n", csum_ctx.consumed, csum_ctx.produced, csum_ctx.blocklength));
 		}
 		if (digest_ctx.active) {
 			digest_ctx.consumed += desc_len;
-			if (digest_ctx.done) {
-				if (digest_ctx.unit_no = src_md5) {
+			if (digest_ctx.done)
+				if (digest_ctx.unit_no = src_md5)
 					digest_ctx.produced = MD5_STATE_LENGTH;
-				} else {
+				else
 					digest_ctx.produced = SHA1_STATE_LENGTH;
-				}
-			}
 			DEBUG(printk("cryptocop_setup_dma_list: digest_ctx producing: consumed=%d, produced=%d, blocklength=%d.\n", digest_ctx.consumed, digest_ctx.produced, digest_ctx.blocklength));
 		}
 		if (cipher_ctx.active) {
@@ -1137,9 +1132,11 @@ static int cryptocop_setup_dma_list(struct cryptocop_operation *operation, struc
 			assert(cipher_ctx.current_src = src_dma);
 			cipher_ctx.consumed += desc_len;
 			cipher_ctx.produced = cipher_ctx.blocklength * (cipher_ctx.consumed / cipher_ctx.blocklength);
-			if (cipher_ctx.cbcmode && !(cipher_ctx.tcfg->flags & CRYPTOCOP_EXPLICIT_IV) && cipher_ctx.produced){
+			if (cipher_ctx.cbcmode &&
+			    !(cipher_ctx.tcfg->flags
+			     & CRYPTOCOP_EXPLICIT_IV) &&
+			    cipher_ctx.produced)
 				cipher_ctx.produced -= cipher_ctx.blocklength; /* Compensate for CBC iv. */
-			}
 			DEBUG(printk("cryptocop_setup_dma_list: cipher_ctx producing: consumed=%d, produced=%d, blocklength=%d.\n", cipher_ctx.consumed, cipher_ctx.produced, cipher_ctx.blocklength));
 		}
 
@@ -1149,12 +1146,11 @@ static int cryptocop_setup_dma_list(struct cryptocop_operation *operation, struc
 		eop_needed_count = 0;
 		if (cipher_ctx.active) {
 			++active_count;
-			if (cipher_ctx.unit_no = src_dma){
+			if (cipher_ctx.unit_no = src_dma)
 				/* mem2mem */
 				meta_out.ciphsel = src_none;
-			} else {
+			else
 				meta_out.ciphsel = cipher_ctx.current_src;
-			}
 			meta_out.ciphconf = cipher_ctx.ciph_conf;
 			meta_out.cbcmode = cipher_ctx.cbcmode;
 			meta_out.decrypt = cipher_ctx.decrypt;
@@ -1223,12 +1219,11 @@ static int cryptocop_setup_dma_list(struct cryptocop_operation *operation, struc
 
 				assert(cipher_ctx.active && cipher_ctx.done);
 
-				if (cipher_ctx.unit_no = src_dma){
+				if (cipher_ctx.unit_no = src_dma)
 					/* mem2mem */
 					ed_mo.ciphsel = src_none;
-				} else {
+				else
 					ed_mo.ciphsel = cipher_ctx.current_src;
-				}
 				ed_mo.ciphconf = cipher_ctx.ciph_conf;
 				ed_mo.cbcmode = cipher_ctx.cbcmode;
 				ed_mo.decrypt = cipher_ctx.decrypt;
@@ -1596,13 +1591,11 @@ int cryptocop_free_session(cryptocop_session_id sid)
 		psess = sess;
 		sess = sess->next;
 	}
-	if (sess){
-		if (psess){
+	if (sess)
+		if (psess)
 			psess->next = sess->next;
-		} else {
+		else
 			cryptocop_sessions = sess->next;
-		}
-	}
 	spin_unlock_irqrestore(&cryptocop_sessions_lock, flags);
 
 	if (!sess) return -EINVAL;
@@ -1610,16 +1603,13 @@ int cryptocop_free_session(cryptocop_session_id sid)
 	/* Remove queued jobs. */
 	spin_lock_irqsave(&cryptocop_job_queue_lock, flags);
 
-	for (i = 0; i < cryptocop_prio_no_prios; i++){
-		if (!list_empty(&(cryptocop_job_queues[i].jobs))){
+	for (i = 0; i < cryptocop_prio_no_prios; i++)
+		if (!list_empty(&(cryptocop_job_queues[i].jobs)))
 			list_for_each_safe(node, tmp, &(cryptocop_job_queues[i].jobs)) {
 				pj = list_entry(node, struct cryptocop_prio_job, node);
-				if (pj->oper->sid = sid) {
+				if (pj->oper->sid = sid)
 					list_move_tail(node, &remove_list);
-				}
 			}
-		}
-	}
 	spin_unlock_irqrestore(&cryptocop_job_queue_lock, flags);
 
 	list_for_each_safe(node, tmp, &remove_list) {
@@ -1653,9 +1643,8 @@ static struct cryptocop_session *get_session(cryptocop_session_id sid)
 
 	spin_lock_irqsave(&cryptocop_sessions_lock, flags);
 	sess = cryptocop_sessions;
-	while (sess && (sess->sid != sid)){
+	while (sess && (sess->sid != sid))
 		sess = sess->next;
-	}
 	spin_unlock_irqrestore(&cryptocop_sessions_lock, flags);
 
 	return sess;
@@ -1779,9 +1768,8 @@ static void get_aes_decrypt_key(unsigned char *dec_key, const unsigned  char *ke
 
 	/* Need to do host byte order correction here since key is byte oriented and the
 	 * kx algorithm is word (u32) oriented. */
-	for (i = 0; i < nk; i+=1) {
+	for (i = 0; i < nk; ++i)
 		w_ring[i] = be32_to_cpu(*(u32*)&key[4*i]);
-	}
 
 	i = (int)nk;
 	w_last_ix = i - 1;
@@ -2055,8 +2043,8 @@ static void cryptocop_job_queue_close(void)
 	spin_lock_irqsave(&cryptocop_process_lock, process_flags);
 
 	/* Empty the job queue. */
-	for (i = 0; i < cryptocop_prio_no_prios; i++){
-		if (!list_empty(&(cryptocop_job_queues[i].jobs))){
+	for (i = 0; i < cryptocop_prio_no_prios; i++)
+		if (!list_empty(&(cryptocop_job_queues[i].jobs)))
 			list_for_each_safe(node, tmp, &(cryptocop_job_queues[i].jobs)) {
 				pj = list_entry(node, struct cryptocop_prio_job, node);
 				list_del(node);
@@ -2069,8 +2057,6 @@ static void cryptocop_job_queue_close(void)
 				delete_internal_operation(pj->iop);
 				kfree(pj);
 			}
-		}
-	}
 	spin_unlock_irqrestore(&cryptocop_process_lock, process_flags);
 
 	/* Remove the running job, if any. */
@@ -2321,9 +2307,8 @@ static int cryptocop_release(struct inode *inode, struct file *filp)
 
 	while (dev){
 		dev_next = dev->next;
-		if (dev->sid != CRYPTOCOP_SESSION_ID_NONE) {
+		if (dev->sid != CRYPTOCOP_SESSION_ID_NONE)
 			(void)cryptocop_free_session(dev->sid);
-		}
 		kfree(dev);
 		dev = dev_next;
 	}
@@ -2353,11 +2338,10 @@ static int cryptocop_ioctl_close_session(struct inode *inode, struct file *filp,
 		dev = dev->next;
 	}
 	if (dev){
-		if (prev_dev){
+		if (prev_dev)
 			prev_dev->next = dev->next;
-		} else {
+		else
 			filp->private_data = dev->next;
-		}
 		err = cryptocop_free_session(dev->sid);
 		if (err) return -EFAULT;
 	} else {
@@ -2401,27 +2385,24 @@ static size_t next_cfg_change_ix(struct strcop_crypto_op *crp_op, size_t ix)
 	size_t ch_ix = INT_MAX;
 	size_t tmp_ix = 0;
 
-	if (crp_op->do_cipher && ((crp_op->cipher_start + crp_op->cipher_len) > ix)){
-		if (crp_op->cipher_start > ix) {
+	if (crp_op->do_cipher &&
+	   ((crp_op->cipher_start + crp_op->cipher_len) > ix))
+		if (crp_op->cipher_start > ix)
 			ch_ix = crp_op->cipher_start;
-		} else {
+		else
 			ch_ix = crp_op->cipher_start + crp_op->cipher_len;
-		}
-	}
 	if (crp_op->do_digest && ((crp_op->digest_start + crp_op->digest_len) > ix)){
-		if (crp_op->digest_start > ix) {
+		if (crp_op->digest_start > ix)
 			tmp_ix = crp_op->digest_start;
-		} else {
+		else
 			tmp_ix = crp_op->digest_start + crp_op->digest_len;
-		}
 		if (tmp_ix < ch_ix) ch_ix = tmp_ix;
 	}
 	if (crp_op->do_csum && ((crp_op->csum_start + crp_op->csum_len) > ix)){
-		if (crp_op->csum_start > ix) {
+		if (crp_op->csum_start > ix)
 			tmp_ix = crp_op->csum_start;
-		} else {
+		else
 			tmp_ix = crp_op->csum_start + crp_op->csum_len;
-		}
 		if (tmp_ix < ch_ix) ch_ix = tmp_ix;
 	}
 	if (ch_ix = INT_MAX) ch_ix = ix;
@@ -2635,11 +2616,10 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 			return -EINVAL;
 		}
 
-		if (oper.decrypt){
+		if (oper.decrypt)
 			ciph_tcfg.flags |= CRYPTOCOP_DECRYPT;
-		} else {
+		else
 			ciph_tcfg.flags |= CRYPTOCOP_ENCRYPT;
-		}
 		ciph_tcfg.next = cop->tfrm_op.tfrm_cfg;
 		cop->tfrm_op.tfrm_cfg = &ciph_tcfg;
 	}
@@ -2861,11 +2841,10 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 		prev_ix = next_ix;
 		next_ix = next_cfg_change_ix(&oper, prev_ix);
 	}
-	if (desc_ix > 0){
+	if (desc_ix > 0)
 		descs[desc_ix-1].next = NULL;
-	} else {
+	else
 		descs[0].next = NULL;
-	}
 	if (oper.do_digest) {
 		DEBUG(printk("cryptocop_ioctl_process: mapping %d byte digest output to iovec %d\n", digest_length, iovix));
 		/* Add outdata iovec, length = <length of type of digest> */
@@ -2881,13 +2860,12 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 		cop->tfrm_op.outdata[iovix].iov_len = 2;
 		++iovix;
 	}
-	if (oper.do_cipher) {
+	if (oper.do_cipher)
 		if (!map_pages_to_iovec(cop->tfrm_op.outdata, iovlen, &iovix, outpages, nooutpages, &pageix, &pageoffset, oper.cipher_outlen)){
 			DEBUG_API(printk("cryptocop_ioctl_process: failed to map pages to iovec.\n"));
 			err = -ENOSYS; /* This should be impossible barring bugs. */
 			goto error_cleanup;
 		}
-	}
 	DEBUG(printk("cryptocop_ioctl_process: setting cop->tfrm_op.outcount %d\n", iovix));
 	cop->tfrm_op.outcount = iovix;
 	assert(iovix <= (nooutpages + 6));
@@ -2942,19 +2920,16 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 
  error_cleanup:
 	/* Release page caches. */
-	for (i = 0; i < noinpages; i++){
+	for (i = 0; i < noinpages; i++)
 		put_page(inpages[i]);
-	}
 	for (i = 0; i < nooutpages; i++){
 		int spdl_err;
 		/* Mark output pages dirty. */
 		spdl_err = set_page_dirty_lock(outpages[i]);
 		DEBUG(if (spdl_err < 0)printk("cryptocop_ioctl_process: set_page_dirty_lock returned %d\n", spdl_err));
 	}
-	for (i = 0; i < nooutpages; i++){
+	for (i = 0; i < nooutpages; i++)
 		put_page(outpages[i]);
-	}
-
 	kfree(digest_result);
 	kfree(inpages);
 	kfree(outpages);
@@ -2987,9 +2962,8 @@ static int cryptocop_ioctl_create_session(struct inode *inode, struct file *filp
 		return -EFAULT;
 	err = copy_from_user(&sop, sess_op, sizeof(struct strcop_session_op));
 	if (err) return -EFAULT;
-	if (sop.cipher != cryptocop_cipher_none) {
+	if (sop.cipher != cryptocop_cipher_none)
 		if (!access_ok(VERIFY_READ, sop.key, sop.keylen)) return -EFAULT;
-	}
 	DEBUG(printk("cryptocop_ioctl_create_session, sess_op:\n"));
 
 	DEBUG(printk("\tcipher:%d\n"
@@ -3362,23 +3336,21 @@ static void print_cryptocop_operation(struct cryptocop_operation *cop)
 			d = d->next;
 		}
 		printk("\n==iniov\n");
-		for (i = 0; i < cop->tfrm_op.incount; i++){
+		for (i = 0; i < cop->tfrm_op.incount; i++)
 			printk("indata[%d]\n"
 			       "base=0x%p\n"
 			       "len=%d\n",
 			       i,
 			       cop->tfrm_op.indata[i].iov_base,
 			       cop->tfrm_op.indata[i].iov_len);
-		}
 		printk("\n==outiov\n");
-		for (i = 0; i < cop->tfrm_op.outcount; i++){
+		for (i = 0; i < cop->tfrm_op.outcount; i++)
 			printk("outdata[%d]\n"
 			       "base=0x%p\n"
 			       "len=%d\n",
 			       i,
 			       cop->tfrm_op.outdata[i].iov_base,
 			       cop->tfrm_op.outdata[i].iov_len);
-		}
 	}
 	printk("------------end print_cryptocop_operation\n");
 }
Signature · 1 line
2.9.3
#569 lore raw

PATCH 4/8 cris-cryptocop: Less function calls in cryptocop_ioctl_process() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Aug 2016 13:31:40 +0200

1. The kfree() function was called in some cases by the cryptocop_ioctl_process() function during error handling even if the passed variable contained a null pointer.

2. Split a condition check for memory allocation failures.

3. Adjust jump targets according to the Linux coding style convention.

4. Omit an unneeded check for the local variable "cop" then at the end.

5. Delete assignments which became unnecessary with this refactoring for two local variables.

---
 arch/cris/arch-v32/drivers/cryptocop.c | 80 ++++++++++++++++++----------------
 1 file changed, 42 insertions(+), 38 deletions(-)
arch/cris/arch-v32/drivers/cryptocop.c +42 -38
index 1165639..26347a2 100644
@@ -2542,7 +2542,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 	if (!jc) {
 		DEBUG_API(printk("cryptocop_ioctl_process: kmalloc\n"));
 		err = -ENOMEM;
-		goto error_cleanup;
+		goto free_cop;
 	}
 	jc->processed = 0;
 
@@ -2575,7 +2575,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 		if (!tc) {
 			DEBUG_API(printk("cryptocop_ioctl_process: no cipher transform in session.\n"));
 			err = -EINVAL;
-			goto error_cleanup;
+			goto free_jc;
 		}
 		ciph_tcfg.tid = CRYPTOCOP_IOCTL_CIPHER_TID;
 		ciph_tcfg.inject_ix = 0;
@@ -2628,14 +2628,14 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 		if (!tc) {
 			DEBUG_API(printk("cryptocop_ioctl_process: no digest transform in session.\n"));
 			err = -EINVAL;
-			goto error_cleanup;
+			goto free_jc;
 		}
 		digest_length = tc->init.alg = cryptocop_alg_md5 ? 16 : 20;
 		digest_result = kmalloc(digest_length, GFP_KERNEL);
 		if (!digest_result) {
 			DEBUG_API(printk("cryptocop_ioctl_process: kmalloc digest_result\n"));
 			err = -EINVAL;
-			goto error_cleanup;
+			goto free_jc;
 		}
 		DEBUG(memset(digest_result, 0xff, digest_length));
 
@@ -2645,7 +2645,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 		if ((oper.digest_start < 0) || (oper.digest_len <= 0) || (oper.digest_start > oper.inlen) || ((oper.digest_start + oper.digest_len) > oper.inlen)){
 			DEBUG_API(printk("cryptocop_ioctl_process: bad digest length\n"));
 			err = -EINVAL;
-			goto error_cleanup;
+			goto free_digest;
 		}
 
 		digest_tcfg.next = cop->tfrm_op.tfrm_cfg;
@@ -2670,9 +2670,8 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 	prev_ix = first_cfg_change_ix(&oper);
 	if (prev_ix > oper.inlen) {
 		DEBUG_API(printk("cryptocop_ioctl_process: length mismatch\n"));
-		nooutpages = noinpages = 0;
 		err = -EINVAL;
-		goto error_cleanup;
+		goto free_digest;
 	}
 	DEBUG(printk("cryptocop_ioctl_process: inlen=%d, cipher_outlen=%d\n", oper.inlen, oper.cipher_outlen));
 
@@ -2682,9 +2681,8 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 	inpages = kmalloc_array(noinpages, sizeof(*inpages), GFP_KERNEL);
 	if (!inpages){
 		DEBUG_API(printk("cryptocop_ioctl_process: kmalloc inpages\n"));
-		nooutpages = noinpages = 0;
 		err = -ENOMEM;
-		goto error_cleanup;
+		goto free_digest;
 	}
 	if (oper.do_cipher){
 		nooutpages = (((unsigned long int)oper.cipher_outdata & ~PAGE_MASK) + oper.cipher_outlen - 1 + ~PAGE_MASK) >> PAGE_SHIFT;
@@ -2694,9 +2692,8 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 					 GFP_KERNEL);
 		if (!outpages){
 			DEBUG_API(printk("cryptocop_ioctl_process: kmalloc outpages\n"));
-			nooutpages = noinpages = 0;
 			err = -ENOMEM;
-			goto error_cleanup;
+			goto free_inpages;
 		}
 	}
 
@@ -2712,9 +2709,8 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 
 	if (err < 0) {
 		up_read(&current->mm->mmap_sem);
-		nooutpages = noinpages = 0;
 		DEBUG_API(printk("cryptocop_ioctl_process: get_user_pages indata\n"));
-		goto error_cleanup;
+		goto free_outpages;
 	}
 	noinpages = err;
 	if (oper.do_cipher){
@@ -2726,9 +2722,8 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 				     NULL);
 		up_read(&current->mm->mmap_sem);
 		if (err < 0) {
-			nooutpages = 0;
 			DEBUG_API(printk("cryptocop_ioctl_process: get_user_pages outdata\n"));
-			goto error_cleanup;
+			goto put_inpages;
 		}
 		nooutpages = err;
 	} else {
@@ -2740,13 +2735,18 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 	cop->tfrm_op.indata = kmalloc_array(noinpages,
 					    sizeof(*cop->tfrm_op.indata),
 					    GFP_KERNEL);
+	if (!cop->tfrm_op.indata) {
+		DEBUG_API(printk("cryptocop_ioctl_process: kmalloc indata\n"));
+		err = -ENOMEM;
+		goto put_outpages;
+	}
 	cop->tfrm_op.outdata = kmalloc_array(6 + nooutpages,
 					     sizeof(*cop->tfrm_op.outdata),
 					     GFP_KERNEL);
-	if (!cop->tfrm_op.indata || !cop->tfrm_op.outdata) {
-		DEBUG_API(printk("cryptocop_ioctl_process: kmalloc iovecs\n"));
+	if (!cop->tfrm_op.outdata) {
+		DEBUG_API(printk("cryptocop_ioctl_process: kmalloc outdata\n"));
 		err = -ENOMEM;
-		goto error_cleanup;
+		goto free_indata;
 	}
 
 	cop->tfrm_op.inlen = oper.inlen - prev_ix;
@@ -2780,7 +2780,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 	if (prev_ix = next_ix){
 		DEBUG_API(printk("cryptocop_ioctl_process: length configuration broken.\n"));
 		err = -EINVAL;  /* This should be impossible barring bugs. */
-		goto error_cleanup;
+		goto free_outdata;
 	}
 	while (prev_ix != next_ix){
 		end_digest = end_csum = cipher_active = digest_active = csum_active = 0;
@@ -2834,7 +2834,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 		if (!descs[desc_ix].cfg){
 			DEBUG_API(printk("cryptocop_ioctl_process: data segment %d (%d to %d) had no active transforms\n", desc_ix, prev_ix, next_ix));
 			err = -EINVAL;
-			goto error_cleanup;
+			goto mark_outpages_dirty;
 		}
 		descs[desc_ix].next = &(descs[desc_ix]) + 1;
 		++desc_ix;
@@ -2864,7 +2864,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 		if (!map_pages_to_iovec(cop->tfrm_op.outdata, iovlen, &iovix, outpages, nooutpages, &pageix, &pageoffset, oper.cipher_outlen)){
 			DEBUG_API(printk("cryptocop_ioctl_process: failed to map pages to iovec.\n"));
 			err = -ENOSYS; /* This should be impossible barring bugs. */
-			goto error_cleanup;
+			goto mark_outpages_dirty;
 		}
 	DEBUG(printk("cryptocop_ioctl_process: setting cop->tfrm_op.outcount %d\n", iovix));
 	cop->tfrm_op.outcount = iovix;
@@ -2878,7 +2878,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 	if ((err = cryptocop_job_queue_insert_user_job(cop)) != 0) {
 		DEBUG_API(printk("cryptocop_ioctl_process: insert job %d\n", err));
 		err = -EINVAL;
-		goto error_cleanup;
+		goto mark_outpages_dirty;
 	}
 
 	DEBUG(printk("cryptocop_ioctl_process: begin wait for result\n"));
@@ -2888,7 +2888,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
         if (!jc->processed){
 		printk(KERN_WARNING "cryptocop_ioctl_process: job not processed at completion\n");
 		err = -EIO;
-		goto error_cleanup;
+		goto mark_outpages_dirty;
 	}
 
 	/* Job process done.  Cipher output should already be correct in job so no post processing of outdata. */
@@ -2900,7 +2900,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 			if (0 != err){
 				DEBUG_API(printk("cryptocop_ioctl_process: copy_to_user, digest length %d, err %d\n", digest_length, err));
 				err = -EFAULT;
-				goto error_cleanup;
+				goto mark_outpages_dirty;
 			}
 		}
 		if (oper.do_csum){
@@ -2909,7 +2909,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 			if (0 != err){
 				DEBUG_API(printk("cryptocop_ioctl_process: copy_to_user, csum, err %d\n", err));
 				err = -EFAULT;
-				goto error_cleanup;
+				goto mark_outpages_dirty;
 			}
 		}
 		err = 0;
@@ -2917,29 +2917,33 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 		DEBUG(printk("cryptocop_ioctl_process: returning err = operation_status = %d\n", cop->operation_status));
 		err = cop->operation_status;
 	}
-
- error_cleanup:
-	/* Release page caches. */
-	for (i = 0; i < noinpages; i++)
-		put_page(inpages[i]);
+ mark_outpages_dirty:
 	for (i = 0; i < nooutpages; i++){
 		int spdl_err;
 		/* Mark output pages dirty. */
 		spdl_err = set_page_dirty_lock(outpages[i]);
 		DEBUG(if (spdl_err < 0)printk("cryptocop_ioctl_process: set_page_dirty_lock returned %d\n", spdl_err));
 	}
+ free_outdata:
+	kfree(cop->tfrm_op.outdata);
+ free_indata:
+	kfree(cop->tfrm_op.indata);
+ put_outpages:
 	for (i = 0; i < nooutpages; i++)
 		put_page(outpages[i]);
-	kfree(digest_result);
-	kfree(inpages);
+ put_inpages:
+	for (i = 0; i < noinpages; i++)
+		put_page(inpages[i]);
+ free_outpages:
 	kfree(outpages);
-	if (cop){
-		kfree(cop->tfrm_op.indata);
-		kfree(cop->tfrm_op.outdata);
-		kfree(cop);
-	}
+ free_inpages:
+	kfree(inpages);
+ free_digest:
+	kfree(digest_result);
+ free_jc:
 	kfree(jc);
-
+ free_cop:
+	kfree(cop);
 	DEBUG(print_lock_status());
 
 	return err;
Signature · 1 line
2.9.3
#570 lore raw

PATCH 5/8 cris-cryptocop: Move an assignment for the variable "nooutpages" in cryptocop_ioctl_process()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Aug 2016 13:38:30 +0200

Move the assignment for the local variable "nooutpages" behind the source code for memory allocations by this function.

---
 arch/cris/arch-v32/drivers/cryptocop.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/cris/arch-v32/drivers/cryptocop.c +3 -1
index 26347a2..cd34723 100644
@@ -2469,7 +2469,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 	struct page                     **inpages = NULL;
 	struct page                     **outpages = NULL;
 	int                             noinpages = 0;
-	int                             nooutpages = 0;
+	int                             nooutpages;
 
 	struct cryptocop_desc           descs[5]; /* Max 5 descriptors are needed, there are three transforms that
 						   * can get connected/disconnected on different places in the indata. */
@@ -2695,6 +2695,8 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 			err = -ENOMEM;
 			goto free_inpages;
 		}
+	} else {
+		nooutpages = 0;
 	}
 
 	/* Acquire the mm page semaphore. */
Signature · 1 line
2.9.3
#571 lore raw

Re: [PATCH 5/8] cris-cryptocop: Move an assignment for the variable "nooutpages" in cryptocop_ioctl_process()

Quoted 25 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Aug 2016 13:38:30 +0200

Move the assignment for the local variable "nooutpages" behind the source code for memory allocations by this function.

---
 arch/cris/arch-v32/drivers/cryptocop.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/cris/arch-v32/drivers/cryptocop.c +1 -1
index 26347a2..cd34723 100644
@@ -2469,7 +2469,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 	struct page                     **inpages = NULL;
 	struct page                     **outpages = NULL;
 	int                             noinpages = 0;
-	int                             nooutpages = 0;
+	int                             nooutpages;
 
 	struct cryptocop_desc           descs[5]; /* Max 5 descriptors are needed, there are three transforms that
 						   * can get connected/disconnected on different places in the indata. */

arch/cris/arch-v32/drivers/cryptocop.c static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig · line 2699

Quoted 5 lines
arch/cris/arch-v32/drivers/cryptocop.c +2 -0
@@ -2695,6 +2695,8 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 			err = -ENOMEM;
 			goto free_inpages;
 		}
+	} else {
+		nooutpages = 0;

Why is it better? 4 characters have becomes 2 lines.

julia

Quoted 7 lines
arch/cris/arch-v32/drivers/cryptocop.c +0 -1
 	}
 
 	/* Acquire the mm page semaphore. */
--

2.9.3

#572 lore raw

Re: [PATCH 5/8] cris-cryptocop: Move an assignment for the variable "nooutpages" in cryptocop_ioctl_process()

Quoted 8 lines
Quoted 8 lines

+++ b/arch/cris/arch-v32/drivers/cryptocop.c

arch/cris/arch-v32/drivers/cryptocop.c +1 -1
@@ -2469,7 +2469,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 	struct page                     **inpages = NULL;
 	struct page                     **outpages = NULL;
 	int                             noinpages = 0;
-	int                             nooutpages = 0;
+	int                             nooutpages;
 
Quoted 10 lines

arch/cris/arch-v32/drivers/cryptocop.c static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig · line 2699

Quoted 8 lines
arch/cris/arch-v32/drivers/cryptocop.c +2 -0
 	struct cryptocop_desc           descs[5]; /* Max 5 descriptors are needed, there are three transforms that
 						   * can get connected/disconnected on different places in the indata. */
@@ -2695,6 +2695,8 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 			err = -ENOMEM;
 			goto free_inpages;
 		}
+	} else {
+		nooutpages = 0;

Why is it better? 4 characters have becomes 2 lines.

I suggest to express in a more precise way where this variable is needed actually.

* It would also be an update candidate for the refactoring "Reduce the scope of a variable", wouldn't it?

* Or would the refactoring "Split the implementation of a function into further functions" more appropriate here?

Regards,
Markus

#573 lore raw

Re: [PATCH 5/8] cris-cryptocop: Move an assignment for the variable "nooutpages" in cryptocop_ioctl_process()

Quoted 19 lines · SF Markus Elfring
Quoted 8 lines
Quoted 8 lines

+++ b/arch/cris/arch-v32/drivers/cryptocop.c

arch/cris/arch-v32/drivers/cryptocop.c +1 -1
@@ -2469,7 +2469,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 	struct page                     **inpages = NULL;
 	struct page                     **outpages = NULL;
 	int                             noinpages = 0;
-	int                             nooutpages = 0;
+	int                             nooutpages;
 
Quoted 10 lines

arch/cris/arch-v32/drivers/cryptocop.c static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig · line 2699

Quoted 8 lines
arch/cris/arch-v32/drivers/cryptocop.c +2 -0
 	struct cryptocop_desc           descs[5]; /* Max 5 descriptors are needed, there are three transforms that
 						   * can get connected/disconnected on different places in the indata. */
@@ -2695,6 +2695,8 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 			err = -ENOMEM;
 			goto free_inpages;
 		}
+	} else {
+		nooutpages = 0;

Why is it better? 4 characters have becomes 2 lines.

Quoted 2 lines

I suggest to express in a more precise way where this variable is needed actually.

The variable is used in the cleanup code at the end of the function. Thus it conceptually has global scope, and it is completely reasonable to initialize it at the beginning of its function, along with noinpages.

This code is horrible in so many ways: no space before {, lots of 0 initializations instead of kzalloc, random use of local cleanup code and a label at the end of the function, the use of DEBUG, the use of printk, the use of the very long function name in strings instead of __func__, constants on the left of a != test, etc. On the other hand there are also very few commits on this code, and even fewer that are specific to this code, so perhaps no one cares about it.

julia

Quoted 12 lines

* It would also be an update candidate for the refactoring "Reduce the scope of a variable", wouldn't it?

* Or would the refactoring "Split the implementation of a function into further functions" more appropriate here?

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

#574 lore raw

PATCH 6/8 cris-cryptocop: Delete two variables in cryptocop_ioctl_process()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Aug 2016 13:40:29 +0200

A zero was assigned to the local variables "cipher_done" and "csum_done" at one place. But they were not read within this function. Thus remove them.

---
 arch/cris/arch-v32/drivers/cryptocop.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
arch/cris/arch-v32/drivers/cryptocop.c +4 -10
index cd34723..a682b1f 100644
@@ -2497,8 +2497,6 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 	int    cipher_active, digest_active, csum_active;
 	int    end_digest, end_csum;
 	int    digest_done = 0;
-	int    cipher_done = 0;
-	int    csum_done = 0;
 
 	DEBUG(printk("cryptocop_ioctl_process\n"));
 
@@ -2794,12 +2792,10 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 			dcfgs[dcfg_ix].src = cryptocop_source_dma;
 			cipher_active = 1;
 
-			if (next_ix = (oper.cipher_start + oper.cipher_len)){
-				cipher_done = 1;
+			if (next_ix = (oper.cipher_start + oper.cipher_len))
 				dcfgs[dcfg_ix].last = 1;
-			} else {
+			else
 				dcfgs[dcfg_ix].last = 0;
-			}
 			dcfgs[dcfg_ix].next = descs[desc_ix].cfg;
 			descs[desc_ix].cfg = &dcfgs[dcfg_ix];
 			++dcfg_ix;
@@ -2823,12 +2819,10 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 			csum_active = 1;
 			dcfgs[dcfg_ix].tid = CRYPTOCOP_IOCTL_CSUM_TID;
 			dcfgs[dcfg_ix].src = cryptocop_source_dma;
-			if (next_ix = (oper.csum_start + oper.csum_len)){
-				csum_done = 1;
+			if (next_ix = (oper.csum_start + oper.csum_len))
 				dcfgs[dcfg_ix].last = 1;
-			} else {
+			else
 				dcfgs[dcfg_ix].last = 0;
-			}
 			dcfgs[dcfg_ix].next = descs[desc_ix].cfg;
 			descs[desc_ix].cfg = &dcfgs[dcfg_ix];
 			++dcfg_ix;
Signature · 1 line
2.9.3
Reviewed-by on v1 6/8
#575 lore raw

Re: [6/8] cris-cryptocop: Delete two variables in cryptocop_ioctl_process()

Hello Markus,

Quoted 8 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Aug 2016 13:40:29 +0200

A zero was assigned to the local variables "cipher_done" and "csum_done" at one place. But they were not read within this function. Thus remove them.

Quoted 48 lines
---
 arch/cris/arch-v32/drivers/cryptocop.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
arch/cris/arch-v32/drivers/cryptocop.c +4 -10
index cd34723..a682b1f 100644
@@ -2497,8 +2497,6 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 	int    cipher_active, digest_active, csum_active;
 	int    end_digest, end_csum;
 	int    digest_done = 0;
-	int    cipher_done = 0;
-	int    csum_done = 0;
 
 	DEBUG(printk("cryptocop_ioctl_process\n"));
 
@@ -2794,12 +2792,10 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 			dcfgs[dcfg_ix].src = cryptocop_source_dma;
 			cipher_active = 1;
 
-			if (next_ix = (oper.cipher_start + oper.cipher_len)){
-				cipher_done = 1;
+			if (next_ix = (oper.cipher_start + oper.cipher_len))
 				dcfgs[dcfg_ix].last = 1;
-			} else {
+			else
 				dcfgs[dcfg_ix].last = 0;
-			}
 			dcfgs[dcfg_ix].next = descs[desc_ix].cfg;
 			descs[desc_ix].cfg = &dcfgs[dcfg_ix];
 			++dcfg_ix;
@@ -2823,12 +2819,10 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 			csum_active = 1;
 			dcfgs[dcfg_ix].tid = CRYPTOCOP_IOCTL_CSUM_TID;
 			dcfgs[dcfg_ix].src = cryptocop_source_dma;
-			if (next_ix = (oper.csum_start + oper.csum_len)){
-				csum_done = 1;
+			if (next_ix = (oper.csum_start + oper.csum_len))
 				dcfgs[dcfg_ix].last = 1;
-			} else {
+			else
 				dcfgs[dcfg_ix].last = 0;
-			}
 			dcfgs[dcfg_ix].next = descs[desc_ix].cfg;
 			descs[desc_ix].cfg = &dcfgs[dcfg_ix];
 			++dcfg_ix;
#576 lore raw

PATCH 7/8 cris-cryptocop: Delete unnecessary variable initialisations in cryptocop_ioctl_process()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Aug 2016 13:57:21 +0200

Nine local variables will be set to an appropriate value a bit later. Thus omit the explicit initialisation which became unnecessary with a previous update step.

---
 arch/cris/arch-v32/drivers/cryptocop.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
arch/cris/arch-v32/drivers/cryptocop.c +9 -13
index a682b1f..1a966dc 100644
@@ -2461,14 +2461,12 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 	struct cryptocop_private        *dev = filp->private_data;
 	struct strcop_crypto_op         *crp_oper = (struct strcop_crypto_op *)arg;
 	struct strcop_crypto_op         oper = {0};
-	int                             err = 0;
-	struct cryptocop_operation      *cop = NULL;
-
-	struct ioctl_job_cb_ctx         *jc = NULL;
-
-	struct page                     **inpages = NULL;
+	int                             err;
+	struct cryptocop_operation      *cop;
+	struct ioctl_job_cb_ctx         *jc;
+	struct page                     **inpages;
 	struct page                     **outpages = NULL;
-	int                             noinpages = 0;
+	int                             noinpages;
 	int                             nooutpages;
 
 	struct cryptocop_desc           descs[5]; /* Max 5 descriptors are needed, there are three transforms that
@@ -2482,16 +2480,14 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 
 	unsigned char                   *digest_result = NULL;
 	int                             digest_length = 0;
-	int                             cblocklen = 0;
+	int                             cblocklen;
 	unsigned char                   csum_result[CSUM_BLOCK_LENGTH];
 	struct cryptocop_session        *sess;
-
-	int    iovlen = 0;
+	int    iovlen;
 	int    iovix = 0;
 	int    pageix = 0;
-	int    pageoffset = 0;
-
-	size_t prev_ix = 0;
+	int    pageoffset;
+	size_t prev_ix;
 	size_t next_ix;
 
 	int    cipher_active, digest_active, csum_active;
Signature · 1 line
2.9.3
#577 lore raw

PATCH 8/8 cris-cryptocop: Apply another recommendation from "checkpatch.pl"

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Aug 2016 14:23:06 +0200

The script "checkpatch.pl" can point out that assignments should usually not be performed within condition checks.
Thus move the assignments for a local variable to separate statements in three functions.

---
 arch/cris/arch-v32/drivers/cryptocop.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
arch/cris/arch-v32/drivers/cryptocop.c +8 -3
index 1a966dc..00231a7 100644
@@ -1510,7 +1510,8 @@ int cryptocop_new_session(cryptocop_session_id *sid, struct cryptocop_transform_
 	while (tfrm_in){
 		int err;
 		++no_tfrms;
-		if ((err = transform_ok(tfrm_in))) {
+		err = transform_ok(tfrm_in);
+		if (err) {
 			DEBUG_API(printk("cryptocop_new_session, bad transform\n"));
 			return err;
 		}
@@ -2276,7 +2277,10 @@ static int cryptocop_job_setup(struct cryptocop_prio_job **pj, struct cryptocop_
 		(*pj)->iop->ctx_in.saved_data = operation->list_op.inlist;
 		(*pj)->iop->ctx_in.saved_data_buf = operation->list_op.in_data_buf;
 	} else {
-		if ((err = cryptocop_setup_dma_list(operation, &(*pj)->iop, alloc_flag))) {
+		err = cryptocop_setup_dma_list(operation,
+					       &(*pj)->iop,
+					       alloc_flag);
+		if (err) {
 			DEBUG_API(printk("cryptocop_job_setup: cryptocop_setup_dma_list failed %d\n", err));
 			kfree(*pj);
 			return err;
@@ -2867,7 +2871,8 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 
 	DEBUG(printk("cryptocop_ioctl_process: inserting job, cb_data=0x%p\n", cop->cb_data));
 
-	if ((err = cryptocop_job_queue_insert_user_job(cop)) != 0) {
+	err = cryptocop_job_queue_insert_user_job(cop);
+	if (err) {
 		DEBUG_API(printk("cryptocop_ioctl_process: insert job %d\n", err));
 		err = -EINVAL;
 		goto mark_outpages_dirty;
Signature · 1 line
2.9.3
#578 lore raw

Re: [PATCH 8/8] cris-cryptocop: Apply another recommendation from "checkpatch.pl"

Quoted 28 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 26 Aug 2016 14:23:06 +0200

The script "checkpatch.pl" can point out that assignments should usually not be performed within condition checks.
Thus move the assignments for a local variable to separate statements in three functions.

---
 arch/cris/arch-v32/drivers/cryptocop.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
arch/cris/arch-v32/drivers/cryptocop.c +2 -1
index 1a966dc..00231a7 100644
@@ -1510,7 +1510,8 @@ int cryptocop_new_session(cryptocop_session_id *sid, struct cryptocop_transform_
 	while (tfrm_in){
 		int err;
 		++no_tfrms;
-		if ((err = transform_ok(tfrm_in))) {
+		err = transform_ok(tfrm_in);
+		if (err) {
 			DEBUG_API(printk("cryptocop_new_session, bad transform\n"));
 			return err;
 		}

arch/cris/arch-v32/drivers/cryptocop.c static int cryptocop_job_setup(struct cryptocop_prio_job **pj, struct cryptocop_ · line 2282

Quoted 7 lines
arch/cris/arch-v32/drivers/cryptocop.c +3 -1
@@ -2276,7 +2277,10 @@ static int cryptocop_job_setup(struct cryptocop_prio_job **pj, struct cryptocop_
 		(*pj)->iop->ctx_in.saved_data = operation->list_op.inlist;
 		(*pj)->iop->ctx_in.saved_data_buf = operation->list_op.in_data_buf;
 	} else {
-		if ((err = cryptocop_setup_dma_list(operation, &(*pj)->iop, alloc_flag))) {
+		err = cryptocop_setup_dma_list(operation,
+					       &(*pj)->iop,
+					       alloc_flag);

Checkpatch didn't say to put every argument on a different line, and that wasn't done before, so why do it now? There is plenty of room for at least &(*pj)->iop on the line before.

julia

Quoted 22 lines
arch/cris/arch-v32/drivers/cryptocop.c +3 -2
+		if (err) {
 			DEBUG_API(printk("cryptocop_job_setup: cryptocop_setup_dma_list failed %d\n", err));
 			kfree(*pj);
 			return err;
@@ -2867,7 +2871,8 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
 
 	DEBUG(printk("cryptocop_ioctl_process: inserting job, cb_data=0x%p\n", cop->cb_data));
 
-	if ((err = cryptocop_job_queue_insert_user_job(cop)) != 0) {
+	err = cryptocop_job_queue_insert_user_job(cop);
+	if (err) {
 		DEBUG_API(printk("cryptocop_ioctl_process: insert job %d\n", err));
 		err = -EINVAL;
 		goto mark_outpages_dirty;
--

2.9.3

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

#579 lore raw

Re: [PATCH 8/8] cris-cryptocop: Apply another recommendation from "checkpatch.pl"

Quoted 10 lines

arch/cris/arch-v32/drivers/cryptocop.c static int cryptocop_job_setup(struct cryptocop_prio_job **pj, struct cryptocop_ · line 2282

Quoted 8 lines
arch/cris/arch-v32/drivers/cryptocop.c +3 -1
@@ -2276,7 +2277,10 @@ static int cryptocop_job_setup(struct cryptocop_prio_job **pj, struct cryptocop_
 		(*pj)->iop->ctx_in.saved_data = operation->list_op.inlist;
 		(*pj)->iop->ctx_in.saved_data_buf = operation->list_op.in_data_buf;
 	} else {
-		if ((err = cryptocop_setup_dma_list(operation, &(*pj)->iop, alloc_flag))) {
+		err = cryptocop_setup_dma_list(operation,
+					       &(*pj)->iop,
+					       alloc_flag);

Checkpatch didn't say to put every argument on a different line,

I agree to this information.

Quoted 1 line

and that wasn't done before, so why do it now?

I tend to give each function parameter its own text line in such an use case (for the known length limitation).

Quoted 1 line

There is plenty of room for at least &(*pj)->iop on the line before.

This is true. - Do you prefer an other indentation approach here?

Regards,
Markus

#580 lore raw

Re: [PATCH 8/8] cris-cryptocop: Apply another recommendation from "checkpatch.pl"

Quoted 16 lines · SF Markus Elfring
Quoted 10 lines

arch/cris/arch-v32/drivers/cryptocop.c static int cryptocop_job_setup(struct cryptocop_prio_job **pj, struct cryptocop_ · line 2282

Quoted 8 lines
arch/cris/arch-v32/drivers/cryptocop.c +3 -1
@@ -2276,7 +2277,10 @@ static int cryptocop_job_setup(struct cryptocop_prio_job **pj, struct cryptocop_
 		(*pj)->iop->ctx_in.saved_data = operation->list_op.inlist;
 		(*pj)->iop->ctx_in.saved_data_buf = operation->list_op.in_data_buf;
 	} else {
-		if ((err = cryptocop_setup_dma_list(operation, &(*pj)->iop, alloc_flag))) {
+		err = cryptocop_setup_dma_list(operation,
+					       &(*pj)->iop,
+					       alloc_flag);

Checkpatch didn't say to put every argument on a different line,

I agree to this information.

Quoted 1 line

and that wasn't done before, so why do it now?

Quoted 7 lines

I tend to give each function parameter its own text line in such an use case (for the known length limitation).

Quoted 1 line

There is plenty of room for at least &(*pj)->iop on the line before.

This is true. - Do you prefer an other indentation approach here?

Very much. Most of the kernel code puts as much information on a line as possible, unless there is a reason to do otherwise. Then more of the code will fit on the screen at one time.

julia

#581 lore raw

Re: cris-cryptocop: Apply another recommendation from "checkpatch.pl"

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

There is plenty of room for at least &(*pj)->iop on the line before.

This is true. - Do you prefer an other indentation approach here?

Very much. Most of the kernel code puts as much information on a line as possible, unless there is a reason to do otherwise. Then more of the code will fit on the screen at one time.

How do you think about to clarify such an implementation detail also in a document like "CodingStyle"?

Regards,
Markus

#582 lore raw

cover KVM: PPC: e500: Fine-tuning for two function implementations

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Aug 2016 19:01:02 +0200

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

Markus Elfring (6):
Use kmalloc_array() in kvm_vcpu_ioctl_config_tlb()
Less function calls in kvm_vcpu_ioctl_config_tlb() after error detection Delete an unnecessary initialisation in kvm_vcpu_ioctl_config_tlb() Replace kzalloc() calls by kcalloc() in two functions
Use kmalloc_array() in kvmppc_e500_tlb_init()
Rename jump labels in kvmppc_e500_tlb_init()

 arch/powerpc/kvm/e500_mmu.c | 71 +++++++++++++++++++++++----------------------
 1 file changed, 36 insertions(+), 35 deletions(-)
Signature · 1 line
2.9.3
#583 lore raw

PATCH 1/6 KVM: PPC: e500: Use kmalloc_array() in kvm_vcpu_ioctl_config_tlb()

From: Markus Elfring <[email protected]>
Date: Sun, 28 Aug 2016 16:30:07 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 arch/powerpc/kvm/e500_mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/e500_mmu.c +1 -1
index 29911a0..26f3737 100644
@@ -779,7 +779,7 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
 
 	num_pages = DIV_ROUND_UP(cfg->array + array_len - 1, PAGE_SIZE) -
 		    cfg->array / PAGE_SIZE;
-	pages = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
+	pages = kmalloc_array(num_pages, sizeof(*pages), GFP_KERNEL);
 	if (!pages)
 		return -ENOMEM;
 
Signature · 1 line
2.9.3
#584 lore raw

PATCH 2/6 KVM: PPC: e500: Less function calls in kvm_vcpu_ioctl_config_tlb() after error detection

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Aug 2016 17:34:46 +0200

The kfree() function was called in two cases by the kvm_vcpu_ioctl_config_tlb() function during error handling even if the passed data structure element contained a null pointer.

* Split a condition check for memory allocation failures.

* Adjust jump targets according to the Linux coding style convention.

---
 arch/powerpc/kvm/e500_mmu.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)
arch/powerpc/kvm/e500_mmu.c +16 -14
index 26f3737..b65a894 100644
@@ -785,35 +785,39 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
 
 	ret = get_user_pages_fast(cfg->array, num_pages, 1, pages);
 	if (ret < 0)
-		goto err_pages;
+		goto free_pages;
 
 	if (ret != num_pages) {
 		num_pages = ret;
 		ret = -EFAULT;
-		goto err_put_page;
+		goto put_pages;
 	}
 
 	virt = vmap(pages, num_pages, VM_MAP, PAGE_KERNEL);
 	if (!virt) {
 		ret = -ENOMEM;
-		goto err_put_page;
+		goto put_pages;
 	}
 
 	privs[0] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[0],
 			   GFP_KERNEL);
+	if (!privs[0]) {
+		ret = -ENOMEM;
+		goto put_pages;
+	}
+
 	privs[1] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[1],
 			   GFP_KERNEL);
-
-	if (!privs[0] || !privs[1]) {
+	if (!privs[1]) {
 		ret = -ENOMEM;
-		goto err_privs;
+		goto free_privs_first;
 	}
 
 	g2h_bitmap = kzalloc(sizeof(u64) * params.tlb_sizes[1],
 	                     GFP_KERNEL);
 	if (!g2h_bitmap) {
 		ret = -ENOMEM;
-		goto err_privs;
+		goto free_privs_second;
 	}
 
 	free_gtlb(vcpu_e500);
@@ -845,16 +849,14 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
 
 	kvmppc_recalc_tlb1map_range(vcpu_e500);
 	return 0;
-
-err_privs:
-	kfree(privs[0]);
+ free_privs_second:
 	kfree(privs[1]);
-
-err_put_page:
+ free_privs_first:
+	kfree(privs[0]);
+ put_pages:
 	for (i = 0; i < num_pages; i++)
 		put_page(pages[i]);
-
-err_pages:
+ free_pages:
 	kfree(pages);
 	return ret;
 }
Signature · 1 line
2.9.3
#585 lore raw

PATCH 3/6 KVM: PPC: e500: Delete an unnecessary initialisation in kvm_vcpu_ioctl_config_tlb()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Aug 2016 17:37:10 +0200

The local variable "g2h_bitmap" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

---
 arch/powerpc/kvm/e500_mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/e500_mmu.c +1 -1
index b65a894..e9c19e9 100644
@@ -743,7 +743,7 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
 	char *virt;
 	struct page **pages;
 	struct tlbe_priv *privs[2] = {};
-	u64 *g2h_bitmap = NULL;
+	u64 *g2h_bitmap;
 	size_t array_len;
 	u32 sets;
 	int num_pages, ret, i;
Signature · 1 line
2.9.3
#586 lore raw

PATCH 4/6 KVM: PPC: e500: Replace kzalloc() calls by kcalloc() in two functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Aug 2016 18:30:38 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kcalloc".

This issue was detected also by using the Coccinelle software.

* Replace the specification of data structures by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 arch/powerpc/kvm/e500_mmu.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
arch/powerpc/kvm/e500_mmu.c +11 -12
index e9c19e9..2be2afc4 100644
@@ -799,22 +799,21 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
 		goto put_pages;
 	}
 
-	privs[0] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[0],
-			   GFP_KERNEL);
+	privs[0] = kcalloc(params.tlb_sizes[0], sizeof(*privs[0]), GFP_KERNEL);
 	if (!privs[0]) {
 		ret = -ENOMEM;
 		goto put_pages;
 	}
 
-	privs[1] = kzalloc(sizeof(struct tlbe_priv) * params.tlb_sizes[1],
-			   GFP_KERNEL);
+	privs[1] = kcalloc(params.tlb_sizes[1], sizeof(*privs[1]), GFP_KERNEL);
 	if (!privs[1]) {
 		ret = -ENOMEM;
 		goto free_privs_first;
 	}
 
-	g2h_bitmap = kzalloc(sizeof(u64) * params.tlb_sizes[1],
-	                     GFP_KERNEL);
+	g2h_bitmap = kcalloc(params.tlb_sizes[1],
+			     sizeof(*g2h_bitmap),
+			     GFP_KERNEL);
 	if (!g2h_bitmap) {
 		ret = -ENOMEM;
 		goto free_privs_second;
@@ -929,20 +928,20 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 	vcpu_e500->gtlb_offset[0] = 0;
 	vcpu_e500->gtlb_offset[1] = KVM_E500_TLB0_SIZE;
 
-	vcpu_e500->gtlb_priv[0] = kzalloc(sizeof(struct tlbe_ref) *
-					  vcpu_e500->gtlb_params[0].entries,
+	vcpu_e500->gtlb_priv[0] = kcalloc(vcpu_e500->gtlb_params[0].entries,
+					  sizeof(struct tlbe_ref),
 					  GFP_KERNEL);
 	if (!vcpu_e500->gtlb_priv[0])
 		goto err;
 
-	vcpu_e500->gtlb_priv[1] = kzalloc(sizeof(struct tlbe_ref) *
-					  vcpu_e500->gtlb_params[1].entries,
+	vcpu_e500->gtlb_priv[1] = kcalloc(vcpu_e500->gtlb_params[1].entries,
+					  sizeof(struct tlbe_ref),
 					  GFP_KERNEL);
 	if (!vcpu_e500->gtlb_priv[1])
 		goto err;
 
-	vcpu_e500->g2h_tlb1_map = kzalloc(sizeof(u64) *
-					  vcpu_e500->gtlb_params[1].entries,
+	vcpu_e500->g2h_tlb1_map = kcalloc(vcpu_e500->gtlb_params[1].entries,
+					  sizeof(*vcpu_e500->g2h_tlb1_map),
 					  GFP_KERNEL);
 	if (!vcpu_e500->g2h_tlb1_map)
 		goto err;
Signature · 1 line
2.9.3
#587 lore raw

PATCH 5/6 KVM: PPC: e500: Use kmalloc_array() in kvmppc_e500_tlb_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Aug 2016 18:40:08 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 arch/powerpc/kvm/e500_mmu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/powerpc/kvm/e500_mmu.c +4 -3
index 2be2afc4..0a2eeb1 100644
@@ -905,8 +905,6 @@ static int vcpu_mmu_init(struct kvm_vcpu *vcpu,
 int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 {
 	struct kvm_vcpu *vcpu = &vcpu_e500->vcpu;
-	int entry_size = sizeof(struct kvm_book3e_206_tlb_entry);
-	int entries = KVM_E500_TLB0_SIZE + KVM_E500_TLB1_SIZE;
 
 	if (e500_mmu_host_init(vcpu_e500))
 		goto err;
@@ -921,7 +919,10 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 	vcpu_e500->gtlb_params[1].ways = KVM_E500_TLB1_SIZE;
 	vcpu_e500->gtlb_params[1].sets = 1;
 
-	vcpu_e500->gtlb_arch = kmalloc(entries * entry_size, GFP_KERNEL);
+	vcpu_e500->gtlb_arch = kmalloc_array(KVM_E500_TLB0_SIZE +
+					     KVM_E500_TLB1_SIZE,
+					     sizeof(*vcpu_e500->gtlb_arch),
+					     GFP_KERNEL);
 	if (!vcpu_e500->gtlb_arch)
 		return -ENOMEM;
 
Signature · 1 line
2.9.3
#588 lore raw

Re: [PATCH 5/6] KVM: PPC: e500: Use kmalloc_array() in kvmppc_e500_tlb_init()

Quoted 30 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Aug 2016 18:40:08 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 arch/powerpc/kvm/e500_mmu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/powerpc/kvm/e500_mmu.c +0 -2
index 2be2afc4..0a2eeb1 100644
@@ -905,8 +905,6 @@ static int vcpu_mmu_init(struct kvm_vcpu *vcpu,
 int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 {
 	struct kvm_vcpu *vcpu = &vcpu_e500->vcpu;
-	int entry_size = sizeof(struct kvm_book3e_206_tlb_entry);
-	int entries = KVM_E500_TLB0_SIZE + KVM_E500_TLB1_SIZE;
 
 	if (e500_mmu_host_init(vcpu_e500))
 		goto err;

arch/powerpc/kvm/e500_mmu.c int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500) · line 925

Quoted 8 lines
arch/powerpc/kvm/e500_mmu.c +4 -1
@@ -921,7 +919,10 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 	vcpu_e500->gtlb_params[1].ways = KVM_E500_TLB1_SIZE;
 	vcpu_e500->gtlb_params[1].sets = 1;
 
-	vcpu_e500->gtlb_arch = kmalloc(entries * entry_size, GFP_KERNEL);
+	vcpu_e500->gtlb_arch = kmalloc_array(KVM_E500_TLB0_SIZE +
+					     KVM_E500_TLB1_SIZE,
+					     sizeof(*vcpu_e500->gtlb_arch),
+					     GFP_KERNEL);

There are changes here that are not mentioned in the commit log.

julia

Quoted 11 lines
arch/powerpc/kvm/e500_mmu.c +0 -1
 	if (!vcpu_e500->gtlb_arch)
 		return -ENOMEM;
 
--

2.9.3

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

#589 lore raw

PATCH 6/6 KVM: PPC: e500: Rename jump labels in kvmppc_e500_tlb_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Aug 2016 18:45:26 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 arch/powerpc/kvm/e500_mmu.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
arch/powerpc/kvm/e500_mmu.c +4 -5
index 0a2eeb1..da8f22b 100644
@@ -933,26 +933,25 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 					  sizeof(struct tlbe_ref),
 					  GFP_KERNEL);
 	if (!vcpu_e500->gtlb_priv[0])
-		goto err;
+		goto free_vcpu;
 
 	vcpu_e500->gtlb_priv[1] = kcalloc(vcpu_e500->gtlb_params[1].entries,
 					  sizeof(struct tlbe_ref),
 					  GFP_KERNEL);
 	if (!vcpu_e500->gtlb_priv[1])
-		goto err;
+		goto free_vcpu;
 
 	vcpu_e500->g2h_tlb1_map = kcalloc(vcpu_e500->gtlb_params[1].entries,
 					  sizeof(*vcpu_e500->g2h_tlb1_map),
 					  GFP_KERNEL);
 	if (!vcpu_e500->g2h_tlb1_map)
-		goto err;
+		goto free_vcpu;
 
 	vcpu_mmu_init(vcpu, vcpu_e500->gtlb_params);
 
 	kvmppc_recalc_tlb1map_range(vcpu_e500);
 	return 0;
-
-err:
+ free_vcpu:
 	free_gtlb(vcpu_e500);
 	return -1;
 }
Signature · 1 line
2.9.3
#590 lore raw

Re: [PATCH 6/6] KVM: PPC: e500: Rename jump labels in kvmppc_e500_tlb_init()

Quoted 34 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 28 Aug 2016 18:45:26 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 arch/powerpc/kvm/e500_mmu.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
arch/powerpc/kvm/e500_mmu.c +3 -3
index 0a2eeb1..da8f22b 100644
@@ -933,26 +933,25 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 					  sizeof(struct tlbe_ref),
 					  GFP_KERNEL);
 	if (!vcpu_e500->gtlb_priv[0])
-		goto err;
+		goto free_vcpu;
 
 	vcpu_e500->gtlb_priv[1] = kcalloc(vcpu_e500->gtlb_params[1].entries,
 					  sizeof(struct tlbe_ref),
 					  GFP_KERNEL);
 	if (!vcpu_e500->gtlb_priv[1])
-		goto err;
+		goto free_vcpu;
 
 	vcpu_e500->g2h_tlb1_map = kcalloc(vcpu_e500->gtlb_params[1].entries,
 					  sizeof(*vcpu_e500->g2h_tlb1_map),
 					  GFP_KERNEL);
 	if (!vcpu_e500->g2h_tlb1_map)
-		goto err;
+		goto free_vcpu;

arch/powerpc/kvm/e500_mmu.c int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500) · line 956

Quoted 10 lines
arch/powerpc/kvm/e500_mmu.c +1 -2
 
 	vcpu_mmu_init(vcpu, vcpu_e500->gtlb_params);
 
 	kvmppc_recalc_tlb1map_range(vcpu_e500);
 	return 0;
-
-err:
+ free_vcpu:
 	free_gtlb(vcpu_e500);
 	return -1;

I doubt that -1 is the best return value. One could guess that it should be -ENOMEM. But see what the call sites expect.

julia

Quoted 9 lines
arch/powerpc/kvm/e500_mmu.c +0 -1
 }
--

2.9.3

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

#591 lore raw

Re: [PATCH 6/6] KVM: PPC: e500: Rename jump labels in kvmppc_e500_tlb_init()

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

From: Markus Elfring <[email protected]>
Date: Sun, 28 Aug 2016 18:45:26 +0200

Adjust jump labels according to the current Linux coding style convention.

With this I get a compile error:

CC arch/powerpc/kvm/e500_mmu.o
/home/paulus/kernel/kvm/arch/powerpc/kvm/e500_mmu.c: In function ‘kvmppc_e500_tlb_init’:
/home/paulus/kernel/kvm/arch/powerpc/kvm/e500_mmu.c:910:3: error: label ‘err’ used but not defined
goto err;
^
/home/paulus/kernel/kvm/scripts/Makefile.build:289: recipe for target 'arch/powerpc/kvm/e500_mmu.o' failed make[2]: *** [arch/powerpc/kvm/e500_mmu.o] Error 1

Paul.

#592 lore raw

PATCH 1/1 KVM: PPC: e500: Rename jump labels in kvmppc_e500_tlb_init()

From: Markus Elfring <[email protected]>
Date: Mon, 12 Sep 2016 22:33:53 +0200

Adjust jump labels according to the current Linux coding style convention.

---

Thanks that five update steps could be integrated into the branch "kvm-ppc-next" of another source code repository.

Quoted 9 lines

With this I get a compile error:

CC arch/powerpc/kvm/e500_mmu.o
/home/paulus/kernel/kvm/arch/powerpc/kvm/e500_mmu.c: In function ‘kvmppc_e500_tlb_init’:
/home/paulus/kernel/kvm/arch/powerpc/kvm/e500_mmu.c:910:3: error: label ‘err’ used but not defined

   goto err;
   ^

/home/paulus/kernel/kvm/scripts/Makefile.build:289: recipe for target 'arch/powerpc/kvm/e500_mmu.o' failed make[2]: *** [arch/powerpc/kvm/e500_mmu.o] Error 1

I overlooked a single goto statement there somehow.

I hope that you like my second approach for this function implementation better.

 arch/powerpc/kvm/e500_mmu.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
arch/powerpc/kvm/e500_mmu.c +5 -6
index 0a2eeb1..ddbf8f0 100644
@@ -907,7 +907,7 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 	struct kvm_vcpu *vcpu = &vcpu_e500->vcpu;
 
 	if (e500_mmu_host_init(vcpu_e500))
-		goto err;
+		goto free_vcpu;
 
 	vcpu_e500->gtlb_params[0].entries = KVM_E500_TLB0_SIZE;
 	vcpu_e500->gtlb_params[1].entries = KVM_E500_TLB1_SIZE;
@@ -933,26 +933,25 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
 					  sizeof(struct tlbe_ref),
 					  GFP_KERNEL);
 	if (!vcpu_e500->gtlb_priv[0])
-		goto err;
+		goto free_vcpu;
 
 	vcpu_e500->gtlb_priv[1] = kcalloc(vcpu_e500->gtlb_params[1].entries,
 					  sizeof(struct tlbe_ref),
 					  GFP_KERNEL);
 	if (!vcpu_e500->gtlb_priv[1])
-		goto err;
+		goto free_vcpu;
 
 	vcpu_e500->g2h_tlb1_map = kcalloc(vcpu_e500->gtlb_params[1].entries,
 					  sizeof(*vcpu_e500->g2h_tlb1_map),
 					  GFP_KERNEL);
 	if (!vcpu_e500->g2h_tlb1_map)
-		goto err;
+		goto free_vcpu;
 
 	vcpu_mmu_init(vcpu, vcpu_e500->gtlb_params);
 
 	kvmppc_recalc_tlb1map_range(vcpu_e500);
 	return 0;
-
-err:
+ free_vcpu:
 	free_gtlb(vcpu_e500);
 	return -1;
 }
Signature · 1 line
2.10.0
#593 lore raw

Re: [PATCH 0/6] KVM: PPC: e500: Fine-tuning for two function implementations

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

From: Markus Elfring <[email protected]>
Date: Sun, 28 Aug 2016 19:01:02 +0200

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

Quoted 7 lines

Markus Elfring (6):
Use kmalloc_array() in kvm_vcpu_ioctl_config_tlb()
Less function calls in kvm_vcpu_ioctl_config_tlb() after error detection Delete an unnecessary initialisation in kvm_vcpu_ioctl_config_tlb() Replace kzalloc() calls by kcalloc() in two functions
Use kmalloc_array() in kvmppc_e500_tlb_init()
Rename jump labels in kvmppc_e500_tlb_init()

Thanks, patches 1-5 applied to my kvm-ppc-next branch.

Paul.

#594 lore raw

cover PowerPC: Fine-tuning for three function implementations

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 29 Aug 2016 11:44:22 +0200

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

Markus Elfring (5):
Use kmalloc_array() in mpic_init()
Use kmalloc_array() in ppc4xx_setup_msi_irqs()
Use kmalloc_array() in hsta_msi_probe()
Rename jump labels in hsta_msi_probe()
Move three assignments in hsta_msi_probe()

 arch/powerpc/sysdev/mpic.c            |  5 +++--
 arch/powerpc/sysdev/ppc4xx_hsta_msi.c | 26 +++++++++++++-------------
 arch/powerpc/sysdev/ppc4xx_msi.c      |  4 +++-
 3 files changed, 19 insertions(+), 16 deletions(-)
Signature · 1 line
2.9.3
#595 lore raw

cover PowerPC: Fine-tuning for three function implementations

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 29 Aug 2016 11:44:22 +0200

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

Markus Elfring (5):
Use kmalloc_array() in mpic_init()
Use kmalloc_array() in ppc4xx_setup_msi_irqs()
Use kmalloc_array() in hsta_msi_probe()
Rename jump labels in hsta_msi_probe()
Move three assignments in hsta_msi_probe()

 arch/powerpc/sysdev/mpic.c            |  5 +++--
 arch/powerpc/sysdev/ppc4xx_hsta_msi.c | 26 +++++++++++++-------------
 arch/powerpc/sysdev/ppc4xx_msi.c      |  4 +++-
 3 files changed, 19 insertions(+), 16 deletions(-)
Signature · 1 line
2.9.3
#596 lore raw

PATCH 1/5 powerpc-mpic: Use kmalloc_array() in mpic_init()

From: Markus Elfring <[email protected]>
Date: Mon, 29 Aug 2016 11:00:11 +0200

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

---
 arch/powerpc/sysdev/mpic.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/sysdev/mpic.c +3 -2
index 7de45b2..5e79c0d24 100644
@@ -1641,8 +1641,9 @@ void __init mpic_init(struct mpic *mpic)
 
 #ifdef CONFIG_PM
 	/* allocate memory to save mpic state */
-	mpic->save_data = kmalloc(mpic->num_sources * sizeof(*mpic->save_data),
-				  GFP_KERNEL);
+	mpic->save_data = kmalloc_array(mpic->num_sources,
+					sizeof(*mpic->save_data),
+					GFP_KERNEL);
 	BUG_ON(mpic->save_data = NULL);
 #endif
 
Signature · 1 line
2.9.3
#597 lore raw

PATCH 2/5 powerpc-MSI: Use kmalloc_array() in ppc4xx_setup_msi_irqs()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 29 Aug 2016 11:11:24 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 arch/powerpc/sysdev/ppc4xx_msi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/sysdev/ppc4xx_msi.c +3 -1
index 8fb8061..0bd5e4b 100644
@@ -89,7 +89,9 @@ static int ppc4xx_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
 	if (type = PCI_CAP_ID_MSIX)
 		pr_debug("ppc4xx msi: MSI-X untested, trying anyway.\n");
 
-	msi_data->msi_virqs = kmalloc((msi_irqs) * sizeof(int), GFP_KERNEL);
+	msi_data->msi_virqs = kmalloc_array(msi_irqs,
+					    sizeof(*msi_data->msi_virqs),
+					    GFP_KERNEL);
 	if (!msi_data->msi_virqs)
 		return -ENOMEM;
 
Signature · 1 line
2.9.3
#598 lore raw

PATCH 3/5 powerpc-MSI-HSTA: Use kmalloc_array() in hsta_msi_probe()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 29 Aug 2016 11:20:39 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 arch/powerpc/sysdev/ppc4xx_hsta_msi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/sysdev/ppc4xx_hsta_msi.c +3 -1
index 52a93dc..691db9a 100644
@@ -156,7 +156,9 @@ static int hsta_msi_probe(struct platform_device *pdev)
 	if (ret)
 		goto out;
 
-	ppc4xx_hsta_msi.irq_map = kmalloc(sizeof(int) * irq_count, GFP_KERNEL);
+	ppc4xx_hsta_msi.irq_map = kmalloc_array(irq_count,
+						sizeof(*ppc4xx_hsta_msi.irq_map),
+						GFP_KERNEL);
 	if (!ppc4xx_hsta_msi.irq_map) {
 		ret = -ENOMEM;
 		goto out1;
Signature · 1 line
2.9.3
#599 lore raw

PATCH 4/5 powerpc-MSI-HSTA: Rename jump labels in hsta_msi_probe()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 29 Aug 2016 11:22:19 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 arch/powerpc/sysdev/ppc4xx_hsta_msi.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
arch/powerpc/sysdev/ppc4xx_hsta_msi.c +6 -9
index 691db9a..3097ddd 100644
@@ -154,14 +154,14 @@ static int hsta_msi_probe(struct platform_device *pdev)
 
 	ret = msi_bitmap_alloc(&ppc4xx_hsta_msi.bmp, irq_count, dev->of_node);
 	if (ret)
-		goto out;
+		goto unmap_io;
 
 	ppc4xx_hsta_msi.irq_map = kmalloc_array(irq_count,
 						sizeof(*ppc4xx_hsta_msi.irq_map),
 						GFP_KERNEL);
 	if (!ppc4xx_hsta_msi.irq_map) {
 		ret = -ENOMEM;
-		goto out1;
+		goto free_bitmap;
 	}
 
 	/* Setup a mapping from irq offsets to hardware irq numbers */
@@ -171,7 +171,7 @@ static int hsta_msi_probe(struct platform_device *pdev)
 		if (ppc4xx_hsta_msi.irq_map[irq] = NO_IRQ) {
 			dev_err(dev, "Unable to map IRQ\n");
 			ret = -EINVAL;
-			goto out2;
+			goto free_irq_map;
 		}
 	}
 
@@ -180,14 +180,11 @@ static int hsta_msi_probe(struct platform_device *pdev)
 		phb->controller_ops.teardown_msi_irqs = hsta_teardown_msi_irqs;
 	}
 	return 0;
-
-out2:
+ free_irq_map:
 	kfree(ppc4xx_hsta_msi.irq_map);
-
-out1:
+ free_bitmap:
 	msi_bitmap_free(&ppc4xx_hsta_msi.bmp);
-
-out:
+ unmap_io:
 	iounmap(ppc4xx_hsta_msi.data);
 	return ret;
 }
Signature · 1 line
2.9.3
#600 lore raw

PATCH 5/5 powerpc-MSI-HSTA: Move three assignments in hsta_msi_probe()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 29 Aug 2016 11:30:48 +0200

Move the assignments for three data structure members to the end so that they will only be performed if the desired resource allocations succeeded by this function.

---
 arch/powerpc/sysdev/ppc4xx_hsta_msi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/powerpc/sysdev/ppc4xx_hsta_msi.c +4 -3
index 3097ddd..57014ce 100644
@@ -143,10 +143,7 @@ static int hsta_msi_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	ppc4xx_hsta_msi.dev = dev;
-	ppc4xx_hsta_msi.address = mem->start;
 	ppc4xx_hsta_msi.data = ioremap(mem->start, resource_size(mem));
-	ppc4xx_hsta_msi.irq_count = irq_count;
 	if (!ppc4xx_hsta_msi.data) {
 		dev_err(dev, "Unable to map memory\n");
 		return -ENOMEM;
@@ -179,6 +176,10 @@ static int hsta_msi_probe(struct platform_device *pdev)
 		phb->controller_ops.setup_msi_irqs = hsta_setup_msi_irqs;
 		phb->controller_ops.teardown_msi_irqs = hsta_teardown_msi_irqs;
 	}
+
+	ppc4xx_hsta_msi.dev = dev;
+	ppc4xx_hsta_msi.address = mem->start;
+	ppc4xx_hsta_msi.irq_count = irq_count;
 	return 0;
  free_irq_map:
 	kfree(ppc4xx_hsta_msi.irq_map);
Signature · 1 line
2.9.3
#601 lore raw

cover s390/debug: Fine-tuning for several function implementations

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 13:54:32 +0200

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

Markus Elfring (17):
Use kmalloc_array() in debug_areas_alloc()
Delete unnecessary braces
Add some spaces for better code readability
Rename jump labels in debug_areas_alloc()
Fix jump targets in debug_info_alloc()
Rename jump labels in debug_info_copy()
Rename jump labels in debug_open()
Fix a jump target in debug_register_mode()
Return directly if a null pointer was passed to debug_unregister() Delete an unnecessary initialisation in debug_prolog_level_fn() Fix indentation in 13 functions
Use memdup_user() rather than duplicating its implementation Improve a size determination in debug_open()
Improve a size determination in debug_sprintf_format_fn() Improve a size determination in debug_raw_header_fn() Improve determination of sizes in debug_info_alloc() Improve another size determination in debug_info_alloc()

 arch/s390/kernel/debug.c | 433 ++++++++++++++++++++++-------------------------
 1 file changed, 204 insertions(+), 229 deletions(-)
Signature · 1 line
2.9.3
#602 lore raw

PATCH 1/17 s390/debug: Use kmalloc_array() in debug_areas_alloc()

From: Markus Elfring <[email protected]>
Date: Thu, 1 Sep 2016 14:41:01 +0200

* Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kmalloc_array".

* Replace the specification of data types by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 arch/s390/kernel/debug.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
arch/s390/kernel/debug.c +4 -5
index aa12de7..8e2be30 100644
@@ -196,14 +196,13 @@ debug_areas_alloc(int pages_per_area, int nr_areas)
 	debug_entry_t*** areas;
 	int i,j;
 
-	areas = kmalloc(nr_areas *
-					sizeof(debug_entry_t**),
-					GFP_KERNEL);
+	areas = kmalloc_array(nr_areas, sizeof(*areas), GFP_KERNEL);
 	if (!areas)
 		goto fail_malloc_areas;
 	for (i = 0; i < nr_areas; i++) {
-		areas[i] = kmalloc(pages_per_area *
-				sizeof(debug_entry_t*),GFP_KERNEL);
+		areas[i] = kmalloc_array(pages_per_area,
+					 sizeof(*areas[i]),
+					 GFP_KERNEL);
 		if (!areas[i]) {
 			goto fail_malloc_areas2;
 		}
Signature · 1 line
2.9.3
#603 lore raw

PATCH 2/17 s390/debug: Delete unnecessary braces

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 1 Sep 2016 15:06:06 +0200

Do not use curly brackets at some source code places where a single statement should be sufficient.

---
 arch/s390/kernel/debug.c | 48 ++++++++++++++++--------------------------------
 1 file changed, 16 insertions(+), 32 deletions(-)
arch/s390/kernel/debug.c +16 -32
index 8e2be30..ddfc5e4 100644
@@ -203,15 +203,13 @@ debug_areas_alloc(int pages_per_area, int nr_areas)
 		areas[i] = kmalloc_array(pages_per_area,
 					 sizeof(*areas[i]),
 					 GFP_KERNEL);
-		if (!areas[i]) {
+		if (!areas[i])
 			goto fail_malloc_areas2;
-		}
 		for(j = 0; j < pages_per_area; j++) {
 			areas[i][j] = kzalloc(PAGE_SIZE, GFP_KERNEL);
 			if(!areas[i][j]) {
-				for(j--; j >=0 ; j--) {
+				for (j--; j >= 0; j--)
 					kfree(areas[i][j]);
-				}
 				kfree(areas[i]);
 				goto fail_malloc_areas2;
 			}
@@ -221,9 +219,8 @@ debug_areas_alloc(int pages_per_area, int nr_areas)
 
 fail_malloc_areas2:
 	for(i--; i >= 0; i--){
-		for(j=0; j < pages_per_area;j++){
+		for (j = 0; j < pages_per_area; j++)
 			kfree(areas[i][j]);
-		}
 		kfree(areas[i]);
 	}
 	kfree(areas);
@@ -303,9 +300,8 @@ debug_areas_free(debug_info_t* db_info)
 	if(!db_info->areas)
 		return;
 	for (i = 0; i < db_info->nr_areas; i++) {
-		for(j = 0; j < db_info->pages_per_area; j++) {
+		for (j = 0; j < db_info->pages_per_area; j++)
 			kfree(db_info->areas[i][j]);
-		}
 		kfree(db_info->areas[i]);
 	}
 	kfree(db_info->areas);
@@ -396,11 +392,9 @@ debug_info_copy(debug_info_t* in, int mode)
 	if (mode = NO_AREAS)
                 goto out;
 
-        for(i = 0; i < in->nr_areas; i++){
-		for(j = 0; j < in->pages_per_area; j++) {
+	for (i = 0; i < in->nr_areas; i++)
+		for (j = 0; j < in->pages_per_area; j++)
 			memcpy(rc->areas[i][j], in->areas[i][j],PAGE_SIZE);
-		}
-        }
 out:
         spin_unlock_irqrestore(&in->lock, flags);
         return rc;
@@ -711,9 +705,8 @@ debug_info_t *debug_register_mode(const char *name, int pages_per_area,
         debug_register_view(rc, &debug_flush_view);
 	debug_register_view(rc, &debug_pages_view);
 out:
-        if (!rc){
+	if (!rc)
 		pr_err("Registering debug feature %s failed\n", name);
-        }
 	mutex_unlock(&debug_mutex);
 	return rc;
 }
@@ -1005,10 +998,9 @@ debug_count_numargs(char *string)
 {
 	int numargs=0;
 
-	while(*string) {
+	while (*string)
 		if(*string++='%')
 			numargs++;
-	}
 	return(numargs);
 }
 
@@ -1114,10 +1106,9 @@ debug_register_view(debug_info_t * id, struct debug_view *view)
 		goto out;
 	}
 	spin_lock_irqsave(&id->lock, flags);
-	for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
+	for (i = 0; i < DEBUG_MAX_VIEWS; i++)
 		if (!id->views[i])
 			break;
-	}
 	if (i = DEBUG_MAX_VIEWS) {
 		pr_err("Registering view %s/%s would exceed the maximum "
 		       "number of views %i\n", id->name, view->name, i);
@@ -1148,10 +1139,9 @@ debug_unregister_view(debug_info_t * id, struct debug_view *view)
 	if (!id)
 		goto out;
 	spin_lock_irqsave(&id->lock, flags);
-	for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
+	for (i = 0; i < DEBUG_MAX_VIEWS; i++)
 		if (id->views[i] = view)
 			break;
-	}
 	if (i = DEBUG_MAX_VIEWS)
 		rc = -1;
 	else {
@@ -1193,9 +1183,8 @@ debug_get_uint(char *buf)
 
 	buf = skip_spaces(buf);
 	rc = simple_strtoul(buf, &buf, 10);
-	if(*buf){
+	if (*buf)
 		rc = -EINVAL;
-	}
 	return rc;
 }
 
@@ -1265,12 +1254,10 @@ debug_prolog_level_fn(debug_info_t * id, struct debug_view *view, char *out_buf)
 {
 	int rc = 0;
 
-	if(id->level = DEBUG_OFF_LEVEL) {
+	if (id->level = DEBUG_OFF_LEVEL)
 		rc = sprintf(out_buf,"-\n");
-	}
-	else {
+	else
 		rc = sprintf(out_buf, "%i\n", id->level);
-	}
 	return rc;
 }
 
@@ -1336,16 +1323,14 @@ static void debug_flush(debug_info_t* id, int area)
                 memset(id->active_entries, 0, id->nr_areas * sizeof(int));
                 for (i = 0; i < id->nr_areas; i++) {
 			id->active_pages[i] = 0;
-			for(j = 0; j < id->pages_per_area; j++) {
+			for (j = 0; j < id->pages_per_area; j++)
                         	memset(id->areas[i][j], 0, PAGE_SIZE);
-			}
 		}
         } else if(area >= 0 && area < id->nr_areas) {
                 id->active_entries[area] = 0;
 		id->active_pages[area] = 0;
-		for(i = 0; i < id->pages_per_area; i++) {
+		for (i = 0; i < id->pages_per_area; i++)
                 	memset(id->areas[area][i],0,PAGE_SIZE);
-		}
         }
         spin_unlock_irqrestore(&id->lock,flags);
 }
@@ -1430,10 +1415,9 @@ debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view,
 {
 	int i, rc = 0;
 
-	for (i = 0; i < id->buf_size; i++) {
+	for (i = 0; i < id->buf_size; i++)
                 rc += sprintf(out_buf + rc, "%02x ",
                               ((unsigned char *) in_buf)[i]);
-        }
 	rc += sprintf(out_buf + rc, "| ");
 	for (i = 0; i < id->buf_size; i++) {
 		unsigned char c = in_buf[i];
Signature · 1 line
2.9.3
#604 lore raw

PATCH 3/17 s390/debug: Add some spaces for better code readability

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 1 Sep 2016 16:00:39 +0200

Use space characters at some source code places according to the Linux coding style convention.

---
 arch/s390/kernel/debug.c | 177 +++++++++++++++++++++++++----------------------
 1 file changed, 93 insertions(+), 84 deletions(-)
arch/s390/kernel/debug.c +93 -84
index ddfc5e4..5bb9108 100644
@@ -205,9 +205,9 @@ debug_areas_alloc(int pages_per_area, int nr_areas)
 					 GFP_KERNEL);
 		if (!areas[i])
 			goto fail_malloc_areas2;
-		for(j = 0; j < pages_per_area; j++) {
+		for (j = 0; j < pages_per_area; j++) {
 			areas[i][j] = kzalloc(PAGE_SIZE, GFP_KERNEL);
-			if(!areas[i][j]) {
+			if (!areas[i][j]) {
 				for (j--; j >= 0; j--)
 					kfree(areas[i][j]);
 				kfree(areas[i]);
@@ -218,7 +218,7 @@ debug_areas_alloc(int pages_per_area, int nr_areas)
 	return areas;
 
 fail_malloc_areas2:
-	for(i--; i >= 0; i--){
+	for (i--; i >= 0; i--) {
 		for (j = 0; j < pages_per_area; j++)
 			kfree(areas[i][j]);
 		kfree(areas[i]);
@@ -271,7 +271,7 @@ debug_info_alloc(const char *name, int pages_per_area, int nr_areas,
 	rc->entry_size     = sizeof(debug_entry_t) + buf_size;
 	strlcpy(rc->name, name, sizeof(rc->name));
 	memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *));
-	memset(rc->debugfs_entries, 0 ,DEBUG_MAX_VIEWS *
+	memset(rc->debugfs_entries, 0, DEBUG_MAX_VIEWS *
 		sizeof(struct dentry*));
 	atomic_set(&(rc->ref_count), 0);
 
@@ -297,7 +297,7 @@ debug_areas_free(debug_info_t* db_info)
 {
 	int i,j;
 
-	if(!db_info->areas)
+	if (!db_info->areas)
 		return;
 	for (i = 0; i < db_info->nr_areas; i++) {
 		for (j = 0; j < db_info->pages_per_area; j++)
@@ -334,7 +334,7 @@ debug_info_create(const char *name, int pages_per_area, int nr_areas,
 
         rc = debug_info_alloc(name, pages_per_area, nr_areas, buf_size,
 				DEBUG_DEFAULT_LEVEL, ALL_AREAS);
-        if(!rc) 
+	if (!rc)
 		goto out;
 
 	rc->mode = mode & ~S_IFMT;
@@ -378,10 +378,10 @@ debug_info_copy(debug_info_t* in, int mode)
 		rc = debug_info_alloc(in->name, in->pages_per_area,
 			in->nr_areas, in->buf_size, in->level, mode);
 		spin_lock_irqsave(&in->lock, flags);
-		if(!rc)
+		if (!rc)
 			goto out;
 		/* has something changed in the meantime ? */
-		if((rc->pages_per_area = in->pages_per_area) &&
+		if ((rc->pages_per_area = in->pages_per_area) &&
 		   (rc->nr_areas = in->nr_areas)) {
 			break;
 		}
@@ -394,7 +394,7 @@ debug_info_copy(debug_info_t* in, int mode)
 
 	for (i = 0; i < in->nr_areas; i++)
 		for (j = 0; j < in->pages_per_area; j++)
-			memcpy(rc->areas[i][j], in->areas[i][j],PAGE_SIZE);
+			memcpy(rc->areas[i][j], in->areas[i][j], PAGE_SIZE);
 out:
         spin_unlock_irqrestore(&in->lock, flags);
         return rc;
@@ -431,12 +431,14 @@ debug_info_put(debug_info_t *db_info)
 			debugfs_remove(db_info->debugfs_entries[i]);
 		}
 		debugfs_remove(db_info->debugfs_root_entry);
-		if(db_info = debug_area_first)
+		if (db_info = debug_area_first)
 			debug_area_first = db_info->next;
-		if(db_info = debug_area_last)
+		if (db_info = debug_area_last)
 			debug_area_last = db_info->prev;
-		if(db_info->prev) db_info->prev->next = db_info->next;
-		if(db_info->next) db_info->next->prev = db_info->prev;
+		if (db_info->prev)
+			db_info->prev->next = db_info->next;
+		if (db_info->next)
+			db_info->next->prev = db_info->prev;
 		debug_info_free(db_info);
 	}
 }
@@ -453,10 +455,13 @@ debug_format_entry(file_private_info_t *p_info)
 	struct debug_view *view = p_info->view;
 	debug_entry_t *act_entry;
 	size_t len = 0;
-	if(p_info->act_entry = DEBUG_PROLOG_ENTRY){
+
+	if (p_info->act_entry = DEBUG_PROLOG_ENTRY) {
 		/* print prolog */
         	if (view->prolog_proc)
-                	len += view->prolog_proc(id_snap,view,p_info->temp_buf);
+			len += view->prolog_proc(id_snap,
+						 view,
+						 p_info->temp_buf);
 		goto out;
 	}
 	if (!id_snap->areas) /* this is true, if we have a prolog only view */
@@ -487,25 +492,25 @@ debug_next_entry(file_private_info_t *p_info)
 	debug_info_t *id;
 
 	id = p_info->debug_info_snap;
-	if(p_info->act_entry = DEBUG_PROLOG_ENTRY){
+	if (p_info->act_entry = DEBUG_PROLOG_ENTRY) {
 		p_info->act_entry = 0;
 		p_info->act_page  = 0;
 		goto out;
 	}
-	if(!id->areas)
+	if (!id->areas)
 		return 1;
 	p_info->act_entry += id->entry_size;
 	/* switch to next page, if we reached the end of the page  */
-	if (p_info->act_entry > (PAGE_SIZE - id->entry_size)){
+	if (p_info->act_entry > (PAGE_SIZE - id->entry_size)) {
 		/* next page */
 		p_info->act_entry = 0;
 		p_info->act_page += 1;
-		if((p_info->act_page % id->pages_per_area) = 0) {
+		if ((p_info->act_page % id->pages_per_area) = 0) {
 			/* next area */
         		p_info->act_area++;
 			p_info->act_page=0;
 		}
-        	if(p_info->act_area >= id->nr_areas)
+		if (p_info->act_area >= id->nr_areas)
 			return 1;
 	}
 out:
@@ -531,10 +536,10 @@ debug_output(struct file *file,		/* file descriptor */
 	p_info = ((file_private_info_t *) file->private_data);
 	if (*offset != p_info->offset) 
 		return -EPIPE;
-	if(p_info->act_area >= p_info->debug_info_snap->nr_areas)
+	if (p_info->act_area >= p_info->debug_info_snap->nr_areas)
 		return 0;
 	entry_offset = p_info->act_entry_offset;
-	while(count < len){
+	while (count < len) {
 		int formatted_line_size;
 		int formatted_line_residue;
 		int user_buf_residue;
@@ -544,16 +549,16 @@ debug_output(struct file *file,		/* file descriptor */
 		formatted_line_residue = formatted_line_size - entry_offset;
 		user_buf_residue = len-count;
 		copy_size = min(user_buf_residue, formatted_line_residue);
-		if(copy_size){
+		if (copy_size) {
 			if (copy_to_user(user_buf + count, p_info->temp_buf
 					+ entry_offset, copy_size))
 				return -EFAULT;
 			count += copy_size;
 			entry_offset += copy_size;
 		}
-		if(copy_size = formatted_line_residue){
+		if (copy_size = formatted_line_residue) {
 			entry_offset = 0;
-			if(debug_next_entry(p_info))
+			if (debug_next_entry(p_info))
 				goto out;
 		}
 	}
@@ -624,20 +629,20 @@ found:
 	/* To copy all the areas is only needed, if we have a view which  */
 	/* formats the debug areas. */
 
-	if(!debug_info->views[i]->format_proc &&
-		!debug_info->views[i]->header_proc){
+	if (!debug_info->views[i]->format_proc &&
+		!debug_info->views[i]->header_proc) {
 		debug_info_snapshot = debug_info_copy(debug_info, NO_AREAS);
 	} else {
 		debug_info_snapshot = debug_info_copy(debug_info, ALL_AREAS);
 	}
 
-	if(!debug_info_snapshot){
+	if (!debug_info_snapshot) {
 		rc = -ENOMEM;
 		goto out;
 	}
 	p_info = kmalloc(sizeof(file_private_info_t),
 						GFP_KERNEL);
-	if(!p_info){
+	if (!p_info) {
 		debug_info_free(debug_info_snapshot);
 		rc = -ENOMEM;
 		goto out;
@@ -669,7 +674,7 @@ debug_close(struct inode *inode, struct file *file)
 {
 	file_private_info_t *p_info;
 	p_info = (file_private_info_t *) file->private_data;
-	if(p_info->debug_info_snap)
+	if (p_info->debug_info_snap)
 		debug_info_free(p_info->debug_info_snap);
 	debug_info_put(p_info->debug_info_org);
 	kfree(file->private_data);
@@ -699,7 +704,7 @@ debug_info_t *debug_register_mode(const char *name, int pages_per_area,
         /* create new debug_info */
 
 	rc = debug_info_create(name, pages_per_area, nr_areas, buf_size, mode);
-	if(!rc) 
+	if (!rc)
 		goto out;
 	debug_register_view(rc, &debug_level_view);
         debug_register_view(rc, &debug_flush_view);
@@ -754,11 +759,11 @@ debug_set_size(debug_info_t* id, int nr_areas, int pages_per_area)
 {
 	unsigned long flags;
 	debug_entry_t *** new_areas;
-	int rc=0;
+	int rc = 0;
 
-	if(!id || (nr_areas <= 0) || (pages_per_area < 0))
+	if (!id || (nr_areas <= 0) || (pages_per_area < 0))
 		return -EINVAL;
-	if(pages_per_area > 0){
+	if (pages_per_area > 0) {
 		new_areas = debug_areas_alloc(pages_per_area, nr_areas);
 		if(!new_areas) {
 			pr_info("Allocating memory for %i pages failed\n",
@@ -769,16 +774,16 @@ debug_set_size(debug_info_t* id, int nr_areas, int pages_per_area)
 	} else {
 		new_areas = NULL;
 	}
-	spin_lock_irqsave(&id->lock,flags);
+	spin_lock_irqsave(&id->lock, flags);
 	debug_areas_free(id);
 	id->areas = new_areas;
 	id->nr_areas = nr_areas;
 	id->pages_per_area = pages_per_area;
 	id->active_area = 0;
-	memset(id->active_entries,0,sizeof(int)*id->nr_areas);
-	memset(id->active_pages, 0, sizeof(int)*id->nr_areas);
-	spin_unlock_irqrestore(&id->lock,flags);
-	pr_info("%s: set new size (%i pages)\n" ,id->name, pages_per_area);
+	memset(id->active_entries, 0, sizeof(int) * id->nr_areas);
+	memset(id->active_pages, 0, sizeof(int) * id->nr_areas);
+	spin_unlock_irqrestore(&id->lock, flags);
+	pr_info("%s: set new size (%i pages)\n", id->name, pages_per_area);
 out:
 	return rc;
 }
@@ -794,17 +799,17 @@ debug_set_level(debug_info_t* id, int new_level)
 	unsigned long flags;
 	if(!id)
 		return;	
-	spin_lock_irqsave(&id->lock,flags);
-        if(new_level = DEBUG_OFF_LEVEL){
+	spin_lock_irqsave(&id->lock, flags);
+	if (new_level = DEBUG_OFF_LEVEL) {
                 id->level = DEBUG_OFF_LEVEL;
-		pr_info("%s: switched off\n",id->name);
+		pr_info("%s: switched off\n", id->name);
         } else if ((new_level > DEBUG_MAX_LEVEL) || (new_level < 0)) {
 		pr_info("%s: level %i is out of range (%i - %i)\n",
                         id->name, new_level, 0, DEBUG_MAX_LEVEL);
         } else {
                 id->level = new_level;
         }
-	spin_unlock_irqrestore(&id->lock,flags);
+	spin_unlock_irqrestore(&id->lock, flags);
 }
 EXPORT_SYMBOL(debug_set_level);
 
@@ -996,10 +1001,10 @@ EXPORT_SYMBOL(debug_exception_common);
 static inline int
 debug_count_numargs(char *string)
 {
-	int numargs=0;
+	int numargs = 0;
 
 	while (*string)
-		if(*string++='%')
+		if (*string++ = '%')
 			numargs++;
 	return(numargs);
 }
@@ -1019,7 +1024,7 @@ __debug_sprintf_event(debug_info_t *id, int level, char *string, ...)
 
 	if (!debug_active || !id->areas)
 		return NULL;
-	numargsÞbug_count_numargs(string);
+	numargs = debug_count_numargs(string);
 
 	if (debug_critical) {
 		if (!spin_trylock_irqsave(&id->lock, flags))
@@ -1027,11 +1032,13 @@ __debug_sprintf_event(debug_info_t *id, int level, char *string, ...)
 	} else
 		spin_lock_irqsave(&id->lock, flags);
 	active = get_active_entry(id);
-	curr_event=(debug_sprintf_entry_t *) DEBUG_DATA(active);
+	curr_event = (debug_sprintf_entry_t *) DEBUG_DATA(active);
 	va_start(ap,string);
-	curr_event->string=string;
-	for(idx=0;idx<min(numargs,(int)(id->buf_size / sizeof(long))-1);idx++)
-		curr_event->args[idx]=va_arg(ap,long);
+	curr_event->string = string;
+	for (idx = 0;
+	     idx < min(numargs, (int)(id->buf_size / sizeof(long)) - 1);
+	     idx++)
+		curr_event->args[idx] = va_arg(ap, long);
 	va_end(ap);
 	debug_finish_entry(id, active, level, 0);
 	spin_unlock_irqrestore(&id->lock, flags);
@@ -1056,7 +1063,7 @@ __debug_sprintf_exception(debug_info_t *id, int level, char *string, ...)
 	if (!debug_active || !id->areas)
 		return NULL;
 
-	numargsÞbug_count_numargs(string);
+	numargs = debug_count_numargs(string);
 
 	if (debug_critical) {
 		if (!spin_trylock_irqsave(&id->lock, flags))
@@ -1064,11 +1071,13 @@ __debug_sprintf_exception(debug_info_t *id, int level, char *string, ...)
 	} else
 		spin_lock_irqsave(&id->lock, flags);
 	active = get_active_entry(id);
-	curr_event=(debug_sprintf_entry_t *)DEBUG_DATA(active);
-	va_start(ap,string);
-	curr_event->string=string;
-	for(idx=0;idx<min(numargs,(int)(id->buf_size / sizeof(long))-1);idx++)
-		curr_event->args[idx]=va_arg(ap,long);
+	curr_event = (debug_sprintf_entry_t *) DEBUG_DATA(active);
+	va_start(ap, string);
+	curr_event->string = string;
+	for (idx = 0;
+	     idx < min(numargs, (int)(id->buf_size / sizeof(long)) - 1);
+	     idx++)
+		curr_event->args[idx] = va_arg(ap, long);
 	va_end(ap);
 	debug_finish_entry(id, active, level, 1);
 	spin_unlock_irqrestore(&id->lock, flags);
@@ -1214,26 +1223,26 @@ debug_input_pages_fn(debug_info_t * id, struct debug_view *view,
 			size_t user_len, loff_t * offset)
 {
 	char *str;
-	int rc,new_pages;
+	int rc, new_pages;
 
 	if (user_len > 0x10000)
                 user_len = 0x10000;
-	if (*offset != 0){
+	if (*offset != 0) {
 		rc = -EPIPE;
 		goto out;
 	}
-	str = debug_get_user_string(user_buf,user_len);
-	if(IS_ERR(str)){
+	str = debug_get_user_string(user_buf, user_len);
+	if (IS_ERR(str)) {
 		rc = PTR_ERR(str);
 		goto out;
 	}
 	new_pages = debug_get_uint(str);
-	if(new_pages < 0){
+	if (new_pages < 0) {
 		rc = -EINVAL;
 		goto free_str;
 	}
-	rc = debug_set_size(id,id->nr_areas, new_pages);
-	if(rc != 0){
+	rc = debug_set_size(id, id->nr_areas, new_pages);
+	if (rc != 0) {
 		rc = -EINVAL;
 		goto free_str;
 	}
@@ -1271,27 +1280,27 @@ debug_input_level_fn(debug_info_t * id, struct debug_view *view,
 			size_t user_len, loff_t * offset)
 {
 	char *str;
-	int rc,new_level;
+	int rc, new_level;
 
 	if (user_len > 0x10000)
                 user_len = 0x10000;
-	if (*offset != 0){
+	if (*offset != 0) {
 		rc = -EPIPE;
 		goto out;
 	}
-	str = debug_get_user_string(user_buf,user_len);
-	if(IS_ERR(str)){
+	str = debug_get_user_string(user_buf, user_len);
+	if (IS_ERR(str)) {
 		rc = PTR_ERR(str);
 		goto out;
 	}
-	if(str[0] = '-'){
+	if (str[0] = '-') {
 		debug_set_level(id, DEBUG_OFF_LEVEL);
 		rc = user_len;
 		goto free_str;
 	} else {
 		new_level = debug_get_uint(str);
 	}
-	if(new_level < 0) {
+	if (new_level < 0) {
 		pr_warn("%s is not a valid level for a debug feature\n", str);
 		rc = -EINVAL;
 	} else {
@@ -1313,12 +1322,12 @@ out:
 static void debug_flush(debug_info_t* id, int area)
 {
         unsigned long flags;
-        int i,j;
+	int i, j;
 
-        if(!id || !id->areas)
+	if (!id || !id->areas)
                 return;
-        spin_lock_irqsave(&id->lock,flags);
-        if(area = DEBUG_FLUSH_ALL){
+	spin_lock_irqsave(&id->lock, flags);
+	if (area = DEBUG_FLUSH_ALL) {
                 id->active_area = 0;
                 memset(id->active_entries, 0, id->nr_areas * sizeof(int));
                 for (i = 0; i < id->nr_areas; i++) {
@@ -1326,13 +1335,13 @@ static void debug_flush(debug_info_t* id, int area)
 			for (j = 0; j < id->pages_per_area; j++)
                         	memset(id->areas[i][j], 0, PAGE_SIZE);
 		}
-        } else if(area >= 0 && area < id->nr_areas) {
+	} else if (area >= 0 && area < id->nr_areas) {
                 id->active_entries[area] = 0;
 		id->active_pages[area] = 0;
 		for (i = 0; i < id->pages_per_area; i++)
-                	memset(id->areas[area][i],0,PAGE_SIZE);
+			memset(id->areas[area][i], 0, PAGE_SIZE);
         }
-        spin_unlock_irqrestore(&id->lock,flags);
+	spin_unlock_irqrestore(&id->lock, flags);
 }
 
 /*
@@ -1349,15 +1358,15 @@ debug_input_flush_fn(debug_info_t * id, struct debug_view *view,
 
 	if (user_len > 0x10000)
                 user_len = 0x10000;
-        if (*offset != 0){
+	if (*offset != 0) {
 		rc = -EPIPE;
                 goto out;
 	}
-        if (copy_from_user(input_buf, user_buf, 1)){
+	if (copy_from_user(input_buf, user_buf, 1)) {
                 rc = -EFAULT;
                 goto out;
         }
-        if(input_buf[0] = '-') { 
+	if (input_buf[0] = '-') {
                 debug_flush(id, DEBUG_FLUSH_ALL);
                 goto out;
         }
@@ -1386,7 +1395,7 @@ debug_raw_header_fn(debug_info_t * id, struct debug_view *view,
         int rc;
 
 	rc = sizeof(debug_entry_t);
-	memcpy(out_buf,entry,sizeof(debug_entry_t));
+	memcpy(out_buf, entry, sizeof(debug_entry_t));
         return rc;
 }
 
@@ -1477,9 +1486,9 @@ debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view,
 	/* count of longs fit into one entry */
 	num_longs = id->buf_size /  sizeof(long); 
 
-	if(num_longs < 1)
+	if (num_longs < 1)
 		goto out; /* bufsize of entry too small */
-	if(num_longs = 1) {
+	if (num_longs = 1) {
 		/* no args, we use only the string */
 		strcpy(out_buf, curr_event->string);
 		rc = strlen(curr_event->string);
@@ -1489,9 +1498,9 @@ debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view,
 	/* number of arguments used for sprintf (without the format string) */
 	num_used_args   = min(DEBUG_SPRINTF_MAX_ARGS, (num_longs - 1));
 
-	memset(index,0, DEBUG_SPRINTF_MAX_ARGS * sizeof(int));
+	memset(index, 0, DEBUG_SPRINTF_MAX_ARGS * sizeof(int));
 
-	for(i = 0; i < num_used_args; i++)
+	for (i = 0; i < num_used_args; i++)
 		index[i] = i;
 
 	rc =  sprintf(out_buf, curr_event->string, curr_event->args[index[0]],
Signature · 6 lines
2.9.3

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

PATCH 4/17 s390/debug: Rename jump labels in debug_areas_alloc()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 1 Sep 2016 18:10:21 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 arch/s390/kernel/debug.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
arch/s390/kernel/debug.c +5 -6
index 5bb9108..0af14a4 100644
@@ -198,33 +198,32 @@ debug_areas_alloc(int pages_per_area, int nr_areas)
 
 	areas = kmalloc_array(nr_areas, sizeof(*areas), GFP_KERNEL);
 	if (!areas)
-		goto fail_malloc_areas;
+		goto exit;
 	for (i = 0; i < nr_areas; i++) {
 		areas[i] = kmalloc_array(pages_per_area,
 					 sizeof(*areas[i]),
 					 GFP_KERNEL);
 		if (!areas[i])
-			goto fail_malloc_areas2;
+			goto free_areas;
 		for (j = 0; j < pages_per_area; j++) {
 			areas[i][j] = kzalloc(PAGE_SIZE, GFP_KERNEL);
 			if (!areas[i][j]) {
 				for (j--; j >= 0; j--)
 					kfree(areas[i][j]);
 				kfree(areas[i]);
-				goto fail_malloc_areas2;
+				goto free_areas;
 			}
 		}
 	}
 	return areas;
-
-fail_malloc_areas2:
+ free_areas:
 	for (i--; i >= 0; i--) {
 		for (j = 0; j < pages_per_area; j++)
 			kfree(areas[i][j]);
 		kfree(areas[i]);
 	}
 	kfree(areas);
-fail_malloc_areas:
+ exit:
 	return NULL;
 
 }
Signature · 1 line
2.9.3
#606 lore raw

PATCH 5/17 s390/debug: Fix jump targets in debug_info_alloc()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 1 Sep 2016 18:26:58 +0200

Adjust jump targets according to the current Linux coding style convention.

---
 arch/s390/kernel/debug.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
arch/s390/kernel/debug.c +8 -9
index 0af14a4..c5da41b 100644
@@ -244,17 +244,17 @@ debug_info_alloc(const char *name, int pages_per_area, int nr_areas,
 
 	rc = kmalloc(sizeof(debug_info_t), GFP_KERNEL);
 	if(!rc)
-		goto fail_malloc_rc;
+		goto exit;
 	rc->active_entries = kcalloc(nr_areas, sizeof(int), GFP_KERNEL);
 	if(!rc->active_entries)
-		goto fail_malloc_active_entries;
+		goto free_rc;
 	rc->active_pages = kcalloc(nr_areas, sizeof(int), GFP_KERNEL);
 	if(!rc->active_pages)
-		goto fail_malloc_active_pages;
+		goto free_entries;
 	if((mode = ALL_AREAS) && (pages_per_area != 0)){
 		rc->areas = debug_areas_alloc(pages_per_area, nr_areas);
 		if(!rc->areas)
-			goto fail_malloc_areas;
+			goto free_pages;
 	} else {
 		rc->areas = NULL;
 	}
@@ -275,14 +275,13 @@ debug_info_alloc(const char *name, int pages_per_area, int nr_areas,
 	atomic_set(&(rc->ref_count), 0);
 
 	return rc;
-
-fail_malloc_areas:
+ free_pages:
 	kfree(rc->active_pages);
-fail_malloc_active_pages:
+ free_entries:
 	kfree(rc->active_entries);
-fail_malloc_active_entries:
+ free_rc:
 	kfree(rc);
-fail_malloc_rc:
+ exit:
 	return NULL;
 }
 
Signature · 1 line
2.9.3
#607 lore raw

PATCH 6/17 s390/debug: Rename jump labels in debug_info_copy()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 1 Sep 2016 18:32:19 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 arch/s390/kernel/debug.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/s390/kernel/debug.c +3 -3
index c5da41b..1f32578 100644
@@ -377,7 +377,7 @@ debug_info_copy(debug_info_t* in, int mode)
 			in->nr_areas, in->buf_size, in->level, mode);
 		spin_lock_irqsave(&in->lock, flags);
 		if (!rc)
-			goto out;
+			goto unlock;
 		/* has something changed in the meantime ? */
 		if ((rc->pages_per_area = in->pages_per_area) &&
 		   (rc->nr_areas = in->nr_areas)) {
@@ -388,12 +388,12 @@ debug_info_copy(debug_info_t* in, int mode)
 	} while (1);
 
 	if (mode = NO_AREAS)
-                goto out;
+		goto unlock;
 
 	for (i = 0; i < in->nr_areas; i++)
 		for (j = 0; j < in->pages_per_area; j++)
 			memcpy(rc->areas[i][j], in->areas[i][j], PAGE_SIZE);
-out:
+ unlock:
         spin_unlock_irqrestore(&in->lock, flags);
         return rc;
 }
Signature · 1 line
2.9.3
#608 lore raw

PATCH 7/17 s390/debug: Rename jump labels in debug_open()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 1 Sep 2016 18:44:17 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 arch/s390/kernel/debug.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
arch/s390/kernel/debug.c +6 -8
index 1f32578..1cce76a 100644
@@ -614,15 +614,13 @@ debug_open(struct inode *inode, struct file *file)
 			continue;
 		else if (debug_info->debugfs_entries[i] =
 			 file->f_path.dentry) {
-			goto found;	/* found view ! */
+			goto copy_info;
 		}
 	}
 	/* no entry found */
 	rc = -EINVAL;
-	goto out;
-
-found:
-
+	goto unlock;
+ copy_info:
 	/* Make snapshot of current debug areas to get it consistent.     */
 	/* To copy all the areas is only needed, if we have a view which  */
 	/* formats the debug areas. */
@@ -636,14 +634,14 @@ found:
 
 	if (!debug_info_snapshot) {
 		rc = -ENOMEM;
-		goto out;
+		goto unlock;
 	}
 	p_info = kmalloc(sizeof(file_private_info_t),
 						GFP_KERNEL);
 	if (!p_info) {
 		debug_info_free(debug_info_snapshot);
 		rc = -ENOMEM;
-		goto out;
+		goto unlock;
 	}
 	p_info->offset = 0;
 	p_info->debug_info_snap = debug_info_snapshot;
@@ -656,7 +654,7 @@ found:
 	file->private_data = p_info;
 	debug_info_get(debug_info);
 	nonseekable_open(inode, file);
-out:
+ unlock:
 	mutex_unlock(&debug_mutex);
 	return rc;
 }
Signature · 1 line
2.9.3
#609 lore raw

PATCH 8/17 s390/debug: Fix a jump target in debug_register_mode()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 1 Sep 2016 19:26:16 +0200

* Move an error message.

* Adjust a jump target according to the current Linux coding style convention.

* Delete a repeated check which became unnecessary with this refactoring.

---
 arch/s390/kernel/debug.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
arch/s390/kernel/debug.c +5 -5
index 1cce76a..c4a4641 100644
@@ -700,14 +700,14 @@ debug_info_t *debug_register_mode(const char *name, int pages_per_area,
         /* create new debug_info */
 
 	rc = debug_info_create(name, pages_per_area, nr_areas, buf_size, mode);
-	if (!rc)
-		goto out;
+	if (!rc) {
+		pr_err("Registering debug feature %s failed\n", name);
+		goto unlock;
+	}
 	debug_register_view(rc, &debug_level_view);
         debug_register_view(rc, &debug_flush_view);
 	debug_register_view(rc, &debug_pages_view);
-out:
-	if (!rc)
-		pr_err("Registering debug feature %s failed\n", name);
+ unlock:
 	mutex_unlock(&debug_mutex);
 	return rc;
 }
Signature · 1 line
2.9.3
#610 lore raw

PATCH 9/17 s390/debug: Return directly if a null pointer was passed to debug_unregister()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 1 Sep 2016 19:34:45 +0200

Return directly at the beginning if a null pointer was passed for the input parameter of this function.

---
 arch/s390/kernel/debug.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
arch/s390/kernel/debug.c +1 -4
index c4a4641..d137150 100644
@@ -736,13 +736,10 @@ void
 debug_unregister(debug_info_t * id)
 {
 	if (!id)
-		goto out;
+		return;
 	mutex_lock(&debug_mutex);
 	debug_info_put(id);
 	mutex_unlock(&debug_mutex);
-
-out:
-	return;
 }
 EXPORT_SYMBOL(debug_unregister);
 
Signature · 1 line
2.9.3
#611 lore raw

Re: [PATCH 09/17] s390/debug: Return directly if a null pointer was passed to debug_unregister()

Am 03.09.2016 14:24, schrieb SF Markus Elfring:

Quoted 20 lines

From: Markus Elfring <[email protected]>
Date: Thu, 1 Sep 2016 19:34:45 +0200

Return directly at the beginning if a null pointer was passed for the input parameter of this function.

---
 arch/s390/kernel/debug.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
arch/s390/kernel/debug.c +0 -1
index c4a4641..d137150 100644
@@ -736,13 +736,10 @@ void
 debug_unregister(debug_info_t * id)
 {
 	if (!id)
-		goto out;

arch/s390/kernel/debug.c void · line 745

Quoted 10 lines
arch/s390/kernel/debug.c +1 -3
+		return;
 	mutex_lock(&debug_mutex);
 	debug_info_put(id);
 	mutex_unlock(&debug_mutex);
-
-out:
-	return;
 }
 EXPORT_SYMBOL(debug_unregister);
 

debug_info_put() will check for NULL, the whole check can be removed.

re,
wh

#612 lore raw

PATCH 10/17 s390/debug: Delete an unnecessary initialisation in debug_prolog_level_fn()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 1 Sep 2016 21:19:02 +0200

The local variable "rc" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

---
 arch/s390/kernel/debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kernel/debug.c +1 -1
index d137150..ef0db06 100644
@@ -1254,7 +1254,7 @@ out:
 static int
 debug_prolog_level_fn(debug_info_t * id, struct debug_view *view, char *out_buf)
 {
-	int rc = 0;
+	int rc;
 
 	if (id->level = DEBUG_OFF_LEVEL)
 		rc = sprintf(out_buf,"-\n");
Signature · 1 line
2.9.3
#613 lore raw

PATCH 11/17 s390/debug: Fix indentation in 13 functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Thu, 1 Sep 2016 23:05:51 +0200

The script "checkpatch.pl" can point the following information out.

ERROR: code indent should use tabs where possible

Thus fix the affected source code places.

---
 arch/s390/kernel/debug.c | 118 +++++++++++++++++++++++------------------------
 1 file changed, 59 insertions(+), 59 deletions(-)
arch/s390/kernel/debug.c +59 -59
index ef0db06..4a12faf 100644
@@ -330,7 +330,7 @@ debug_info_create(const char *name, int pages_per_area, int nr_areas,
 {
 	debug_info_t* rc;
 
-        rc = debug_info_alloc(name, pages_per_area, nr_areas, buf_size,
+	rc = debug_info_alloc(name, pages_per_area, nr_areas, buf_size,
 				DEBUG_DEFAULT_LEVEL, ALL_AREAS);
 	if (!rc)
 		goto out;
@@ -338,21 +338,21 @@ debug_info_create(const char *name, int pages_per_area, int nr_areas,
 	rc->mode = mode & ~S_IFMT;
 
 	/* create root directory */
-        rc->debugfs_root_entry = debugfs_create_dir(rc->name,
+	rc->debugfs_root_entry = debugfs_create_dir(rc->name,
 					debug_debugfs_root_entry);
 
 	/* append new element to linked list */
-        if (!debug_area_first) {
-                /* first element in list */
-                debug_area_first = rc;
-                rc->prev = NULL;
-        } else {
-                /* append element to end of list */
-                debug_area_last->next = rc;
-                rc->prev = debug_area_last;
-        }
-        debug_area_last = rc;
-        rc->next = NULL;
+	if (!debug_area_first) {
+		/* first element in list */
+		debug_area_first = rc;
+		rc->prev = NULL;
+	} else {
+		/* append element to end of list */
+		debug_area_last->next = rc;
+		rc->prev = debug_area_last;
+	}
+	debug_area_last = rc;
+	rc->next = NULL;
 
 	debug_info_get(rc);
 out:
@@ -394,8 +394,8 @@ debug_info_copy(debug_info_t* in, int mode)
 		for (j = 0; j < in->pages_per_area; j++)
 			memcpy(rc->areas[i][j], in->areas[i][j], PAGE_SIZE);
  unlock:
-        spin_unlock_irqrestore(&in->lock, flags);
-        return rc;
+	spin_unlock_irqrestore(&in->lock, flags);
+	return rc;
 }
 
 /*
@@ -456,7 +456,7 @@ debug_format_entry(file_private_info_t *p_info)
 
 	if (p_info->act_entry = DEBUG_PROLOG_ENTRY) {
 		/* print prolog */
-        	if (view->prolog_proc)
+		if (view->prolog_proc)
 			len += view->prolog_proc(id_snap,
 						 view,
 						 p_info->temp_buf);
@@ -476,7 +476,7 @@ debug_format_entry(file_private_info_t *p_info)
 		len += view->format_proc(id_snap, view, p_info->temp_buf + len,
 						DEBUG_DATA(act_entry));
 out:
-        return len;
+	return len;
 }
 
 /*
@@ -505,7 +505,7 @@ debug_next_entry(file_private_info_t *p_info)
 		p_info->act_page += 1;
 		if ((p_info->act_page % id->pages_per_area) = 0) {
 			/* next area */
-        		p_info->act_area++;
+			p_info->act_area++;
 			p_info->act_page=0;
 		}
 		if (p_info->act_area >= id->nr_areas)
@@ -697,15 +697,14 @@ debug_info_t *debug_register_mode(const char *name, int pages_per_area,
 	BUG_ON(!initialized);
 	mutex_lock(&debug_mutex);
 
-        /* create new debug_info */
-
+	/* create new debug_info */
 	rc = debug_info_create(name, pages_per_area, nr_areas, buf_size, mode);
 	if (!rc) {
 		pr_err("Registering debug feature %s failed\n", name);
 		goto unlock;
 	}
 	debug_register_view(rc, &debug_level_view);
-        debug_register_view(rc, &debug_flush_view);
+	debug_register_view(rc, &debug_flush_view);
 	debug_register_view(rc, &debug_pages_view);
  unlock:
 	mutex_unlock(&debug_mutex);
@@ -794,14 +793,14 @@ debug_set_level(debug_info_t* id, int new_level)
 		return;	
 	spin_lock_irqsave(&id->lock, flags);
 	if (new_level = DEBUG_OFF_LEVEL) {
-                id->level = DEBUG_OFF_LEVEL;
+		id->level = DEBUG_OFF_LEVEL;
 		pr_info("%s: switched off\n", id->name);
-        } else if ((new_level > DEBUG_MAX_LEVEL) || (new_level < 0)) {
+	} else if ((new_level > DEBUG_MAX_LEVEL) || (new_level < 0)) {
 		pr_info("%s: level %i is out of range (%i - %i)\n",
-                        id->name, new_level, 0, DEBUG_MAX_LEVEL);
-        } else {
-                id->level = new_level;
-        }
+			id->name, new_level, 0, DEBUG_MAX_LEVEL);
+	} else {
+		id->level = new_level;
+	}
 	spin_unlock_irqrestore(&id->lock, flags);
 }
 EXPORT_SYMBOL(debug_set_level);
@@ -1175,7 +1174,7 @@ debug_get_user_string(const char __user *user_buf, size_t user_len)
 		buffer[user_len - 1] = 0;
 	else
 		buffer[user_len] = 0;
-        return buffer;
+	return buffer;
 }
 
 static inline int
@@ -1219,7 +1218,7 @@ debug_input_pages_fn(debug_info_t * id, struct debug_view *view,
 	int rc, new_pages;
 
 	if (user_len > 0x10000)
-                user_len = 0x10000;
+		user_len = 0x10000;
 	if (*offset != 0) {
 		rc = -EPIPE;
 		goto out;
@@ -1276,7 +1275,7 @@ debug_input_level_fn(debug_info_t * id, struct debug_view *view,
 	int rc, new_level;
 
 	if (user_len > 0x10000)
-                user_len = 0x10000;
+		user_len = 0x10000;
 	if (*offset != 0) {
 		rc = -EPIPE;
 		goto out;
@@ -1314,26 +1313,26 @@ out:
  
 static void debug_flush(debug_info_t* id, int area)
 {
-        unsigned long flags;
+	unsigned long flags;
 	int i, j;
 
 	if (!id || !id->areas)
-                return;
+		return;
 	spin_lock_irqsave(&id->lock, flags);
 	if (area = DEBUG_FLUSH_ALL) {
-                id->active_area = 0;
-                memset(id->active_entries, 0, id->nr_areas * sizeof(int));
-                for (i = 0; i < id->nr_areas; i++) {
+		id->active_area = 0;
+		memset(id->active_entries, 0, id->nr_areas * sizeof(int));
+		for (i = 0; i < id->nr_areas; i++) {
 			id->active_pages[i] = 0;
 			for (j = 0; j < id->pages_per_area; j++)
-                        	memset(id->areas[i][j], 0, PAGE_SIZE);
+				memset(id->areas[i][j], 0, PAGE_SIZE);
 		}
 	} else if (area >= 0 && area < id->nr_areas) {
-                id->active_entries[area] = 0;
+		id->active_entries[area] = 0;
 		id->active_pages[area] = 0;
 		for (i = 0; i < id->pages_per_area; i++)
 			memset(id->areas[area][i], 0, PAGE_SIZE);
-        }
+	}
 	spin_unlock_irqrestore(&id->lock, flags);
 }
 
@@ -1346,35 +1345,36 @@ debug_input_flush_fn(debug_info_t * id, struct debug_view *view,
 			struct file *file, const char __user *user_buf,
 			size_t user_len, loff_t * offset)
 {
-        char input_buf[1];
-        int rc = user_len;
+	char input_buf[1];
+	int rc = user_len;
 
 	if (user_len > 0x10000)
-                user_len = 0x10000;
+		user_len = 0x10000;
 	if (*offset != 0) {
 		rc = -EPIPE;
-                goto out;
+		goto out;
 	}
 	if (copy_from_user(input_buf, user_buf, 1)) {
-                rc = -EFAULT;
-                goto out;
-        }
+		rc = -EFAULT;
+		goto out;
+	}
 	if (input_buf[0] = '-') {
-                debug_flush(id, DEBUG_FLUSH_ALL);
-                goto out;
-        }
-        if (isdigit(input_buf[0])) {
-                int area = ((int) input_buf[0] - (int) '0');
-                debug_flush(id, area);
-                goto out;
-        }
+		debug_flush(id, DEBUG_FLUSH_ALL);
+		goto out;
+	}
+	if (isdigit(input_buf[0])) {
+		int area = ((int) input_buf[0] - (int) '0');
+
+		debug_flush(id, area);
+		goto out;
+	}
 
 	pr_info("Flushing debug data failed because %c is not a valid "
 		 "area\n", input_buf[0]);
 
 out:
-        *offset += user_len;
-        return rc;              /* number of input characters */
+	*offset += user_len;
+	return rc;              /* number of input characters */
 }
 
 /*
@@ -1385,11 +1385,11 @@ static int
 debug_raw_header_fn(debug_info_t * id, struct debug_view *view,
 			int area, debug_entry_t * entry, char *out_buf)
 {
-        int rc;
+	int rc;
 
 	rc = sizeof(debug_entry_t);
 	memcpy(out_buf, entry, sizeof(debug_entry_t));
-        return rc;
+	return rc;
 }
 
 /*
@@ -1418,8 +1418,8 @@ debug_hex_ascii_format_fn(debug_info_t * id, struct debug_view *view,
 	int i, rc = 0;
 
 	for (i = 0; i < id->buf_size; i++)
-                rc += sprintf(out_buf + rc, "%02x ",
-                              ((unsigned char *) in_buf)[i]);
+		rc += sprintf(out_buf + rc, "%02x ",
+			      ((unsigned char *) in_buf)[i]);
 	rc += sprintf(out_buf + rc, "| ");
 	for (i = 0; i < id->buf_size; i++) {
 		unsigned char c = in_buf[i];
Signature · 1 line
2.9.3
#614 lore raw

PATCH 12/17 s390/debug: Use memdup_user() rather than duplicating its implementation

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 2 Sep 2016 08:45:26 +0200

Reuse existing functionality from memdup_user() instead of keeping duplicate source code.

---
 arch/s390/kernel/debug.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
arch/s390/kernel/debug.c +3 -7
index 4a12faf..a9fcf72 100644
@@ -1162,13 +1162,9 @@ debug_get_user_string(const char __user *user_buf, size_t user_len)
 {
 	char* buffer;
 
-	buffer = kmalloc(user_len + 1, GFP_KERNEL);
-	if (!buffer)
-		return ERR_PTR(-ENOMEM);
-	if (copy_from_user(buffer, user_buf, user_len) != 0) {
-		kfree(buffer);
-		return ERR_PTR(-EFAULT);
-	}
+	buffer = memdup_user(user_buf, user_len + 1);
+	if (IS_ERR(buffer))
+		return PTR_ERR(buffer);
 	/* got the string, now strip linefeed. */
 	if (buffer[user_len - 1] = '\n')
 		buffer[user_len - 1] = 0;
Signature · 1 line
2.9.3
#615 lore raw

Re: [PATCH 12/17] s390/debug: Use memdup_user() rather than duplicating its implementation

reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…

Hi Markus,

[auto build test WARNING on s390/features]
[also build test WARNING on v4.8-rc4 next-20160825]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
[Suggest to use git(>=2.9.0) format-patch --base=<commit> (or --base=auto for convenience) to record what (public, well-known) commit your patch series was built on] [Check https://git-scm.com/docs/git-format-patch for more information]

url:    https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/s390-debug-Fine-tuning-for-several-function-implementations/20160903-204622
base:   https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git features
config: s390-allmodconfig (attached as .config)
compiler: s390x-linux-gnu-gcc (Debian 5.4.0-6) 5.4.0 20160609

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=s390

All warnings (new ones prefixed by >>):

arch/s390/kernel/debug.c: In function 'debug_get_user_string':

>> arch/s390/kernel/debug.c:1167:10: warning: return makes pointer from integer without a cast [-Wint-conversion]
      return PTR_ERR(buffer);
             ^

vim +1167 arch/s390/kernel/debug.c

1151 id->debugfs_entries[i] = NULL;
1152 }
1153 spin_unlock_irqrestore(&id->lock, flags);
1154 debugfs_remove(dentry);
1155 out:
1156 return rc;
1157 }
1158 EXPORT_SYMBOL(debug_unregister_view);
1159
1160 static inline char *
1161 debug_get_user_string(const char __user *user_buf, size_t user_len)
1162 {
1163 char* buffer;
1164
1165 buffer = memdup_user(user_buf, user_len + 1);
1166 if (IS_ERR(buffer))

> 1167			return PTR_ERR(buffer);

1168 /* got the string, now strip linefeed. */
1169 if (buffer[user_len - 1] == '\n')
1170 buffer[user_len - 1] = 0;
1171 else
1172 buffer[user_len] = 0;
1173 return buffer;
1174 }
1175

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#616 lore raw

PATCH 13/17 s390/debug: Improve a size determination in debug_open()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 2 Sep 2016 09:02:22 +0200

* Replace the specification of a data type by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

* Improve source code layout for one function call.

---
 arch/s390/kernel/debug.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/s390/kernel/debug.c +1 -2
index a9fcf72..32ceb5e 100644
@@ -636,8 +636,7 @@ debug_open(struct inode *inode, struct file *file)
 		rc = -ENOMEM;
 		goto unlock;
 	}
-	p_info = kmalloc(sizeof(file_private_info_t),
-						GFP_KERNEL);
+	p_info = kmalloc(sizeof(*p_info), GFP_KERNEL);
 	if (!p_info) {
 		debug_info_free(debug_info_snapshot);
 		rc = -ENOMEM;
Signature · 1 line
2.9.3
#617 lore raw

PATCH 14/17 s390/debug: Improve a size determination in debug_sprintf_format_fn()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 2 Sep 2016 14:32:08 +0200

Replace a multiplication by a reference for a local array variable as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer.

---
 arch/s390/kernel/debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kernel/debug.c +1 -1
index 32ceb5e..6792a9c 100644
@@ -1486,7 +1486,7 @@ debug_sprintf_format_fn(debug_info_t * id, struct debug_view *view,
 	/* number of arguments used for sprintf (without the format string) */
 	num_used_args   = min(DEBUG_SPRINTF_MAX_ARGS, (num_longs - 1));
 
-	memset(index, 0, DEBUG_SPRINTF_MAX_ARGS * sizeof(int));
+	memset(index, 0, sizeof(index));
 
 	for (i = 0; i < num_used_args; i++)
 		index[i] = i;
Signature · 1 line
2.9.3
#618 lore raw

PATCH 15/17 s390/debug: Improve a size determination in debug_raw_header_fn()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 2 Sep 2016 14:34:22 +0200

* Replace the specification of a data type by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

* Return a constant directly without storing the desired value in a local variable.

---
 arch/s390/kernel/debug.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
arch/s390/kernel/debug.c +2 -5
index 6792a9c..ff8e705 100644
@@ -1380,11 +1380,8 @@ static int
 debug_raw_header_fn(debug_info_t * id, struct debug_view *view,
 			int area, debug_entry_t * entry, char *out_buf)
 {
-	int rc;
-
-	rc = sizeof(debug_entry_t);
-	memcpy(out_buf, entry, sizeof(debug_entry_t));
-	return rc;
+	memcpy(out_buf, entry, sizeof(*entry));
+	return sizeof(*entry);
 }
 
 /*
Signature · 1 line
2.9.3
#619 lore raw

PATCH 16/17 s390/debug: Improve determination of sizes in debug_info_alloc()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 2 Sep 2016 14:39:00 +0200

* Replace two multiplications by references for an array in a local data structure as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer.

* Improve source code layout for one function call.

---
 arch/s390/kernel/debug.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/s390/kernel/debug.c +2 -3
index ff8e705..408a8da 100644
@@ -269,9 +269,8 @@ debug_info_alloc(const char *name, int pages_per_area, int nr_areas,
 	rc->buf_size       = buf_size;
 	rc->entry_size     = sizeof(debug_entry_t) + buf_size;
 	strlcpy(rc->name, name, sizeof(rc->name));
-	memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *));
-	memset(rc->debugfs_entries, 0, DEBUG_MAX_VIEWS *
-		sizeof(struct dentry*));
+	memset(rc->views, 0, sizeof(rc->views));
+	memset(rc->debugfs_entries, 0, sizeof(rc->debugfs_entries));
 	atomic_set(&(rc->ref_count), 0);
 
 	return rc;
Signature · 1 line
2.9.3
#620 lore raw

PATCH 17/17 s390/debug: Improve another size determination in debug_info_alloc()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 2 Sep 2016 14:41:02 +0200

Replace the specification of a data type by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 arch/s390/kernel/debug.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/s390/kernel/debug.c +1 -2
index 408a8da..ffc6af6 100644
@@ -241,8 +241,7 @@ debug_info_alloc(const char *name, int pages_per_area, int nr_areas,
 	debug_info_t* rc;
 
 	/* alloc everything */
-
-	rc = kmalloc(sizeof(debug_info_t), GFP_KERNEL);
+	rc = kmalloc(sizeof(*rc), GFP_KERNEL);
 	if(!rc)
 		goto exit;
 	rc->active_entries = kcalloc(nr_areas, sizeof(int), GFP_KERNEL);
Signature · 1 line
2.9.3
#621 lore raw

Re: [PATCH 00/17] s390/debug: Fine-tuning for several function implementations

In reply to SF Markus Elfring
Quoted 25 lines · On Sat, 3 Sep 2016 14:04:18 +0200 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 13:54:32 +0200

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

Markus Elfring (17):
Use kmalloc_array() in debug_areas_alloc()
Delete unnecessary braces
Add some spaces for better code readability
Rename jump labels in debug_areas_alloc()
Fix jump targets in debug_info_alloc()
Rename jump labels in debug_info_copy()
Rename jump labels in debug_open()
Fix a jump target in debug_register_mode()
Return directly if a null pointer was passed to debug_unregister() Delete an unnecessary initialisation in debug_prolog_level_fn() Fix indentation in 13 functions
Use memdup_user() rather than duplicating its implementation Improve a size determination in debug_open()
Improve a size determination in debug_sprintf_format_fn() Improve a size determination in debug_raw_header_fn() Improve determination of sizes in debug_info_alloc() Improve another size determination in debug_info_alloc()

Quoted 2 lines
 arch/s390/kernel/debug.c | 433 ++++++++++++++++++++++-------------------------
 1 file changed, 204 insertions(+), 229 deletions(-)

While I agree that the old code in arch/s390/kernel/debug.c does not abide to the current coding style standards, I doubt there is much value in these patches. To be honest I got annoyed after the third patch and stopped reading after the forth.

NAK.

Signature · 4 lines
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.
#622 lore raw

Re: s390/debug: Fine-tuning for several function implementations

Quoted 2 lines

While I agree that the old code in arch/s390/kernel/debug.c does not abide to the current coding style standards, I doubt there is much value in these patches.

How do you value the recommended compliance with the current Linux coding style convention?

Will my contribution be useful for further considerations?

Quoted 1 line

To be honest I got annoyed after the third patch

Thanks for your response.

Quoted 1 line

and stopped reading after the forth.

Does anybody in your company care for further improvements also in this software module?

Are there still opportunities to continue development in more constructive ways here?

Regards,
Markus

#623 lore raw

Re: s390/debug: Fine-tuning for several function implementations

In reply to Martin Schwidefsky
Quoted 2 lines

While I agree that the old code in arch/s390/kernel/debug.c does not abide to the current coding style standards,

Thanks for this kind of acknowledgement.

Is such an information worth for further development considerations?

Quoted 1 line

I doubt there is much value in these patches.

I assume that your doubts could be adjusted, couldn't they?

Are there any other concerns involved in the background?

Quoted 1 line

To be honest I got annoyed after the third patch

Which of the proposed changes did trigger such a reaction?

I find this response also a bit surprising because of the aspect that I offered you some results from my work as a free software developer.

Quoted 1 line

and stopped reading after the forth.

I imagine that you could have aborted the review of my update suggestions a bit too early for your debug software module.

I agree that the value is varying for the presented 17 update steps. But I hope that their value is potentially bigger overall than you categorise them at first glance.

Now I would like to try to get a bit of your software development attention once more for two of them at least. I hope that it can be easier to clarify their value.

* Do the implementations of the functions "debug_areas_alloc"
and "debug_get_user_string" need another look together with a more detailed source code review?

* How do you think about to use functions like "kmalloc_array" and "memdup_user" there instead?

Regards,
Markus

#624 lore raw

cover sparc: bpf_jit: Fine-tuning for bpf_jit_compile()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 18:28:02 +0200

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

Markus Elfring (4):
Use kmalloc_array()
Move four assignments
Avoid assignment for the variable "flen" if BPF JIT is disabled. Rename jump labels

 arch/sparc/net/bpf_jit_comp.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
Signature · 1 line
2.9.3
#625 lore raw

PATCH 1/4 sparc: bpf_jit: Use kmalloc_array() in bpf_jit_compile()

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 17:10:20 +0200

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

---
 arch/sparc/net/bpf_jit_comp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/net/bpf_jit_comp.c +1 -1
index a6d9204..ced1393 100644
@@ -372,7 +372,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
 	if (!bpf_jit_enable)
 		return;
 
-	addrs = kmalloc(flen * sizeof(*addrs), GFP_KERNEL);
+	addrs = kmalloc_array(flen, sizeof(*addrs), GFP_KERNEL);
 	if (addrs = NULL)
 		return;
 
Signature · 1 line
2.9.3
maintainer
#626 lore raw

Re: [PATCH 1/4] sparc: bpf_jit: Use kmalloc_array() in bpf_jit_compile()

Quoted 8 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 17:10:20 +0200

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

When you talk about "issue", could you please explain yourself what concrete "issue" you were seeing ?!

This particular multiplication here is guaranteed to never overflow, so at best a minor cleanup if you will.

(Do you actually have a sparc to test out your changes?)

Quoted 19 lines
---
  arch/sparc/net/bpf_jit_comp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/net/bpf_jit_comp.c +1 -1
index a6d9204..ced1393 100644
@@ -372,7 +372,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
  	if (!bpf_jit_enable)
  		return;
 
-	addrs = kmalloc(flen * sizeof(*addrs), GFP_KERNEL);
+	addrs = kmalloc_array(flen, sizeof(*addrs), GFP_KERNEL);
  	if (addrs = NULL)
  		return;
 
#627 lore raw

PATCH 2/4 sparc: bpf_jit: Move four assignments in bpf_jit_compile()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 17:45:28 +0200

Move the assignments for four local variables a bit at the beginning so that they will only be performed if a corresponding memory allocation succeeded by this function.

---
 arch/sparc/net/bpf_jit_comp.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
arch/sparc/net/bpf_jit_comp.c +8 -4
index ced1393..a927470 100644
@@ -362,10 +362,10 @@ do {	*prog++ = BR_OPC | WDISP22(OFF);		\
 
 void bpf_jit_compile(struct bpf_prog *fp)
 {
-	unsigned int cleanup_addr, proglen, oldproglen = 0;
-	u32 temp[8], *prog, *func, seen = 0, pass;
-	const struct sock_filter *filter = fp->insns;
-	int i, flen = fp->len, pc_ret0 = -1;
+	unsigned int cleanup_addr, proglen, oldproglen;
+	u32 temp[8], *prog, *func, seen, pass;
+	const struct sock_filter *filter;
+	int i, flen = fp->len, pc_ret0;
 	unsigned int *addrs;
 	void *image;
 
@@ -385,6 +385,10 @@ void bpf_jit_compile(struct bpf_prog *fp)
 	}
 	cleanup_addr = proglen; /* epilogue address */
 	image = NULL;
+	filter = fp->insns;
+	oldproglen = 0;
+	pc_ret0 = -1;
+	seen = 0;
 	for (pass = 0; pass < 10; pass++) {
 		u8 seen_or_pass0 = (pass = 0) ? (SEEN_XREG | SEEN_DATAREF | SEEN_MEM) : seen;
 
Signature · 1 line
2.9.3
#628 lore raw

Re: [PATCH 2/4] sparc: bpf_jit: Move four assignments in bpf_jit_compile()

Hi Markus,

Quoted 32 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 17:45:28 +0200

Move the assignments for four local variables a bit at the beginning so that they will only be performed if a corresponding memory allocation succeeded by this function.

---
 arch/sparc/net/bpf_jit_comp.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
arch/sparc/net/bpf_jit_comp.c +4 -4
index ced1393..a927470 100644
@@ -362,10 +362,10 @@ do {      *prog++ = BR_OPC | WDISP22(OFF);                \
 
 void bpf_jit_compile(struct bpf_prog *fp)
 {
-       unsigned int cleanup_addr, proglen, oldproglen = 0;
-       u32 temp[8], *prog, *func, seen = 0, pass;
-       const struct sock_filter *filter = fp->insns;
-       int i, flen = fp->len, pc_ret0 = -1;
+       unsigned int cleanup_addr, proglen, oldproglen;
+       u32 temp[8], *prog, *func, seen, pass;
+       const struct sock_filter *filter;
+       int i, flen = fp->len, pc_ret0;
        unsigned int *addrs;
        void *image;
 

arch/sparc/net/bpf_jit_comp.c void bpf_jit_compile(struct bpf_prog *fp) · line 393

Quoted 9 lines
arch/sparc/net/bpf_jit_comp.c +4 -0
@@ -385,6 +385,10 @@ void bpf_jit_compile(struct bpf_prog *fp)
        }
        cleanup_addr = proglen; /* epilogue address */
        image = NULL;
+       filter = fp->insns;
+       oldproglen = 0;
+       pc_ret0 = -1;
+       seen = 0;
        for (pass = 0; pass < 10; pass++) {
                u8 seen_or_pass0 = (pass = 0) ? (SEEN_XREG | SEEN_DATAREF | SEEN_MEM) : seen;

This is utterly pointless, why?

If you were moving the assignments on declaration onto separate lines at the top of the file then ok, but why all the way down here?

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
#629 lore raw

Re: [PATCH 2/4] sparc: bpf_jit: Move four assignments in bpf_jit_compile()

Quoted 5 lines
Quoted 5 lines

Date: Sat, 3 Sep 2016 17:45:28 +0200

Move the assignments for four local variables a bit at the beginning so that they will only be performed if a corresponding memory allocation succeeded by this function.

…

Quoted 25 lines
Quoted 25 lines
arch/sparc/net/bpf_jit_comp.c +8 -4
@@ -362,10 +362,10 @@ do {      *prog++ = BR_OPC | WDISP22(OFF);                \
 
 void bpf_jit_compile(struct bpf_prog *fp)
 {
-       unsigned int cleanup_addr, proglen, oldproglen = 0;
-       u32 temp[8], *prog, *func, seen = 0, pass;
-       const struct sock_filter *filter = fp->insns;
-       int i, flen = fp->len, pc_ret0 = -1;
+       unsigned int cleanup_addr, proglen, oldproglen;
+       u32 temp[8], *prog, *func, seen, pass;
+       const struct sock_filter *filter;
+       int i, flen = fp->len, pc_ret0;
        unsigned int *addrs;
        void *image;
 
@@ -385,6 +385,10 @@ void bpf_jit_compile(struct bpf_prog *fp)
        }
        cleanup_addr = proglen; /* epilogue address */
        image = NULL;
+       filter = fp->insns;
+       oldproglen = 0;
+       pc_ret0 = -1;
+       seen = 0;
        for (pass = 0; pass < 10; pass++) {
                u8 seen_or_pass0 = (pass = 0) ? (SEEN_XREG | SEEN_DATAREF | SEEN_MEM) : seen;

…

Quoted 2 lines

If you were moving the assignments on declaration onto separate lines at the top of the file then ok,

I see another software design option where the transformation result might be looking more pleasing for you again.

Quoted 1 line

but why all the way down here?

* How do you think about the reason I gave in the short commit message?

* Are you interested in an other software refactoring instead?
http://refactoring.com/catalog/reduceScopeOfVariable.html

Would you eventually like to move the source code for this for loop into another function?
http://refactoring.com/catalog/extractMethod.html

Regards,
Markus

#630 lore raw

Re: [PATCH 2/4] sparc: bpf_jit: Move four assignments in bpf_jit_compile()

Hi Markus,

Quoted 35 lines · SF Markus Elfring
Quoted 5 lines
Quoted 5 lines

Date: Sat, 3 Sep 2016 17:45:28 +0200

Move the assignments for four local variables a bit at the beginning so that they will only be performed if a corresponding memory allocation succeeded by this function.

…

Quoted 25 lines
Quoted 25 lines
arch/sparc/net/bpf_jit_comp.c +8 -4
@@ -362,10 +362,10 @@ do {      *prog++ = BR_OPC | WDISP22(OFF);                \
 
 void bpf_jit_compile(struct bpf_prog *fp)
 {
-       unsigned int cleanup_addr, proglen, oldproglen = 0;
-       u32 temp[8], *prog, *func, seen = 0, pass;
-       const struct sock_filter *filter = fp->insns;
-       int i, flen = fp->len, pc_ret0 = -1;
+       unsigned int cleanup_addr, proglen, oldproglen;
+       u32 temp[8], *prog, *func, seen, pass;
+       const struct sock_filter *filter;
+       int i, flen = fp->len, pc_ret0;
        unsigned int *addrs;
        void *image;
 
@@ -385,6 +385,10 @@ void bpf_jit_compile(struct bpf_prog *fp)
        }
        cleanup_addr = proglen; /* epilogue address */
        image = NULL;
+       filter = fp->insns;
+       oldproglen = 0;
+       pc_ret0 = -1;
+       seen = 0;
        for (pass = 0; pass < 10; pass++) {
                u8 seen_or_pass0 = (pass == 0) ? (SEEN_XREG | SEEN_DATAREF | SEEN_MEM) : seen;

…

Quoted 2 lines

If you were moving the assignments on declaration onto separate lines at the top of the file then ok,

Quoted 7 lines

I see another software design option where the transformation result might be looking more pleasing for you again.

Quoted 1 line

but why all the way down here?

* How do you think about the reason I gave in the short commit message?

Does this change improve the resulting binary? I.e. does it make it smaller or faster? If it's smaller, by how much? if it's faster, measure it.

Otherwise this change is useless churn - you're making the code more complicated, longer and harder to read for practically no benefit.

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
#631 lore raw

Re: sparc: bpf_jit: Move four assignments in bpf_jit_compile()

Quoted 1 line

Does this change improve the resulting binary?

I hope so. - I propose to give the refactorings "Reduce scope of variable" and "Extract a function" (and the corresponding consequences) another look.

Quoted 1 line

I.e. does it make it smaller or faster?

It is generally possible that a specific code generation variant will also affect the run time properties you mentioned.

Quoted 2 lines

Otherwise this change is useless churn - you're making the code more complicated, longer and harder to read for practically no benefit.

I imagine that there other reasons you could eventually accept for this use case, aren't there?

Regards,
Markus

#632 lore raw

Re: sparc: bpf_jit: Move four assignments in bpf_jit_compile()

Hi Markus,

Quoted 4 lines · SF Markus Elfring
Quoted 1 line

Does this change improve the resulting binary?

I hope so. - I propose to give the refactorings "Reduce scope of variable" and "Extract a function" (and the corresponding consequences) another look.

So you _think_ it does. Come back with real proof.

I must also point out that these sorts of optimisations are things the compiler does automatically when compiling this code. Therefore it's highly likely that this change will make absolutely no difference whatsoever. (And no it won't improve compile speed in any justifiable way)

Quoted 4 lines
Quoted 1 line

I.e. does it make it smaller or faster?

It is generally possible that a specific code generation variant will also affect the run time properties you mentioned.

It's _possible_? Come back with benchmarks.

I must also point out that this is a "slow path" i.e. as long as it's not stupidly inefficient, the speed doesn't matter that much. This change isn't going to improve the speed of this function by any amount that matters.

Quoted 5 lines
Quoted 2 lines

Otherwise this change is useless churn - you're making the code more complicated, longer and harder to read for practically no benefit.

I imagine that there other reasons you could eventually accept for this use case, aren't there?

Unless you have some pretty damn good proof that these changes improve things, there is absolutely no reason to take them as-is - you are making the code longer and more difficult to read for no benefit and wasting everyone's time in the process.

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
#633 lore raw

Re: sparc: bpf_jit: Move four assignments in bpf_jit_compile()

Quoted 4 lines
Quoted 2 lines

I hope so. - I propose to give the refactorings "Reduce scope of variable" and "Extract a function" (and the corresponding consequences) another look.

So you _think_ it does. Come back with real proof.

Which test environments would you find acceptable for further clarification?

Quoted 2 lines

I must also point out that these sorts of optimisations are things the compiler does automatically when compiling this code.

Do you take this detail for granted?

Quoted 2 lines

Therefore it's highly likely that this change will make absolutely no difference whatsoever.

I find this outcome unlikely.

Quoted 1 line

(And no it won't improve compile speed in any justifiable way)

This was not a goal of my update suggestion for the function "bpf_jit_compile".

Quoted 4 lines
Quoted 2 lines

It is generally possible that a specific code generation variant will also affect the run time properties you mentioned.

It's _possible_? Come back with benchmarks.

Which code generation variant would be useful to be clarified further?

Should we avoid to compare software things similar to "apples" and "oranges"
(while these fruits can make more fun)? ;-)

Quoted 2 lines

I must also point out that this is a "slow path" i.e. as long as it's not stupidly inefficient, the speed doesn't matter that much.

Can this execution path become warmer (or even "hot") for some other use cases?

Quoted 2 lines

This change isn't going to improve the speed of this function by any amount that matters.

This is also possible.

Quoted 2 lines

Unless you have some pretty damn good proof that these changes improve things, there is absolutely no reason to take them as-is

Would you care for a better source code structure?

Quoted 1 line

- you are making the code longer

Yes. - This is true for the suggested update in this function.

Quoted 1 line

and more difficult to read for no benefit

I proposed specific benefits for this software module.

Quoted 1 line

and wasting everyone's time in the process.

I assume that a few contributors can take the presented ideas for further considerations. Will their value evolve a bit more later?

Regards,
Markus

#634 lore raw

Re: sparc: bpf_jit: Move four assignments in bpf_jit_compile()

Hi Markus,

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

I hope so. - I propose to give the refactorings "Reduce scope of variable" and "Extract a function" (and the corresponding consequences) another look.

So you _think_ it does. Come back with real proof.

Which test environments would you find acceptable for further clarification?

Compiling it on GCC for Sparc, obviously.

Quoted 4 lines
Quoted 2 lines

I must also point out that these sorts of optimisations are things the compiler does automatically when compiling this code.

Do you take this detail for granted?

I trust that the GCC developers have done their work well.

Quoted 4 lines
Quoted 2 lines

Therefore it's highly likely that this change will make absolutely no difference whatsoever.

I find this outcome unlikely.

Then provide proof.

Quoted 3 lines
Quoted 1 line

(And no it won't improve compile speed in any justifiable way)

This was not a goal of my update suggestion for the function "bpf_jit_compile".

I'm looking for some glimmer of usefullness in this patch. I'm not seeing any.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

It is generally possible that a specific code generation variant will also affect the run time properties you mentioned.

It's _possible_? Come back with benchmarks.

Which code generation variant would be useful to be clarified further?

Should we avoid to compare software things similar to "apples" and "oranges"
(while these fruits can make more fun)? ;-)

Write a benchmark that exercises this function. Measure the time it took without this change, measure the time it took with this change, is there a difference.

You cannot expect people to take you seriously if you're proposing performance changes without any actual ability or interest in producing performance related data to go along with them.

Quoted 4 lines
Quoted 2 lines

I must also point out that this is a "slow path" i.e. as long as it's not stupidly inefficient, the speed doesn't matter that much.

Can this execution path become warmer (or even "hot") for some other use cases?

That is for you to prove.

Quoted 10 lines
Quoted 2 lines

This change isn't going to improve the speed of this function by any amount that matters.

This is also possible.

Quoted 2 lines

Unless you have some pretty damn good proof that these changes improve things, there is absolutely no reason to take them as-is

Would you care for a better source code structure?

You're essentially saying "I think doing things this way is better" and providing _nothing_ else. I think that things are perfectly fine the way they are. Convince me with data or something else. Was this suggested by some expert? Is this part of some big tree-wide effort to do this that was started by some expert? Did someone do this to some other driver and you're applying the same fix elsewhere?

Quoted 8 lines
Quoted 1 line

- you are making the code longer

Yes. - This is true for the suggested update in this function.

Quoted 1 line

and more difficult to read for no benefit

I proposed specific benefits for this software module.

What benefits? You have not proved that this change produces any useful benefits.

Quoted 4 lines
Quoted 1 line

and wasting everyone's time in the process.

I assume that a few contributors can take the presented ideas for further considerations. Will their value evolve a bit more later?

I am subscribed to four fairly high traffic mailing lists and I read hundreds of patches each week. You are the only person proposing changes like these ones as you are (as far as I know) the only person who thinks they have any value.

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
#635 lore raw

Re: sparc: bpf_jit: Move four assignments in bpf_jit_compile()

Quoted 3 lines
Quoted 1 line

Which test environments would you find acceptable for further clarification?

Compiling it on GCC for Sparc, obviously.

Are there any more configuration details to consider?

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

I must also point out that these sorts of optimisations are things the compiler does automatically when compiling this code.

Do you take this detail for granted?

I trust that the GCC developers have done their work well.

Will any more compiler implementations matter here?

Do you like software which can run better by default also without application of special compilation parameters?

Quoted 1 line

I'm looking for some glimmer of usefullness in this patch. I'm not seeing any.

Thanks for your honest feedback.

Quoted 6 lines
Quoted 2 lines

Should we avoid to compare software things similar to "apples" and "oranges"
(while these fruits can make more fun)? ;-)

Write a benchmark that exercises this function. Measure the time it took without this change, measure the time it took with this change, is there a difference.

Is an accepted test system already available for the purpose that every commit would be checked in the way automatically you expect here?

Quoted 3 lines

You cannot expect people to take you seriously if you're proposing performance changes without any actual ability or interest in producing performance related data to go along with them.

I suggested small changes which I found "logical".

Quoted 1 line

You're essentially saying "I think doing things this way is better"

Yes …

Quoted 1 line

and providing _nothing_ else.

You might be looking for more information than I can practically give you at the moment.

Quoted 1 line

I think that things are perfectly fine the way they are.

I have got an other impression for "perfection" in this software module. I found an implementation detail for further considerations.

Quoted 1 line

Convince me with data or something else.

I imagine that the "else" can become harder than you find reasonable.

Quoted 1 line

Did someone do this to some other driver and you're applying the same fix elsewhere?

Is a similar software development discussion still running for other modules?

Quoted 1 line

You are the only person proposing changes like these ones as you are

I am picking special software improvement opportunities up.

Quoted 1 line

(as far as I know) the only person who thinks they have any value.

I can accept that the value of specific changes will usually be categorised as lower than updates that you prefer so far.

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

maintainer
#636 lore raw

Re: sparc: bpf_jit: Move four assignments in bpf_jit_compile()

In reply to SF Markus Elfring

From: SF Markus Elfring <[email protected]>
Date: Sun, 4 Sep 2016 07:45:04 +0200

Quoted 4 lines
Quoted 1 line

and wasting everyone's time in the process.

I assume that a few contributors can take the presented ideas for further considerations. Will their value evolve a bit more later?

No, really, you are wasting everyone's time.

And as the sole maintainer of the sparc port, you are specifically wasting mine.

maintainer
#637 lore raw

Re: sparc: bpf_jit: Move four assignments in bpf_jit_compile()

In reply to SF Markus Elfring

Markus, I'm really not going to consider any of these changes.

And your replies to the feedback you were given disappoint me even more.

Please don't submit any more sparc patches until you can get you act in gear and not waste everyone's time.

Thank you.

#638 lore raw

Re: sparc: bpf_jit: Move four assignments in bpf_jit_compile()

Hi David,

Quoted 8 lines · David Miller

Markus, I'm really not going to consider any of these changes.

And your replies to the feedback you were given disappoint me even more.

Please don't submit any more sparc patches until you can get you act in gear and not waste everyone's time.

In Markus' defence, he does occasionally write okay patches, (for example the kmalloc(a * b) => kmalloc_array(a, b) changes get my small tick of approval) however he also submits a lot of patches which are little more than moving stuff around pointlessly.

I really wish he'd concentrate on the former rather than the latter.

He's not another Nick Krause.

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
#639 lore raw

Re: sparc: bpf_jit: Move four assignments in bpf_jit_compile()

Quoted 3 lines

In Markus' defence, he does occasionally write okay patches, (for example the kmalloc(a * b) => kmalloc_array(a, b) changes get my small tick of approval)

Thanks for another bit of acceptance for this kind of software change.

Quoted 1 line

however he also submits a lot of patches which are little more than moving stuff around

This is true to some degree.

Quoted 1 line

pointlessly.

Do we agree to disagree on the value of some collateral software evolutions I'm proposing for a while?

Quoted 1 line

I really wish he'd concentrate on the former rather than the latter.

I am on the way for such a software development adventure.
There are further improvement opportunities to consider besides the main route, aren't there?

Quoted 1 line

He's not another Nick Krause.

Are you going to remember me under an other nickname anyhow?

Regards,
Markus

#640 lore raw

Re: sparc: bpf_jit: Move four assignments in bpf_jit_compile()

Hi Markus,

Quoted 5 lines · SF Markus Elfring
Quoted 1 line

I really wish he'd concentrate on the former rather than the latter.

I am on the way for such a software development adventure.
There are further improvement opportunities to consider besides the main route, aren't there?

You're missing the point here. Find something useful to change.

People are going through the kernel finding functions that should be static for example - this is useful as it provides better documentation for those functions (static = not used outside this file) and fixes errors reported by GCC and static code checkers. Those changes are useful.

Another useful change would be ensuring that every struct that has a bool member is kzalloc'd instead of kmalloc'd as this eliminates a possible source of undefined behaviour. (A bool is effectively a u8 with behaviour defined for when that value is 0 or 1, kmalloc'd memory can have any data in it, therefore it's possible and likely that a kmalloc'd struct with a bool member will end up with some value for that member that isn't 0 or 1. kzalloc eliminates this possibility.)

Moving four assignments because you think they might improve stuff is just annoying people.

Quoted 3 lines
Quoted 1 line

He's not another Nick Krause.

Are you going to remember me under an other nickname anyhow?

Nick Krause submitted patches that make yours look good. At least yours compile.

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
maintainer
#641 lore raw

Re: [PATCH 2/4] sparc: bpf_jit: Move four assignments in bpf_jit_compile()

In reply to Julian Calaby
Quoted 2 lines · Julian Calaby

Otherwise this change is useless churn - you're making the code more complicated, longer and harder to read for practically no benefit.

He has been doing that for years now. And wasted maintainer resources along the way, discussing all the pointless churn. There are zero indications that this will ever change from his side.

Do not feed.

Bjørn
--
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

#642 lore raw

PATCH 3/4 sparc: bpf_jit: Avoid assignment for "flen" if BPF JIT is disabled

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 18:00:03 +0200

Move the assignment for the local variable "flen" a bit at the beginning so that it will only be performed if BPF JIT is enabled for this function.

---
 arch/sparc/net/bpf_jit_comp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/sparc/net/bpf_jit_comp.c +2 -1
index a927470..a6b6e29 100644
@@ -365,13 +365,14 @@ void bpf_jit_compile(struct bpf_prog *fp)
 	unsigned int cleanup_addr, proglen, oldproglen;
 	u32 temp[8], *prog, *func, seen, pass;
 	const struct sock_filter *filter;
-	int i, flen = fp->len, pc_ret0;
+	int i, flen, pc_ret0;
 	unsigned int *addrs;
 	void *image;
 
 	if (!bpf_jit_enable)
 		return;
 
+	flen = fp->len;
 	addrs = kmalloc_array(flen, sizeof(*addrs), GFP_KERNEL);
 	if (addrs = NULL)
 		return;
Signature · 1 line
2.9.3
maintainer
#643 lore raw

Re: [PATCH 3/4] sparc: bpf_jit: Avoid assignment for "flen" if BPF JIT is disabled

Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 18:00:03 +0200

Move the assignment for the local variable "flen" a bit at the beginning so that it will only be performed if BPF JIT is enabled for this function.

Why is that a particular issue (did you measure some improvement when you say "fine-tuning" as per subject) ?

That's all not in critical path here by the way, same for patch 2.

#644 lore raw

PATCH 4/4 sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 18:14:19 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 arch/sparc/net/bpf_jit_comp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/sparc/net/bpf_jit_comp.c +3 -3
index a6b6e29..3aa19a1 100644
@@ -761,7 +761,7 @@ cond_branch:			f_offset = addrs[i + filter[i].jf];
 
 			default:
 				/* hmm, too complex filter, give up with jit compiler */
-				goto out;
+				goto free_addresses;
 			}
 			ilen = (void *) prog - (void *) temp;
 			if (image) {
@@ -793,7 +793,7 @@ cond_branch:			f_offset = addrs[i + filter[i].jf];
 		if (proglen = oldproglen) {
 			image = module_alloc(proglen);
 			if (!image)
-				goto out;
+				goto free_addresses;
 		}
 		oldproglen = proglen;
 	}
@@ -806,7 +806,7 @@ cond_branch:			f_offset = addrs[i + filter[i].jf];
 		fp->bpf_func = (void *)image;
 		fp->jited = 1;
 	}
-out:
+ free_addresses:
 	kfree(addrs);
 	return;
 }
Signature · 1 line
2.9.3
maintainer NAK
#645 lore raw

Re: [PATCH 4/4] sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 18:14:19 +0200

Adjust jump labels according to the current Linux coding style convention.

NAK, just noise.

Quoted 36 lines
---
  arch/sparc/net/bpf_jit_comp.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
arch/sparc/net/bpf_jit_comp.c +3 -3
index a6b6e29..3aa19a1 100644
@@ -761,7 +761,7 @@ cond_branch:			f_offset = addrs[i + filter[i].jf];
 
  			default:
  				/* hmm, too complex filter, give up with jit compiler */
-				goto out;
+				goto free_addresses;
  			}
  			ilen = (void *) prog - (void *) temp;
  			if (image) {
@@ -793,7 +793,7 @@ cond_branch:			f_offset = addrs[i + filter[i].jf];
  		if (proglen = oldproglen) {
  			image = module_alloc(proglen);
  			if (!image)
-				goto out;
+				goto free_addresses;
  		}
  		oldproglen = proglen;
  	}
@@ -806,7 +806,7 @@ cond_branch:			f_offset = addrs[i + filter[i].jf];
  		fp->bpf_func = (void *)image;
  		fp->jited = 1;
  	}
-out:
+ free_addresses:
  	kfree(addrs);
  	return;
  }
maintainer
#646 lore raw

Re: [PATCH 4/4] sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

From: Daniel Borkmann <[email protected]>
Date: Sat, 03 Sep 2016 18:52:44 +0200

Quoted 10 lines · SF Markus Elfring
Quoted 7 lines

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 18:14:19 +0200

Adjust jump labels according to the current Linux coding style convention.

NAK, just noise.

And frankly I hate that leading space.

#647 lore raw

Re: sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

Quoted 3 lines
Quoted 1 line

NAK, just noise.

And frankly I hate that leading space.

Would you like to comment the recent update of the document "CodingStyle" any more?
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/Documentation/CodingStyle?id†5a1caa4b6b886babdd9d67e7c3608be4567a51

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

maintainer
#648 lore raw

Re: sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

From: SF Markus Elfring <[email protected]>
Date: Sun, 4 Sep 2016 08:50:20 +0200

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

NAK, just noise.

And frankly I hate that leading space.

Would you like to comment the recent update of the document "CodingStyle" any more?
https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/Documentation/CodingStyle?id†5a1caa4b6b886babdd9d67e7c3608be4567a51

You seem to lack understanding of the difference between absolute requirements and "advice".

As Sparc maintainer I can choose to not take this "advice", and I so choose to do so.

If you want to be completely ignored by me, then keep arguing the way you are right now.
--
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

#649 lore raw

Re: sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

Quoted 7 lines
Quoted 1 line

https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/Documentation/CodingStyle?id†5a1caa4b6b886babdd9d67e7c3608be4567a51

You seem to lack understanding of the difference between absolute requirements and "advice".

As Sparc maintainer I can choose to not take this "advice", and I so choose to do so.

Your conclusion can be fine in principle.

I am just curious on how much further software development "fun" the recent update by a topic like "CodingStyle: Clarify and complete chapter 7" will trigger.

Quoted 1 line

If you want to be completely ignored by me,

I hope that this action does not need to happen.

Quoted 1 line

then keep arguing the way you are right now.

I guess that I will stumble on more software improvement opportunities you find harder to become comfortable with.

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

maintainer
#650 lore raw

Re: sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

From: SF Markus Elfring <[email protected]>
Date: Sun, 4 Sep 2016 09:20:55 +0200

Quoted 2 lines

I guess that I will stumble on more software improvement opportunities you find harder to become comfortable with.

Improvement is a matter of opinion. So your statement assumes that your changes are an improvement, and everyone in this thread clearly disagrees with that.

This is why everything you are doing here is so irritating.

It's not because I find improvements "uncomfortable", but rather it's because your changes are not seen as improvements in the first place.

#651 lore raw

Re: sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

Quoted 2 lines

It's not because I find improvements "uncomfortable", but rather it's because your changes are not seen as improvements in the first place.

What is your software development opinion for the update step "[1/4] sparc: bpf_jit: Use kmalloc_array() in bpf_jit_compile()" from this small patch series?

Regards,
Markus

maintainer
#652 lore raw

Re: sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

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

https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/commit/Documentation/CodingStyle?id†5a1caa4b6b886babdd9d67e7c3608be4567a51

[ + Jonathan for above commit in linux-next ]

Quoted 10 lines
Quoted 5 lines

You seem to lack understanding of the difference between absolute requirements and "advice".

As Sparc maintainer I can choose to not take this "advice", and I so choose to do so.

Your conclusion can be fine in principle.

I am just curious on how much further software development "fun" the recent update by a topic like "CodingStyle: Clarify and complete chapter 7" will trigger.

I don't want to drag this thread onwards for (way) too long, but clearly "it is advised to indent labels with a single space (not tab)" (from diff in above commit) doesn't really reflect the majority of kernel practice we have in-tree today and actually rather adds more confusion than any clarification whatsoever:

   $ git grep -n "^\ [a-z_]*:" -- '*.[ch]' | wc -l
   4919
   $ git grep -n "^[a-z_]*:" -- '*.[ch]' | wc -l
   54686

A CodingStyle document should document what's regarded as a general consensus of kernel coding practices, and thus should represent the /majority/ of coding style, which (if I didn't screw up my git-grep line completely) above 9% does not really reflect at all. So, new folks starting with kernel hacking reading this are rather misguided, and code-wise it just adds up to have more inconsistencies from new patches, or worse, have noisy patches (like this one) flying around that try to brute-force everything into this advice.
--
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

#653 lore raw

Re: Clarification for source code formatting around jump labels

Quoted 5 lines
Quoted 2 lines

I am just curious on how much further software development "fun" the recent update by a topic like "CodingStyle: Clarify and complete chapter 7" will trigger.

I don't want to drag this thread onwards for (way) too long, but clearly "it is advised to indent labels with a single space (not tab)" (from diff in above commit)

How do you think about the reason (which you omitted from your quotation) for this advice?

“…,
so that "diff -p" does not confuse labels with functions. …”

Quoted 7 lines

doesn't really reflect the majority of kernel practice we have in-tree today and actually rather adds more confusion than any clarification whatsoever:

  $ git grep -n "^\ [a-z_]*:" -- '*.[ch]' | wc -l
  4919
  $ git grep -n "^[a-z_]*:" -- '*.[ch]' | wc -l
  54686

So there is a mixture already.

Quoted 3 lines

A CodingStyle document should document what's regarded as a general consensus of kernel coding practices, and thus should represent the /majority/ of coding style, which (if I didn't screw up my git-grep line completely)

1. Is the used character class specification complete in the shown regular expression?

2. I guess that you should use the regex operator "plus" (instead of the asterisk).

3. Would you like to try another source code analysis out which can be a bit safer with the usage of the semantic patch language?

Quoted 1 line

above 9% does not really reflect at all.

How tolerant are you for using an extra space character before the identifier for a jump label?

Quoted 4 lines

So, new folks starting with kernel hacking reading this are rather misguided, and code-wise it just adds up to have more inconsistencies from new patches, or worse, have noisy patches (like this one) flying around that try to brute-force everything into this advice.

In which ways would you prefer that the style specifications should be clarified further?

Where should source code become more consistent?

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

maintainer
#654 lore raw

Re: Clarification for source code formatting around jump labels

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

I am just curious on how much further software development "fun" the recent update by a topic like "CodingStyle: Clarify and complete chapter 7" will trigger.

I don't want to drag this thread onwards for (way) too long, but clearly "it is advised to indent labels with a single space (not tab)" (from diff in above commit)

How do you think about the reason (which you omitted from your quotation) for this advice?

“…,
so that "diff -p" does not confuse labels with functions. …”

Yep, since this recently came up in a different thread as well, please see here, for example:

http://patchwork.ozlabs.org/patch/664966/

Quoted 10 lines
Quoted 7 lines

doesn't really reflect the majority of kernel practice we have in-tree today and actually rather adds more confusion than any clarification whatsoever:

   $ git grep -n "^\ [a-z_]*:" -- '*.[ch]' | wc -l
   4919
   $ git grep -n "^[a-z_]*:" -- '*.[ch]' | wc -l
   54686

So there is a mixture already.

[...]

Quoted 4 lines

In which ways would you prefer that the style specifications should be clarified further?

Where should source code become more consistent?

It would likely make sense to document that git config mentioned in the link above as a recommendation for that paragraph, and stick with what is used in the vast majority of cases already, meaning no leading space before labels.
--
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

#655 lore raw

Re: sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

In reply to Daniel Borkmann

Hi Daniel,

Preliminary note: the SNR of Markus Elfring is incredibly low. I advise you just ignore him.

Quoted 9 lines · Daniel Borkmann

I don't want to drag this thread onwards for (way) too long, but clearly "it is advised to indent labels with a single space (not tab)" (from diff in above commit) doesn't really reflect the majority of kernel practice we have in-tree today and actually rather adds more confusion than any clarification whatsoever:

   $ git grep -n "^\ [a-z_]*:" -- '*.[ch]' | wc -l
   4919
   $ git grep -n "^[a-z_]*:" -- '*.[ch]' | wc -l
   54686

Well the documentation update in question has not hit mainline yet, so it's not really surprising.

Quoted 2 lines

A CodingStyle document should document what's regarded as a general consensus of kernel coding practices, and thus should represent the /majority/ of coding style,

I beg to disagree. Recommendations are not meant to document what people are currently doing but what we think they should be doing. By your reasoning, we would have killed all the devm infrastructure, because at some point in time (and it might still be the case) most drivers were not using it.

There is a rationale for the leading space, it is given in the patch, but sadly you decided to not quote it above.

Quoted 2 lines

which (if I didn't screw up my git-grep line completely) above 9% does not really reflect at all. So, new folks starting with kernel hacking reading this are rather

Your grep patterns are slightly inaccurate. Space doesn't need to be escaped, labels can use capital letters, and except for the first character, digits are accepted too. Also to be completely fair, you should also count the labels which are intended using tabs. But it doesn't change the balance noticeably anyway, so no big deal.

Quoted 3 lines

misguided, and code-wise it just adds up to have more inconsistencies from new patches, or worse, have noisy patches (like this one) flying around that try to brute-force everything into this advice.

Guys who like to waste our time with pointless patches will always find a way to do that, sadly, so I don't think this point is relevant.

The acceptance of an optional single space before labels dates back to at least June 2007, as supported by the very first incarnation of checkpatch.pl. So nothing really new here, except for a preference (my preference, admittedly, but I'm know I'm not alone) being expressed in the coding style document.

My assumption was that the behavior of "diff -p" would never change, as despite the language-specificity of its long option name, it seemed too generic to be loaded with C-specific rules.

Now I see in http://patchwork.ozlabs.org/patch/664966/ that Peter Zijlstra reportedly changed the behavior of "diff -p" so that it handles unindented C labels nicely. If this actually happens, it could change my point of view. However I can't find this commit in upstream diffutils. Peter, can you please clarify the situation? Is it just a local hack on your own instance of "diff"?

Even if upstream diff is ever changed, it will take some time until new versions propagate to all developers. And until this happens, my preference for one-space-indented labels will remain.

Also git has its own implementation of "diff", so any change in the behavior of GNU diff's -p and/or --show-c-function options should be reflected there as well for consistency.

Signature · 2 lines
Jean Delvare
SUSE L3 Support
maintainer
#656 lore raw

Re: sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

Quoted 6 lines · Jean Delvare

Now I see in http://patchwork.ozlabs.org/patch/664966/ that Peter Zijlstra reportedly changed the behavior of "diff -p" so that it handles unindented C labels nicely. If this actually happens, it could change my point of view. However I can't find this commit in upstream diffutils. Peter, can you please clarify the situation? Is it just a local hack on your own instance of "diff"?

I have it in my local .gitconfig, and recommend it to people who send me patches.

I've never tried to get diffutils fixed, although maybe I should.

#657 lore raw

Re: sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

Quoted 10 lines · Peter Zijlstra
Quoted 6 lines · Jean Delvare

Now I see in http://patchwork.ozlabs.org/patch/664966/ that Peter Zijlstra reportedly changed the behavior of "diff -p" so that it handles unindented C labels nicely. If this actually happens, it could change my point of view. However I can't find this commit in upstream diffutils. Peter, can you please clarify the situation? Is it just a local hack on your own instance of "diff"?

I have it in my local .gitconfig, and recommend it to people who send me patches.

What does it look like, please?

Quoted 1 line

I've never tried to get diffutils fixed, although maybe I should.

If you don't want one-space-indented labels to become the norm, then yes you should.

Signature · 2 lines
Jean Delvare
SUSE L3 Support
maintainer
#658 lore raw

Re: sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

Quoted 9 lines · Jean Delvare
Quoted 8 lines · Peter Zijlstra
Quoted 6 lines · Jean Delvare

Now I see in http://patchwork.ozlabs.org/patch/664966/ that Peter Zijlstra reportedly changed the behavior of "diff -p" so that it handles unindented C labels nicely. If this actually happens, it could change my point of view. However I can't find this commit in upstream diffutils. Peter, can you please clarify the situation? Is it just a local hack on your own instance of "diff"?

Quoted 4 lines
Quoted 2 lines

I have it in my local .gitconfig, and recommend it to people who send me patches.

What does it look like, please?

[diff "default"]

        xfuncname = "^[[:alpha:]$_].*[^:]$"
[core]
	abbrev = 12
[alias]
	one = show -s --pretty='format:%h (\"%s\")'

[rerere]
enable = true
enabled = true
autoupdate = true

#659 lore raw

Re: sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

Hi Peter,

Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · Jean Delvare
Quoted 2 lines · Peter Zijlstra

I have it in my local .gitconfig, and recommend it to people who send me patches.

What does it look like, please?

[diff "default"]

        xfuncname = "^[[:alpha:]$_].*[^:]$"

OK, I see. As mentioned somewhere else, it fails for labels which have comments. I was also surprised by the $ but apparently it's valid in identifiers for at least some incarnations of C o.O

My worry is that you recommending it to contributors on a individual and opportunity basis, doesn't scale. Basing coding style recommendations on a personal quirk doesn't strike me as the best idea ever in the long run.

The reason why I proposed an update to CodingStyle regarding this topic was precisely to avoid having to repeat the same to contributors, like you do (although our recommendations are different.)

While looking at the syntax of your example, I have found something which looks more promising. git already has predefined xfuncname definitions for various languages, including C. These can be enabled based on file name patterns via gitattributes. The following .gitattribute file placed at the root of the kernel source tree achieves what you want:

*.c diff=cpp
*.h diff=cpp

The major difference between git config and gitattributes is that the latter can be part of the project itself, just like gitignore. So we could just push that .gitattribute file upstream, and then labels without leading spaces would no longer be a problem, at least within git. It would still be a problem for me as an inveterate quilt user, at least until GNU diff gets "fixed." Which I did not even try, as I'm not sure if upstream really considers this a bug in the first place.

And just for completeness, git's "cpp" predefined pattern doesn't actually support $ as part of identifiers.

Signature · 2 lines
Jean Delvare
SUSE L3 Support
maintainer
#660 lore raw

Re: sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

Quoted 5 lines · Jean Delvare
Quoted 2 lines

[diff "default"]

        xfuncname = "^[[:alpha:]$_].*[^:]$"

OK, I see. As mentioned somewhere else, it fails for labels which have comments.

Heh, There's labels that have comments?

Quoted 4 lines

My worry is that you recommending it to contributors on a individual and opportunity basis, doesn't scale. Basing coding style recommendations on a personal quirk doesn't strike me as the best idea ever in the long run.

Don't care too much, I simply will not take any patch that adds stupid spaces :-)

Quoted 7 lines

While looking at the syntax of your example, I have found something which looks more promising. git already has predefined xfuncname definitions for various languages, including C. These can be enabled based on file name patterns via gitattributes. The following .gitattribute file placed at the root of the kernel source tree achieves what you want:

Quoted 8 lines

*.c diff=cpp
*.h diff=cpp

The major difference between git config and gitattributes is that the latter can be part of the project itself, just like gitignore. So we could just push that .gitattribute file upstream, and then labels without leading spaces would no longer be a problem, at least within git.

Works for me, and last time this came up Linus agreed with the "whitespace before labels is stupid" thing. Although I cannot find a link to that just now.

Quoted 1 line

It would still be a problem for me as an inveterate quilt user,

Add the below to your .quiltrc or environment:

QUILT_DIFF_OPTS="-F ^[[:alpha:]\$_].*[^:]\$"

Same caveat about labels with comments, but then I'd not take a patch doing that in the first place.

maintainer
#661 lore raw

Re: sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Jean Delvare
Quoted 2 lines

[diff "default"]
        xfuncname = "^[[:alpha:]$_].*[^:]$"

OK, I see. As mentioned somewhere else, it fails for labels which have comments.

Heh, There's labels that have comments?

Only a few dozen.

The pattern with the perl-like $_ took me a depressingly long time to parse followed by a self forehead slap.

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

#662 lore raw

Re: sparc: bpf_jit: Rename jump labels in bpf_jit_compile()

In reply to Peter Zijlstra

Hi Peter,

Quoted 8 lines · Peter Zijlstra
Quoted 5 lines · Jean Delvare
Quoted 2 lines

[diff "default"]

        xfuncname = "^[[:alpha:]$_].*[^:]$"

OK, I see. As mentioned somewhere else, it fails for labels which have comments.

Heh, There's labels that have comments?

Yes, 43.

Quoted 18 lines
Quoted 4 lines

My worry is that you recommending it to contributors on a individual and opportunity basis, doesn't scale. Basing coding style recommendations on a personal quirk doesn't strike me as the best idea ever in the long run.

Don't care too much, I simply will not take any patch that adds stupid spaces :-)

Quoted 10 lines

While looking at the syntax of your example, I have found something which looks more promising. git already has predefined xfuncname definitions for various languages, including C. These can be enabled based on file name patterns via gitattributes. The following .gitattribute file placed at the root of the kernel source tree achieves what you want:

*.c diff=cpp
*.h diff=cpp

Quoted 7 lines
Quoted 5 lines

The major difference between git config and gitattributes is that the latter can be part of the project itself, just like gitignore. So we could just push that .gitattribute file upstream, and then labels without leading spaces would no longer be a problem, at least within git.

Works for me,

OK, I'll send a patch now.

Quoted 3 lines

and last time this came up Linus agreed with the "whitespace before labels is stupid" thing. Although I cannot find a link to that just now.

Murphy's law applies, you can never find links again the day you desperately need them. If you ever get your hands on that one again, please let me know, I really would like to read that post.

Quoted 5 lines
Quoted 1 line

It would still be a problem for me as an inveterate quilt user,

Add the below to your .quiltrc or environment:

QUILT_DIFF_OPTS="-F ^[[:alpha:]\$_].*[^:]\$"

I didn't know this option existed, thanks for the pointer.

Now I'm sure I won't try to get the behavior of GNU diff option -p changed, as I think I know what the answer would be.

Quoted 2 lines

Same caveat about labels with comments, but then I'd not take a patch doing that in the first place.

I'll improve the regular expression if I ever have to (I don't think a function declaration can have a colon anywhere?), but I'm happy if it works in 99.9 % of the cases, thank sagain.

Signature · 2 lines
Jean Delvare
SUSE L3 Support
#663 lore raw

cover tile-module: Fine-tuning for module_alloc()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 20:52:10 +0200

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

Markus Elfring (2):
Use kmalloc_array()
Rename jump labels

 arch/tile/kernel/module.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
Signature · 1 line
2.9.3
#664 lore raw

PATCH 1/2 tile-module: Use kmalloc_array() in module_alloc()

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 20:40:57 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 arch/tile/kernel/module.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/tile/kernel/module.c +1 -1
index 2305084..dce4120 100644
@@ -43,7 +43,7 @@ void *module_alloc(unsigned long size)
 	int npages;
 
 	npages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
-	pages = kmalloc(npages * sizeof(struct page *), GFP_KERNEL);
+	pages = kmalloc_array(npages, sizeof(*pages), GFP_KERNEL);
 	if (pages = NULL)
 		return NULL;
 	for (; i < npages; ++i) {
Signature · 1 line
2.9.3
#665 lore raw

PATCH 2/2 tile-module: Rename jump labels in module_alloc()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 20:45:20 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 arch/tile/kernel/module.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
arch/tile/kernel/module.c +4 -5
index dce4120..09233fb 100644
@@ -49,23 +49,22 @@ void *module_alloc(unsigned long size)
 	for (; i < npages; ++i) {
 		pages[i] = alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
 		if (!pages[i])
-			goto error;
+			goto free_pages;
 	}
 
 	area = __get_vm_area(size, VM_ALLOC, MEM_MODULE_START, MEM_MODULE_END);
 	if (!area)
-		goto error;
+		goto free_pages;
 	area->nr_pages = npages;
 	area->pages = pages;
 
 	if (map_vm_area(area, prot_rwx, pages)) {
 		vunmap(area->addr);
-		goto error;
+		goto free_pages;
 	}
 
 	return area->addr;
-
-error:
+ free_pages:
 	while (--i >= 0)
 		__free_page(pages[i]);
 	kfree(pages);
Signature · 1 line
2.9.3
#666 lore raw

Re: [PATCH 0/2] tile-module: Fine-tuning for module_alloc()

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

From: Markus Elfring <[email protected]>
Date: Sat, 3 Sep 2016 20:52:10 +0200

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

Quoted 6 lines

Markus Elfring (2):
Use kmalloc_array()
Rename jump labels

  arch/tile/kernel/module.c | 11 +++++------
  1 file changed, 5 insertions(+), 6 deletions(-)

Thanks! Taken into the tile tree.

Signature · 2 lines
Chris Metcalf, Mellanox Technologies
http://www.mellanox.com
#667 lore raw

cover perf/x86/cqm: Fine-tuning for two function implementations

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 4 Sep 2016 19:40:40 +0200

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

Markus Elfring (4):
Use kmalloc_array() in intel_mbm_init()
Replace two kmalloc() calls by kmalloc_array() in intel_mbm_init() One check and another variable less in intel_mbm_init() Rename jump labels in intel_cqm_init()

 arch/x86/events/intel/cqm.c | 52 ++++++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 27 deletions(-)
Signature · 1 line
2.9.3
#668 lore raw

PATCH 1/4 perf/x86/cqm: Use kmalloc_array() in intel_mbm_init()

From: Markus Elfring <[email protected]>
Date: Sun, 4 Sep 2016 17:28:13 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 arch/x86/events/intel/cqm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/events/intel/cqm.c +3 -2
index 783c49d..ec61522 100644
@@ -1651,8 +1651,9 @@ static int intel_mbm_init(void)
 		goto out;
 	}
 
-	array_size = sizeof(struct hrtimer) * mbm_socket_max;
-	mbm_timers = kmalloc(array_size, GFP_KERNEL);
+	mbm_timers = kmalloc_array(mbm_socket_max,
+				   sizeof(*mbm_timers),
+				   GFP_KERNEL);
 	if (!mbm_timers) {
 		ret = -ENOMEM;
 		goto out;
Signature · 1 line
2.9.3
maintainer
#669 lore raw

Re: [PATCH 1/4] perf/x86/cqm: Use kmalloc_array() in intel_mbm_init()

Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 4 Sep 2016 17:28:13 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

Quoted 5 lines

This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

Again, lack of actual reason..

#670 lore raw

PATCH 2/4 perf/x86/cqm: Replace two kmalloc() calls by kmalloc_array() in intel_mbm_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 4 Sep 2016 18:25:09 +0200

1. A multiplication for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kmalloc_array".

2. Replace the specification of a data structure by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.

3. Delete the local variable "array_size" which became unnecessary with this refactoring.

---
 arch/x86/events/intel/cqm.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
arch/x86/events/intel/cqm.c +7 -4
index ec61522..29f756e 100644
@@ -1637,15 +1637,18 @@ static const struct x86_cpu_id intel_mbm_total_match[] = {
 
 static int intel_mbm_init(void)
 {
-	int ret = 0, array_size, maxid = cqm_max_rmid + 1;
+	int ret = 0, maxid = cqm_max_rmid + 1;
 
 	mbm_socket_max = topology_max_packages();
-	array_size = sizeof(struct sample) * maxid * mbm_socket_max;
-	mbm_local = kmalloc(array_size, GFP_KERNEL);
+	mbm_local = kmalloc_array(maxid * mbm_socket_max,
+				  sizeof(*mbm_local),
+				  GFP_KERNEL);
 	if (!mbm_local)
 		return -ENOMEM;
 
-	mbm_total = kmalloc(array_size, GFP_KERNEL);
+	mbm_total = kmalloc_array(maxid * mbm_socket_max,
+				  sizeof(*mbm_total),
+				  GFP_KERNEL);
 	if (!mbm_total) {
 		ret = -ENOMEM;
 		goto out;
Signature · 1 line
2.9.3
maintainer
#671 lore raw

Re: [PATCH 2/4] perf/x86/cqm: Replace two kmalloc() calls by kmalloc_array() in intel_mbm_init()

Quoted 7 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 4 Sep 2016 18:25:09 +0200

1. A multiplication for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kmalloc_array".

Quoted 6 lines

2. Replace the specification of a data structure by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention.

3. Delete the local variable "array_size" which became unnecessary with this refactoring.

3 is an admission you made the code worse in absense of other improvements.

#672 lore raw

PATCH 3/4 perf/x86/cqm: One check and another variable less in intel_mbm_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 4 Sep 2016 19:06:33 +0200

1. Adjust a jump target to eliminate an extra check at the end.

2. Move a jump label according to the current Linux coding style convention.

3. Return only constant values for the success or failure indication.

4. Delete the local variable "ret" which became unnecessary with this refactoring.

---
 arch/x86/events/intel/cqm.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
arch/x86/events/intel/cqm.c +10 -15
index 29f756e..304caf53 100644
@@ -1637,7 +1637,7 @@ static const struct x86_cpu_id intel_mbm_total_match[] = {
 
 static int intel_mbm_init(void)
 {
-	int ret = 0, maxid = cqm_max_rmid + 1;
+	int const maxid = cqm_max_rmid + 1;
 
 	mbm_socket_max = topology_max_packages();
 	mbm_local = kmalloc_array(maxid * mbm_socket_max,
@@ -1649,25 +1649,20 @@ static int intel_mbm_init(void)
 	mbm_total = kmalloc_array(maxid * mbm_socket_max,
 				  sizeof(*mbm_total),
 				  GFP_KERNEL);
-	if (!mbm_total) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	if (!mbm_total)
+		goto free_mbm;
 
 	mbm_timers = kmalloc_array(mbm_socket_max,
 				   sizeof(*mbm_timers),
 				   GFP_KERNEL);
-	if (!mbm_timers) {
-		ret = -ENOMEM;
-		goto out;
-	}
-	mbm_hrtimer_init();
+	if (!mbm_timers)
+		goto free_mbm;
 
-out:
-	if (ret)
-		mbm_cleanup();
-
-	return ret;
+	mbm_hrtimer_init();
+	return 0;
+ free_mbm:
+	mbm_cleanup();
+	return -ENOMEM;
 }
 
 static int __init intel_cqm_init(void)
Signature · 1 line
2.9.3
maintainer
#673 lore raw

Re: [PATCH 3/4] perf/x86/cqm: One check and another variable less in intel_mbm_init()

Quoted 6 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 4 Sep 2016 19:06:33 +0200

1. Adjust a jump target to eliminate an extra check at the end.

2. Move a jump label according to the current Linux coding style convention.

WTF does that even mean?

Quoted 5 lines

3. Return only constant values for the success or failure indication.

4. Delete the local variable "ret" which became unnecessary with this refactoring.

Also, 4 things should be 4 patches if anything.

Quoted 39 lines
---
 arch/x86/events/intel/cqm.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)
arch/x86/events/intel/cqm.c +4 -10
index 29f756e..304caf53 100644
@@ -1637,7 +1637,7 @@ static const struct x86_cpu_id intel_mbm_total_match[] = {
 
 static int intel_mbm_init(void)
 {
-	int ret = 0, maxid = cqm_max_rmid + 1;
+	int const maxid = cqm_max_rmid + 1;
 
 	mbm_socket_max = topology_max_packages();
 	mbm_local = kmalloc_array(maxid * mbm_socket_max,
@@ -1649,25 +1649,20 @@ static int intel_mbm_init(void)
 	mbm_total = kmalloc_array(maxid * mbm_socket_max,
 				  sizeof(*mbm_total),
 				  GFP_KERNEL);
-	if (!mbm_total) {
-		ret = -ENOMEM;
-		goto out;
-	}
+	if (!mbm_total)
+		goto free_mbm;
 
 	mbm_timers = kmalloc_array(mbm_socket_max,
 				   sizeof(*mbm_timers),
 				   GFP_KERNEL);
-	if (!mbm_timers) {
-		ret = -ENOMEM;
-		goto out;
-	}
-	mbm_hrtimer_init();
+	if (!mbm_timers)

arch/x86/events/intel/cqm.c static int intel_mbm_init(void) · line 1663

Quoted 10 lines
arch/x86/events/intel/cqm.c +4 -5
+		goto free_mbm;
 
-out:
-	if (ret)
-		mbm_cleanup();
-
-	return ret;
+	mbm_hrtimer_init();
+	return 0;
+ free_mbm:

No!! no stupid indented labels.

Quoted 3 lines
arch/x86/events/intel/cqm.c +2 -0
+	mbm_cleanup();
+	return -ENOMEM;
 }
#674 lore raw

PATCH 4/4 perf/x86/cqm: Rename jump labels in intel_cqm_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 4 Sep 2016 19:23:57 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 arch/x86/events/intel/cqm.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
arch/x86/events/intel/cqm.c +6 -7
index 304caf53..6cf508a 100644
@@ -1701,7 +1701,7 @@ static int __init intel_cqm_init(void)
 		if (c->x86_cache_occ_scale != cqm_l3_scale) {
 			pr_err("Multiple LLC scale values, disabling\n");
 			ret = -EINVAL;
-			goto out;
+			goto put_cpus;
 		}
 	}
 
@@ -1719,19 +1719,19 @@ static int __init intel_cqm_init(void)
 	str = kstrdup(scale, GFP_KERNEL);
 	if (!str) {
 		ret = -ENOMEM;
-		goto out;
+		goto put_cpus;
 	}
 
 	event_attr_intel_cqm_llc_scale.event_str = str;
 
 	ret = intel_cqm_setup_rmid_cache();
 	if (ret)
-		goto out;
+		goto put_cpus;
 
 	if (mbm_enabled)
 		ret = intel_mbm_init();
 	if (ret && !cqm_enabled)
-		goto out;
+		goto put_cpus;
 
 	if (cqm_enabled && mbm_enabled)
 		intel_cqm_events_group.attrs = intel_cmt_mbm_events_attr;
@@ -1743,7 +1743,7 @@ static int __init intel_cqm_init(void)
 	ret = perf_pmu_register(&intel_cqm_pmu, "intel_cqm", -1);
 	if (ret) {
 		pr_err("Intel CQM perf registration failed: %d\n", ret);
-		goto out;
+		goto put_cpus;
 	}
 
 	if (cqm_enabled)
@@ -1760,8 +1760,7 @@ static int __init intel_cqm_init(void)
 			  intel_cqm_cpu_starting, NULL);
 	cpuhp_setup_state(CPUHP_AP_PERF_X86_CQM_ONLINE, "AP_PERF_X86_CQM_ONLINE",
 			  NULL, intel_cqm_cpu_exit);
-
-out:
+ put_cpus:
 	put_online_cpus();
 
 	if (ret) {
Signature · 1 line
2.9.3
#676 lore raw

cover ACPI-video: Fine-tuning for several function implementations

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 18:22:11 +0200

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

Markus Elfring (21):
Use kmalloc_array() in acpi_video_get_levels()
Return directly after a failed device query
Delete an error message for a failed kzalloc() call
Rename jump labels in acpi_video_get_levels()
Delete an unnecessary initialisation in acpi_video_get_levels() Move four assignments in acpi_video_get_levels()
Rename jump labels in acpi_video_bus_add()
Improve a size determination in acpi_video_bus_add() Rename jump labels in acpi_video_register()
Return directly after a failed input_allocate_device() Rename jump labels in acpi_video_bus_add_notify_handler() Delete unnecessary if statement in acpi_video_switch_brightness() Improve a jump target in acpi_video_switch_brightness() Improve a size determination in acpi_video_device_enumerate() Delete an unnecessary initialisation in acpi_video_device_enumerate() Rename jump labels in acpi_video_device_enumerate()
Delete an unnecessary initialisation in acpi_video_init_brightness() Rename jump labels in acpi_video_init_brightness()
Rename a jump label in acpi_video_device_lcd_query_levels() Improve a size determination in acpi_video_dev_register_backlight() Improve a size determination in acpi_video_bus_get_one_device()

 drivers/acpi/acpi_video.c | 114 +++++++++++++++++++++-------------------------
 1 file changed, 52 insertions(+), 62 deletions(-)
Signature · 1 line
2.10.0
#677 lore raw

PATCH 1/21 ACPI-video: Use kmalloc_array() in acpi_video_get_levels()

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 11:33:30 +0200

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

---
 drivers/acpi/acpi_video.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/acpi/acpi_video.c +3 -2
index c5557d0..3d39b53 100644
@@ -784,8 +784,9 @@ int acpi_video_get_levels(struct acpi_device *device,
 		goto out;
 	}
 
-	br->levels = kmalloc((obj->package.count + 2) * sizeof *(br->levels),
-				GFP_KERNEL);
+	br->levels = kmalloc_array(obj->package.count + 2,
+				   sizeof(*br->levels),
+				   GFP_KERNEL);
 	if (!br->levels) {
 		result = -ENOMEM;
 		goto out_free;
Signature · 1 line
2.10.0
#678 lore raw

PATCH 2/21 ACPI-video: Return directly after a failed device query

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 13:25:01 +0200

Return directly after a function call "acpi_video_device_lcd_query_levels" failed at the beginning.

---
 drivers/acpi/acpi_video.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/acpi/acpi_video.c +1 -2
index 3d39b53..8f0807a 100644
@@ -768,8 +768,7 @@ int acpi_video_get_levels(struct acpi_device *device,
 								&obj))) {
 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
 						"LCD brightness level\n"));
-		result = -ENODEV;
-		goto out;
+		return -ENODEV;
 	}
 
 	if (obj->package.count < 2) {
Signature · 1 line
2.10.0
#679 lore raw

PATCH 3/21 ACPI-video: Delete an error message for a failed kzalloc() call

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 13:57:33 +0200

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

---
 drivers/acpi/acpi_video.c | 1 -
 1 file changed, 1 deletion(-)
drivers/acpi/acpi_video.c +0 -1
index 8f0807a..420d125 100644
@@ -778,7 +778,6 @@ int acpi_video_get_levels(struct acpi_device *device,
 
 	br = kzalloc(sizeof(*br), GFP_KERNEL);
 	if (!br) {
-		printk(KERN_ERR "can't allocate memory\n");
 		result = -ENOMEM;
 		goto out;
 	}
Signature · 1 line
2.10.0
#680 lore raw

PATCH 4/21 ACPI-video: Rename jump labels in acpi_video_get_levels()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 14:11:43 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 drivers/acpi/acpi_video.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/acpi/acpi_video.c +6 -7
index 420d125..82987db 100644
@@ -773,13 +773,13 @@ int acpi_video_get_levels(struct acpi_device *device,
 
 	if (obj->package.count < 2) {
 		result = -EINVAL;
-		goto out;
+		goto free_object;
 	}
 
 	br = kzalloc(sizeof(*br), GFP_KERNEL);
 	if (!br) {
 		result = -ENOMEM;
-		goto out;
+		goto free_object;
 	}
 
 	br->levels = kmalloc_array(obj->package.count + 2,
@@ -787,7 +787,7 @@ int acpi_video_get_levels(struct acpi_device *device,
 				   GFP_KERNEL);
 	if (!br->levels) {
 		result = -ENOMEM;
-		goto out_free;
+		goto free_brightness;
 	}
 
 	for (i = 0; i < obj->package.count; i++) {
@@ -843,13 +843,12 @@ int acpi_video_get_levels(struct acpi_device *device,
 	*dev_br = br;
 	if (pmax_level)
 		*pmax_level = max_level;
-
-out:
+ free_object:
 	kfree(obj);
 	return result;
-out_free:
+ free_brightness:
 	kfree(br);
-	goto out;
+	goto free_object;
 }
 EXPORT_SYMBOL(acpi_video_get_levels);
 
Signature · 1 line
2.10.0
#681 lore raw

PATCH 5/21 ACPI-video: Delete an unnecessary initialisation in acpi_video_get_levels()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 14:23:55 +0200

The local variable "br" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

---
 drivers/acpi/acpi_video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_video.c +1 -1
index 82987db..0799865 100644
@@ -760,7 +760,7 @@ int acpi_video_get_levels(struct acpi_device *device,
 	union acpi_object *obj = NULL;
 	int i, max_level = 0, count = 0, level_ac_battery = 0;
 	union acpi_object *o;
-	struct acpi_video_device_brightness *br = NULL;
+	struct acpi_video_device_brightness *br;
 	int result = 0;
 	u32 value;
 
Signature · 1 line
2.10.0
#682 lore raw

PATCH 6/21 ACPI-video: Move four assignments in acpi_video_get_levels()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 14:40:46 +0200

Move the assignments for four local variables so that they will only be performed if the corresponding data processing succeeded by this function.

---
 drivers/acpi/acpi_video.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/acpi/acpi_video.c +6 -2
index 0799865..0fca196 100644
@@ -758,10 +758,10 @@ int acpi_video_get_levels(struct acpi_device *device,
 			  int *pmax_level)
 {
 	union acpi_object *obj = NULL;
-	int i, max_level = 0, count = 0, level_ac_battery = 0;
+	int i, max_level, count, level_ac_battery;
 	union acpi_object *o;
 	struct acpi_video_device_brightness *br;
-	int result = 0;
+	int result;
 	u32 value;
 
 	if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device->handle,
@@ -790,6 +790,8 @@ int acpi_video_get_levels(struct acpi_device *device,
 		goto free_brightness;
 	}
 
+	max_level = 0;
+	count = 0;
 	for (i = 0; i < obj->package.count; i++) {
 		o = (union acpi_object *)&obj->package.elements[i];
 		if (o->type != ACPI_TYPE_INTEGER) {
@@ -814,6 +816,7 @@ int acpi_video_get_levels(struct acpi_device *device,
 	 * In this case, the first two elements in _BCL packages
 	 * are also supported brightness levels that OS should take care of.
 	 */
+	level_ac_battery = 0;
 	for (i = 2; i < count; i++) {
 		if (br->levels[i] = br->levels[0])
 			level_ac_battery++;
@@ -843,6 +846,7 @@ int acpi_video_get_levels(struct acpi_device *device,
 	*dev_br = br;
 	if (pmax_level)
 		*pmax_level = max_level;
+	result = 0;
  free_object:
 	kfree(obj);
 	return result;
Signature · 1 line
2.10.0
#683 lore raw

PATCH 7/21 ACPI-video: Rename jump labels in acpi_video_bus_add()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 15:01:23 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 drivers/acpi/acpi_video.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/acpi/acpi_video.c +4 -5
index 0fca196..8003c90 100644
@@ -1983,14 +1983,14 @@ static int acpi_video_bus_add(struct acpi_device *device)
 	acpi_video_bus_find_cap(video);
 	error = acpi_video_bus_check(video);
 	if (error)
-		goto err_free_video;
+		goto free_video;
 
 	mutex_init(&video->device_list_lock);
 	INIT_LIST_HEAD(&video->video_device_list);
 
 	error = acpi_video_bus_get_devices(video, device);
 	if (error)
-		goto err_put_video;
+		goto put_devices;
 
 	printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s  rom: %s  post: %s)\n",
 	       ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
@@ -2005,11 +2005,10 @@ static int acpi_video_bus_add(struct acpi_device *device)
 	acpi_video_bus_add_notify_handler(video);
 
 	return 0;
-
-err_put_video:
+ put_devices:
 	acpi_video_bus_put_devices(video);
 	kfree(video->attached_array);
-err_free_video:
+ free_video:
 	kfree(video);
 	device->driver_data = NULL;
 
Signature · 1 line
2.10.0
#684 lore raw

PATCH 8/21 ACPI-video: Improve a size determination in acpi_video_bus_add()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 15:16:26 +0200

Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/acpi/acpi_video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_video.c +1 -1
index 8003c90..c9fbc6e 100644
@@ -1958,7 +1958,7 @@ static int acpi_video_bus_add(struct acpi_device *device)
 			return -ENODEV;
 	}
 
-	video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
+	video = kzalloc(sizeof(*video), GFP_KERNEL);
 	if (!video)
 		return -ENOMEM;
 
Signature · 1 line
2.10.0
#685 lore raw

PATCH 9/21 ACPI-video: Rename jump labels in acpi_video_register()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 15:28:12 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 drivers/acpi/acpi_video.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/acpi/acpi_video.c +3 -4
index c9fbc6e..74e5a40 100644
@@ -2080,22 +2080,21 @@ int acpi_video_register(void)
 		 * if the function of acpi_video_register is already called,
 		 * don't register the acpi_vide_bus again and return no error.
 		 */
-		goto leave;
+		goto unlock;
 	}
 
 	dmi_check_system(video_dmi_table);
 
 	ret = acpi_bus_register_driver(&acpi_video_bus);
 	if (ret)
-		goto leave;
+		goto unlock;
 
 	/*
 	 * When the acpi_video_bus is loaded successfully, increase
 	 * the counter reference.
 	 */
 	register_count = 1;
-
-leave:
+ unlock:
 	mutex_unlock(&register_count_mutex);
 	return ret;
 }
Signature · 1 line
2.10.0
#686 lore raw

PATCH 10/21 ACPI-video: Return directly after a failed input_allocate_device()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 15:46:19 +0200

* Return directly after a call of the function "input_allocate_device" failed at the beginning.

* Delete the jump label "out" which became unnecessary with this refactoring.

---
 drivers/acpi/acpi_video.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/acpi/acpi_video.c +2 -5
index 74e5a40..6c871dd 100644
@@ -1852,10 +1852,8 @@ static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video)
 	int error;
 
 	video->input = input = input_allocate_device();
-	if (!input) {
-		error = -ENOMEM;
-		goto out;
-	}
+	if (!input)
+		return -ENOMEM;
 
 	error = acpi_video_bus_start_devices(video);
 	if (error)
@@ -1895,7 +1893,6 @@ err_stop_dev:
 err_free_input:
 	input_free_device(input);
 	video->input = NULL;
-out:
 	return error;
 }
 
Signature · 1 line
2.10.0
#687 lore raw

PATCH 11/21 ACPI-video: Rename jump labels in acpi_video_bus_add_notify_handler()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 15:50:12 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 drivers/acpi/acpi_video.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/acpi/acpi_video.c +4 -5
index 6c871dd..fe9b40e 100644
@@ -1857,7 +1857,7 @@ static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video)
 
 	error = acpi_video_bus_start_devices(video);
 	if (error)
-		goto err_free_input;
+		goto free_device;
 
 	snprintf(video->phys, sizeof(video->phys),
 			"%s/video/input0", acpi_device_hid(video->device));
@@ -1879,7 +1879,7 @@ static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video)
 
 	error = input_register_device(input);
 	if (error)
-		goto err_stop_dev;
+		goto stop_devices;
 
 	mutex_lock(&video->device_list_lock);
 	list_for_each_entry(dev, &video->video_device_list, entry)
@@ -1887,10 +1887,9 @@ static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video)
 	mutex_unlock(&video->device_list_lock);
 
 	return 0;
-
-err_stop_dev:
+ stop_devices:
 	acpi_video_bus_stop_devices(video);
-err_free_input:
+ free_device:
 	input_free_device(input);
 	video->input = NULL;
 	return error;
Signature · 1 line
2.10.0
#688 lore raw

PATCH 12/21 ACPI-video: Delete unnecessary if statement in acpi_video_switch_brightness()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 16:10:40 +0200

Move a function call into an else branch for successful function execution. Omit a duplicate check for the local variable "result" then at the end.

---
 drivers/acpi/acpi_video.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/acpi/acpi_video.c +3 -5
index fe9b40e..0362a43 100644
@@ -1372,14 +1372,12 @@ acpi_video_switch_brightness(struct work_struct *work)
 	level_next = acpi_video_get_next_level(device, level_current, event);
 
 	result = acpi_video_device_lcd_set_level(device, level_next);
-
-	if (!result)
-		backlight_force_update(device->backlight,
-				       BACKLIGHT_UPDATE_HOTKEY);
-
 out:
 	if (result)
 		printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
+	else
+		backlight_force_update(device->backlight,
+				       BACKLIGHT_UPDATE_HOTKEY);
 }
 
 int acpi_video_get_edid(struct acpi_device *device, int type, int device_id,
Signature · 1 line
2.10.0
#689 lore raw

PATCH 13/21 ACPI-video: Improve a jump target in acpi_video_switch_brightness()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 16:34:08 +0200

* Avoid another duplicate check for the local variable "result" then at the end.

* Jump directly to an error message in the case that the desired brightness can not be switched.

---
 drivers/acpi/acpi_video.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/acpi/acpi_video.c +3 -3
index 0362a43..fe10d3f 100644
@@ -1361,19 +1361,19 @@ acpi_video_switch_brightness(struct work_struct *work)
 		return;
 
 	if (!device->brightness)
-		goto out;
+		goto report_failure;
 
 	result = acpi_video_device_lcd_get_level_current(device,
 							 &level_current,
 							 false);
 	if (result)
-		goto out;
+		goto report_failure;
 
 	level_next = acpi_video_get_next_level(device, level_current, event);
 
 	result = acpi_video_device_lcd_set_level(device, level_next);
-out:
 	if (result)
+ report_failure:
 		printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
 	else
 		backlight_force_update(device->backlight,
Signature · 1 line
2.10.0
#690 lore raw

PATCH 14/21 ACPI-video: Improve a size determination in acpi_video_device_enumerate()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 16:45:41 +0200

Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/acpi/acpi_video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_video.c +1 -1
index fe10d3f..df06390 100644
@@ -1268,7 +1268,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
 			  dod->package.count));
 
 	active_list = kcalloc(1 + dod->package.count,
-			      sizeof(struct acpi_video_enumerated_device),
+			      sizeof(*active_list),
 			      GFP_KERNEL);
 	if (!active_list) {
 		status = -ENOMEM;
Signature · 1 line
2.10.0
#691 lore raw

PATCH 15/21 ACPI-video: Delete an unnecessary initialisation in acpi_video_device_enumerate()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 16:54:55 +0200

The local variable "dod" will be set to an appropriate value a bit later. Thus omit the explicit initialisation at the beginning.

---
 drivers/acpi/acpi_video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_video.c +1 -1
index df06390..fcf74e7 100644
@@ -1245,7 +1245,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
 	int i;
 	struct acpi_video_enumerated_device *active_list;
 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-	union acpi_object *dod = NULL;
+	union acpi_object *dod;
 	union acpi_object *obj;
 
 	if (!video->cap._DOD)
Signature · 1 line
2.10.0
#692 lore raw

PATCH 16/21 ACPI-video: Rename jump labels in acpi_video_device_enumerate()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 17:01:30 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 drivers/acpi/acpi_video.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/acpi/acpi_video.c +3 -4
index fcf74e7..2fc775a 100644
@@ -1261,7 +1261,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
 	if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
 		ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
 		status = -EFAULT;
-		goto out;
+		goto free_buffer;
 	}
 
 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
@@ -1272,7 +1272,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
 			      GFP_KERNEL);
 	if (!active_list) {
 		status = -ENOMEM;
-		goto out;
+		goto free_buffer;
 	}
 
 	count = 0;
@@ -1296,8 +1296,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
 
 	video->attached_array = active_list;
 	video->attached_count = count;
-
-out:
+ free_buffer:
 	kfree(buffer.pointer);
 	return status;
 }
Signature · 1 line
2.10.0
#693 lore raw

PATCH 17/21 ACPI-video: Delete an unnecessary initialisation in acpi_video_init_brightness()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 17:20:22 +0200

The local variable "result" will be assigned with a statement that follows it directly. Thus omit the explicit initialisation at the beginning.

---
 drivers/acpi/acpi_video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_video.c +1 -1
index 2fc775a..5f1ef6e 100644
@@ -872,7 +872,7 @@ acpi_video_init_brightness(struct acpi_video_device *device)
 	int i, max_level = 0;
 	unsigned long long level, level_old;
 	struct acpi_video_device_brightness *br = NULL;
-	int result = -EINVAL;
+	int result;
 
 	result = acpi_video_get_levels(device->dev, &br, &max_level);
 	if (result)
Signature · 1 line
2.10.0
#694 lore raw

PATCH 18/21 ACPI-video: Rename jump labels in acpi_video_init_brightness()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 17:28:45 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 drivers/acpi/acpi_video.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/acpi/acpi_video.c +5 -7
index 5f1ef6e..5566f68 100644
@@ -888,11 +888,11 @@ acpi_video_init_brightness(struct acpi_video_device *device)
 	result = acpi_video_device_lcd_get_level_current(device,
 							 &level_old, true);
 	if (result)
-		goto out_free_levels;
+		goto free_levels;
 
 	result = acpi_video_bqc_quirk(device, max_level, level_old);
 	if (result)
-		goto out_free_levels;
+		goto free_levels;
 	/*
 	 * cap._BQC may get cleared due to _BQC is found to be broken
 	 * in acpi_video_bqc_quirk, so check again here.
@@ -912,17 +912,15 @@ acpi_video_init_brightness(struct acpi_video_device *device)
 			break;
 	if (i = br->count || !level)
 		level = max_level;
-
-set_level:
+ set_level:
 	result = acpi_video_device_lcd_set_level(device, level);
 	if (result)
-		goto out_free_levels;
+		goto free_levels;
 
 	ACPI_DEBUG_PRINT((ACPI_DB_INFO,
 			  "found %d brightness levels\n", br->count - 2));
 	return 0;
-
-out_free_levels:
+ free_levels:
 	kfree(br->levels);
 	kfree(br);
 	device->brightness = NULL;
Signature · 1 line
2.10.0
#695 lore raw

PATCH 19/21 ACPI-video: Rename a jump label in acpi_video_device_lcd_query_levels()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 17:34:40 +0200

Adjust a jump label according to the current Linux coding style convention.

---
 drivers/acpi/acpi_video.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/acpi/acpi_video.c +2 -3
index 5566f68..231fab3 100644
@@ -329,14 +329,13 @@ acpi_video_device_lcd_query_levels(acpi_handle handle,
 	if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
 		printk(KERN_ERR PREFIX "Invalid _BCL data\n");
 		status = -EFAULT;
-		goto err;
+		goto free_buffer;
 	}
 
 	*levels = obj;
 
 	return 0;
-
-err:
+ free_buffer:
 	kfree(buffer.pointer);
 
 	return status;
Signature · 1 line
2.10.0
#696 lore raw

PATCH 20/21 ACPI-video: Improve a size determination in acpi_video_dev_register_backlight()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 17:45:40 +0200

Replace the specification of a data structure by a reference for a local variable as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/acpi/acpi_video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_video.c +1 -1
index 231fab3..9685725 100644
@@ -1685,7 +1685,7 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
 		pci_dev_put(pdev);
 	}
 
-	memset(&props, 0, sizeof(struct backlight_properties));
+	memset(&props, 0, sizeof(props));
 	props.type = BACKLIGHT_FIRMWARE;
 	props.max_brightness = device->brightness->count - 3;
 	device->backlight = backlight_device_register(name,
Signature · 1 line
2.10.0
#697 lore raw

PATCH 21/21 ACPI-video: Improve a size determination in acpi_video_bus_get_one_device()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 17:50:04 +0200

Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/acpi/acpi_video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/acpi_video.c +1 -1
index 9685725..4cd693e 100644
@@ -1084,7 +1084,7 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
 	if (ACPI_FAILURE(status))
 		return 0;
 
-	data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
+	data = kzalloc(sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
Signature · 1 line
2.10.0
#698 lore raw

Re: [PATCH 00/21] ACPI-video: Fine-tuning for several function implementations

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

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 18:22:11 +0200

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

Markus Elfring (21):
Use kmalloc_array() in acpi_video_get_levels()
Return directly after a failed device query
Delete an error message for a failed kzalloc() call Rename jump labels in acpi_video_get_levels()
Delete an unnecessary initialisation in acpi_video_get_levels() Move four assignments in acpi_video_get_levels() Rename jump labels in acpi_video_bus_add()
Improve a size determination in acpi_video_bus_add() Rename jump labels in acpi_video_register()
Return directly after a failed input_allocate_device() Rename jump labels in acpi_video_bus_add_notify_handler() Delete unnecessary if statement in acpi_video_switch_brightness() Improve a jump target in acpi_video_switch_brightness()

Quoted 8 lines

Improve a size determination in acpi_video_device_enumerate() Delete an unnecessary initialisation in acpi_video_device_enumerate() Rename jump labels in acpi_video_device_enumerate()
Delete an unnecessary initialisation in acpi_video_init_brightness() Rename jump labels in acpi_video_init_brightness()
Rename a jump label in acpi_video_device_lcd_query_levels() Improve a size determination in acpi_video_dev_register_backlight() Improve a size determination in acpi_video_bus_get_one_device()

I'd prefer this to be combined into fewer patches that each will address several issues of one type, ie. put all label renames into one patch, all size determination improvements into another one and so on.

Thanks,
Rafael

#699 lore raw

Re: ACPI-video: Fine-tuning for several function implementations

Quoted 2 lines

I'd prefer this to be combined into fewer patches that each will address several issues of one type,

I understand your concern a bit in principle.

Quoted 1 line

ie. put all label renames into one patch,

Are any of my update suggestions controversial here?

Quoted 1 line

all size determination improvements into another one and so on.

I am unsure about the acceptance for the selected software change opportunities. So I chose a very specific patch granularity intentionally.

I tend to provide some change ideas for each affected function implementation individually. I imagine that this way should support the recombination of update steps to some degree already, shouldn't it?

Regards,
Markus

#700 lore raw

Re: ACPI-video: Fine-tuning for several function implementations

Quoted 9 lines · SF Markus Elfring
Quoted 2 lines

I'd prefer this to be combined into fewer patches that each will address several issues of one type,

I understand your concern a bit in principle.

Quoted 1 line

ie. put all label renames into one patch,

Are any of my update suggestions controversial here?

Well, the label renames have a little value in general IMO, but that depends on a particular case.

Anyway, if there's something I don't like in particular, I'll let you know.

Quoted 8 lines
Quoted 1 line

all size determination improvements into another one and so on.

I am unsure about the acceptance for the selected software change opportunities. So I chose a very specific patch granularity intentionally.

I tend to provide some change ideas for each affected function implementation individually. I imagine that this way should support the recombination of update steps to some degree already, shouldn't it?

However, it's a pain to review 20 patches if you could review 4 instead.

Please take the reviewers' time into consideration too.

Thanks,
Rafael

#701 lore raw

Re: ACPI-video: Fine-tuning for several function implementations

Quoted 1 line

Anyway, if there's something I don't like in particular, I'll let you know.

Thanks for your general interest.

I hope that occasional disagreements can be resolved in constructive ways.

Quoted 1 line

However, it's a pain to review 20 patches if you could review 4 instead.

Are there any more possibilities to improve the convenience for this change review process with advanced tools?

Quoted 1 line

Please take the reviewers' time into consideration too.

I am trying this to some degree.

But I guess that it is hard to do something about corresponding efforts when various contributors can easily spot many software update opportunities in the discussed source files, isn't it?

Regards,
Markus

#702 lore raw

Re: ACPI-video: Fine-tuning for several function implementations

Quoted 13 lines · SF Markus Elfring
Quoted 1 line

Anyway, if there's something I don't like in particular, I'll let you know.

Thanks for your general interest.

I hope that occasional disagreements can be resolved in constructive ways.

Quoted 1 line

However, it's a pain to review 20 patches if you could review 4 instead.

Are there any more possibilities to improve the convenience for this change review process with advanced tools?

Quoted 7 lines
Quoted 1 line

Please take the reviewers' time into consideration too.

I am trying this to some degree.

But I guess that it is hard to do something about corresponding efforts when various contributors can easily spot many software update opportunities in the discussed source files, isn't it?

OK, look.

Your patches happen to modify code maintained by me. From my perspective the value of the changes made by them is marginal. Nevertheless, I might take them if you made my life somewhat easier, so I've tried to tell you politely how to do that.

If you're not willing to do it, though, this is where it ends. And attempts to convince me that I may not want my life to be easier after all are not likely to succeed.

Thanks,
Rafael

#703 lore raw

Re: ACPI-video: Fine-tuning for several function implementations

Quoted 2 lines

Your patches happen to modify code maintained by me. From my perspective the value of the changes made by them is marginal.

Thanks for another bit of interesting information.

Quoted 1 line

Nevertheless, I might take them if you made my life somewhat easier,

I am also looking for further approaches to help you there.

Quoted 1 line

so I've tried to tell you politely how to do that.

This feedback is generally fine.

Quoted 1 line

If you're not willing to do it,

My willingness is depending on also some factors.

Quoted 1 line

though, this is where it ends.

I hope that a bit more clarification can improve the situation.

Quoted 2 lines

And attempts to convince me that I may not want my life to be easier after all are not likely to succeed.

We usually want that life will become more comfortable.

I chose to contribute something to Linux source files for this purpose. My knowledge evolved in the way that I am using some tools for static source code analysis. Such advanced tools can point various change opportunities out. I picked a few special search patterns up. It happened then that hundreds of source files were found which contain update candidates. I am trying to inform the corresponding developers about improvement possibilities in affected systems.

Further challenges are relevant then as usual.

* Handling of the search process and their results

* Communication between contributors

Search patterns can occasionally be categorised as "too special". The software technology contains also the risk for showing "false positives".

The reactions of code reviewers are varying between rejection and acceptance. Now I would like to determine again which details of the proposed changes have got a higher chance for acceptance.

The discussed concrete patch series is just another example for usual difficulties or more interesting software development challenges. I hope that they can be resolved in a systematic way.
I sent analysis results as a series of small software updates. I find it important to understand them also in the way that they belong to software design patterns. I can imagine that it is harder to recognise the involved patterns from the presented combination of update steps.

Would you like to check and clarify these patterns once more before the desired improvements will happen (in a software area you maintain)?

So there are further constraints to consider. My software development experience leaded me to a very specific kind of patch granularity here.
My software development interest evolved also in the way that I dared to fiddle with the source files "drivers/acpi/processor_perflib.c" and "drivers/acpi/processor_throttling.c" yesterday.
The consequence is that I would to publish a corresponding series of 30 update steps for integration into another source code repository. It seems that I need to wait a bit more for the next contribution attempt before the change acceptance will fit to such an approach.

Regards,
Markus

#704 lore raw

v2 cover ACPI-video: Fine-tuning for several function implementations

In reply to Rafael J. Wysocki

From 2a7010a6555091b685ed51d91fea23ff9058047c Mon Sep 17 00:00:00 2001
From: Markus Elfring <[email protected]>
Date: Wed, 9 Aug 2017 17:16:15 +0200
Subject: [PATCH v2 0/9] ACPI-video: Fine-tuning for several function implementations

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

Markus Elfring (9):
Use kmalloc_array() in acpi_video_get_levels()
Return directly after a failed device query
Delete an error message for a failed kzalloc() call Return directly after a failed input_allocate_device() Delete unnecessary if statement in acpi_video_switch_brightness() Improve a jump target in acpi_video_switch_brightness() Delete an unnecessary initialisation in three functions Move four assignments in acpi_video_get_levels() Improve a size determination in four functions

---

v2:
* Desired changes were rebased on source files from Linux next-20170803.

* Some update steps were recombined.

 drivers/acpi/acpi_video.c | 53 ++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 28 deletions(-)
Signature · 1 line
2.13.4
#705 lore raw

PATCH v2 1/9 ACPI-video: Use kmalloc_array() in acpi_video_get_levels()

From: Markus Elfring <[email protected]>
Date: Wed, 9 Aug 2017 14:52:25 +0200

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

---
 drivers/acpi/acpi_video.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/acpi/acpi_video.c +3 -2
index 0972ec0e2eb8..1aaf2b591ca8 100644
@@ -832,8 +832,9 @@ int acpi_video_get_levels(struct acpi_device *device,
 	 * in order to account for buggy BIOS which don't export the first two
 	 * special levels (see below)
 	 */
-	br->levels = kmalloc((obj->package.count + ACPI_VIDEO_FIRST_LEVEL) *
-	                     sizeof(*br->levels), GFP_KERNEL);
+	br->levels = kmalloc_array(obj->package.count + ACPI_VIDEO_FIRST_LEVEL,
+				   sizeof(*br->levels),
+				   GFP_KERNEL);
 	if (!br->levels) {
 		result = -ENOMEM;
 		goto out_free;
Signature · 1 line
2.13.4
#706 lore raw

PATCH v2 2/9 ACPI-video: Return directly after a failed device query

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 9 Aug 2017 15:00:45 +0200

Return directly after a function call "acpi_video_device_lcd_query_levels" failed at the beginning.

---
 drivers/acpi/acpi_video.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/acpi/acpi_video.c +1 -2
index 1aaf2b591ca8..7a9cda6c0a6b 100644
@@ -811,8 +811,7 @@ int acpi_video_get_levels(struct acpi_device *device,
 								&obj))) {
 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
 						"LCD brightness level\n"));
-		result = -ENODEV;
-		goto out;
+		return -ENODEV;
 	}
 
 	if (obj->package.count < ACPI_VIDEO_FIRST_LEVEL) {
Signature · 1 line
2.13.4
#707 lore raw

PATCH v2 3/9 ACPI-video: Delete an error message for a failed kzalloc() call

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 9 Aug 2017 15:07:53 +0200

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

---
 drivers/acpi/acpi_video.c | 1 -
 1 file changed, 1 deletion(-)
drivers/acpi/acpi_video.c +0 -1
index 7a9cda6c0a6b..f83ece9c830c 100644
@@ -821,7 +821,6 @@ int acpi_video_get_levels(struct acpi_device *device,
 
 	br = kzalloc(sizeof(*br), GFP_KERNEL);
 	if (!br) {
-		printk(KERN_ERR "can't allocate memory\n");
 		result = -ENOMEM;
 		goto out;
 	}
Signature · 1 line
2.13.4
#708 lore raw

PATCH v2 4/9 ACPI-video: Return directly after a failed input_allocate_device()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 9 Aug 2017 15:15:16 +0200

* Return directly after a call of the function "input_allocate_device" failed at the beginning.

* Delete the jump label "out" which became unnecessary with this refactoring.

---
 drivers/acpi/acpi_video.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/acpi/acpi_video.c +2 -5
index f83ece9c830c..09ea1f115f55 100644
@@ -1903,10 +1903,8 @@ static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video)
 	int error;
 
 	video->input = input = input_allocate_device();
-	if (!input) {
-		error = -ENOMEM;
-		goto out;
-	}
+	if (!input)
+		return -ENOMEM;
 
 	error = acpi_video_bus_start_devices(video);
 	if (error)
@@ -1946,7 +1944,6 @@ static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video)
 err_free_input:
 	input_free_device(input);
 	video->input = NULL;
-out:
 	return error;
 }
 
Signature · 1 line
2.13.4
#709 lore raw

PATCH v2 5/9 ACPI-video: Delete unnecessary if statement in acpi_video_switch_brightness()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 9 Aug 2017 15:43:17 +0200

Move a function call into an else branch for successful function execution. Omit a duplicate check for the local variable "result" then at the end.

---
 drivers/acpi/acpi_video.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/acpi/acpi_video.c +3 -5
index 09ea1f115f55..8295ae1deab9 100644
@@ -1422,14 +1422,12 @@ acpi_video_switch_brightness(struct work_struct *work)
 	level_next = acpi_video_get_next_level(device, level_current, event);
 
 	result = acpi_video_device_lcd_set_level(device, level_next);
-
-	if (!result)
-		backlight_force_update(device->backlight,
-				       BACKLIGHT_UPDATE_HOTKEY);
-
 out:
 	if (result)
 		printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
+	else
+		backlight_force_update(device->backlight,
+				       BACKLIGHT_UPDATE_HOTKEY);
 }
 
 int acpi_video_get_edid(struct acpi_device *device, int type, int device_id,
Signature · 1 line
2.13.4
#710 lore raw

PATCH v2 6/9 ACPI-video: Improve a jump target in acpi_video_switch_brightness()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 9 Aug 2017 15:45:35 +0200

* Avoid another duplicate check for the local variable "result" then at the end.

* Jump directly to an error message in the case that the desired brightness can not be switched.

---
 drivers/acpi/acpi_video.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/acpi/acpi_video.c +3 -3
index 8295ae1deab9..e279ed221961 100644
@@ -1411,19 +1411,19 @@ acpi_video_switch_brightness(struct work_struct *work)
 		return;
 
 	if (!device->brightness)
-		goto out;
+		goto report_failure;
 
 	result = acpi_video_device_lcd_get_level_current(device,
 							 &level_current,
 							 false);
 	if (result)
-		goto out;
+		goto report_failure;
 
 	level_next = acpi_video_get_next_level(device, level_current, event);
 
 	result = acpi_video_device_lcd_set_level(device, level_next);
-out:
 	if (result)
+ report_failure:
 		printk(KERN_ERR PREFIX "Failed to switch the brightness\n");
 	else
 		backlight_force_update(device->backlight,
Signature · 1 line
2.13.4
#711 lore raw

PATCH v2 7/9 ACPI-video: Delete an unnecessary initialisation in three functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 9 Aug 2017 15:55:35 +0200

Three local variables will be set to appropriate values a bit later. Thus omit the explicit initialisation at the beginning of these functions.

---
 drivers/acpi/acpi_video.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/acpi/acpi_video.c +3 -3
index e279ed221961..a899faf6ff84 100644
@@ -803,7 +803,7 @@ int acpi_video_get_levels(struct acpi_device *device,
 	union acpi_object *obj = NULL;
 	int i, max_level = 0, count = 0, level_ac_battery = 0;
 	union acpi_object *o;
-	struct acpi_video_device_brightness *br = NULL;
+	struct acpi_video_device_brightness *br;
 	int result = 0;
 	u32 value;
 
@@ -921,7 +921,7 @@ acpi_video_init_brightness(struct acpi_video_device *device)
 	int i, max_level = 0;
 	unsigned long long level, level_old;
 	struct acpi_video_device_brightness *br = NULL;
-	int result = -EINVAL;
+	int result;
 
 	result = acpi_video_get_levels(device->dev, &br, &max_level);
 	if (result)
@@ -1295,7 +1295,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
 	int i;
 	struct acpi_video_enumerated_device *active_list;
 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-	union acpi_object *dod = NULL;
+	union acpi_object *dod;
 	union acpi_object *obj;
 
 	if (!video->cap._DOD)
Signature · 1 line
2.13.4
#712 lore raw

PATCH v2 8/9 ACPI-video: Move four assignments in acpi_video_get_levels()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 9 Aug 2017 16:21:17 +0200

Move the assignments for four local variables so that they will only be performed if the corresponding data processing succeeded by this function.

---
 drivers/acpi/acpi_video.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/acpi/acpi_video.c +6 -3
index a899faf6ff84..3cc1798676ab 100644
@@ -801,10 +801,10 @@ int acpi_video_get_levels(struct acpi_device *device,
 			  int *pmax_level)
 {
 	union acpi_object *obj = NULL;
-	int i, max_level = 0, count = 0, level_ac_battery = 0;
+	int i, max_level, count, level_ac_battery;
 	union acpi_object *o;
 	struct acpi_video_device_brightness *br;
-	int result = 0;
+	int result;
 	u32 value;
 
 	if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device->handle,
@@ -838,6 +838,8 @@ int acpi_video_get_levels(struct acpi_device *device,
 		goto out_free;
 	}
 
+	max_level = 0;
+	count = 0;
 	for (i = 0; i < obj->package.count; i++) {
 		o = (union acpi_object *)&obj->package.elements[i];
 		if (o->type != ACPI_TYPE_INTEGER) {
@@ -863,6 +865,7 @@ int acpi_video_get_levels(struct acpi_device *device,
 	 * In this case, the first two elements in _BCL packages
 	 * are also supported brightness levels that OS should take care of.
 	 */
+	level_ac_battery = 0;
 	for (i = ACPI_VIDEO_FIRST_LEVEL; i < count; i++) {
 		if (br->levels[i] = br->levels[ACPI_VIDEO_AC_LEVEL])
 			level_ac_battery++;
@@ -895,7 +898,7 @@ int acpi_video_get_levels(struct acpi_device *device,
 	*dev_br = br;
 	if (pmax_level)
 		*pmax_level = max_level;
-
+	result = 0;
 out:
 	kfree(obj);
 	return result;
Signature · 1 line
2.13.4
#713 lore raw

PATCH v2 9/9 ACPI-video: Improve a size determination in four functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 9 Aug 2017 16:45:29 +0200

Replace the specification of a data structures by variable references as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/acpi/acpi_video.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/acpi/acpi_video.c +4 -4
index 3cc1798676ab..d999f4e49b98 100644
@@ -1140,7 +1140,7 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
 	if (ACPI_FAILURE(status))
 		return 0;
 
-	data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
+	data = kzalloc(sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
@@ -1321,7 +1321,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
 			  dod->package.count));
 
 	active_list = kcalloc(1 + dod->package.count,
-			      sizeof(struct acpi_video_enumerated_device),
+			      sizeof(*active_list),
 			      GFP_KERNEL);
 	if (!active_list) {
 		status = -ENOMEM;
@@ -1742,7 +1742,7 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
 		pci_dev_put(pdev);
 	}
 
-	memset(&props, 0, sizeof(struct backlight_properties));
+	memset(&props, 0, sizeof(props));
 	props.type = BACKLIGHT_FIRMWARE;
 	props.max_brightness  		device->brightness->count - ACPI_VIDEO_FIRST_LEVEL - 1;
@@ -2007,7 +2007,7 @@ static int acpi_video_bus_add(struct acpi_device *device)
 			return -ENODEV;
 	}
 
-	video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
+	video = kzalloc(sizeof(*video), GFP_KERNEL);
 	if (!video)
 		return -ENOMEM;
 
Signature · 1 line
2.13.4
#714 lore raw

cover ACPI-APEI-HEST: Fine-tuning for three function implementations

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 22:05:05 +0200

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

Markus Elfring (7):
Fix a typo in a comment line
Use kmalloc_array() in hest_ghes_dev_register() Move an assignment in hest_ghes_dev_register() Rename jump labels in hest_ghes_dev_register() Rename jump labels in acpi_hest_init() Reduce the scope for a variable in acpi_hest_init() Rename jump labels in hest_parse_ghes()

 drivers/acpi/apei/hest.c | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)
Signature · 1 line
2.10.0
#715 lore raw

PATCH 1/7 ACPI-APEI-HEST: Fix a typo in a comment line

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 20:37:38 +0200

Add a missing character to the fourth word at the beginning of this file.

---
 drivers/acpi/apei/hest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/apei/hest.c +1 -1
index 20b3fcf..e170885 100644
@@ -1,5 +1,5 @@
 /*
- * APEI Hardware Error Souce Table support
+ * APEI Hardware Error Source Table support
  *
  * HEST describes error sources in detail; communicates operational
  * parameters (i.e. severity levels, masking bits, and threshold
Signature · 1 line
2.10.0
#716 lore raw

PATCH 2/7 ACPI-APEI-HEST: Use kmalloc_array() in hest_ghes_dev_register()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 20:55:33 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus reuse the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/acpi/apei/hest.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/apei/hest.c +3 -1
index e170885..a852237 100644
@@ -186,7 +186,9 @@ static int __init hest_ghes_dev_register(unsigned int ghes_count)
 	struct ghes_arr ghes_arr;
 
 	ghes_arr.count = 0;
-	ghes_arr.ghes_devs = kmalloc(sizeof(void *) * ghes_count, GFP_KERNEL);
+	ghes_arr.ghes_devs = kmalloc_array(ghes_count,
+					   sizeof(*ghes_arr.ghes_devs),
+					   GFP_KERNEL);
 	if (!ghes_arr.ghes_devs)
 		return -ENOMEM;
 
Signature · 1 line
2.10.0
#717 lore raw

PATCH 3/7 ACPI-APEI-HEST: Move an assignment in hest_ghes_dev_register()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 21:15:22 +0200

Move one assignment for a data structure member in one local variable so that its setting will only be performed after a corresponding memory allocation succeeded by this function.

---
 drivers/acpi/apei/hest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/apei/hest.c +1 -1
index a852237..26f5e78 100644
@@ -185,13 +185,13 @@ static int __init hest_ghes_dev_register(unsigned int ghes_count)
 	int rc, i;
 	struct ghes_arr ghes_arr;
 
-	ghes_arr.count = 0;
 	ghes_arr.ghes_devs = kmalloc_array(ghes_count,
 					   sizeof(*ghes_arr.ghes_devs),
 					   GFP_KERNEL);
 	if (!ghes_arr.ghes_devs)
 		return -ENOMEM;
 
+	ghes_arr.count = 0;
 	rc = apei_hest_parse(hest_parse_ghes, &ghes_arr);
 	if (rc)
 		goto err;
Signature · 1 line
2.10.0
#718 lore raw

PATCH 4/7 ACPI-APEI-HEST: Rename jump labels in hest_ghes_dev_register()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 21:22:55 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 drivers/acpi/apei/hest.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/acpi/apei/hest.c +4 -4
index 26f5e78..03dd7d3 100644
@@ -194,14 +194,14 @@ static int __init hest_ghes_dev_register(unsigned int ghes_count)
 	ghes_arr.count = 0;
 	rc = apei_hest_parse(hest_parse_ghes, &ghes_arr);
 	if (rc)
-		goto err;
-out:
+		goto unregister;
+ free_array:
 	kfree(ghes_arr.ghes_devs);
 	return rc;
-err:
+ unregister:
 	for (i = 0; i < ghes_arr.count; i++)
 		platform_device_unregister(ghes_arr.ghes_devs[i]);
-	goto out;
+	goto free_array;
 }
 
 static int __init setup_hest_disable(char *str)
Signature · 1 line
2.10.0
#719 lore raw

PATCH 5/7 ACPI-APEI-HEST: Rename jump labels in acpi_hest_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 21:30:06 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 drivers/acpi/apei/hest.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/acpi/apei/hest.c +5 -5
index 03dd7d3..ddff1b1 100644
@@ -226,12 +226,12 @@ void __init acpi_hest_init(void)
 	status = acpi_get_table(ACPI_SIG_HEST, 0,
 				(struct acpi_table_header **)&hest_tab);
 	if (status = AE_NOT_FOUND)
-		goto err;
+		goto disable_hest;
 	else if (ACPI_FAILURE(status)) {
 		const char *msg = acpi_format_exception(status);
 		pr_err(HEST_PFX "Failed to get table, %s\n", msg);
 		rc = -EINVAL;
-		goto err;
+		goto disable_hest;
 	}
 
 	if (!acpi_disable_cmcff)
@@ -240,14 +240,14 @@ void __init acpi_hest_init(void)
 	if (!ghes_disable) {
 		rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count);
 		if (rc)
-			goto err;
+			goto disable_hest;
 		rc = hest_ghes_dev_register(ghes_count);
 		if (rc)
-			goto err;
+			goto disable_hest;
 	}
 
 	pr_info(HEST_PFX "Table parsing has been initialized.\n");
 	return;
-err:
+ disable_hest:
 	hest_disable = 1;
 }
Signature · 1 line
2.10.0
#720 lore raw

PATCH 6/7 ACPI-APEI-HEST: Reduce the scope for a variable in acpi_hest_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 21:50:34 +0200

Move the definition for the local variable "ghes_count" into an if branch so that the corresponding setting will only be performed if GHES could be enabled by this function.

---
 drivers/acpi/apei/hest.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/acpi/apei/hest.c +2 -1
index ddff1b1..0e629c0 100644
@@ -216,7 +216,6 @@ void __init acpi_hest_init(void)
 {
 	acpi_status status;
 	int rc = -ENODEV;
-	unsigned int ghes_count = 0;
 
 	if (hest_disable) {
 		pr_info(HEST_PFX "Table parsing disabled.\n");
@@ -238,6 +237,8 @@ void __init acpi_hest_init(void)
 		apei_hest_parse(hest_parse_cmc, NULL);
 
 	if (!ghes_disable) {
+		unsigned int ghes_count = 0;
+
 		rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count);
 		if (rc)
 			goto disable_hest;
Signature · 1 line
2.10.0
#721 lore raw

PATCH 7/7 ACPI-APEI-HEST: Rename jump labels in hest_parse_ghes()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 21:56:02 +0200

Adjust jump labels according to the current Linux coding style convention.

---
 drivers/acpi/apei/hest.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/acpi/apei/hest.c +3 -3
index 0e629c0..d5b75fe 100644
@@ -167,15 +167,15 @@ static int __init hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data)
 
 	rc = platform_device_add_data(ghes_dev, &hest_hdr, sizeof(void *));
 	if (rc)
-		goto err;
+		goto put_device;
 
 	rc = platform_device_add(ghes_dev);
 	if (rc)
-		goto err;
+		goto put_device;
 	ghes_arr->ghes_devs[ghes_arr->count++] = ghes_dev;
 
 	return 0;
-err:
+ put_device:
 	platform_device_put(ghes_dev);
 	return rc;
 }
Signature · 1 line
2.10.0
#722 lore raw

Re: [PATCH 0/7] ACPI-APEI-HEST: Fine-tuning for three function implementations

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

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 22:05:05 +0200

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

Quoted 8 lines

Markus Elfring (7):
Fix a typo in a comment line
Use kmalloc_array() in hest_ghes_dev_register() Move an assignment in hest_ghes_dev_register() Rename jump labels in hest_ghes_dev_register() Rename jump labels in acpi_hest_init() Reduce the scope for a variable in acpi_hest_init() Rename jump labels in hest_parse_ghes()

Like in the other patch series I've just commented, please put all label renames into one patch.

Thanks,
Rafael

#723 lore raw

Re: ACPI-APEI-HEST: Fine-tuning for three function implementations

Quoted 1 line

Like in the other patch series I've just commented,

Thanks for your quick response.

Quoted 1 line

please put all label renames into one patch.

Could you accept these update suggestions generally?

I would prefer to avoid squashing special changes together by default.

Regards,
Markus

#724 lore raw

Re: ACPI-APEI-HEST: Fine-tuning for three function implementations

Quoted 11 lines · SF Markus Elfring
Quoted 1 line

Like in the other patch series I've just commented,

Thanks for your quick response.

Quoted 1 line

please put all label renames into one patch.

Could you accept these update suggestions generally?

I would prefer to avoid squashing special changes together by default.

Well, as I said elsewhere, if you make the same type of change in multiple places in one piece of code (or code maintained by the same maintainer), you make it easier to review those changes if they go in one patch.

Thanks,
Rafael

#725 lore raw

Re: ACPI-APEI-HEST: Fine-tuning for three function implementations

Quoted 2 lines

Well, as I said elsewhere, if you make the same type of change in multiple places in one piece of code (or code maintained by the same maintainer),

I can imagine that my update suggestions will also trigger some additional development efforts. I assume that some contributors appreciate fine-grained patch series, don't they?

Quoted 1 line

you make it easier to review those changes if they go in one patch.

It might look convenient. But I find that there are more aspects to consider for a better patch granularity.

Regards,
Markus

#726 lore raw

v2 cover ACPI-APEI-HEST: Fine-tuning for two function implementations

In reply to Rafael J. Wysocki

From: Markus Elfring <[email protected]>
Date: Wed, 9 Aug 2017 19:45:43 +0200

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

Markus Elfring (4):
Fix a typo in a comment line
Use kmalloc_array() in hest_ghes_dev_register() Move an assignment in hest_ghes_dev_register() Reduce the scope for a variable in acpi_hest_init()

---

v2:
* Desired changes were rebased on source files from Linux next-20170803.

* The number of update steps was reduced.

 drivers/acpi/apei/hest.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
Signature · 1 line
2.13.4
#727 lore raw

PATCH v2 1/4 ACPI-APEI-HEST: Fix a typo in a comment line

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 20:37:38 +0200

Add a missing character to the fourth word at the beginning of this file.

---
 drivers/acpi/apei/hest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/apei/hest.c +1 -1
index 456b488eb1df..832a930e98f2 100644
@@ -1,5 +1,5 @@
 /*
- * APEI Hardware Error Souce Table support
+ * APEI Hardware Error Source Table support
  *
  * HEST describes error sources in detail; communicates operational
  * parameters (i.e. severity levels, masking bits, and threshold
Signature · 1 line
2.13.4
#728 lore raw

PATCH v2 2/4 ACPI-APEI-HEST: Use kmalloc_array() in hest_ghes_dev_register()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 20:55:33 +0200

* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus reuse the corresponding function "kmalloc_array".

This issue was detected by using the Coccinelle software.

* Replace the specification of a data type by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/acpi/apei/hest.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/apei/hest.c +3 -1
index 832a930e98f2..24d1d3cd3371 100644
@@ -195,7 +195,9 @@ static int __init hest_ghes_dev_register(unsigned int ghes_count)
 	struct ghes_arr ghes_arr;
 
 	ghes_arr.count = 0;
-	ghes_arr.ghes_devs = kmalloc(sizeof(void *) * ghes_count, GFP_KERNEL);
+	ghes_arr.ghes_devs = kmalloc_array(ghes_count,
+					   sizeof(*ghes_arr.ghes_devs),
+					   GFP_KERNEL);
 	if (!ghes_arr.ghes_devs)
 		return -ENOMEM;
 
Signature · 1 line
2.13.4
#729 lore raw

PATCH v2 3/4 ACPI-APEI-HEST: Move an assignment in hest_ghes_dev_register()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 21:15:22 +0200

Move one assignment for a data structure member in one local variable so that its setting will only be performed after a corresponding memory allocation succeeded by this function.

---
 drivers/acpi/apei/hest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/apei/hest.c +1 -1
index 24d1d3cd3371..94b9bd494c20 100644
@@ -194,13 +194,13 @@ static int __init hest_ghes_dev_register(unsigned int ghes_count)
 	int rc, i;
 	struct ghes_arr ghes_arr;
 
-	ghes_arr.count = 0;
 	ghes_arr.ghes_devs = kmalloc_array(ghes_count,
 					   sizeof(*ghes_arr.ghes_devs),
 					   GFP_KERNEL);
 	if (!ghes_arr.ghes_devs)
 		return -ENOMEM;
 
+	ghes_arr.count = 0;
 	rc = apei_hest_parse(hest_parse_ghes, &ghes_arr);
 	if (rc)
 		goto err;
Signature · 1 line
2.13.4
#730 lore raw

PATCH v2 4/4 ACPI-APEI-HEST: Reduce the scope for a variable in acpi_hest_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 5 Sep 2016 21:50:34 +0200

Move the definition for the local variable "ghes_count" into an if branch so that the corresponding setting will only be performed if GHES could be enabled by this function.

---
 drivers/acpi/apei/hest.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/acpi/apei/hest.c +2 -1
index 94b9bd494c20..c0d81387ce18 100644
@@ -225,7 +225,6 @@ void __init acpi_hest_init(void)
 {
 	acpi_status status;
 	int rc = -ENODEV;
-	unsigned int ghes_count = 0;
 
 	if (hest_disable) {
 		pr_info(HEST_PFX "Table parsing disabled.\n");
@@ -248,6 +247,8 @@ void __init acpi_hest_init(void)
 		goto err;
 
 	if (!ghes_disable) {
+		unsigned int ghes_count = 0;
+
 		rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count);
 		if (rc)
 			goto err;
Signature · 1 line
2.13.4
#731 lore raw

cover cfag12864b: Fine-tuning for cfag12864b_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 10 Sep 2016 16:17:01 +0200

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

Markus Elfring (7):
Use kmalloc_array()
Delete an error message for a failed kmalloc_array() call Return directly if the driver "ks0108" was not initialized Return directly after a failed get_zeroed_page() Rename jump labels
Return an error code only as a constant
Adjust two checks for null pointers

 drivers/auxdisplay/cfag12864b.c | 37 +++++++++++++------------------------
 1 file changed, 13 insertions(+), 24 deletions(-)
Signature · 1 line
2.10.0