linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Murzin <vladimir.murzin@arm.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: mark.rutland@arm.com, devicetree@vger.kernel.org,
	linux@arm.linux.org.uk, pawel.moll@arm.com, arnd@arndb.de,
	ijc+devicetree@hellion.org.uk, gregkh@linuxfoundation.org,
	daniel.lezcano@linaro.org, linux-kernel@vger.kernel.org,
	robh+dt@kernel.org, andy.shevchenko@gmail.com,
	galak@codeaurora.org, linux-serial@vger.kernel.org,
	u.kleine-koenig@pengutronix.de, linux-api@vger.kernel.org,
	jslaby@suse.cz, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2 02/10] clockevents/drivers: add MPS2 Timer driver
Date: Tue, 02 Feb 2016 14:06:59 +0000	[thread overview]
Message-ID: <56B0B803.8010003@arm.com> (raw)
In-Reply-To: <alpine.DEB.2.11.1602021351440.25254@nanos>

On 02/02/16 13:04, Thomas Gleixner wrote:
> On Tue, 2 Feb 2016, Vladimir Murzin wrote:
>> +static int __init mps2_clockevent_init(struct device_node *np)
>> +{
>> +	void __iomem *base;
>> +	struct clk *clk;
>> +	struct clockevent_mps2 *ce;
>> +	u32 rate;
>> +	int irq, ret;
>> +	const char *name = "mps2-clkevt";
>> +
>> +	ret = of_property_read_u32(np, "clock-frequency", &rate);
>> +	if (ret) {
>> +		clk = of_clk_get(np, 0);
>> +		if (IS_ERR(clk)) {
>> +			ret = PTR_ERR(clk);
>> +			pr_err("failed to get clock for clockevent: %d\n", ret);
>> +			goto err_clk_get;
>> +		}
>> +
>> +		ret = clk_prepare_enable(clk);
>> +		if (ret) {
>> +			pr_err("failed to enable clock for clockevent: %d\n", ret);
>> +			clk_put(clk);
>> +			goto err_clk_enable;
>> +		}
>> +
>> +		rate = clk_get_rate(clk);
>> +	}
> 
> So in case that "clock-frequency" is available in DT, what enables and
> configures the clock?

They are fixed-clock, so I ended up this *cough* mess *cough* shortcut.
I'd be glad if you share your thoughts what is preferred way to cope
with it (is it worth to do at all?)

> 
>> +err_ia_alloc:
>> +	kfree(ce);
>> +err_ce_alloc:
>> +err_get_irq:
>> +	iounmap(base);
>> +err_iomap:
>> +	clk_disable_unprepare(clk);
> 
> clk is not initialized when "clock-frequency" is available in DT. The compiler
> should have told you ....

Shame on me, I've completely messed it up :( Thanks for pointing at it,
I'll fix this an other places you pointed at...

> 
>> +err_clk_enable:
>> +	clk_put(clk);
> 
> Put without get ....

or double clk_put() if clk_prepare_enable() failed... shame, shame, shame

> 
>> +static int __init mps2_clocksource_init(struct device_node *np)
>> +{
>> +	void __iomem *base;
>> +	struct clk *clk;
>> +	u32 rate;
>> +	int ret;
>> +	const char *name = "mps2-clksrc";
>> +
>> +	ret = of_property_read_u32(np, "clock-frequency", &rate);
>> +	if (ret) {
>> +		clk = of_clk_get(np, 0);
>> +		if (IS_ERR(clk)) {
>> +			ret = PTR_ERR(clk);
>> +			pr_err("failed to get clock for clocksource: %d\n", ret);
>> +			goto err_clk_get;
>> +		}
>> +
>> +		ret = clk_prepare_enable(clk);
>> +		if (ret) {
>> +			pr_err("failed to enable clock for clocksource: %d\n", ret);
>> +			clk_put(clk);
>> +			goto err_clk_enable;
>> +		}
>> +
>> +		rate = clk_get_rate(clk);
>> +	}
> 
> Same problem as above.
> 
>> +err_clocksource_init:
>> +	iounmap(base);
>> +err_iomap:
>> +	clk_disable_unprepare(clk);
> 
> Ditto.
> 
>> +err_clk_enable:
>> +	clk_put(clk);
> 
> Ditto.
> 
>> +err_clk_get:
>> +	return ret;
>> +}
>> +
>> +static void __init mps2_timer_init(struct device_node *np)
>> +{
>> +	static int has_clocksource, has_clockevent;
>> +	int ret;
>> +
>> +	if (!has_clocksource) {
>> +		ret = mps2_clocksource_init(np);
>> +		if (!ret) {
>> +			has_clocksource = 1;
>> +			return;
>> +		}
>> +	}
>> +
>> +	if (!has_clockevent) {
>> +		ret = mps2_clockevent_init(np);
>> +		if (!ret) {
>> +			has_clockevent = 1;
>> +			return;
>> +		}
>> +	}
> 
> You take randomly the first timer as clocksource and the second one as
> clockevent. If clocksource init fails, you try to install it as clockevent.
> 
> Sorry, but I really cannot follow the logic here.
> 

It has been done as a response on Daniel's comment [1]. I'm quite happy
to get known what init sequence is expected here.

[1]
http://lists.infradead.org/pipermail/linux-arm-kernel/2015-November/388223.html

Thanks for your time, Thomas!

Vladimir

> Thanks,
> 
> 	tglx
> 
> 
> 

  reply	other threads:[~2016-02-02 14:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-02 11:39 [PATCH v2 00/10] Support for Cortex-M Prototyping System Vladimir Murzin
2016-02-02 11:39 ` [PATCH v2 01/10] dt-bindings: document the MPS2 timer bindings Vladimir Murzin
2016-02-02 11:39 ` [PATCH v2 02/10] clockevents/drivers: add MPS2 Timer driver Vladimir Murzin
     [not found]   ` <1454413199-26573-3-git-send-email-vladimir.murzin-5wv7dgnIgG8@public.gmane.org>
2016-02-02 13:04     ` Thomas Gleixner
2016-02-02 14:06       ` Vladimir Murzin [this message]
2016-02-02 11:39 ` [PATCH v2 03/10] dt-bindings: document the MPS2 UART bindings Vladimir Murzin
2016-02-02 11:39 ` [PATCH v2 04/10] serial: mps2-uart: add MPS2 UART driver Vladimir Murzin
     [not found]   ` <1454413199-26573-5-git-send-email-vladimir.murzin-5wv7dgnIgG8@public.gmane.org>
2016-02-07  7:11     ` Greg KH
     [not found]       ` <20160207071154.GA32017-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2016-02-08 11:16         ` Vladimir Murzin
     [not found]           ` <56B87928.7020803-5wv7dgnIgG8@public.gmane.org>
2016-02-08 16:52             ` Greg KH
2016-02-08 17:17               ` Vladimir Murzin
     [not found]                 ` <56B8CDC5.5010504-5wv7dgnIgG8@public.gmane.org>
2016-02-08 17:28                   ` Greg KH
2016-02-02 11:39 ` [PATCH v2 05/10] serial: mps2-uart: add support for early console Vladimir Murzin
2016-02-02 11:39 ` [PATCH v2 06/10] ARM: mps2: introduce MPS2 platform Vladimir Murzin
2016-02-02 11:39 ` [PATCH v2 07/10] ARM: mps2: add low-level debug support Vladimir Murzin
2016-02-02 11:39 ` [PATCH v2 08/10] ARM: configs: add MPS2 defconfig Vladimir Murzin
2016-02-02 11:39 ` [PATCH v2 09/10] ARM: dts: introduce MPS2 AN385/AN386 Vladimir Murzin
2016-02-02 11:39 ` [PATCH v2 10/10] ARM: dts: introduce MPS2 AN399/AN400 Vladimir Murzin

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=56B0B803.8010003@arm.com \
    --to=vladimir.murzin@arm.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=arnd@arndb.de \
    --cc=daniel.lezcano@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=jslaby@suse.cz \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=u.kleine-koenig@pengutronix.de \
    /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).