public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Daniel Golle <daniel@makrotopia.org>,
	Richard Weinberger <richard@nod.at>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Artem Bityutskiy <Artem.Bityutskiy@nokia.com>,
	<linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] ubi: don't decrease ubi->ref_count on detach error
Date: Tue, 28 Nov 2023 10:18:59 +0800	[thread overview]
Message-ID: <f55da3cf-47ca-e942-0713-1133279eab46@huawei.com> (raw)
In-Reply-To: <8d48839a1bf928886e86de8fdc09dc0676fc187f.1701132215.git.daniel@makrotopia.org>

在 2023/11/28 8:45, Daniel Golle 写道:
> If attempting to detach a UBI device while it is still busy, detaching
> is refused. However, the reference counter is still being decreased
> despite the error. Rework detach function to only decrease the reference
> counter once all conditions for detachment are met.
>
> Fixes: cdfa788acd13 ("UBI: prepare attach and detach functions")
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
> v2: also catch negative ref_count and add ubi_assert as suggested
>
>   drivers/mtd/ubi/build.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)

Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>

>
> diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
> index 7d4ff1193db6f..2316f6014c7f5 100644
> --- a/drivers/mtd/ubi/build.c
> +++ b/drivers/mtd/ubi/build.c
> @@ -1099,16 +1099,17 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
>   
>   	spin_lock(&ubi_devices_lock);
>   	put_device(&ubi->dev);
> -	ubi->ref_count -= 1;
> -	if (ubi->ref_count) {
> +	if (ubi->ref_count != 1) {
>   		if (!anyway) {
>   			spin_unlock(&ubi_devices_lock);
>   			return -EBUSY;
>   		}
>   		/* This may only happen if there is a bug */
>   		ubi_err(ubi, "%s reference count %d, destroy anyway",
> -			ubi->ubi_name, ubi->ref_count);
> +			ubi->ubi_name, ubi->ref_count - 1);
>   	}
> +	ubi->ref_count -= 1;
> +	ubi_assert(ubi->ref_count == 0);
>   	ubi_devices[ubi_num] = NULL;
>   	spin_unlock(&ubi_devices_lock);
>   



______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

      reply	other threads:[~2023-11-28  2:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-27 17:09 [PATCH] ubi: don't decrease ubi->ref_count on detach error Daniel Golle
2023-11-27 20:25 ` Richard Weinberger
2023-11-27 22:06   ` Daniel Golle
2023-11-28  0:45   ` [PATCH v2] " Daniel Golle
2023-11-28  2:18     ` Zhihao Cheng [this message]

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=f55da3cf-47ca-e942-0713-1133279eab46@huawei.com \
    --to=chengzhihao1@huawei.com \
    --cc=Artem.Bityutskiy@nokia.com \
    --cc=daniel@makrotopia.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.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