Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1913546rdb; Tue, 3 Oct 2023 05:13:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFW5e+AOI5b9u0GHksUMVByFPpCKNUc8KV2CX1vlzRsWZG/NIhC+e4bZxSvc5NsgMs1By/O X-Received: by 2002:a17:90b:1009:b0:268:7ec:51ae with SMTP id gm9-20020a17090b100900b0026807ec51aemr11495880pjb.41.1696335234023; Tue, 03 Oct 2023 05:13:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696335234; cv=none; d=google.com; s=arc-20160816; b=l3iBp97/pHrSUmt5+zhonkn1uIpQNS6R4jC2Cu87xqAe6Er8DqthNKUvoJlmWxSJmA vQhP1SJAA3HoG0+pgQxZGuxti8GeIPTGZ9+HGehB4ePbG0KhYYNAMevXCN+zSQQNShfr G1CQcKKeYfmGv9oPbzH/kXxdUJq54PJMlqMnlGfzW/3VDzzu6OS7ooNe2wurKM2EuoBC HosLJDbs/f4Qe2SrY/oeCdcQ4FFwNzVLg5vVqyqn74wnNYz04ULBwDTVVB0G0XHxh0p3 s9iYpKMpDBXe4BrQ06TC3yCOz4zOT7Vx01uABltbPKG+GdPEPhut0aW2+fV31H1IaA29 e02Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=grCapwZaW6liwEhLXZoRANZmXZGUzFD5F5Ufy/5KnRg=; fh=+w/9POKVoj53JhYT0tlpl5pCQfjDrGitnrqHAlSCSys=; b=zut+wRaBe7VKc4JjYEs+TrWi8mQBbOd9tXtn5CelFCtMd3QB9eBut5kYtoYq/sTOWO eS9iB24G2jlOBy87R/ytvELmcD7jhx8EVbTMvIa7SACnJPNTNXatigskhcVbi9lqZtc+ LFCOZX9i2HJUF8aSM1UfX1NQrFLjlHCfWybAID/AcugR4kGZ0PFr7yFCnqpCK9Ekymw+ Is+Y60250B+9EBJC6GE8DilZOCEiXBmYHr7gVOer9RgjkPYWYEt9AX1RDeR7fXu+frww +p3/+r+agmyWa+6K2fHG1+m+9UmphIBTh9Fdc8snMCEP8JPNv9amacfFwRLrjwy8ywHM 0IGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id o15-20020a17090ac70f00b00277507e8085si9397876pjt.55.2023.10.03.05.13.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 05:13:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 5ABA980752B3; Tue, 3 Oct 2023 05:13:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232131AbjJCMNl (ORCPT + 99 others); Tue, 3 Oct 2023 08:13:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231942AbjJCMNl (ORCPT ); Tue, 3 Oct 2023 08:13:41 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 61788AF; Tue, 3 Oct 2023 05:13:37 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 553C11FB; Tue, 3 Oct 2023 05:14:15 -0700 (PDT) Received: from pluto (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BCDEA3F59C; Tue, 3 Oct 2023 05:13:35 -0700 (PDT) Date: Tue, 3 Oct 2023 13:13:33 +0100 From: Cristian Marussi To: "Peng Fan (OSS)" Cc: Sudeep Holla , Michael Turquette , Stephen Boyd , Peng Fan , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org Subject: Re: [PATCH v4 2/2] clk: scmi: add set/get_parent support Message-ID: References: <20231003-scmi-clock-v3-v4-0-358d7f916a05@nxp.com> <20231003-scmi-clock-v3-v4-2-358d7f916a05@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231003-scmi-clock-v3-v4-2-358d7f916a05@nxp.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 03 Oct 2023 05:13:50 -0700 (PDT) On Tue, Oct 03, 2023 at 07:48:49PM +0800, Peng Fan (OSS) wrote: > From: Peng Fan > > SCMI v3.2 adds set/get parent clock commands, so update the clk driver > to support them. > Hi, in general LGTM, BUT I have just spotted one more *bad* thing that have to be fixe down below which I have missed previously, my bad. > Signed-off-by: Peng Fan > --- > drivers/clk/clk-scmi.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 57 insertions(+), 1 deletion(-) > > diff --git a/drivers/clk/clk-scmi.c b/drivers/clk/clk-scmi.c > index 2e1337b511eb..e7a27fda561b 100644 > --- a/drivers/clk/clk-scmi.c > +++ b/drivers/clk/clk-scmi.c > @@ -24,6 +24,7 @@ struct scmi_clk { > struct clk_hw hw; > const struct scmi_clock_info *info; > const struct scmi_protocol_handle *ph; > + struct clk_parent_data *parent_data; > }; > > #define to_scmi_clk(clk) container_of(clk, struct scmi_clk, hw) > @@ -78,6 +79,43 @@ static int scmi_clk_set_rate(struct clk_hw *hw, unsigned long rate, > return scmi_proto_clk_ops->rate_set(clk->ph, clk->id, rate); > } > > +static int scmi_clk_set_parent(struct clk_hw *hw, u8 parent_index) > +{ > + struct scmi_clk *clk = to_scmi_clk(hw); > + > + return scmi_proto_clk_ops->parent_set(clk->ph, clk->id, parent_index); > +} > + > +static u8 scmi_clk_get_parent(struct clk_hw *hw) > +{ > + struct scmi_clk *clk = to_scmi_clk(hw); > + u32 parent_id, p_idx; > + int ret; > + > + ret = scmi_proto_clk_ops->parent_get(clk->ph, clk->id, &parent_id); > + if (ret) > + return 0; > + > + for (p_idx = 0; p_idx < clk->info->num_parents; p_idx++) { > + if (clk->parent_data[p_idx].index == parent_id) > + break; > + } > + > + if (p_idx == clk->info->num_parents) > + return 0; > + > + return p_idx; > +} > + > +static int scmi_clk_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) > +{ > + /* > + * Suppose all the requested rates are supported, and let firmware > + * to handle the left work. > + */ > + return 0; > +} > + > static int scmi_clk_enable(struct clk_hw *hw) > { > struct scmi_clk *clk = to_scmi_clk(hw); > @@ -139,6 +177,9 @@ static const struct clk_ops scmi_clk_ops = { > .set_rate = scmi_clk_set_rate, > .prepare = scmi_clk_enable, > .unprepare = scmi_clk_disable, > + .set_parent = scmi_clk_set_parent, > + .get_parent = scmi_clk_get_parent, > + .determine_rate = scmi_clk_determine_rate, > }; > > static const struct clk_ops scmi_atomic_clk_ops = { > @@ -148,6 +189,9 @@ static const struct clk_ops scmi_atomic_clk_ops = { > .enable = scmi_clk_atomic_enable, > .disable = scmi_clk_atomic_disable, > .is_enabled = scmi_clk_atomic_is_enabled, > + .set_parent = scmi_clk_set_parent, > + .get_parent = scmi_clk_get_parent, > + .determine_rate = scmi_clk_determine_rate, > }; > > static int scmi_clk_ops_init(struct device *dev, struct scmi_clk *sclk, > @@ -158,9 +202,10 @@ static int scmi_clk_ops_init(struct device *dev, struct scmi_clk *sclk, > > struct clk_init_data init = { > .flags = CLK_GET_RATE_NOCACHE, > - .num_parents = 0, > + .num_parents = sclk->info->num_parents, > .ops = scmi_ops, > .name = sclk->info->name, > + .parent_data = sclk->parent_data, > }; > > sclk->hw.init = &init; > @@ -250,6 +295,17 @@ static int scmi_clocks_probe(struct scmi_device *sdev) > else > scmi_ops = &scmi_clk_ops; > > + /* Initialize clock parent data. */ > + if (sclk->info->num_parents > 0) { > + sclk->parent_data = devm_kcalloc(dev, sclk->info->num_parents, > + sizeof(*sclk->parent_data), GFP_KERNEL); > + Here, you missed to check the return value of devm_kcalloc() before carrying on. > + for (int i = 0; i < sclk->info->num_parents; i++) { > + sclk->parent_data[i].index = sclk->info->parents[i]; > + sclk->parent_data[i].hw = hws[sclk->info->parents[i]]; > + } > + } > + Other than this, FWIW: Reviewed-by: Cristian Marussi Thanks, Cristian