[PATCH] sdhci: Be more strict with get_min_clock() usage

From: Anton Vorontsov
Date: Tue Aug 04 2009 - 13:21:03 EST


get_min_clock() makes sense only with NONSTANDARD_CLOCK quirk and when
set_clock() callback is specified.

The patch should cause no functional changes, it just makes the code
self-documented and avoids any possible misuse of get_min_clock().

Suggested-by: Pierre Ossman <pierre@xxxxxxxxx>
Signed-off-by: Anton Vorontsov <avorontsov@xxxxxxxxxxxxx>
---

On Sat, Aug 01, 2009 at 10:04:43AM +0200, Pierre Ossman wrote:
[...]
> Hmm... I don't think this is quite right. Right now you kill the
> warning without verifying that there is a mechanism to go lower.
[...]
> > - mmc->f_min = host->max_clk / 256;
> > + if (host->ops->get_min_clock)
> > + mmc->f_min = host->ops->get_min_clock(host);
> > + else
> > + mmc->f_min = host->max_clk / 256;
> > mmc->f_max = host->max_clk;
> > mmc->caps = MMC_CAP_SDIO_IRQ;
>
> You should be checking ops->set_clock and SDHCI_QUIRK_NONSTANDARD_CLOCK
> here.

Well, it makes no sense to specify .get_min_clock() w/o .set_clock().

But okay, to make things self documented and to avoid misuses, we'd
better add these checks.

Thanks Pierre!

drivers/mmc/host/sdhci.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index fc96f8c..7f7f45b 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -1772,7 +1772,8 @@ int sdhci_add_host(struct sdhci_host *host)
* Set host parameters.
*/
mmc->ops = &sdhci_ops;
- if (host->ops->get_min_clock)
+ if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK &&
+ host->ops->set_clock && host->ops->get_min_clock)
mmc->f_min = host->ops->get_min_clock(host);
else
mmc->f_min = host->max_clk / 256;
--
1.6.3.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/