Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp627404ima; Fri, 15 Mar 2019 10:17:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqyjCHwdDVy1Azv48TwsHcZOurzhUV8v0+3zsrLNtqXzdSVVIDYacjubb7XCF846x88MRcsy X-Received: by 2002:a63:5149:: with SMTP id r9mr4550925pgl.142.1552670279041; Fri, 15 Mar 2019 10:17:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552670279; cv=none; d=google.com; s=arc-20160816; b=Aiu5skxlbzjQ4ge70d7BdRb8erGZgjec/Wmg6q0HX5nLtpA1mAlWlHh8VlzVP9h3Un hd3ob+oF+VIueiuITOsBwgCsBmpV13wuh6/9eyjys/eyV782YqG8og7M6h0AH6pAtwTb qrg+ezQxPjxcnq2TzP2qc0Jyq/10iqtVsYqCJmqP0He2/2HdxxDlv3rCXjLUIRtdq52S WpQZ5Y+dMwAkPtuT6AWm8S9kooLWq+Tm/41goguaoMgBRFgk8yZobK+e0ajxmBTFxtPR tFX1jX6icSMXqp/ielPssKqL08DFSErwpJvtBBhhv9PGPTPRSJkegEFwKfq689lUall+ fi7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:user-agent:message-id:to:cc:subject :from:references:in-reply-to:content-transfer-encoding:mime-version :dkim-signature; bh=BkJeWg2hAEFLiMQklb+47ZFAe8nOr4XPyHDK0RBodBY=; b=a9nWgn6V0QUnFmdhiarOGbINLZrRghNBlOYSbQn33Fzh56jge27kfP3My76QvCcxaB bigB42LhU8cEQLCkI5P9jO/V5iQRSl1jUYaW4MsjsCPBcjPrAjC2kraDf47kH7nGsDNk OuBrcSrGH87SuOF2iNLTOSgRuAGBKJaQLdRN1pyn2q4pTLk7E/KNVwEv1EnGO2MkoNBi TRhAV6EYDBqKYXALydWPzYntcncLJxc3pSN2T/c5Yri8YlWqGnYyK6TQ7OiYKxP6SXcO T7vO3qdlMwUt98EG6v/o736JLInNoJvKuOzF6NQTRRNNOt8qQTRiC18EcO4XB7Mf8iug VpMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DGyXZRh4; 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 ck9si2388712plb.196.2019.03.15.10.17.44; Fri, 15 Mar 2019 10:17:59 -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=DGyXZRh4; 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 S1729592AbfCORRB (ORCPT + 99 others); Fri, 15 Mar 2019 13:17:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:47354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727001AbfCORRB (ORCPT ); Fri, 15 Mar 2019 13:17:01 -0400 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 3FA8721019; Fri, 15 Mar 2019 17:17:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552670220; bh=V3/XgsQWVmPCXl4GDlQD79hp94lmq10+5QAqPCddwss=; h=In-Reply-To:References:From:Subject:Cc:To:Date:From; b=DGyXZRh4ufdls23OelKLRSrvihXBHg7ql0YkMRNtlzVz/aSCH1IKWvAVeFJEtn50M VtJoAUMEx11YABdxMbMp3h6+Dr9/SzKdVS85BR0CDCxDTrkg9XqJUgTF8Z7zFTvHjt 3cwQh6PAh0yn6R6GHf5FAC3BhNVPQkSCFDKQPLfs= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <3e6aa4c392ccdd3bac76b556645139536e61e5e6.camel@baylibre.com> References: <20190226223429.193873-1-sboyd@kernel.org> <20190226223429.193873-7-sboyd@kernel.org> <3e6aa4c392ccdd3bac76b556645139536e61e5e6.camel@baylibre.com> From: Stephen Boyd Subject: Re: [PATCH v2 6/8] clk: Allow parents to be specified without string names Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Miquel Raynal , Russell King , Jeffrey Hugo , Chen-Yu Tsai To: Jerome Brunet , Michael Turquette Message-ID: <155267021941.20095.16439182841724325601@swboyd.mtv.corp.google.com> User-Agent: alot/0.8 Date: Fri, 15 Mar 2019 10:16:59 -0700 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Jerome Brunet (2019-03-15 03:01:53) > On Tue, 2019-02-26 at 14:34 -0800, Stephen Boyd wrote: > > --- > > drivers/clk/clk.c | 260 ++++++++++++++++++++++++++--------- > > include/linux/clk-provider.h | 19 +++ > > 2 files changed, 217 insertions(+), 62 deletions(-) >=20 > Sorry for the delay. >=20 > With the fix you sent to Jeffrey > Tested by porting the aoclk controller of Amlogic g12a SoC. > This allowed to test > * hws only table > * parent_data with a mix of hw pointers and fw_name (with different input > controllers and also an input that is optional and never provided) >=20 > Tested-by: Jerome Brunet >=20 > With the small comment below >=20 > Reviewed-by Jerome Brunet >=20 Awesome. Thanks! I need to Cc Rob H to hopefully get an ack on the concept of relying on DT so I'll resend this series again next week. It would also be nice if I can throw in a couple more patches to let drivers specify a DT node when registering a clk if they don't have a struct device on hand and let drivers lookup with clk_lookups somehow. >=20 > >=20 > > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > > index 937b8d092d17..3d01e8c56400 100644 > > --- a/drivers/clk/clk.c > > +++ b/drivers/clk/clk.c > > @@ -39,6 +39,13 @@ static LIST_HEAD(clk_notifier_list); > > =20 >=20 > [...] >=20 > > =20 > > +static int clk_cpy_name(const char *dst, const char *src, bool must_ex= ist) > > +{ > > + if (!src) { > > + if (must_exist) > > + return -EINVAL; > > + return 0; > > + } > > + > > + dst =3D kstrdup_const(src, GFP_KERNEL); > > + if (!dst) > > + return -ENOMEM; > > + > > + return 0; > > +} > > + > > +static int clk_core_populate_parent_map(struct clk_core *core) > > +{ > > + const struct clk_init_data *init =3D core->hw->init; > > + u8 num_parents =3D init->num_parents; > > + const char * const *parent_names =3D init->parent_names; > > + const struct clk_hw **parent_hws =3D init->parent_hws; > > + const struct clk_parent_data *parent_data =3D init->parent_data; > > + int i, ret =3D 0; > > + struct clk_parent_map *parents, *parent; > > + > > + if (!num_parents) > > + return 0; > > + > > + /* > > + * Avoid unnecessary string look-ups of clk_core's possible paren= ts by > > + * having a cache of names/clk_hw pointers to clk_core pointers. > > + */ > > + parents =3D kcalloc(num_parents, sizeof(*parents), GFP_KERNEL); > > + core->parents =3D parents; > > + if (!parents) > > + return -ENOMEM; > > + > > + /* Copy everything over because it might be __initdata */ > > + for (i =3D 0, parent =3D parents; i < num_parents; i++, parent++)= { > > + if (parent_names) { > > + /* throw a WARN if any entries are NULL */ > > + WARN(!parent_names[i], > > + "%s: invalid NULL in %s's .parent_names\n= ", > > + __func__, core->name); > > + ret =3D clk_cpy_name(parent->name, parent_names[i= ], > > + true); > > + } else if (parent_data) { >=20 > While testing, I mistakenly left both parent_names and parent_data. I was > surprised that parent_data did not take precedence of parent_names. >=20 > Maybe it should ? (... but I understand we are not supposed to provide bo= th) I don't think we can. We have a problem where drivers don't initialize the init structure properly, opting to just throw it on the stack and leave junk in there that they overwrite. We'd have to go through all the init structures and initialize them. I suppose we could make a macro for that: DECLARE_CLK_INIT_DATA(init); or something like that that does this. We could bury a magic number in there under some debug option too so that we can make sure drivers are doing this properly. Otherwise we're left to doing these weird tricks like I've done here. Regardless. I'll have to add a comment to this fact in the code. Thanks. >=20 > > + parent->hw =3D parent_data[i].hw; > > + ret =3D clk_cpy_name(parent->fw_name, > > + parent_data[i].fw_name, false); > > + if (!ret) > > + ret =3D clk_cpy_name(parent->name, > > + parent_data[i].name, > > + false); > > + } else if (parent_hws) { > > + parent->hw =3D parent_hws[i]; > > + } else { >=20 > Maybe there should also some kinda of check to verify if more than one op= tion > (among hws, parent_data and parent_names) was provided and throw a warn ? >=20 > Could be useful with drivers move away from parent_names ? Same thing. It would be nice but we're sort of unable to do so unless we do what I suggest above. Should we do it?