mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Rogério Brito" <rbrito@ime.usp.br>
To: linux-kernel@vger.kernel.org
Cc: Alexander Holler <holler@ahsoftware.de>,
	"Gustavo F. Padovan" <padovan@profusion.mobi>,
	rbrito@ime.usp.br
Subject: [PATCH 01/02] ath3k: Avoid duplication of code
Date: Thu, 27 Jan 2011 21:22:56 -0200	[thread overview]
Message-ID: <20110127232252.GA3493@ime.usp.br> (raw)

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.


Signed-off-by: Rogério Brito <rbrito@ime.usp.br>

---

I am sending here two proposals for rewriting the code.  This is the
first one. The second uses the ternary operator and seems to have more
usage in the kernel (or, at least, under mm).

---

diff --git a/drivers/bluetooth/ath3k.c b/drivers/bluetooth/ath3k.c
index a126e61..0043781 100644
--- a/drivers/bluetooth/ath3k.c
+++ b/drivers/bluetooth/ath3k.c
@@ -116,13 +116,13 @@ 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;
+	if (ret)
+		return -EIO;
+	else
+		return 0;
 }
 
 static void ath3k_disconnect(struct usb_interface *intf)

             reply	other threads:[~2011-01-27 23:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-27 23:22 Rogério Brito [this message]
2011-01-28  9:05 ` Miguel Ojeda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110127232252.GA3493@ime.usp.br \
    --to=rbrito@ime.usp.br \
    --cc=holler@ahsoftware.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=padovan@profusion.mobi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®