From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 64F21CE835C for ; Mon, 30 Sep 2024 15:24:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Date:Cc:To:From :Subject:Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=tFT8xvcdCCOt1oHhs0HAysvao9T3ZDQjy/bfNbAxhBU=; b=hZYQA20tG5FUdDMh5Icav+aDuu aRgdxvqi4Lx7WTN9/iE9+dozRgm1ZDASZxv6q1zHCiZPjF0J0cu0zyyAj6cSrRBsBs5Cu6M7ejGOS xbZ69zcCUUdx6DL87fbTrCGKjRiZYbdodmMWsutbLxnHVhr5P+IESHOuiYkzjzQr4CfdN6RRWN56p SkJ/wSjQKzfbLtvDmth+raS1+BMJw3upxXg/dvTjrNI/58/timIGx1e026gyt+SrYAe6lzaurwtPW FuiK1/nceb44Hd2Dxzl4Zssb6SFG/KrKKq/pvj/BVHeADyxpOpiPXFcsp7vpPuRBD8kr4CDxduJSm j3yk+84Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1svIGM-000000002ow-1Oho; Mon, 30 Sep 2024 15:24:38 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1svIEI-000000002WY-1IgX for linux-arm-kernel@lists.infradead.org; Mon, 30 Sep 2024 15:22:31 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1svIEE-00080z-3Q; Mon, 30 Sep 2024 17:22:26 +0200 Received: from [2a0a:edc0:0:900:1d::4e] (helo=lupine) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1svIED-002f6a-AE; Mon, 30 Sep 2024 17:22:25 +0200 Received: from pza by lupine with local (Exim 4.96) (envelope-from ) id 1svIED-000DI0-0o; Mon, 30 Sep 2024 17:22:25 +0200 Message-ID: Subject: Re: [heads-up] Re: [PATCH] reset: Further simplify locking with guard() From: Philipp Zabel To: Krzysztof Kozlowski , Al Viro Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Linus Torvalds , Peter Zijlstra Date: Mon, 30 Sep 2024 17:22:25 +0200 In-Reply-To: <97b2b218-b46e-41a8-9379-09b76569f3f1@linaro.org> References: <20240927-reset-guard-v1-1-293bf1302210@pengutronix.de> <20240928222702.GX3550746@ZenIV> <97b2b218-b46e-41a8-9379-09b76569f3f1@linaro.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240930_082230_366560_FCAE7D19 X-CRM114-Status: GOOD ( 19.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On So, 2024-09-29 at 20:48 +0200, Krzysztof Kozlowski wrote: > On 29/09/2024 00:27, Al Viro wrote: > > On Fri, Sep 27, 2024 at 04:02:32PM +0200, Philipp Zabel wrote: > > > Use guard(mutex) to automatically unlock mutexes when going out of > > > scope. Simplify error paths by removing a goto and manual mutex > > > unlocking in multiple places. > >=20 > > And that, folks, is a live example of the reasons why guard() is an > > attractive nuisance. We really need a very loud warning on > > cleanup.h stuff - otherwise such patches from well-meaning folks > > will keep coming. Thank you for the analysis. It think I'll drop this entirely. [...] > >=20 > > Guess what happens if you take goto out_put prior to the entire thing, > > in > > ret =3D __reset_add_reset_gpio_device(&args); > > if (ret) { > > rstc =3D ERR_PTR(ret); > > goto out_put; > > } > > That patch adds implicit mutex_unlock() at the points where we leave > > the scope. Which extends to the end of function. In other words, ther= e is > > one downstream of out_put, turning any goto out_put upstream of guard()= into > > a bug. > >=20 >=20 > cleanup.h also mentions that one should do not mix cleanup with existing > goto, because of possibility of above issue. Yes, d5934e76316e ("cleanup: Add usage and style documentation"), last paragraph. > But except careful review, this patch should have been simply compile > tested which would point to the issue above. Any guard/scope works must > be checked with clang W=3D1, which reports jumps over init. Thank you, I was missing a CC=3Dclang W=3D1 build in my pre-flight checks. That's fixed now. regards Philipp