2022-09-25 20:48:16

by Elijah Conners

[permalink] [raw]
Subject: [PATCH] blk-iocost: explicitly declare long in seq_printf

On lines 3038 and 3048, seq_printf() is used with iocg->cfg_weight /
WEIGHT_ONE. This operation is a long, not an unsigned int, so the usage
of %u in this printf() function is unusual. While C will automatically
promote iocg->cfg_weight / WEIGHT_ONE to an unsigned int—and safely—it
is ultimately better to tell seq_printf() that this is a long.

Signed-off-by: Elijah Conners <[email protected]>
---
block/blk-iocost.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index 7936e5f5821c..78aae116793e 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -3035,7 +3035,7 @@ static u64 ioc_weight_prfill(struct seq_file *sf, struct blkg_policy_data *pd,
struct ioc_gq *iocg = pd_to_iocg(pd);

if (dname && iocg->cfg_weight)
- seq_printf(sf, "%s %u\n", dname, iocg->cfg_weight / WEIGHT_ONE);
+ seq_printf(sf, "%s %ld\n", dname, iocg->cfg_weight / WEIGHT_ONE);
return 0;
}

@@ -3045,7 +3045,7 @@ static int ioc_weight_show(struct seq_file *sf, void *v)
struct blkcg *blkcg = css_to_blkcg(seq_css(sf));
struct ioc_cgrp *iocc = blkcg_to_iocc(blkcg);

- seq_printf(sf, "default %u\n", iocc->dfl_weight / WEIGHT_ONE);
+ seq_printf(sf, "default %ld\n", iocc->dfl_weight / WEIGHT_ONE);
blkcg_print_blkgs(sf, blkcg, ioc_weight_prfill,
&blkcg_policy_iocost, seq_cft(sf)->private, false);
return 0;
--
2.29.2.windows.2


2022-09-26 06:06:38

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] blk-iocost: explicitly declare long in seq_printf

Hi Elijah,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on axboe-block/for-next]
[also build test WARNING on linus/master v6.0-rc7 next-20220923]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Elijah-Conners/blk-iocost-explicitly-declare-long-in-seq_printf/20220926-044530
base: https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
config: x86_64-defconfig
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/69c3e0ff7554edafb2667c06d60c974f1f1f6246
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Elijah-Conners/blk-iocost-explicitly-declare-long-in-seq_printf/20220926-044530
git checkout 69c3e0ff7554edafb2667c06d60c974f1f1f6246
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

block/blk-iocost.c: In function 'ioc_weight_prfill':
>> block/blk-iocost.c:3038:38: warning: format '%ld' expects argument of type 'long int', but argument 4 has type 'u32' {aka 'unsigned int'} [-Wformat=]
3038 | seq_printf(sf, "%s %ld\n", dname, iocg->cfg_weight / WEIGHT_ONE);
| ~~^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| long int u32 {aka unsigned int}
| %d
block/blk-iocost.c: In function 'ioc_weight_show':
>> block/blk-iocost.c:3048:35: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'unsigned int' [-Wformat=]
3048 | seq_printf(sf, "default %ld\n", iocc->dfl_weight / WEIGHT_ONE);
| ~~^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| long int unsigned int
| %d


vim +3038 block/blk-iocost.c

3030
3031 static u64 ioc_weight_prfill(struct seq_file *sf, struct blkg_policy_data *pd,
3032 int off)
3033 {
3034 const char *dname = blkg_dev_name(pd->blkg);
3035 struct ioc_gq *iocg = pd_to_iocg(pd);
3036
3037 if (dname && iocg->cfg_weight)
> 3038 seq_printf(sf, "%s %ld\n", dname, iocg->cfg_weight / WEIGHT_ONE);
3039 return 0;
3040 }
3041
3042
3043 static int ioc_weight_show(struct seq_file *sf, void *v)
3044 {
3045 struct blkcg *blkcg = css_to_blkcg(seq_css(sf));
3046 struct ioc_cgrp *iocc = blkcg_to_iocc(blkcg);
3047
> 3048 seq_printf(sf, "default %ld\n", iocc->dfl_weight / WEIGHT_ONE);
3049 blkcg_print_blkgs(sf, blkcg, ioc_weight_prfill,
3050 &blkcg_policy_iocost, seq_cft(sf)->private, false);
3051 return 0;
3052 }
3053

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (3.43 kB)
config (137.85 kB)
Download all attachments