Re: [PATCH] ext4: replace snprintf in show functions with sysfs_emit

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

 



On Tue 12-10-21 20:28:51, Qing Wang wrote:
> coccicheck complains about the use of snprintf() in sysfs show functions.
> 
> Fix the coccicheck warning:
> WARNING: use scnprintf or sprintf.
> 
> Use sysfs_emit instead of scnprintf or sprintf makes more sense.
> 
> Signed-off-by: Qing Wang <wangqing@xxxxxxxx>

Makes sense. Feel free to add:

Reviewed-by: Jan Kara <jack@xxxxxxx>

								Honza


> ---
>  fs/ext4/sysfs.c | 34 +++++++++++++++++-----------------
>  1 file changed, 17 insertions(+), 17 deletions(-)
> 
> diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
> index 2314f74..2a4ae3d 100644
> --- a/fs/ext4/sysfs.c
> +++ b/fs/ext4/sysfs.c
> @@ -63,7 +63,7 @@ static ssize_t session_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
>  {
>  	struct super_block *sb = sbi->s_buddy_cache->i_sb;
>  
> -	return snprintf(buf, PAGE_SIZE, "%lu\n",
> +	return sysfs_emit(buf, "%lu\n",
>  			(part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) -
>  			 sbi->s_sectors_written_start) >> 1);
>  }
> @@ -72,7 +72,7 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
>  {
>  	struct super_block *sb = sbi->s_buddy_cache->i_sb;
>  
> -	return snprintf(buf, PAGE_SIZE, "%llu\n",
> +	return sysfs_emit(buf, "%llu\n",
>  			(unsigned long long)(sbi->s_kbytes_written +
>  			((part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) -
>  			  EXT4_SB(sb)->s_sectors_written_start) >> 1)));
> @@ -130,8 +130,8 @@ static ssize_t trigger_test_error(struct ext4_sb_info *sbi,
>  static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf)
>  {
>  	if (!sbi->s_journal)
> -		return snprintf(buf, PAGE_SIZE, "<none>\n");
> -	return snprintf(buf, PAGE_SIZE, "%d\n",
> +		return sysfs_emit(buf, "<none>\n");
> +	return sysfs_emit(buf, "%d\n",
>  			task_pid_vnr(sbi->s_journal->j_task));
>  }
>  
> @@ -357,7 +357,7 @@ static void *calc_ptr(struct ext4_attr *a, struct ext4_sb_info *sbi)
>  
>  static ssize_t __print_tstamp(char *buf, __le32 lo, __u8 hi)
>  {
> -	return snprintf(buf, PAGE_SIZE, "%lld\n",
> +	return sysfs_emit(buf, "%lld\n",
>  			((time64_t)hi << 32) + le32_to_cpu(lo));
>  }
>  
> @@ -374,7 +374,7 @@ static ssize_t ext4_attr_show(struct kobject *kobj,
>  
>  	switch (a->attr_id) {
>  	case attr_delayed_allocation_blocks:
> -		return snprintf(buf, PAGE_SIZE, "%llu\n",
> +		return sysfs_emit(buf, "%llu\n",
>  				(s64) EXT4_C2B(sbi,
>  		       percpu_counter_sum(&sbi->s_dirtyclusters_counter)));
>  	case attr_session_write_kbytes:
> @@ -382,11 +382,11 @@ static ssize_t ext4_attr_show(struct kobject *kobj,
>  	case attr_lifetime_write_kbytes:
>  		return lifetime_write_kbytes_show(sbi, buf);
>  	case attr_reserved_clusters:
> -		return snprintf(buf, PAGE_SIZE, "%llu\n",
> +		return sysfs_emit(buf, "%llu\n",
>  				(unsigned long long)
>  				atomic64_read(&sbi->s_resv_clusters));
>  	case attr_sra_exceeded_retry_limit:
> -		return snprintf(buf, PAGE_SIZE, "%llu\n",
> +		return sysfs_emit(buf, "%llu\n",
>  				(unsigned long long)
>  			percpu_counter_sum(&sbi->s_sra_exceeded_retry_limit));
>  	case attr_inode_readahead:
> @@ -394,42 +394,42 @@ static ssize_t ext4_attr_show(struct kobject *kobj,
>  		if (!ptr)
>  			return 0;
>  		if (a->attr_ptr == ptr_ext4_super_block_offset)
> -			return snprintf(buf, PAGE_SIZE, "%u\n",
> +			return sysfs_emit(buf, "%u\n",
>  					le32_to_cpup(ptr));
>  		else
> -			return snprintf(buf, PAGE_SIZE, "%u\n",
> +			return sysfs_emit(buf, "%u\n",
>  					*((unsigned int *) ptr));
>  	case attr_pointer_ul:
>  		if (!ptr)
>  			return 0;
> -		return snprintf(buf, PAGE_SIZE, "%lu\n",
> +		return sysfs_emit(buf, "%lu\n",
>  				*((unsigned long *) ptr));
>  	case attr_pointer_u8:
>  		if (!ptr)
>  			return 0;
> -		return snprintf(buf, PAGE_SIZE, "%u\n",
> +		return sysfs_emit(buf, "%u\n",
>  				*((unsigned char *) ptr));
>  	case attr_pointer_u64:
>  		if (!ptr)
>  			return 0;
>  		if (a->attr_ptr == ptr_ext4_super_block_offset)
> -			return snprintf(buf, PAGE_SIZE, "%llu\n",
> +			return sysfs_emit(buf, "%llu\n",
>  					le64_to_cpup(ptr));
>  		else
> -			return snprintf(buf, PAGE_SIZE, "%llu\n",
> +			return sysfs_emit(buf, "%llu\n",
>  					*((unsigned long long *) ptr));
>  	case attr_pointer_string:
>  		if (!ptr)
>  			return 0;
> -		return snprintf(buf, PAGE_SIZE, "%.*s\n", a->attr_size,
> +		return sysfs_emit(buf, "%.*s\n", a->attr_size,
>  				(char *) ptr);
>  	case attr_pointer_atomic:
>  		if (!ptr)
>  			return 0;
> -		return snprintf(buf, PAGE_SIZE, "%d\n",
> +		return sysfs_emit(buf, "%d\n",
>  				atomic_read((atomic_t *) ptr));
>  	case attr_feature:
> -		return snprintf(buf, PAGE_SIZE, "supported\n");
> +		return sysfs_emit(buf, "supported\n");
>  	case attr_first_error_time:
>  		return print_tstamp(buf, sbi->s_es, s_first_error_time);
>  	case attr_last_error_time:
> -- 
> 2.7.4
> 
-- 
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR



[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux