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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>

Reviewed-by: Marco Felsch <m.felsch@xxxxxxxxxxxxxx>

> ---
>  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
> 
> 
> 




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux