init: refactor devt_from_partuuid

The code in devt_from_partuuid is very convoluted.  Refactor a bit by
sanitizing the goto and variable name usage.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Christoph Hellwig
2020-11-14 19:35:28 +01:00
committed by Jens Axboe
parent c2637e80a0
commit e036bb8e0c

View File

@@ -105,13 +105,10 @@ no_match:
*/ */
static dev_t devt_from_partuuid(const char *uuid_str) static dev_t devt_from_partuuid(const char *uuid_str)
{ {
dev_t res = 0;
struct uuidcmp cmp; struct uuidcmp cmp;
struct device *dev = NULL; struct device *dev = NULL;
struct gendisk *disk; dev_t devt = 0;
struct hd_struct *part;
int offset = 0; int offset = 0;
bool clear_root_wait = false;
char *slash; char *slash;
cmp.uuid = uuid_str; cmp.uuid = uuid_str;
@@ -120,52 +117,49 @@ static dev_t devt_from_partuuid(const char *uuid_str)
/* Check for optional partition number offset attributes. */ /* Check for optional partition number offset attributes. */
if (slash) { if (slash) {
char c = 0; char c = 0;
/* Explicitly fail on poor PARTUUID syntax. */ /* Explicitly fail on poor PARTUUID syntax. */
if (sscanf(slash + 1, if (sscanf(slash + 1, "PARTNROFF=%d%c", &offset, &c) != 1)
"PARTNROFF=%d%c", &offset, &c) != 1) { goto clear_root_wait;
clear_root_wait = true;
goto done;
}
cmp.len = slash - uuid_str; cmp.len = slash - uuid_str;
} else { } else {
cmp.len = strlen(uuid_str); cmp.len = strlen(uuid_str);
} }
if (!cmp.len) { if (!cmp.len)
clear_root_wait = true; goto clear_root_wait;
goto done;
}
dev = class_find_device(&block_class, NULL, &cmp, dev = class_find_device(&block_class, NULL, &cmp, &match_dev_by_uuid);
&match_dev_by_uuid);
if (!dev) if (!dev)
goto done; return 0;
res = dev->devt; if (offset) {
/*
* Attempt to find the requested partition by adding an offset
* to the partition number found by UUID.
*/
struct hd_struct *part;
/* Attempt to find the partition by offset. */ part = disk_get_part(dev_to_disk(dev),
if (!offset) dev_to_part(dev)->partno + offset);
goto no_offset; if (part) {
devt = part_devt(part);
res = 0; put_device(part_to_dev(part));
disk = part_to_disk(dev_to_part(dev)); }
part = disk_get_part(disk, dev_to_part(dev)->partno + offset); } else {
if (part) { devt = dev->devt;
res = part_devt(part);
put_device(part_to_dev(part));
} }
no_offset:
put_device(dev); put_device(dev);
done: return devt;
if (clear_root_wait) {
pr_err("VFS: PARTUUID= is invalid.\n" clear_root_wait:
"Expected PARTUUID=<valid-uuid-id>[/PARTNROFF=%%d]\n"); pr_err("VFS: PARTUUID= is invalid.\n"
if (root_wait) "Expected PARTUUID=<valid-uuid-id>[/PARTNROFF=%%d]\n");
pr_err("Disabling rootwait; root= is invalid.\n"); if (root_wait)
root_wait = 0; pr_err("Disabling rootwait; root= is invalid.\n");
} root_wait = 0;
return res; return 0;
} }
/** /**