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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 53BFEC678DB for ; Sat, 4 Mar 2023 19:54:29 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AB7DE85A33; Sat, 4 Mar 2023 20:54:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sholland.org header.i=@sholland.org header.b="MPKkI0Uy"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="iRhIEH1K"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8B70385A4D; Sat, 4 Mar 2023 20:54:24 +0100 (CET) Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DFFF885A33 for ; Sat, 4 Mar 2023 20:54:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=samuel@sholland.org Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 713EF32001BB; Sat, 4 Mar 2023 14:54:15 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Sat, 04 Mar 2023 14:54:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1677959655; x=1678046055; bh=o3TFbXMCAWv5F7r2j1mKziHWifV2714q/DW zlDOsaqk=; b=MPKkI0Uy5dfxj6BwBNWQidiuIS9eFf7lQRaOXGpUjf1b+3z5I7R Qkmsy3YAgYUSpyO1FHrZkCFO22ls3B0wkwmEjNAwWyiacsvPmS9Qt+/7aYwpgp0a ecTQe89MwOKEO8Iglh9SXTAW7R87ZrnSZLFy6uhvOKHENyMZm3O2PeyCxGLs6HK4 36//L7D061BKzU0dRpRVM/yPjZYNECQhD8MuHTnkoygUKkeCLEyJAg8JV1ZUOAhR jFyn8Xic16hNEXes5JCByzt/cEABZfUrFeXI1r/YroyebaL80Z6pM6RjaUusQAbM flQvAynvGj4f8GK13vjdcIRN8ARDOkisKKQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1677959655; x=1678046055; bh=o3TFbXMCAWv5F7r2j1mKziHWifV2714q/DW zlDOsaqk=; b=iRhIEH1KZ1Wj7Ut7fXEJBG2uJ2/8ZRnp5lXKzXFosX9rtMX01Uu 67TDLtWm/kQc9KM4vVS7gsvVUfZe0M/WmC8YTLkyggFb8GQ/0je5nEzsswOJM2P4 ZFFu/FvobJBwHZ7f5oi+D9PvPEgCk0mGy9a1uvcub8CyTH4d5g8817gOYdE9vTXu niG2pqCq/4fFSJ/QAXj55zDU/fWVDB5ptqA29Ve+YamhsqtDhxIu8h33Eig29+9F vBPfK2MbGbkHVnRA8pmnyrf4iCRLUBHmy2ZALmkH42QuX7KCCi3KqBZxGr3ev+Yq 0DgUo2mLuswRX17C6/zKEd78vUOkO60IrVw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvddtuddguddvkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfvvehfhffujggtgfesthekredttdefjeenucfhrhhomhepufgr mhhuvghlucfjohhllhgrnhguuceoshgrmhhuvghlsehshhholhhlrghnugdrohhrgheqne cuggftrfgrthhtvghrnhepgeeikeeufedvvdeuteeivdeiffdtgfdtfeejgfetfeefgeff gfdvffehjedvueeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepshgrmhhuvghlsehshhholhhlrghnugdrohhrgh X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 4 Mar 2023 14:54:13 -0500 (EST) Message-ID: <67f94f4f-e6a7-8d84-9755-0ea3d0e2faae@sholland.org> Date: Sat, 4 Mar 2023 13:54:12 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux ppc64le; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Content-Language: en-US To: =?UTF-8?Q?Michal_Such=c3=a1nek?= , Sean Anderson Cc: Lukasz Majewski , Simon Glass , Dario Binacchi , Jean-Jacques Hiblot , Neil Armstrong , Peng Fan , u-boot@lists.denx.de References: <20230220055940.41890-1-samuel@sholland.org> <20230220055940.41890-2-samuel@sholland.org> <20230220104618.GK19419@kitsune.suse.cz> <20230220194239.GN19419@kitsune.suse.cz> From: Samuel Holland Subject: Re: [PATCH 1/6] clk: Handle error pointers in clk_valid() In-Reply-To: <20230220194239.GN19419@kitsune.suse.cz> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On 2/20/23 13:42, Michal Suchánek wrote: > On Mon, Feb 20, 2023 at 10:57:17AM -0500, Sean Anderson wrote: >> >> On 2/20/23 05:46, Michal Suchánek wrote: >>> On Sun, Feb 19, 2023 at 11:59:34PM -0600, Samuel Holland wrote: >>>> Some clk uclass functions, such as devm_clk_get() and clk_get_parent(), >>>> return error pointers. clk_valid() should not consider these pointers >>>> to be valid. >>>> >>>> Fixes: 8a1661f20e6c ("drivers: clk: Handle gracefully NULL pointers") >>>> Signed-off-by: Samuel Holland >>>> --- >>>> >>>> include/clk.h | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/include/clk.h b/include/clk.h >>>> index d91285235f7..4acb878ec6d 100644 >>>> --- a/include/clk.h >>>> +++ b/include/clk.h >>>> @@ -671,7 +671,7 @@ static inline bool clk_dev_binded(struct clk *clk) >>>> */ >>>> static inline bool clk_valid(struct clk *clk) >>>> { >>>> - return clk && !!clk->dev; >>>> + return clk && !IS_ERR(clk) && !!clk->dev; >>>> } >>>> int soc_clk_dump(void); >>> >>> Maybe it would be better to avoid the error pointers instead, there >>> should not be that many places where they are returned. >> >> This not quite the right way to phrase this. Instead, I would ask: where >> are places where the return value is not checked correctly? It's perfectly > > Pretty much everywhere where clk_get_parent is used outside of core code > absolutely no error checking is done. There are 105 uses of ERR_PTR in drivers/clk, mostly in CCF clock registration functions. There is also devm_clk_get() with about 30 callers. Those mostly seem to have reasonable error checking; the error pointer ends up as the driver probe function's return value via PTR_ERR. >> fine to pass NULL or uninitialized clocks to other clock functions, but it's >> not OK to ignore errors. > > Is there some documentation on what is the distinction, specifically? > > If there isn't it's meaningless and NULL can be returned on error > simplifying the code, thinking about the code, debugging, pretty much > everything. What should I do for v2? Keep this patch? Convert clk_get_parent() to return NULL instead of ERR_PTR, and hope nobody uses clk_valid() on the pointer returned from devm_clk_get()? Regards, Samuel