[PATCH 07/18] commands: stat: remove code duplication for type info

Marco Felsch m.felsch at pengutronix.de
Wed May 31 09:44:57 PDT 2023


On 23-05-31, Ahmad Fatoum wrote:
> stat prints a line with partitioning/type info for cdevs, but not all
> cdevs have these, so we want to skip printing when it's empty.
> Instead of duplicating the check, just utilize printf returning the
> number of characters written.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>

Reviewed-by: Marco Felsch <m.felsch at pengutronix.de>

> ---
>  fs/fs.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/fs.c b/fs/fs.c
> index 368458cc54f8..ba60766a065a 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -69,6 +69,8 @@ EXPORT_SYMBOL(mkmodestr);
>  
>  void cdev_print(const struct cdev *cdev)
>  {
> +	int nbytes;
> +
>  	if (cdev->dev || cdev->master || cdev->partname) {
>  		printf("Origin: %s", dev_name(cdev->dev) ?: "None");
>  		if (cdev->master)
> @@ -96,15 +98,17 @@ void cdev_print(const struct cdev *cdev)
>  	}
>  	printf("\n");
>  
> -	if (cdev->filetype || cdev->dos_partition_type || *cdev->uuid) {
> -		if (cdev->filetype)
> -			printf("Filetype: %s\t", file_type_to_string(cdev->filetype));
> -		if (cdev->dos_partition_type)
> -			printf("DOS parttype: 0x%02x\t", cdev->dos_partition_type);
> -		if (*cdev->uuid)
> -			printf("UUID: %s", cdev->uuid);
> +	nbytes = 0;
> +
> +	if (cdev->filetype)
> +		nbytes += printf("Filetype: %s\t", file_type_to_string(cdev->filetype));
> +	if (cdev->dos_partition_type)
> +		nbytes += printf("DOS parttype: 0x%02x\t", cdev->dos_partition_type);
> +	if (*cdev->uuid)
> +		nbytes += printf("UUID: %s", cdev->uuid);
> +
> +	if (nbytes)
>  		printf("\n");
> -	}
>  }
>  EXPORT_SYMBOL(cdev_print);
>  
> -- 
> 2.39.2
> 
> 
> 



More information about the barebox mailing list