[linux-sunxi] [PATCH RESEND] mmc: sunxi: Check the value returned by clk_round_rate

2016-08-23 Thread Jean-Francois Moine
clk_round_rate() may return an error. Check it.

Signed-off-by: Jean-Francois Moine 
Acked-by: Maxime Ripard 
---
Rebase on linux-next
---
 drivers/mmc/host/sunxi-mmc.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index 2ec91ce..142ab3f 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -692,7 +692,8 @@ static int sunxi_mmc_clk_set_phase(struct sunxi_mmc_host 
*host,
 static int sunxi_mmc_clk_set_rate(struct sunxi_mmc_host *host,
  struct mmc_ios *ios)
 {
-   u32 rate, rval, clock = ios->clock;
+   long rate;
+   u32 rval, clock = ios->clock;
int ret;
 
/* 8 bit DDR requires a higher module clock */
@@ -701,13 +702,18 @@ static int sunxi_mmc_clk_set_rate(struct sunxi_mmc_host 
*host,
clock <<= 1;
 
rate = clk_round_rate(host->clk_mmc, clock);
-   dev_dbg(mmc_dev(host->mmc), "setting clk to %d, rounded %d\n",
+   if (rate < 0) {
+   dev_err(mmc_dev(host->mmc), "error rounding clk to %d: %ld\n",
+   clock, rate);
+   return rate;
+   }
+   dev_dbg(mmc_dev(host->mmc), "setting clk to %d, rounded %ld\n",
clock, rate);
 
/* setting clock rate */
ret = clk_set_rate(host->clk_mmc, rate);
if (ret) {
-   dev_err(mmc_dev(host->mmc), "error setting clk to %d: %d\n",
+   dev_err(mmc_dev(host->mmc), "error setting clk to %ld: %d\n",
rate, ret);
return ret;
}
-- 
2.9.3

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[linux-sunxi] [PATCH RESEND] mmc: sunxi: Check the value returned by clk_round_rate

2016-08-13 Thread Jean-Francois Moine
clk_round_rate() may return an error. Check it.

Signed-off-by: Jean-Francois Moine 
Acked-by: Maxime Ripard 
---
This patch was initially sent in a patch series about the MMC new mode,
but it may be applied independently.
---
 drivers/mmc/host/sunxi-mmc.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index 2ee4c21..ba647b7 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -656,7 +656,8 @@ static int sunxi_mmc_oclk_onoff(struct sunxi_mmc_host 
*host, u32 oclk_en)
 static int sunxi_mmc_clk_set_rate(struct sunxi_mmc_host *host,
  struct mmc_ios *ios)
 {
-   u32 rate, oclk_dly, rval, sclk_dly;
+   long rate;
+   u32 oclk_dly, rval, sclk_dly;
u32 clock = ios->clock;
int ret;
 
@@ -666,13 +667,18 @@ static int sunxi_mmc_clk_set_rate(struct sunxi_mmc_host 
*host,
clock <<= 1;
 
rate = clk_round_rate(host->clk_mmc, clock);
-   dev_dbg(mmc_dev(host->mmc), "setting clk to %d, rounded %d\n",
+   if (rate < 0) {
+   dev_err(mmc_dev(host->mmc), "error rounding clk to %d: %ld\n",
+   clock, rate);
+   return rate;
+   }
+   dev_dbg(mmc_dev(host->mmc), "setting clk to %d, rounded %ld\n",
clock, rate);
 
/* setting clock rate */
ret = clk_set_rate(host->clk_mmc, rate);
if (ret) {
-   dev_err(mmc_dev(host->mmc), "error setting clk to %d: %d\n",
+   dev_err(mmc_dev(host->mmc), "error setting clk to %ld: %d\n",
rate, ret);
return ret;
}
-- 
2.9.2

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.