mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Zhiguo Niu <zhiguo.niu@unisoc.com>, axboe@kernel.dk, hch@lst.de
Cc: bvanassche@acm.org, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, niuzhiguo84@gmail.com,
	ke.wang@unisoc.com, Hao_hao.Wang@unisoc.com
Subject: Re: [PATCH V3] block: uapi: Use unsigned int type for IOPRIO_PRIO_MASK
Date: Wed, 31 Jul 2024 18:28:22 +0900	[thread overview]
Message-ID: <dafe01f5-5f08-4298-b020-7e3c80e4f15d@kernel.org> (raw)
In-Reply-To: <1722409287-12183-1-git-send-email-zhiguo.niu@unisoc.com>

On 7/31/24 16:01, Zhiguo Niu wrote:
> Generally, the input of IOPRIO_PRIO_DATA has 16 bits, but the output of
> IOPRIO_PRIO_DATA will be expanded to "UL" from IOPRIO_PRIO_MASK.
>  #define IOPRIO_PRIO_MASK	((1UL << IOPRIO_CLASS_SHIFT) - 1)
> This is not reasonable and meaningless, unsigned int is more suitable for it.
> 
> So if use format "%d" to print IOPRIO_PRIO_DATA directly, there will be a
> build warning or error showned as the following, which is from the
> local test when I modify f2fs codes.
> 
> 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
> 
> When modules use IOPRIO_PRIO_CLASS & IOPRIO_PRIO_LEVEL get ioprio's class and
> level, their outputs are both unsigned int.
>  IOPRIO_CLASS_MASK is:
>  #define IOPRIO_CLASS_SHIFT	13
>  #define IOPRIO_NR_CLASSES	8
>  #define IOPRIO_CLASS_MASK	(IOPRIO_NR_CLASSES - 1)
>  IOPRIO_LEVEL_MASK is:
>  #define IOPRIO_LEVEL_NR_BITS	3
>  #define IOPRIO_NR_LEVELS	(1 << IOPRIO_LEVEL_NR_BITS)
>  #define IOPRIO_LEVEL_MASK	(IOPRIO_NR_LEVELS - 1)
> 
> Ioprio is passed along as an int internally, so we should not be using an
> unsigned long for IOPRIO_PRIO_MASK to not end up with IOPRIO_PRIO_DATA
> returning an unsigned long as well.

I would write this commit message like this:


An ioprio is passed internally as an int value. When IOPRIO_PRIO_CLASS() and
IOPRIO_PRIO_LEVEL() are used to extract from it the priority class and level,
the values obtained are thus also int.
However, the IOPRIO_PRIO_MASK() macro used to define the IOPRIO_PRIO_DATA()
macro is defined as:

#define IOPRIO_PRIO_MASK	((1UL << IOPRIO_CLASS_SHIFT) - 1)

that is, the macro gives an unsigned long value, which leads to
IOPRIO_PRIO_DATA() also returning an unsigned long.

Make things consistent between class, level and data and use int everywhere by
removing forced unsigned long from IOPRIO_PRIO_MASK.



-- 
Damien Le Moal
Western Digital Research


  reply	other threads:[~2024-07-31  9:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-31  7:01 Zhiguo Niu
2024-07-31  9:28 ` Damien Le Moal [this message]
2024-07-31 11:07   ` Zhiguo Niu

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=dafe01f5-5f08-4298-b020-7e3c80e4f15d@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=Hao_hao.Wang@unisoc.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=hch@lst.de \
    --cc=ke.wang@unisoc.com \
    --cc=linux-block@vger.kernel.org \
    --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®