Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3556914rdh; Mon, 27 Nov 2023 18:19:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSXsIeUDFQZlpQId8suQwCjRzjkTyfST2py4H2GxVUGQKwuUWNLDaJ+cuB+sFxZfAD6FOD X-Received: by 2002:a05:6a20:6d98:b0:18b:902f:892 with SMTP id gl24-20020a056a206d9800b0018b902f0892mr12609797pzb.40.1701137960700; Mon, 27 Nov 2023 18:19:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701137960; cv=none; d=google.com; s=arc-20160816; b=VQwf/dP6AA7yVK/H7r5ypwrRMM1FbqNZAUNUMyTomr5ItNa52xPCUn5I9v5LQc1eth D4eqzVCCw44+Yi586v0Xqj41E91XUzafqyOsLPuU4DJmy7RPxckbcN7h0SxHQ5zwih5l +CKJooduMZZ/VEa+r4c5uu/alwkSYlKy46FU5zHECkdCcZaHBr3y80IXUVS+7cSfATiW 8PZ61qXHdO/Evv3schRqeMD3hXxD8SbAlKA1imultoBJYiLnY+92KuuBzIPS3ue32Hqh EVgoF+5XWWAWftGvrSvvKl2L7KTmGX+8Jonf+ogcdW8BoSwWAD2ozOl6VW0iADXYC7Gf etdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:to:subject; bh=onpxilFedrZM2zwLisw4gq3oppIm7JO8eKHkmeo5xVo=; fh=VUJUSFTYkTSQxk1NhkP99H/Ir7/tzRUhpSBYxvUV7wE=; b=mXynZKvmVAEXICtIr1UecgiQpASpmPwTrwI3fAZp9O4+FifCcs7T1W1B+aM/R2O0L+ VSbP8dwilQGhCVAZ9P4wmjAXWu6HeHkMmREnCNf7Ji2qCuDfNaT/2spgGhjxmxHzv69F tQzl1CfjBcRAQHZdKoQlfpgRsiBX1I/qhb5DmFCrlH1sA6rRmcgQ06jvkpCOnxg3+4bH PdoUTVOR62JKuE9P2eEHxiNLOxj7gav8yADNY2s84xEdByEG2nbb+nobhVuxqdNxV7K+ 6APBh4UgkQtrvy81pWdqzPhiWW1gppTMujeuTYSVCl4p8Y4xXmi3p0MohHN790YJehmg Mnbw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id f9-20020a170902ab8900b001cfc033064dsi5148563plr.92.2023.11.27.18.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 18:19:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7639580A9188; Mon, 27 Nov 2023 18:19:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234383AbjK1CTJ (ORCPT + 99 others); Mon, 27 Nov 2023 21:19:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231623AbjK1CTI (ORCPT ); Mon, 27 Nov 2023 21:19:08 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 287F71B1 for ; Mon, 27 Nov 2023 18:19:14 -0800 (PST) Received: from kwepemm000013.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SfQxp1QDPzMnTd; Tue, 28 Nov 2023 10:14:22 +0800 (CST) Received: from [10.174.178.46] (10.174.178.46) by kwepemm000013.china.huawei.com (7.193.23.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 28 Nov 2023 10:19:11 +0800 Subject: Re: [PATCH v2] ubi: don't decrease ubi->ref_count on detach error To: Daniel Golle , Richard Weinberger , Miquel Raynal , Vignesh Raghavendra , Artem Bityutskiy , , References: <771902199.32600.1701116758852.JavaMail.zimbra@nod.at> <8d48839a1bf928886e86de8fdc09dc0676fc187f.1701132215.git.daniel@makrotopia.org> From: Zhihao Cheng Message-ID: Date: Tue, 28 Nov 2023 10:18:59 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <8d48839a1bf928886e86de8fdc09dc0676fc187f.1701132215.git.daniel@makrotopia.org> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.46] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000013.china.huawei.com (7.193.23.81) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 27 Nov 2023 18:19:19 -0800 (PST) ?? 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 > --- > 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 > > 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); >