Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp121712imm; Fri, 31 Aug 2018 19:48:28 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbpZgbjn162/k3aDcrDVcFoD9BLwG0mqd7W6BTHEeogsLF6Rbs5Z11b14l+xb2CGF0A9AtA X-Received: by 2002:a63:f111:: with SMTP id f17-v6mr16618240pgi.87.1535770108519; Fri, 31 Aug 2018 19:48:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535770108; cv=none; d=google.com; s=arc-20160816; b=SCAI3YcLkHYMDRBGrPtnC/EsqEZrEOc0A7ZeD2YbpqvXN4UNAV7QBTn7bD50HqDVKX 0Bk2ENVGC27B4EeQIV7GilgkKredPm3QA1jw6G4CGXaNfROo/ElOcTogYDvkso4raCW8 Ko/Ebrvn5Hq7rPccbQjaF5mO9HWlAR0npmDTcLxh1pVdnspVu2hMJRokPDflLFIv/P4C QNJg+cXPzjuJVEhmj2yz4esafaSnB9o9ecGtz889dWkwtnaYObAvysJL8/SlczY1zNnh ibPKYGw/pnCW/Zt2py+ZG7+0zkgjuTpJ4LaQX0TPKcaLJ0gPC4Vxylm39CGx65umU3h/ UMNw== 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:arc-authentication-results; bh=GtyzvA+pQPaZNkrIaJu9gsjFv2p/cvoDEgJCX5eBe1Y=; b=aggvSlvwOGw1mnXdtMB7BguCOQw5hStg0Im0UCRzGP8GL5lwOghwBnoaYOo+IC3WG7 IConqCPgz4dRzR50esbKOu1P0jq5kPPj9BXJt8VoLBtyNYHHAlwfSUTBeanJazDhN4Mm om8jaUkC3UxQSOYzk+Q+k9FvNIsXVfB/ra+JxGGKH3ZUvfM7hPkVRwLZHeDoSfKpKT/w 8v8y3OifPk2pz21So2yOnityZsMaqsCERDYHE0Ff9HujoY+50uZdhad3WrjiwLcUQHtR vbwYyKlcdLf9KDoVzLv6eKTYrhcAeVekes8bxH15jNuQjB1THEPnCWyUflHwDKSoUl6x 55cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="tRF19/f1"; 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 o1-v6si12395119pfe.259.2018.08.31.19.48.14; Fri, 31 Aug 2018 19:48:28 -0700 (PDT) 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="tRF19/f1"; 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 S1727273AbeIAG4J (ORCPT + 99 others); Sat, 1 Sep 2018 02:56:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:51860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725870AbeIAG4J (ORCPT ); Sat, 1 Sep 2018 02:56:09 -0400 Received: from localhost (unknown [104.132.0.94]) (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 8618F20841; Sat, 1 Sep 2018 02:45:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1535769950; bh=aNvxFNm/VKHMUCMozq0LGliYHp3pCKPgA8sJHqz6DrQ=; h=To:From:In-Reply-To:Cc:References:Subject:Date:From; b=tRF19/f1H/YyPtq+RgTvgjSCa4ANNILbViGKQ88C4oq0bDYjtjJpRbEtPb3lfO1Pa FXpq5NEjt27Nxlz2L2LkH0j6T/7O4LLGP4c6vw45bLQGQexQp1i+jZf+fw4vzGM7tT quYKw9cK1XmAlr0oo+AJRstSzlvZhxk1Q4oSmlK4= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: Andy Shevchenko , Michael Turquette , Phil Edworthy , Russell King From: Stephen Boyd In-Reply-To: <1535724443-21150-2-git-send-email-phil.edworthy@renesas.com> Cc: Geert Uytterhoeven , Simon Horman , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Phil Edworthy References: <1535724443-21150-1-git-send-email-phil.edworthy@renesas.com> <1535724443-21150-2-git-send-email-phil.edworthy@renesas.com> Message-ID: <153576994987.19113.11376893046599589648@swboyd.mtv.corp.google.com> User-Agent: alot/0.7 Subject: Re: [PATCH v5 1/2] clk: Add of_clk_get_by_name_optional() function Date: Fri, 31 Aug 2018 19:45:49 -0700 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Phil Edworthy (2018-08-31 07:07:22) > diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c > index 9ab3db8..4adb99e 100644 > --- a/drivers/clk/clkdev.c > +++ b/drivers/clk/clkdev.c > @@ -54,30 +54,29 @@ EXPORT_SYMBOL(of_clk_get); > = > static struct clk *__of_clk_get_by_name(struct device_node *np, > const char *dev_id, > - const char *name) > + const char *name, > + bool optional) > { > struct clk *clk =3D ERR_PTR(-ENOENT); > + struct device_node *child =3D np; > + int index =3D 0; > = > /* Walk up the tree of devices looking for a clock that matches */ > while (np) { > - int index =3D 0; > = > /* > * For named clocks, first look up the name in the > * "clock-names" property. If it cannot be found, then > - * index will be an error code, and of_clk_get() will fai= l. > + * index will be an error code. > */ > if (name) > index =3D of_property_match_string(np, "clock-nam= es", name); > - clk =3D __of_clk_get(np, index, dev_id, name); > - if (!IS_ERR(clk)) { > - break; > - } else if (name && index >=3D 0) { > - if (PTR_ERR(clk) !=3D -EPROBE_DEFER) > - pr_err("ERROR: could not get clock %pOF:%= s(%i)\n", > - np, name ? name : "", index); > + if (index >=3D 0) > + clk =3D __of_clk_get(np, index, dev_id, name); > + if (!IS_ERR(clk)) Was this change necessary? It looks like we can leave it all alone and keep passing a negative number to __of_clk_get() and have that return an error pointer which we then return immediately as an error. But, if the clock is optional and we've passed a name here, shouldn't we treat an error from of_property_match_string() as success too? This is all looking pretty fragile so maybe it can be better commented and also more explicit instead of relying on the reader to jump through all the function calls to figure out what the return value is in some cases. > return clk; > - } > + if (name && index >=3D 0) > + break; And this causes us to duplicate logic down below because we have to check it again if it's not optional or some other error condition? > = > /* > * No matching clock found on this node. If the parent n= ode > @@ -89,6 +88,16 @@ static struct clk *__of_clk_get_by_name(struct device_= node *np, > break; > } > = > + /* The clock is not valid, but it could be optional or deferred */ > + if (optional && PTR_ERR(clk) =3D=3D -ENOENT) { > + clk =3D NULL; > + pr_info("no optional clock %pOF:%s\n", child, > + name ? name : ""); Is this intentionally pr_info? > + } else if (name && index >=3D 0 && PTR_ERR(clk) !=3D -EPROBE_DEFE= R) { > + pr_err("ERROR: could not get clock %pOF:%s(%i)\n", > + child, name, index); > + } > + > return clk; > } > =20