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 E736AC678D5 for ; Sat, 4 Mar 2023 20:43:45 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5439A859A9; Sat, 4 Mar 2023 21:43:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.b="BIPclH7L"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="DjntZdRe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A9A8685A42; Sat, 4 Mar 2023 21:43:41 +0100 (CET) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 70A66859A9 for ; Sat, 4 Mar 2023 21:43:39 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=msuchanek@suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 32D1022B45; Sat, 4 Mar 2023 20:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1677962619; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ebMz2gRf4az75xRg4u6C6i7+ohgeB8mZs0NoVD8fsMk=; b=BIPclH7LlwFOo3Fl5MSJDvjVT8NwpQTdtgXPKcz1cXnb++c9IPp+qLpccPtfWAcmNwBaI9 M9BUKGSOm/Vn6DkFC06N/O0zzV+TbXFeDyDk1fjPxoy50uk+C5J1gd/IXRyITkjFHAJS0y JtwHys8v7LgRQaV5GA7D8fkkk0sVEZg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1677962619; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ebMz2gRf4az75xRg4u6C6i7+ohgeB8mZs0NoVD8fsMk=; b=DjntZdRec0zJsRxuKNmgXv3+hHI5ch+PT4Yd+O044A8AFKHC/v71tNoKMuLY/ni+lKP/PD 9SDpHTEs3sv66YBQ== Received: from kitsune.suse.cz (kitsune.suse.cz [10.100.12.127]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id A97E42C141; Sat, 4 Mar 2023 20:43:38 +0000 (UTC) Date: Sat, 4 Mar 2023 21:43:37 +0100 From: Michal =?iso-8859-1?Q?Such=E1nek?= To: Samuel Holland Cc: Sean Anderson , Lukasz Majewski , Simon Glass , Dario Binacchi , Jean-Jacques Hiblot , Neil Armstrong , Peng Fan , u-boot@lists.denx.de Subject: Re: [PATCH 1/6] clk: Handle error pointers in clk_valid() Message-ID: <20230304204337.GJ19419@kitsune.suse.cz> References: <20230220055940.41890-1-samuel@sholland.org> <20230220055940.41890-2-samuel@sholland.org> <20230220104618.GK19419@kitsune.suse.cz> <20230220194239.GN19419@kitsune.suse.cz> <67f94f4f-e6a7-8d84-9755-0ea3d0e2faae@sholland.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <67f94f4f-e6a7-8d84-9755-0ea3d0e2faae@sholland.org> User-Agent: Mutt/1.10.1 (2018-07-13) 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 Sat, Mar 04, 2023 at 01:54:12PM -0600, Samuel Holland wrote: > 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. Yes, there are too many. clk_valid should check both. Reviewed-by: Michal Suchánek Thanks Michal