[PATCH] part: return -ENOSYS when get_info not valid.

Heinrich Schuchardt xypron.glpk at gmx.de
Tue Oct 19 17:23:11 CEST 2021


On 10/19/21 15:35, zhaohui.shi wrote:
> From: schspa <schspa at gmail.com>
>
> In some case, get_info() interface can be NULL, add this check to stop
> from crash.

Thank you for reviewing the partition driver code.

There seems to be no driver missing a get_info implementation. Where did
you run into a problem?

Why should we only check .get_info and not .test and not .print?

>
> Signed-off-by: schspa <schspa at gmail.com>

Please, provide a name.

> ---
>   disk/part.c | 7 +++++++
>   1 file changed, 7 insertions(+)
>
> diff --git a/disk/part.c b/disk/part.c
> index a6a8f7052b..7af3240ec7 100644
> --- a/disk/part.c
> +++ b/disk/part.c
> @@ -668,6 +668,13 @@ int part_get_info_by_name_type(struct blk_desc *dev_desc, const char *name,
>   	part_drv = part_driver_lookup_type(dev_desc);
>   	if (!part_drv)
>   		return -1;
> +
> +	if (!part_drv->get_info) {
> +		PRINTF("## Driver %s does not have the get_info() method\n",
> +		       part_drv->name);

Please, use log_debug() to avoid noise on the console on every boot.

Best regards

Heinrich

> +		return -ENOSYS;
> +	}
> +
>   	for (i = 1; i < part_drv->max_entries; i++) {
>   		ret = part_drv->get_info(dev_desc, i, info);
>   		if (ret != 0) {
>


More information about the U-Boot mailing list