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 BE894C433FE for ; Thu, 28 Apr 2022 12:01:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=9qc87lzSpfat6CoHOdAJEjaSb3vW8tGdlzXuSUt29ws=; b=OufGQW7mquF/S921sJzmk5zm6A 3TOmUaragP7msL05qLUinB9+sZA9SyEXZgEcDADZjAP0VTM5uI0E5H/OCNoWixTTySZIErAp4IMim cqJiQNP3b4bvyq38rCa6D+Gim5GjZuY/iNNITwNNS19IukjbZAg+SQ45/I1Cyh0+UO75v1p9X7lWE gZSMHy759qvyu6hWUgwr0u78T2eJWqXntoxWXS/zC+8b9GvBrkxY3CwJqkp1qesmD4+rPzKvGpUmt Z3qB1kgoyWQeKSL36LnePmL5EY8w2r1x6YSGL/8ws1RnSFimF8xJsCnp5paQAqgEQZeLYBH39pziB rmJIvF5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk2oD-006dnV-R3; Thu, 28 Apr 2022 11:59:46 +0000 Received: from relay3-d.mail.gandi.net ([2001:4b98:dc4:8::223]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nk2la-006cLZ-Hv for linux-arm-kernel@lists.infradead.org; Thu, 28 Apr 2022 11:57:06 +0000 Received: (Authenticated sender: paul.kocialkowski@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id CCC2760013; Thu, 28 Apr 2022 11:56:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1651147016; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+kqXswugkVGOFt41Krx7tQpUugV0n6joxlQ9XVQuB0Q=; b=Fq3Bt+Ci0xehqSuJ8c4Y2n0tntzUcIy4uISssoFKE3gVIVGz24SRm8YajWiw56CEid62UO bzcCDEibxZfLI6JORx8JgBK78pdymi0UvXomDrtLSSLTawuQOQy4GFRVZOAJFhq4/3IqGq 2MYAzLKD6HLGa+9Jt+c2V00sUm+vXY/tCBHqmUeEIgF5paLxsa4op4XmJaA4vNSpduBqm4 tsODikDhsvqZBAxV8MxYUJ0q1CleG8naewtqWIIeQepk6XHhoaQnOXkeyy6K4lIaO/MqyE 8gd6XI2JU7yYvXpT9fEk8mJyJ/MtMRMjsCNlJmzHTqY6ahOv4NnOPuRfQ6i0ng== Date: Thu, 28 Apr 2022 13:56:49 +0200 From: Paul Kocialkowski To: Dan Carpenter Cc: Ian Cowan , mripard@kernel.org, mchehab@kernel.org, gregkh@linuxfoundation.org, wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org, linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: Re: [PATCH] staging: sunxi: cedrus: centralize cedrus_open exit Message-ID: References: <20220423180111.91602-1-ian@linux.cowan.aero> <20220425092048.GL2462@kadam> <20220425100057.GB2090@kadam> <20220428102608.GU2462@kadam> MIME-Version: 1.0 In-Reply-To: <20220428102608.GU2462@kadam> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220428_045702_923688_EB305E9E X-CRM114-Status: GOOD ( 22.28 ) 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: , Content-Type: multipart/mixed; boundary="===============0333863333665902274==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============0333863333665902274== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="llYjTutXsM3Kb7Ne" Content-Disposition: inline --llYjTutXsM3Kb7Ne Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Dan, On Thu 28 Apr 22, 13:26, Dan Carpenter wrote: > On Tue, Apr 26, 2022 at 09:39:03AM +0200, Paul Kocialkowski wrote: > >=20 > > > Do-everything gotos are the most bug prone style of error handling. > > > Imagine the function is trying to do three things. It fails part way > > > through. Now you're trying to undo the second thing which was never > > > done. Just moments ago I was just looking at one of these do-everyth= ing > > > bugs where it was using uninitialized memory. > >=20 > > So by that you mean having just one label for all error handling instead > > of labels for each undo step? > >=20 >=20 > Yes. Don't do that. If you try to free everything, half the stuff is > not allocated so you will undo things which have not been done and it > leads to a bug. > > > I've also seen conditionals used in error labels to undo stuff. > >=20 >=20 > I don't understand what you're describing? Typically that would look like: void *foo =3D NULL; void *bar =3D NULL; foo =3D alloc(...); if (!foo) goto single_error; bar =3D alloc(...); if (!bar) goto single_error; =2E.. single_error: if (bar) free(bar); if (foo) free(foo); > > Would you recommend duplicating error cleanup in each error condition? > > It feels like another set of issue on its own, besides the obvious down= side > > of duplication. >=20 > Let me write a blog about it: >=20 > https://staticthinking.wordpress.com/2022/04/28/free-the-last-thing-style/ Good writeup, thanks! The part about unwinding loops especially, I've always wondered about the right way to go about it. Cheers, Paul=20 --=20 Paul Kocialkowski, Bootlin Embedded Linux and kernel engineering https://bootlin.com --llYjTutXsM3Kb7Ne Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEJZpWjZeIetVBefti3cLmz3+fv9EFAmJqgQEACgkQ3cLmz3+f v9H8zgf/USKoNw7Qr8vIWY2/+HjO33Pop6QIuHHsAlwlS/ThzGh7qy0+ZldEXwEt Phh7ZRqCl9Y38R7uF2W3dRzOGdq10Ra4wUQUM/zX/TGeSCneOoljbtMoXvaHiZSc ui9HWxYRLC9QAGU0cDvU4peogw+qbWFG9jqWfxTfxuj6SRK/Lo/Gsd+KHa3rHt+7 sS0k0oarxxVrg5bJaBOrL/yO1THV+e/0buB4zvCUFuGyQ1SBzEyGG8jCg5kw0tCp gouOJjLf1t/oGPRLNvVq6WywSEMFkR4T96zXuMkn5aB8HaoLndbaSYkC0gXnOTiy 30hHyTS8W5/fOFGguzpbD3XKUqwTUw== =jQV4 -----END PGP SIGNATURE----- --llYjTutXsM3Kb7Ne-- --===============0333863333665902274== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============0333863333665902274==--