public inbox for linux-mmc@vger.kernel.org
 help / color / mirror / Atom feed
From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Boris BREZILLON <b.brezillon@overkiz.com>
Cc: Nicolas Ferre <nicolas.ferre@atmel.com>,
	Ludovic Desroches <ludovic.desroches@atmel.com>,
	Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>,
	Chris Ball <cjb@laptop.org>,
	linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v3 2/7] mmc: atmel-mci: prepare clk before calling enable
Date: Tue, 16 Jul 2013 18:13:24 +0100	[thread overview]
Message-ID: <20130716171324.GF24642@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <1373987208-24120-1-git-send-email-b.brezillon@overkiz.com>

On Tue, Jul 16, 2013 at 05:06:48PM +0200, Boris BREZILLON wrote:
> @@ -389,9 +391,13 @@ static int atmci_regs_show(struct seq_file *s, void *v)
>  	 * consistent.
>  	 */
>  	spin_lock_bh(&host->lock);
> -	clk_enable(host->mck);
> +	ret = clk_prepare_enable(host->mck);
> +	if (ret) {
> +		spin_unlock_bh(&host->lock);
> +		goto out;
> +	}

NAK.  This is buggy.  clk_prepare() can sleep.  Calling clk_prepare()
even via clk_prepare_enable() is a blatent bug.

>  	memcpy_fromio(buf, host->regs, ATMCI_REGS_SIZE);
> -	clk_disable(host->mck);
> +	clk_disable_unprepare(host->mck);
>  	spin_unlock_bh(&host->lock);

Now, given that the CLK API counts enables/disables, having the spin lock
around the clk API calls is utterly pointless.  This should be:

	ret = clk_prepare_enable(host->mck);
	if (ret)
		goto out;

	spin_lock_bh(&host->lock);
	memcpy_fromio(buf, host->regs, ATMCI_REGS_SIZE);
	spin_unlock_bh(&host->lock);

	clk_disable_unprepare(host->mclk);

or, if you really need to have the clock enabled/disabled within the
spinlock (very very very unlikely):

	ret = clk_prepare(host->mck);
	if (ret)
		goto out;

	spin_lock_bh(&host->lock);
	ret = clk_enable(host->mck);
	if (ret == 0) {
		memcpy_fromio(buf, host->regs, ATMCI_REGS_SIZE);
		clk_disable(host->mck);
	}
	spin_unlock_bh(&host->lock);

	clk_unprepare(host->mclk);
	if (ret)
		goto out;

> @@ -1279,7 +1286,7 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
>  
>  		spin_lock_bh(&host->lock);
>  		if (!host->mode_reg) {
> -			clk_enable(host->mck);
> +			clk_prepare_enable(host->mck);

Again, buggy - calling clk_prepare beneath a spinlock is illegal.

      parent reply	other threads:[~2013-07-16 17:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1373986995-23899-1-git-send-email-b.brezillon@overkiz.com>
2013-07-16 15:06 ` [PATCH v3 2/7] mmc: atmel-mci: prepare clk before calling enable Boris BREZILLON
2013-07-16 15:13   ` Thomas Petazzoni
2013-07-16 15:49     ` boris brezillon
2013-07-16 17:13   ` Russell King - ARM Linux [this message]

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=20130716171324.GF24642@n2100.arm.linux.org.uk \
    --to=linux@arm.linux.org.uk \
    --cc=b.brezillon@overkiz.com \
    --cc=cjb@laptop.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ludovic.desroches@atmel.com \
    --cc=nicolas.ferre@atmel.com \
    --cc=plagnioj@jcrosoft.com \
    /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