Skip to contentSkip to conversation

ath3k: Avoid duplication of code

PATCH In review Rogério Brito 3 participants 6 messages Jan 27, 2011 – Feb 2, 2011 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 ath3k: Avoid duplication of code

Hi.

In commit 86e09287e4f8c81831b4d4118a48597565f0d21b, to reduce memory usage, the functions of the ath3k module were rewritten to release the firmware blob after it has been loaded (successfully or not).

The resuting code has some redundancy and the compiler can potentially produce better code if we omit a function call that is unconditionally executed in

,----

| 	if (ath3k_load_firmware(udev, firmware)) {
| 		release_firmware(firmware);
| 		return -EIO;
| 	}
| 	release_firmware(firmware);
| 
| 	return 0;
| }

`----

It may also be argued that the code becomes easier to read, and also to see the code coverage of the snippet in question.

---

This is the second (preferred?) version of the patch in question.

---

drivers/bluetooth/ath3k.c +2 -5
index a126e61..d51c5a3 100644
@@ -116,13 +116,10 @@ static int ath3k_probe(struct usb_interface *intf,
 		return -EIO;
 	}
 
-	if (ath3k_load_firmware(udev, firmware)) {
-		release_firmware(firmware);
-		return -EIO;
-	}
+	ret = ath3k_load_firmware(udev, firmware);
 	release_firmware(firmware);
 
-	return 0;
+	return ret ? -EIO : 0;
 }
 
 static void ath3k_disconnect(struct usb_interface *intf)
#1 lore raw

Hello Rogério,

Am 28.01.2011 00:24, schrieb Rogério Brito:

Quoted 13 lines

The resuting code has some redundancy and the compiler can potentially produce better code if we omit a function call that is unconditionally executed in

drivers/bluetooth/ath3k.c +0 -0
index a126e61..d51c5a3 100644
@@ -116,13 +116,10 @@ static int ath3k_probe(struct usb_interface *intf,
  		return -EIO;
  	}
 

drivers/bluetooth/ath3k.c static int ath3k_probe(struct usb_interface *intf, · line 123

Quoted 10 lines
drivers/bluetooth/ath3k.c +2 -5
-	if (ath3k_load_firmware(udev, firmware)) {
-		release_firmware(firmware);
-		return -EIO;
-	}
+	ret = ath3k_load_firmware(udev, firmware);
  	release_firmware(firmware);
 
-	return 0;
+	return ret ? -EIO : 0;
  }

Looks nice, but doesn't compile. I assume you should at least try to compile the stuff you want to change. ;)

Regards,

Alexander

#2 lore raw

PATCH 1/1 ath3k: Avoid duplication of code

Hi.

In commit 86e09287e4f8c81831b4d4118a48597565f0d21b, to reduce memory usage, the functions of the ath3k module were rewritten to release the firmware blob after it has been loaded (successfully or not).

The resuting code has some redundancy and the compiler can potentially produce better code if we omit a function call that is unconditionally executed in

,----

| 	if (ath3k_load_firmware(udev, firmware)) {
| 		release_firmware(firmware);
| 		return -EIO;
|	}
|	release_firmware(firmware);
|
|	return 0;
| }

`----

It may also be argued that the rewritten code becomes easier to read, and also to see the code coverage of the snippet in question.

Cc Alexander Holler <[email protected]>
Cc "Gustavo F. Padovan" <[email protected]>
Cc Miguel Ojeda <[email protected]>

---

Thanks for all the feedback on the previous patches. The one that didn't compile before was sent without a hunk. This time everything all the basics are verified.

