From: Jiri Slaby <jirislaby@kernel.org>
To: "Martin Liška" <mliska@suse.cz>, linux-kernel@vger.kernel.org
Cc: linux-block@vger.kernel.org, axboe@kernel.dk
Subject: Re: [PATCH] block: fix Werror=format with GCC 13
Date: Wed, 26 Oct 2022 09:18:13 +0200 [thread overview]
Message-ID: <bc107c62-25ab-f959-c5bc-d5bacc511f20@kernel.org> (raw)
In-Reply-To: <f70c7a11-e81e-f6b9-a403-315117f4aa3a@suse.cz>
On 24. 10. 22, 21:01, Martin Liška wrote:
> Starting with GCC 13, since
> [g3b3083a598ca3f4b] c: C2x enums wider than int [PR36113]
>
> GCC promotes enum values with larger than integer types to a wider type.
> In case of the anonymous enum type in blk-iocost.c it is:
>
> enum {
> MILLION = 1000000,
> ...
>
> WEIGHT_ONE = 1 << 16,
> ...
> VTIME_PER_SEC_SHIFT = 37,
> VTIME_PER_SEC = 1LLU << VTIME_PER_SEC_SHIFT,
> ...
>
> as seen VTIME_PER_SEC cannot fit into 32-bits (int type), thus one needs
> to use 'long unsigned int' in the format string.
>
> It fixes then the following 2 warnings:
>
> block/blk-iocost.c: In function ‘ioc_weight_prfill’:
> block/blk-iocost.c:3035:37: error: format ‘%u’ expects argument of type ‘unsigned int’, but argument 4 has type ‘long unsigned int’ [-Werror=format=]
> 3035 | seq_printf(sf, "%s %u\n", dname, iocg->cfg_weight / WEIGHT_ONE);
> | ~^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> | | |
> | unsigned int long unsigned int
> | %lu
> block/blk-iocost.c: In function ‘ioc_weight_show’:
> block/blk-iocost.c:3045:34: error: format ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘long unsigned int’ [-Werror=format=]
> 3045 | seq_printf(sf, "default %u\n", iocc->dfl_weight / WEIGHT_ONE);
> | ~^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> | | |
> | unsigned int long unsigned int
> | %lu
But introduces two with gcc-12 ;):
> block/blk-iocost.c: In function ‘ioc_weight_prfill’:
> block/blk-iocost.c:3037:38: error: format ‘%lu’ expects argument of
type ‘long unsigned int’, but argument 4 has type ‘u32’ {aka ‘unsigned
int’} [-Werror=format=]
> 3037 | seq_printf(sf, "%s %lu\n", dname,
iocg->cfg_weight / WEIGHT_ONE);
> | ~~^
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> | |
|
> | long unsigned int
u32 {aka unsigned int}
> | %u
Note that:
1) the specs says enum behaves as int, or uint in some cases
2) iocc->dfl_weight is u32, i.e. uint
WEIGHT_ONE is 1 << 16, i.e. int
so the promotion should be to s32/int. Or not?
I think gcc-13 is wrong -- incosistent with gcc-12 at least.
> Signed-off-by: Martin Liska <mliska@suse.cz>
> ---
> 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 495396425bad..f165bac9bffb 100644
> --- a/block/blk-iocost.c
> +++ b/block/blk-iocost.c
> @@ -3032,7 +3032,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 %lu\n", dname, iocg->cfg_weight / WEIGHT_ONE);
> return 0;
> }
>
> @@ -3042,7 +3042,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 %lu\n", iocc->dfl_weight / WEIGHT_ONE);
> blkcg_print_blkgs(sf, blkcg, ioc_weight_prfill,
> &blkcg_policy_iocost, seq_cft(sf)->private, false);
> return 0;
thanks,
--
js
suse labs
next prev parent reply other threads:[~2022-10-26 7:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-24 19:01 [PATCH] block: fix Werror=format with GCC 13 Martin Liška
2022-10-26 7:18 ` Jiri Slaby [this message]
2022-10-26 8:16 ` David Laight
2022-10-26 20:11 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bc107c62-25ab-f959-c5bc-d5bacc511f20@kernel.org \
--to=jirislaby@kernel.org \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mliska@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox