Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3371131rdh; Mon, 27 Nov 2023 12:26:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFwCX79hgX2jFWeB/oPZq8KUVXiHBeu710Zc3nA3M8qyh+5q9ONJ1aBa1s18RelkP116iS1 X-Received: by 2002:a92:760b:0:b0:35c:966e:3f7e with SMTP id r11-20020a92760b000000b0035c966e3f7emr8913612ilc.11.1701116780578; Mon, 27 Nov 2023 12:26:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701116780; cv=none; d=google.com; s=arc-20160816; b=CKGjblOQlkupwZ2X5onJeJAjvDgPDgL8Osqp55/DaLax+Uz2oprcgRMvFBFyChfIaf JGDdyVdUdDYMst6ZaMKKl2Gu4Uag7hxNdAT+js53N4Lh2S3eQS0/x7cHUODm9cFpLlht DJh83lnU6OFpf4n/wYhr05GT6uuGlG4+5AeRpmYq8vSjEmUvRGLzcHTr7wkuht5GW/Ha sKN4AEJ5StXTnv7ghBnBvRDBO03fdPRt5Bs1Gbrxt0v4Sod8UVjYZp70ndx59shYwMRG 0qAyz3YMi9C/Ap+3X+afZjpauEOVF6jLtwfrUtnT0M/mGVJ7I9QKjhn/6cxjG9FAB3gF RPRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date; bh=rvkzAOgY2O7lHlRaRy5RYwky9OB/mSoQDG6T4hyl+p0=; fh=W/tpg1gjtv+tpeXZjMV4iyZZkWO83qpI844r2ZAGJLk=; b=zx2ev4DOsRSMu0AEcauafk5tlkCyjM25pZO2wgnNGAb0DWrkmjb+Q2IeUAwrdv4VRl B0+4MMW5ySyywFy1gaKBRTd7ZWJz8YBCW0L3JMUJL0sW2SVaxFz64rilsOfPytwjxEoM mrRqIfwm3GEqLnt+LmkoiTEphAIJVeQFTbBJ1psbhxfKuFlm5w4PB0pu9HRitPmp1xzg vq0SAynAhugFpP2yS/MaqG42iP0v+mG2jIWjCO3vcgg2n0DSFR75wr35J1zB2HAqaxKz nBk+UHASlYjbwVNOnesvKAp+UeISPV5DxvbyUmkgLxE44PtHsftfm6lCcH66AFcltlNG fppQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id t11-20020a63dd0b000000b005c17124d9b9si1976279pgg.74.2023.11.27.12.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 12:26:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 510DC805BCA5; Mon, 27 Nov 2023 12:26:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231767AbjK0U0A convert rfc822-to-8bit (ORCPT + 99 others); Mon, 27 Nov 2023 15:26:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbjK0UZ7 (ORCPT ); Mon, 27 Nov 2023 15:25:59 -0500 Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C2EBD59 for ; Mon, 27 Nov 2023 12:26:02 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 016D96413F60; Mon, 27 Nov 2023 21:26:00 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id uLRVYHk-f5Lg; Mon, 27 Nov 2023 21:25:59 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 3013E6340E00; Mon, 27 Nov 2023 21:25:59 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id K3yrBMph3TqV; Mon, 27 Nov 2023 21:25:59 +0100 (CET) Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lithops.sigma-star.at (Postfix) with ESMTP id 0CF816413F60; Mon, 27 Nov 2023 21:25:59 +0100 (CET) Date: Mon, 27 Nov 2023 21:25:58 +0100 (CET) From: Richard Weinberger To: Daniel Golle Cc: Miquel Raynal , Vignesh Raghavendra , Artem Bityutskiy , linux-mtd , linux-kernel , John Crispin Message-ID: <771902199.32600.1701116758852.JavaMail.zimbra@nod.at> In-Reply-To: <9857609999c5b7196417474938a7a09892cd1612.1701104870.git.daniel@makrotopia.org> References: <9857609999c5b7196417474938a7a09892cd1612.1701104870.git.daniel@makrotopia.org> Subject: Re: [PATCH] ubi: don't decrease ubi->ref_count on detach error MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-Originating-IP: [195.201.40.130] X-Mailer: Zimbra 8.8.12_GA_3807 (ZimbraWebClient - FF97 (Linux)/8.8.12_GA_3809) Thread-Topic: don't decrease ubi->ref_count on detach error Thread-Index: chpmDIpsyDGT4mmuCnlwjJ5qLzrYdQ== X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Mon, 27 Nov 2023 12:26:18 -0800 (PST) ----- Ursprüngliche Mail ----- > Von: "Daniel Golle" > An: "richard" , "Miquel Raynal" , "Vignesh Raghavendra" , > "Artem Bityutskiy" , "linux-mtd" , "linux-kernel" > > CC: "John Crispin" > Gesendet: Montag, 27. November 2023 18:09:14 > Betreff: [PATCH] ubi: don't decrease ubi->ref_count on detach error > 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 refcnt > once all conditions for detachment are met. > > Fixes: cdfa788acd13 ("UBI: prepare attach and detach functions") > Signed-off-by: Daniel Golle Good catch! Did you find this by review or while testing? > --- > drivers/mtd/ubi/build.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c > index 7d4ff1193db6f..f47987ee9a31b 100644 > --- a/drivers/mtd/ubi/build.c > +++ b/drivers/mtd/ubi/build.c > @@ -1099,16 +1099,16 @@ 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) { Is there a specific reason why you have modified the check to test only for ref_count being positive? If rec_counts turns negative, due to a bug, we could still stop it here. > 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; Please add there an ubi_asert() which tests whether ref_count is really zero. ...just to be more bullet proof. Thanks, //richard