Skip to contentSkip to conversation

ARM: mach-shmobile: sh7372 divide-by-zero FSIDIV fix

PATCH In review Magnus Damm 2 participants 4 messages Jun 9, 2011 – Jun 10, 2011

Subsystems (4)
lore
Share & tools
lore

Magnus Damm

author maintainer
#0 lore raw

PATCH 1/1 ARM: mach-shmobile: sh7372 divide-by-zero FSIDIV fix

From: Magnus Damm <[email protected]>

Update the sh7372 FSIDIV clock code to bail out
with -EINVAL in case of rate is zero.

Without this fix divide-by-zero is triggering
on sh7372 platforms during system wide resume
of Suspend-to-RAM.

---

 arch/arm/mach-shmobile/clock-sh7372.c |    3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-shmobile/clock-sh7372.c +3 -0
@@ -460,6 +460,9 @@ static int fsidiv_set_rate(struct clk *c
 {
 	int idx;
 
+	if (!rate)
+		return -EINVAL;
+
 	idx = (clk->parent->rate / rate) & 0xffff;
 	if (idx < 2)
 		return -EINVAL;
#1 lore raw
Quoted 8 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Update the sh7372 FSIDIV clock code to bail out
with -EINVAL in case of rate is zero.

Without this fix divide-by-zero is triggering
on sh7372 platforms during system wide resume
of Suspend-to-RAM.

Hi Magnus,

I'm unsure that I understand how rate ends up being zero in the situation you describe.

Quoted 24 lines

---

 arch/arm/mach-shmobile/clock-sh7372.c |    3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-shmobile/clock-sh7372.c +3 -1
@@ -460,6 +460,9 @@ static int fsidiv_set_rate(struct clk *c
 {
 	int idx;
 
+	if (!rate)
+		return -EINVAL;
+
 	idx = (clk->parent->rate / rate) & 0xffff;
 	if (idx < 2)
 		return -EINVAL;
--

To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#2 lore raw
In reply to Magnus Damm
Quoted 6 lines · Simon Horman
Quoted 5 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Update the sh7372 FSIDIV clock code to bail out
with -EINVAL in case of rate is zero.

Quoted 8 lines
Quoted 3 lines

Without this fix divide-by-zero is triggering
on sh7372 platforms during system wide resume
of Suspend-to-RAM.

Hi Magnus,

I'm unsure that I understand how rate ends up being zero in the situation you describe.

Hi Simon,

During Suspend-to-RAM resume the function clks_core_resume() in drivers/sh/clk/core.c gets executed. This function goes through all clocks and sets their rate. In some cases the rate happens to be zero, and for the FSIDIV the zero turns into a divide-by-zero.

This can easily be triggered by using Suspend-to-RAM on for instance a Mackerel board.

/ magnus

#3 lore raw
In reply to Magnus Damm
Quoted 16 lines · Magnus Damm
Quoted 6 lines · Simon Horman
Quoted 5 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Update the sh7372 FSIDIV clock code to bail out
with -EINVAL in case of rate is zero.

Quoted 8 lines
Quoted 3 lines

Without this fix divide-by-zero is triggering
on sh7372 platforms during system wide resume
of Suspend-to-RAM.

Hi Magnus,

I'm unsure that I understand how rate ends up being zero in the situation you describe.

Quoted 6 lines

Hi Simon,

During Suspend-to-RAM resume the function clks_core_resume() in drivers/sh/clk/core.c gets executed. This function goes through all clocks and sets their rate. In some cases the rate happens to be zero, and for the FSIDIV the zero turns into a divide-by-zero.

Ok, understood.