drivers/bluetooth/ath3k.c +3 -5
index a126e61..42fa531 100644
@@ -106,6 +106,7 @@ static int ath3k_probe(struct usb_interface *intf,
 {
 	const struct firmware *firmware;
 	struct usb_device *udev = interface_to_usbdev(intf);
+	int ret;
 
 	BT_DBG("intf %p id %p", intf, id);
 
@@ -116,13 +117,10 @@ static int ath3k_probe(struct usb_interface *intf,
 		return -EIO;
 	}
 
-	if (ath3k_load_firmware(udev, firmware)) {
-		release_firmware(firmware);
-		return -EIO;
-	}
+	ret = ath3k_load_firmware(udev, firmware);
 	release_firmware(firmware);
 
-	return 0;
+	return ret ? -EIO : 0;
 }
 
 static void ath3k_disconnect(struct usb_interface *intf)
Signature · 3 lines
Rogério Brito : rbrito@{mackenzie,ime.usp}.br : GPG key 1024D/7C2CAEB8
http://www.ime.usp.br/~rbrito : http://meusite.mackenzie.com.br/rbrito
Projects: algorithms.berlios.de : lame.sf.net : vrms.alioth.debian.org
#3 lore raw

Am 28.01.2011 23:18, schrieb Rogério Brito:

Quoted 3 lines

Thanks for all the feedback on the previous patches. The one that didn't compile before was sent without a hunk. This time everything all the basics are verified.

They both had the same error, so I assume none of them compiled.

Besides that I don't have an opinion on your patch.

That stuff is only executed once when a device will be attached. The only reason I had a look at the code, was that I once got an out of memory error after I've attached such an device to a memory constrained (embedded) system.

Regards,

Alexander

#4 lore raw

Hi, Alexander.

Quoted 6 lines · Alexander Holler

Am 28.01.2011 23:18, schrieb Rogério Brito:

Quoted 3 lines

Thanks for all the feedback on the previous patches. The one that didn't compile before was sent without a hunk. This time everything all the basics are verified.

They both had the same error, so I assume none of them compiled.

No, they both compiled. It was just that I messed up when generating my patches (with git add --interactive). My git-fu is currently low, but improving. :)

Anyway, the new version that I sent (when applied) compiles, and makes it shorter to read the code (some could say that it more explicitly exposes what happens in the function).

Regards,

Signature · 3 lines
Rogério Brito : rbrito@{ime.usp.br,gmail.com} : GPG key 4096R/BCFCAAAA
http://rb.doesntexist.org : Packages for LaTeX : algorithms.berlios.de
DebianQA: http://qa.debian.org/developer.php?login=rbrito%40ime.usp.br
#5 lore raw
In reply to Rogério Brito

Hi Rogério,

Quoted 22 lines · Rogério Brito

Hi.

In commit 86e09287e4f8c81831b4d4118a48597565f0d21b, to reduce memory usage, the functions of the ath3k module were rewritten to release the firmware blob after it has been loaded (successfully or not).

The resuting code has some redundancy and the compiler can potentially produce better code if we omit a function call that is unconditionally executed in

,----

| 	if (ath3k_load_firmware(udev, firmware)) {
| 		release_firmware(firmware);
| 		return -EIO;
|	}
|	release_firmware(firmware);
|
|	return 0;
| }

`----

Quoted 8 lines

It may also be argued that the rewritten code becomes easier to read, and also to see the code coverage of the snippet in question.

Cc Alexander Holler <[email protected]>
Cc "Gustavo F. Padovan" <[email protected]>
Cc Miguel Ojeda <[email protected]>

Please send me your patch in a 'git format-patch' way, so I can apply it without having to edit the commit message. And add "Bluetooth:" to the beginning of the commit title.

Quoted 23 lines

---

Thanks for all the feedback on the previous patches. The one that didn't compile before was sent without a hunk. This time everything all the basics are verified.

drivers/bluetooth/ath3k.c +1 -0
index a126e61..42fa531 100644
@@ -106,6 +106,7 @@ static int ath3k_probe(struct usb_interface *intf,
 {
 	const struct firmware *firmware;
 	struct usb_device *udev = interface_to_usbdev(intf);
+	int ret;
 
 	BT_DBG("intf %p id %p", intf, id);
 
@@ -116,13 +117,10 @@ static int ath3k_probe(struct usb_interface *intf,
 		return -EIO;
 	}

drivers/bluetooth/ath3k.c static int ath3k_probe(struct usb_interface *intf, · line 123

Quoted 10 lines
drivers/bluetooth/ath3k.c +2 -5
 
-	if (ath3k_load_firmware(udev, firmware)) {
-		release_firmware(firmware);
-		return -EIO;
-	}
+	ret = ath3k_load_firmware(udev, firmware);
 	release_firmware(firmware);
 
-	return 0;
+	return ret ? -EIO : 0;

just return ret;
It is enough.

Regards,

Signature · 2 lines
Gustavo F. Padovan
http://profusion.mobi