cmd/usb_mass_storage.c: Rework ums_init() ret logic slightly
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> Acked-by: Marek Vasut <marex@denx.de> Signed-off-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
parent
eb6b50f631
commit
a238b0dacf
@ -56,7 +56,7 @@ static int ums_init(const char *devtype, const char *devnums_part_str)
|
|||||||
struct blk_desc *block_dev;
|
struct blk_desc *block_dev;
|
||||||
disk_partition_t info;
|
disk_partition_t info;
|
||||||
int partnum;
|
int partnum;
|
||||||
int ret;
|
int ret = -1;
|
||||||
struct ums *ums_new;
|
struct ums *ums_new;
|
||||||
|
|
||||||
s = strdup(devnums_part_str);
|
s = strdup(devnums_part_str);
|
||||||
@ -85,16 +85,12 @@ static int ums_init(const char *devtype, const char *devnums_part_str)
|
|||||||
partnum = 0;
|
partnum = 0;
|
||||||
|
|
||||||
/* f_mass_storage.c assumes SECTOR_SIZE sectors */
|
/* f_mass_storage.c assumes SECTOR_SIZE sectors */
|
||||||
if (block_dev->blksz != SECTOR_SIZE) {
|
if (block_dev->blksz != SECTOR_SIZE)
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
ums_new = realloc(ums, (ums_count + 1) * sizeof(*ums));
|
ums_new = realloc(ums, (ums_count + 1) * sizeof(*ums));
|
||||||
if (!ums_new) {
|
if (!ums_new)
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
ums = ums_new;
|
ums = ums_new;
|
||||||
|
|
||||||
/* if partnum = 0, expose all partitions */
|
/* if partnum = 0, expose all partitions */
|
||||||
@ -110,10 +106,8 @@ static int ums_init(const char *devtype, const char *devnums_part_str)
|
|||||||
ums[ums_count].write_sector = ums_write_sector;
|
ums[ums_count].write_sector = ums_write_sector;
|
||||||
|
|
||||||
name = malloc(UMS_NAME_LEN);
|
name = malloc(UMS_NAME_LEN);
|
||||||
if (!name) {
|
if (!name)
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
snprintf(name, UMS_NAME_LEN, "UMS disk %d", ums_count);
|
snprintf(name, UMS_NAME_LEN, "UMS disk %d", ums_count);
|
||||||
ums[ums_count].name = name;
|
ums[ums_count].name = name;
|
||||||
ums[ums_count].block_dev = *block_dev;
|
ums[ums_count].block_dev = *block_dev;
|
||||||
@ -127,9 +121,7 @@ static int ums_init(const char *devtype, const char *devnums_part_str)
|
|||||||
ums_count++;
|
ums_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ums_count)
|
if (ums_count)
|
||||||
ret = -1;
|
|
||||||
else
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
Loading…
Reference in New Issue
Block a user