public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Ricardo H H Kojo <ricardo.kojo@ime.usp.br>
Cc: Ellian Carlos <elliancarlos@gmail.com>,
	Gabriel B L de Oliveira <gabrielblo@ime.usp.br>,
	linux-block@vger.kernel.org
Subject: Re: [PATCH 1/2] nullblk: main: use lock guards
Date: Sat, 18 Apr 2026 07:58:33 -0600	[thread overview]
Message-ID: <90eed72d-d097-4dc6-ab90-6f08e14c57fa@kernel.dk> (raw)
In-Reply-To: <20260418043837.721045-2-ricardo.kojo@ime.usp.br>

On 4/17/26 10:38 PM, Ricardo H H Kojo wrote:
> Use guard() and scoped_guard() for handling mutex and spin locks instead of
> manually locking and unlocking. This prevents forgotten locks due to early
> exits and remove the need of gotos.
> 
> Signed-off-by: Ricardo H H Kojo <ricardo.kojo@ime.usp.br>
> Co-developed-by: Ellian Carlos <elliancarlos@gmail.com>
> Signed-off-by: Ellian Carlos <elliancarlos@gmail.com>
> Co-developed-by: Gabriel B L de Oliveira <gabrielblo@ime.usp.br>
> Signed-off-by: Gabriel B L de Oliveira <gabrielblo@ime.usp.br>
> ---
>  drivers/block/null_blk/main.c     | 74 +++++++++++++------------------
>  drivers/block/null_blk/null_blk.h |  1 +
>  2 files changed, 32 insertions(+), 43 deletions(-)
> 
> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
> index f8c0fd57e041..fbe34e8a6c93 100644
> --- a/drivers/block/null_blk/main.c
> +++ b/drivers/block/null_blk/main.c
> @@ -423,9 +423,8 @@ static int nullb_apply_submit_queues(struct nullb_device *dev,
>  {
>  	int ret;
>  
> -	mutex_lock(&lock);
> +	guard(mutex)(&lock);
>  	ret = nullb_update_nr_hw_queues(dev, submit_queues, dev->poll_queues);
> -	mutex_unlock(&lock);
>  
>  	return ret;
>  }

If you're going to use lock guards instead, why on earth is this not
just:

{
	guard(mutex)(&lock);
	return nullb_update_nr_hw_queues(dev, submit_queues, dev->poll_queues);
}

?!

This odd intermediate state you opted for makes no sense.

-- 
Jens Axboe

  reply	other threads:[~2026-04-18 13:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-18  4:38 [PATCH 0/2] nullblk: use lock guards Ricardo H H Kojo
2026-04-18  4:38 ` [PATCH 1/2] nullblk: main: " Ricardo H H Kojo
2026-04-18 13:58   ` Jens Axboe [this message]
2026-04-18  4:38 ` [PATCH 2/2] nullblk: zoned: " Ricardo H H Kojo

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=90eed72d-d097-4dc6-ab90-6f08e14c57fa@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=elliancarlos@gmail.com \
    --cc=gabrielblo@ime.usp.br \
    --cc=linux-block@vger.kernel.org \
    --cc=ricardo.kojo@ime.usp.br \
    /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