mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Zhiguo Niu <zhiguo.niu@unisoc.com>, axboe@kernel.dk
Cc: dlemoal@kernel.org, linux-kernel@vger.kernel.org,
	niuzhiguo84@gmail.com, ke.wang@unisoc.com
Subject: Re: [PATCH] block: uapi: Fix compliation warning of using IOPRIO_PRIO_DATA
Date: Fri, 31 May 2024 13:13:07 -0700	[thread overview]
Message-ID: <e1719623-a42e-4394-b840-2741975ead37@acm.org> (raw)
In-Reply-To: <1717155071-20409-1-git-send-email-zhiguo.niu@unisoc.com>

On 5/31/24 04:31, Zhiguo Niu wrote:
> Generally, the input of IOPRIO_PRIO_DATA has 16 bits. If use format "%d"
> to printk IOPRIO_PRIO_DATA, there will be the following warning or error.
> 
> fs/f2fs/sysfs.c:348:31: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
>     return sysfs_emit(buf, "%s,%d\n",
>                                ~^
>                                %ld
> 
> This is because the output of IOPRIO_PRIO_DATA is converted to "UL" from
> IOPRIO_PRIO_MASK, which is not reasonable. unsigned int is more suitable.
> 
> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
> ---
>   include/uapi/linux/ioprio.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/uapi/linux/ioprio.h b/include/uapi/linux/ioprio.h
> index bee2bdb0..9ead07f 100644
> --- a/include/uapi/linux/ioprio.h
> +++ b/include/uapi/linux/ioprio.h
> @@ -11,7 +11,7 @@
>   #define IOPRIO_CLASS_SHIFT	13
>   #define IOPRIO_NR_CLASSES	8
>   #define IOPRIO_CLASS_MASK	(IOPRIO_NR_CLASSES - 1)
> -#define IOPRIO_PRIO_MASK	((1UL << IOPRIO_CLASS_SHIFT) - 1)
> +#define IOPRIO_PRIO_MASK	((1U << IOPRIO_CLASS_SHIFT) - 1)
>   
>   #define IOPRIO_PRIO_CLASS(ioprio)	\
>   	(((ioprio) >> IOPRIO_CLASS_SHIFT) & IOPRIO_CLASS_MASK)

This change is safe even if the mask is applied to an expression with more bits
than an int because of the integer promotion rules. Hence:

Reviewed-by: Bart Van Assche <bvanassche@acm.org>

  reply	other threads:[~2024-05-31 20:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-31 11:31 Zhiguo Niu
2024-05-31 20:13 ` Bart Van Assche [this message]
2024-07-09  3:27   ` Zhiguo Niu
2024-07-09  4:50     ` Damien Le Moal

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=e1719623-a42e-4394-b840-2741975ead37@acm.org \
    --to=bvanassche@acm.org \
    --cc=axboe@kernel.dk \
    --cc=dlemoal@kernel.org \
    --cc=ke.wang@unisoc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=niuzhiguo84@gmail.com \
    --cc=zhiguo.niu@unisoc.com \
    /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

all inboxes | Powered by JetHome®