devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Cc: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>,
	linux-sh@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	devicetree@vger.kernel.org,
	Mike Turquette <mturquette@linaro.org>
Subject: Re: [PATCH 3/3] clk: shmobile: Add R8A7790 clocks support
Date: Wed, 06 Nov 2013 00:57:16 +0100	[thread overview]
Message-ID: <2199055.1gOuVSSAtq@avalon> (raw)
In-Reply-To: <87r4avnsc6.wl%kuninori.morimoto.gx@renesas.com>

Hi Morimoto-san,

On Tuesday 05 November 2013 00:52:29 Kuninori Morimoto wrote:
> Hi Laurent
> 
> > +Required Properties:
> > +
> > +  - compatible: Must be "renesas,r8a7790-cpg-clocks"
> > +  - reg: Base address and length of the memory resource used by the CPG
> > +  - clocks: Reference to the parent clock
> > +  - #clock-cells: Must be 1
> > +  - clock-output-names: The name of the clocks, must be "main", "pll1",
> > +    "pll3", "lb", "qspi", "sdh", "sd0", "sd1".
> 
> (snip)
> 
> > +	for (i = 0; i < CPG_NUM_CLOCKS; ++i) {
> > +		const struct clk_div_table *table = NULL;
> > +		const char *parent_name = "main";
> > +		const char *name;
> > +		unsigned int shift;
> > +		unsigned int mult = 1;
> > +		unsigned int div = 1;
> > +		struct clk *clk;
> > +
> > +		of_property_read_string_index(np, "clock-output-names", i,
> > +					      &name);
> > +
> > +		switch (i) {
> > +		case R8A7790_CLK_MAIN:
> > +			parent_name = of_clk_get_parent_name(np, 0);
> > +			div = config->extal_div;
> > +			break;
> > +		case R8A7790_CLK_PLL1:
> > +			mult = config->pll1_mult / 2;
> > +			break;
> > +		case R8A7790_CLK_PLL3:
> > +			mult = config->pll3_mult;
> > +			break;
> > +		case R8A7790_CLK_LB:
> > +			div = cpg_mode & BIT(18) ? 36 : 24;
> > +			break;
> > +		case R8A7790_CLK_QSPI:
> > +			div = (cpg_mode & (BIT(3) | BIT(2) | BIT(1))) == BIT(2)
> > +			    ? 16 : 20;
> > +			break;
> > +		case R8A7790_CLK_SDH:
> > +			table = cpg_sdh_div_table;
> > +			shift = 8;
> > +			break;
> > +		case R8A7790_CLK_SD0:
> > +			table = cpg_sd01_div_table;
> > +			shift = 4;
> > +			break;
> > +		case R8A7790_CLK_SD1:
> > +			table = cpg_sd01_div_table;
> > +			shift = 0;
> > +			break;
> > +		}
> 
> Is this clock-output-names realy "Required" property ?
> The "name" and "order" seem fixed, then,
> I guess it can simply use "name array" ?

The clock-output-names property is required by the of_clk_get_parent_name() 
function. The property is mandatory for all clocks that need to be referenced 
by name, which is the case of all non-leaf clocks on our platforms. We thus 
need it.

> > +static void __init r8a7790_cpg_clocks_init(struct device_node *np)
> > +{
> > +	const struct cpg_pll_config *config;
> > +	struct r8a7790_cpg *cpg;
> > +	struct clk **clks;
> > +	unsigned int i;
> > +
> > +	cpg = kzalloc(sizeof(*cpg), GFP_KERNEL);
> > +	clks = kzalloc(CPG_NUM_CLOCKS * sizeof(*clks), GFP_KERNEL);
> > +	if (cpg == NULL || clks == NULL) {
> > +		kfree(clks);
> > +		kfree(cpg);
> > +		pr_err("%s: failed to allocate cpg\n", __func__);
> > +		return;
> > +	}
> > +
> > +	spin_lock_init(&cpg->lock);
> > +
> > +	cpg->data.clks = clks;
> > +	cpg->data.clk_num = CPG_NUM_CLOCKS;
> > +
> > +	cpg->reg = of_iomap(np, 0);
> > +	if (WARN_ON(cpg->reg == NULL)) {
> > +		kfree(cpg->data.clks);
> > +		kfree(cpg);
> > +		return;
> > +	}
> 
> Above 2 error cases are doing same thing.
> If can use goto xxx_error.

Good point.

Given that a failure to allocate memory or ioremap registers will lead to a 
boot failure, I wonder whether we couldn't just remove the kfree() calls and 
leak memory. Is there a point in cleaning up behind us if the system will no 
boot due to missing core clocks anyway ?

-- 
Regards,

Laurent Pinchart


  reply	other threads:[~2013-11-05 23:57 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-29 14:55 [PATCH 0/3] Renesas R8A7790 Common Clock Framework support Laurent Pinchart
2013-10-29 14:55 ` [PATCH 1/3] clk: shmobile: Add DIV6 clock support Laurent Pinchart
2013-10-29 23:33   ` Kumar Gala
2013-10-29 23:54     ` Laurent Pinchart
2013-10-29 23:56       ` Kumar Gala
2013-10-29 14:55 ` [PATCH 2/3] clk: shmobile: Add MSTP " Laurent Pinchart
2013-10-29 23:36   ` Kumar Gala
2013-10-30  0:06     ` Laurent Pinchart
2013-10-30  0:19       ` Kumar Gala
2013-10-31 15:15         ` Laurent Pinchart
2013-11-06  2:09   ` Simon Horman
2013-11-06 12:22     ` Laurent Pinchart
2013-11-06  8:33   ` Magnus Damm
2013-11-06 12:13     ` Laurent Pinchart
2013-10-29 14:55 ` [PATCH 3/3] clk: shmobile: Add R8A7790 clocks support Laurent Pinchart
2013-10-29 23:56   ` Kumar Gala
2013-11-05  7:56   ` Magnus Damm
2013-11-05 23:47     ` Laurent Pinchart
2013-11-06  8:19       ` Magnus Damm
2013-11-06 12:45         ` Laurent Pinchart
2013-11-05  8:52   ` Kuninori Morimoto
2013-11-05 23:57     ` Laurent Pinchart [this message]
2013-11-06  0:54       ` Kuninori Morimoto
2013-11-06  1:00         ` Laurent Pinchart
2013-11-06  2:31           ` Kuninori Morimoto
     [not found]             ` <8738na1csg.wl%kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org>
2013-11-06 12:41               ` Laurent Pinchart
2013-11-07  3:22                 ` Kuninori Morimoto
2013-11-07  7:20                   ` Kuninori Morimoto
2013-11-07 12:15                     ` Laurent Pinchart
2013-11-08  0:06                       ` Kuninori Morimoto
2013-11-08  1:00                         ` Laurent Pinchart
2013-11-08  6:02                           ` Kuninori Morimoto
2013-11-06  7:18   ` Simon Horman
2013-11-06 12:56     ` Laurent Pinchart
2013-11-08  6:34       ` Simon Horman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2199055.1gOuVSSAtq@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=devicetree@vger.kernel.org \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=mturquette@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).