[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <f55da3cf-47ca-e942-0713-1133279eab46@huawei.com>
Date: Tue, 28 Nov 2023 10:18:59 +0800
From: Zhihao Cheng <chengzhihao1@...wei.com>
To: Daniel Golle <daniel@...rotopia.org>,
Richard Weinberger <richard@....at>,
Miquel Raynal <miquel.raynal@...tlin.com>,
Vignesh Raghavendra <vigneshr@...com>,
Artem Bityutskiy <Artem.Bityutskiy@...ia.com>,
<linux-mtd@...ts.infradead.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2] ubi: don't decrease ubi->ref_count on detach error
在 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@...rotopia.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@...wei.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);
>
Powered by blists - more mailing lists