Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3504909imu; Fri, 30 Nov 2018 01:11:12 -0800 (PST) X-Google-Smtp-Source: AFSGD/V7Mp5+Axx2fG8NLzhM61U9PqrjsK8mADybGbuD8ANePOl1KSaG80aNpIQNLpKiTgR/IiL7 X-Received: by 2002:a17:902:a03:: with SMTP id 3mr4957365plo.112.1543569072720; Fri, 30 Nov 2018 01:11:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543569072; cv=none; d=google.com; s=arc-20160816; b=vvsCAWyWVSNjKT+gUaJWvigZ07GyjkTqWefqCUZ/0fNpUZ7V4ojEdQtMqQpgu8Tnyh Blnz5LMUccG2ew97h0KWYImSveVcN8fb/6pJD1L+3VThzzGaLBtPlGoyW9HtawrHVfVH S1O8Rvy1flxDtbnduK1lges4R+wOlGorAP1W6/XQkk06nJ3Gq9WyMXAgVbqpZrIJFlFH X9ge5lro9y3Go1M6p0UpYsr3WexL+Aeq5iFS+iLbkxb2jL0q2rgyQb9GD0wa/VTTkZdd pP60DECP++Aanh0Do4WwCuJ0rssIhPPtNzM00+ZLaeJUkic90DMZ2pls9zn0QBd+nqyA 4tCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:user-agent:message-id :references:cc:in-reply-to:from:to:content-transfer-encoding :mime-version:dkim-signature; bh=qnsoq0Pd3ZcWPxwwhAkjfFTAa3GlyGyVwHAPj5kQDjc=; b=D32cywqGOZgyC4VyxijGvaxQajoRPvzgQhQpVtGf9Sf4Rv8l20rhKEt40DLzA7uiCU OkJK/k+ASFAQQbDzoJarwQQ8hMs7R+btdfA9enS93/82jpxokyJoHBsPToCAPvfSy/b3 PPEtd1JS2lccjDib+kReJ+QXzyB78Ws2dPLrUiTGArBPRTd2SLtgPogWL7xe9m6qudVX SsiMQdn0F+NAdVz6mZ3IehGfdj8EYjdBkefK/IeeRNeWLoHGh+xxbhIAwU0JnZ09kcXZ zUvK9b8dKc9mzsY8SLis7eHuU8mJlR5tKOPvxMnHa0GpXlGYcKCqjxoOY6u93e8FyT3r cfdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dteVGgIS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i64si4292034pge.361.2018.11.30.01.10.58; Fri, 30 Nov 2018 01:11:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dteVGgIS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726867AbeK3URl (ORCPT + 99 others); Fri, 30 Nov 2018 15:17:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:46260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726558AbeK3URl (ORCPT ); Fri, 30 Nov 2018 15:17:41 -0500 Received: from localhost (unknown [104.132.0.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 384BD20868; Fri, 30 Nov 2018 09:09:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543568942; bh=c4z90kPgWBsUx4oXIOj7WmhJSMKbWcc9L+/YrgUV8Aw=; h=To:From:In-Reply-To:Cc:References:Subject:Date:From; b=dteVGgIS93aRuEtZ8dwFG6HMPIaYdQhz1BNT7FKtwuJVZA/JLYFnbqR39Fo7k1u8U dIOv4VQImvxFn8WCEOoeL2mE6hRkt3njIa6qaXrD0s1/WjP+K2squu0QZVomPvpjNA vIEdCHyp0CLpKVOpadFV4OlxtiTAnl9VqLEUHugo= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: Michael Turquette , Phil Edworthy , Russell King From: Stephen Boyd In-Reply-To: <20181120141445.21378-1-phil.edworthy@renesas.com> Cc: Andy Shevchenko , Geert Uytterhoeven , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Phil Edworthy References: <20181120141445.21378-1-phil.edworthy@renesas.com> Message-ID: <154356894146.88331.4169293505438588293@swboyd.mtv.corp.google.com> User-Agent: alot/0.7 Subject: Re: [PATCH v8] clk: Add (devm_)clk_get_optional() functions Date: Fri, 30 Nov 2018 01:09:01 -0800 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Phil Edworthy (2018-11-20 06:14:45) > This adds clk_get_optional() and devm_clk_get_optional() functions to get > optional clocks. > They behave the same as (devm_)clk_get except where there is no clock > producer. In this case, instead of returning -ENOENT, the function > returns NULL. This makes error checking simpler and allows > clk_prepare_enable, etc to be called on the returned reference > without additional checks. Ok. I guess that works by virtue of how -ENOENT is returned by various functions that are called deeper in the clk_get() path? I'm cautiously optimistic. So cautious, we should probably add a comment to these optional functions that indicate they rely on the functions they call to return -ENOENT under the various conditions that make a clk optional. > = > diff --git a/include/linux/clk.h b/include/linux/clk.h > index a7773b5c0b9f..3ea3c78f62dd 100644 > --- a/include/linux/clk.h > +++ b/include/linux/clk.h > @@ -383,6 +383,17 @@ int __must_check devm_clk_bulk_get_all(struct device= *dev, > */ > struct clk *devm_clk_get(struct device *dev, const char *id); > = > +/** > + * devm_clk_get_optional - lookup and obtain a managed reference to an o= ptional > + * clock producer. > + * @dev: device for clock "consumer" > + * @id: clock consumer ID > + * > + * Behaves the same as devm_clk_get except where there is no clock produ= cer. In Please add () around devm_clk_get() so we know it's a function. > + * this case, instead of returning -ENOENT, the function returns NULL. > + */ > +struct clk *devm_clk_get_optional(struct device *dev, const char *id); > + > /** > * devm_get_clk_from_child - lookup and obtain a managed reference to a > * clock producer from child node. > @@ -718,6 +729,12 @@ static inline struct clk *devm_clk_get(struct device= *dev, const char *id) > return NULL; > } > = > +static inline struct clk *devm_clk_get_optional(struct device *dev, > + const char *id) > +{ > + return NULL; > +} > + > static inline int __must_check devm_clk_bulk_get(struct device *dev, int= num_clks, > struct clk_bulk_data *cl= ks) > { > @@ -862,6 +879,16 @@ static inline void clk_bulk_disable_unprepare(int nu= m_clks, > clk_bulk_unprepare(num_clks, clks); > } > = > +static inline struct clk *clk_get_optional(struct device *dev, const cha= r *id) Any kernel doc for this function? > +{ > + struct clk *clk =3D clk_get(dev, id); > + > + if (clk =3D=3D ERR_PTR(-ENOENT)) > + clk =3D NULL; > + > + return clk; > +} > +