All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] cmd/usb_mass_storage.c: Rework ums_init() ret logic slightly
Date: Wed, 20 Apr 2016 17:46:53 +0200	[thread overview]
Message-ID: <5717A46D.5090001@denx.de> (raw)
In-Reply-To: <1461164516-28568-1-git-send-email-trini@konsulko.com>

On 04/20/2016 05:01 PM, Tom Rini wrote:
> Previously, ret could be used uninitialized if
> blk_get_device_part_str() failed.  Default to ret being set to -1 so
> that we always return an err up if we have a problem and then invert the
> logic on testing ums_count as when that is non-zero is the time we can
> return 0.
> 
> Cc: John Tobias <john.tobias.ph@gmail.com>
> Cc: Marek Vasut <marex@denx.de>
> Signed-off-by: Tom Rini <trini@konsulko.com>
> ---
>  cmd/usb_mass_storage.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/cmd/usb_mass_storage.c b/cmd/usb_mass_storage.c
> index ac53a73..b03d567 100644
> --- a/cmd/usb_mass_storage.c
> +++ b/cmd/usb_mass_storage.c
> @@ -56,7 +56,7 @@ static int ums_init(const char *devtype, const char *devnums_part_str)
>  	struct blk_desc *block_dev;
>  	disk_partition_t info;
>  	int partnum;
> -	int ret;
> +	int ret = -1;
>  	struct ums *ums_new;
>  
>  	s = strdup(devnums_part_str);
> @@ -86,13 +86,11 @@ static int ums_init(const char *devtype, const char *devnums_part_str)
>  
>  		/* f_mass_storage.c assumes SECTOR_SIZE sectors */
>  		if (block_dev->blksz != SECTOR_SIZE) {

You can also drop the {} braces now.

Otherwise,

Acked-by: Marek Vasut <marex@denx.de>

> -			ret = -1;
>  			goto cleanup;
>  		}
>  
>  		ums_new = realloc(ums, (ums_count + 1) * sizeof(*ums));
>  		if (!ums_new) {
> -			ret = -1;
>  			goto cleanup;
>  		}
>  		ums = ums_new;
> @@ -111,7 +109,6 @@ static int ums_init(const char *devtype, const char *devnums_part_str)
>  
>  		name = malloc(UMS_NAME_LEN);
>  		if (!name) {
> -			ret = -1;
>  			goto cleanup;
>  		}
>  		snprintf(name, UMS_NAME_LEN, "UMS disk %d", ums_count);
> @@ -127,9 +124,7 @@ static int ums_init(const char *devtype, const char *devnums_part_str)
>  		ums_count++;
>  	}
>  
> -	if (!ums_count)
> -		ret = -1;
> -	else
> +	if (ums_count)
>  		ret = 0;
>  
>  cleanup:
> 


-- 
Best regards,
Marek Vasut

  reply	other threads:[~2016-04-20 15:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-20  9:45 [U-Boot] [PULL] u-boot-usb/master Marek Vasut
2016-04-20 15:01 ` [U-Boot] [PATCH] cmd/usb_mass_storage.c: Rework ums_init() ret logic slightly Tom Rini
2016-04-20 15:46   ` Marek Vasut [this message]
2016-04-20 17:20     ` Tom Rini
2016-04-21 11:27   ` Tom Rini
2016-04-21 11:26 ` [U-Boot] [PULL] u-boot-usb/master Tom Rini

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=5717A46D.5090001@denx.de \
    --to=marex@denx.de \
    --cc=u-boot@lists.denx.de \
    /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 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.