All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/02] ath3k: Avoid duplication of code
@ 2011-01-27 23:22 Rogério Brito
  2011-01-28  9:05 ` Miguel Ojeda
  0 siblings, 1 reply; 2+ messages in thread
From: Rogério Brito @ 2011-01-27 23:22 UTC (permalink / raw)
  To: linux-kernel; +Cc: Alexander Holler, Gustavo F. Padovan, rbrito

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)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 01/02] ath3k: Avoid duplication of code
  2011-01-27 23:22 [PATCH 01/02] ath3k: Avoid duplication of code Rogério Brito
@ 2011-01-28  9:05 ` Miguel Ojeda
  0 siblings, 0 replies; 2+ messages in thread
From: Miguel Ojeda @ 2011-01-28  9:05 UTC (permalink / raw)
  To: Rogério Brito; +Cc: linux-kernel, Alexander Holler, Gustavo F. Padovan

Hi,

2011/1/28 Rogério Brito <rbrito@ime.usp.br>:
> 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;

We don't need "else" after a return statement, in order to avoid a
indentation level.

>  }
>
>  static void ath3k_disconnect(struct usb_interface *intf)
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-01-28  9:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-27 23:22 [PATCH 01/02] ath3k: Avoid duplication of code Rogério Brito
2011-01-28  9:05 ` Miguel Ojeda

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.