mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-06-13 15:03:58 +03:00
disk/part.c: ensure strings in struct disk_partition are valid after successful get_info
Not all ->get_info implementations necessarily populate all the string members of struct disk_partition. Currently, only part_get_info_by_type() (and thereby part_get_info) ensure that the uuid strings are initialized; part_get_info_by_type() and part_get_info_by_uuid() do not. In fact, the latter could lead to a false positive match - if the ->get_info backend does not populate info->uuid, stale contents in info could cause the strncasecmp() to succeed. None of the functions currently ensure that the ->name and ->type strings are initialized. Instead of forcing all callers of any of these functions to pre-initialize info, or all implementations of the ->get_info method to ensure there are valid C strings in all four fields, create a small helper function and factor all invocations of ->get_info through that. This also consolidates the -ENOSYS check and standardizes on using log_debug() for reporting absence, instead of the current mix of PRINTF and log_debug(). It does mean we have to special-case -ENOSYS in the error cases inside the loops in the _by_uuid() and _by_name() functions, but it's still a net win in #LOC. Acked-by: Quentin Schulz <quentin.schulz@cherry.de> Signed-off-by: Rasmus Villemoes <ravi@prevas.dk> Tested-by: Anshul Dalal <anshuld@ti.com>
This commit is contained in:
committed by
Tom Rini
parent
365a7079fb
commit
3c2a947533
@@ -509,6 +509,22 @@ struct part_driver {
|
||||
int (*test)(struct blk_desc *desc);
|
||||
};
|
||||
|
||||
/**
|
||||
* part_driver_get_info() - Call the part_driver's get_info method
|
||||
*
|
||||
* On success, string members of info are guaranteed to be properly
|
||||
* initialized, though they may be empty.
|
||||
*
|
||||
* @drv: Partition driver
|
||||
* @desc: Block device descriptor
|
||||
* @part: Partition number to read
|
||||
* @info: Returned partition information
|
||||
*
|
||||
* Return: 0 on success, negative errno on failure.
|
||||
*/
|
||||
int part_driver_get_info(struct part_driver *drv, struct blk_desc *desc, int part,
|
||||
struct disk_partition *info);
|
||||
|
||||
/* Declare a new U-Boot partition 'driver' */
|
||||
#define U_BOOT_PART_TYPE(__name) \
|
||||
ll_entry_declare(struct part_driver, __name, part_driver)
|
||||
|
||||
Reference in New Issue
Block a user