mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
To: Chaitanya Kulkarni <kch@nvidia.com>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: axboe@kernel.dk, johannes.thumshirn@wdc.com, bvanassche@acm.org,
	ming.lei@redhat.com, shinichiro.kawasaki@wdc.com,
	vincent.fu@samsung.com, yukuai3@huawei.com
Subject: Re: [PATCH 5/6] null_blk: don't use magic numbers in the code
Date: Wed, 5 Oct 2022 14:05:59 +0900	[thread overview]
Message-ID: <0e3894bf-7d06-bac9-8efc-fa73bf3fb902@opensource.wdc.com> (raw)
In-Reply-To: <20221005031701.79077-6-kch@nvidia.com>

On 10/5/22 12:17, Chaitanya Kulkarni wrote:
> Insteasd of using the hardcoded value use meaningful macro for tag
> available value of -1U in get_tag() and __alloc_cmd().
> 
> While at it return early on error to get rid of the extra indentation
> in __alloc_cmd().
> 
> Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>

> ---
>  drivers/block/null_blk/main.c | 30 +++++++++++++++---------------
>  1 file changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
> index 765c1ca0edf5..eda5050d6dee 100644
> --- a/drivers/block/null_blk/main.c
> +++ b/drivers/block/null_blk/main.c
> @@ -24,6 +24,8 @@
>  #define TICKS_PER_SEC		50ULL
>  #define TIMER_INTERVAL		(NSEC_PER_SEC / TICKS_PER_SEC)
>  
> +#define NULL_REQ_TAG_NOT_AVAILABLE (-1U)
> +
>  #ifdef CONFIG_BLK_DEV_NULL_BLK_FAULT_INJECTION
>  static DECLARE_FAULT_ATTR(null_timeout_attr);
>  static DECLARE_FAULT_ATTR(null_requeue_attr);
> @@ -730,7 +732,7 @@ static unsigned int get_tag(struct nullb_queue *nq)
>  	do {
>  		tag = find_first_zero_bit(nq->tag_map, nq->queue_depth);
>  		if (tag >= nq->queue_depth)
> -			return -1U;
> +			return NULL_REQ_TAG_NOT_AVAILABLE;
>  	} while (test_and_set_bit_lock(tag, nq->tag_map));
>  
>  	return tag;
> @@ -749,21 +751,19 @@ static struct nullb_cmd *__alloc_cmd(struct nullb_queue *nq, struct bio *bio)
>  	unsigned int tag;
>  
>  	tag = get_tag(nq);
> -	if (tag != -1U) {
> -		cmd = &nq->cmds[tag];
> -		cmd->tag = tag;
> -		cmd->error = BLK_STS_OK;
> -		cmd->nq = nq;
> -		cmd->bio = bio;
> -		if (nq->dev->irqmode == NULL_IRQ_TIMER) {
> -			hrtimer_init(&cmd->timer, CLOCK_MONOTONIC,
> -				     HRTIMER_MODE_REL);
> -			cmd->timer.function = null_cmd_timer_expired;
> -		}
> -		return cmd;
> +	if (tag == NULL_REQ_TAG_NOT_AVAILABLE)
> +		return NULL;
> +	cmd = &nq->cmds[tag];
> +	cmd->tag = tag;
> +	cmd->error = BLK_STS_OK;
> +	cmd->nq = nq;
> +	cmd->bio = bio;
> +	if (nq->dev->irqmode == NULL_IRQ_TIMER) {
> +		hrtimer_init(&cmd->timer, CLOCK_MONOTONIC,
> +				HRTIMER_MODE_REL);
> +		cmd->timer.function = null_cmd_timer_expired;
>  	}
> -
> -	return NULL;
> +	return cmd;
>  }
>  
>  static struct nullb_cmd *alloc_cmd(struct nullb_queue *nq, struct bio *bio)

-- 
Damien Le Moal
Western Digital Research


  reply	other threads:[~2022-10-05  5:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-05  3:16 [PATCH 0/6] null_blk: allow REQ_OP_WRITE_ZEROES and cleanup Chaitanya Kulkarni
2022-10-05  3:16 ` [PATCH 1/6] null_blk: allow write zeores on non-membacked Chaitanya Kulkarni
2022-10-05  4:54   ` Damien Le Moal
2022-10-05  5:24     ` Chaitanya Kulkarni
2022-10-05 18:33       ` Chaitanya Kulkarni
2022-10-05  3:16 ` [PATCH 2/6] null_blk: allow write zeores on membacked Chaitanya Kulkarni
2022-10-05  4:57   ` Damien Le Moal
2022-10-05  5:10     ` Chaitanya Kulkarni
2022-10-05 17:18   ` Brian Foster
2022-10-05  3:16 ` [PATCH 3/6] null_blk: code cleaup Chaitanya Kulkarni
2022-10-05  5:02   ` Damien Le Moal
2022-10-05  5:21     ` Chaitanya Kulkarni
2022-10-05  3:16 ` [PATCH 4/6] null_blk: initialize cmd->bio in __alloc_cmd() Chaitanya Kulkarni
2022-10-05  5:04   ` Damien Le Moal
2022-10-05  3:17 ` [PATCH 5/6] null_blk: don't use magic numbers in the code Chaitanya Kulkarni
2022-10-05  5:05   ` Damien Le Moal [this message]
2022-10-05  3:17 ` [PATCH 6/6] null_blk: remove extra space in switch condition Chaitanya Kulkarni
2022-10-05  5:06   ` 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=0e3894bf-7d06-bac9-8efc-fa73bf3fb902@opensource.wdc.com \
    --to=damien.lemoal@opensource.wdc.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=johannes.thumshirn@wdc.com \
    --cc=kch@nvidia.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=shinichiro.kawasaki@wdc.com \
    --cc=vincent.fu@samsung.com \
    --cc=yukuai3@huawei.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

Powered by JetHome