diff mbox

[U-Boot] usb: gadget: dfu: discard dead code

Message ID 1462242322-1107-1-git-send-email-van.freenix@gmail.com
State Accepted
Commit 12ff19dbfd93abdb62b7b326fee3f5bfa659a75e
Delegated to: Przemyslaw Marczak
Headers show

Commit Message

Peng Fan May 3, 2016, 2:25 a.m. UTC
Reported by Coverity:
Logically dead code (DEADCODE)
dead_error_line: Execution cannot reach this statement:
(f_dfu->strings + --i).s = ....

If calloc failed, i is still 0 and no need to call free,
so discard the dead code.

Signed-off-by: Peng Fan <van.freenix@gmail.com>
Cc: "Łukasz Majewski" <l.majewski@samsung.com>
Cc: Marek Vasut <marex@denx.de>
---
 drivers/usb/gadget/f_dfu.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

Comments

Tom Rini May 3, 2016, 9:29 p.m. UTC | #1
On Tue, May 03, 2016 at 10:25:22AM +0800, Peng Fan wrote:

> Reported by Coverity:
> Logically dead code (DEADCODE)
> dead_error_line: Execution cannot reach this statement:
> (f_dfu->strings + --i).s = ....
> 
> If calloc failed, i is still 0 and no need to call free,
> so discard the dead code.
> 
> Signed-off-by: Peng Fan <van.freenix@gmail.com>
> Cc: "Łukasz Majewski" <l.majewski@samsung.com>
> Cc: Marek Vasut <marex@denx.de>

Reviewed-by: Tom Rini <trini@konsulko.com>
Łukasz Majewski May 6, 2016, 9:12 a.m. UTC | #2
Hi Peng,

> Reported by Coverity:
> Logically dead code (DEADCODE)
> dead_error_line: Execution cannot reach this statement:
> (f_dfu->strings + --i).s = ....
> 
> If calloc failed, i is still 0 and no need to call free,
> so discard the dead code.
> 
> Signed-off-by: Peng Fan <van.freenix@gmail.com>
> Cc: "Łukasz Majewski" <l.majewski@samsung.com>
> Cc: Marek Vasut <marex@denx.de>
> ---
>  drivers/usb/gadget/f_dfu.c | 10 +---------
>  1 file changed, 1 insertion(+), 9 deletions(-)
> 
> diff --git a/drivers/usb/gadget/f_dfu.c b/drivers/usb/gadget/f_dfu.c
> index 7d88008..8e7c981 100644
> --- a/drivers/usb/gadget/f_dfu.c
> +++ b/drivers/usb/gadget/f_dfu.c
> @@ -636,7 +636,7 @@ dfu_prepare_strings(struct f_dfu *f_dfu, int n)
>  
>  	f_dfu->strings = calloc(sizeof(struct usb_string), n + 1);
>  	if (!f_dfu->strings)
> -		goto enomem;
> +		return -ENOMEM;
>  
>  	for (i = 0; i < n; ++i) {
>  		de = dfu_get_entity(i);
> @@ -647,14 +647,6 @@ dfu_prepare_strings(struct f_dfu *f_dfu, int n)
>  	f_dfu->strings[i].s = NULL;
>  
>  	return 0;
> -
> -enomem:
> -	while (i)
> -		f_dfu->strings[--i].s = NULL;
> -
> -	free(f_dfu->strings);
> -
> -	return -ENOMEM;
>  }
>  
>  static int dfu_prepare_function(struct f_dfu *f_dfu, int n)

Acked-by: Lukasz Majewski <l.majewski@samsung.com>

Applied to u-boot-dfu tree.

Tested-at: Odroid U3 (Exynos4412)
diff mbox

Patch

diff --git a/drivers/usb/gadget/f_dfu.c b/drivers/usb/gadget/f_dfu.c
index 7d88008..8e7c981 100644
--- a/drivers/usb/gadget/f_dfu.c
+++ b/drivers/usb/gadget/f_dfu.c
@@ -636,7 +636,7 @@  dfu_prepare_strings(struct f_dfu *f_dfu, int n)
 
 	f_dfu->strings = calloc(sizeof(struct usb_string), n + 1);
 	if (!f_dfu->strings)
-		goto enomem;
+		return -ENOMEM;
 
 	for (i = 0; i < n; ++i) {
 		de = dfu_get_entity(i);
@@ -647,14 +647,6 @@  dfu_prepare_strings(struct f_dfu *f_dfu, int n)
 	f_dfu->strings[i].s = NULL;
 
 	return 0;
-
-enomem:
-	while (i)
-		f_dfu->strings[--i].s = NULL;
-
-	free(f_dfu->strings);
-
-	return -ENOMEM;
 }
 
 static int dfu_prepare_function(struct f_dfu *f_dfu, int n)