Thread (28 messages) 28 messages, 5 authors, 2016-03-08
STALE3732d

[PATCH 2/4] pwm: omap-dmtimer: add sanity checking for load and match values

From: David Rivshin Allworx <hidden>
Date: 2016-02-01 18:35:03
Also in: linux-omap, linux-pwm

On Fri, 29 Jan 2016 23:26:52 -0500
"David Rivshin (Allworx)" [off-list ref] wrote:
From: David Rivshin <redacted>

Add sanity checking to ensure that we do not program load or match
values that are out of range if a user requests period or duty_cycle
values which are not achievable. The match value cannot be less than
the load value (but can be equal), and neither can be 0xffffffff.
This means that there must be at least one fclk cycle between load
and match, and another between match and overflow.

Fixes: 6604c6556db9 ("pwm: Add PWM driver for OMAP using dual-mode
timers") Signed-off-by: David Rivshin [off-list ref]
---
 [...]
quoted hunk ↗ jump to hunk
@@ -149,6 +149,24 @@ static int pwm_omap_dmtimer_config(struct pwm_chip *chip, 
period_cycles = pwm_omap_dmtimer_get_clock_cycles(clk_rate, period_ns); 
duty_cycles = pwm_omap_dmtimer_get_clock_cycles(clk_rate, duty_ns); 

+	if (period_cycles < 2) {
+		dev_info(chip->dev,
+			"period %dns is too short for clock rate %luHz\n",
+			period_ns, clk_rate);
+		goto err_einval;
+	}
 [...]

I had some second thoughts on this over the weekend:
1) Perhaps the return should be -ERANGE instead of -EINVAL for this case?
2) Is dev_info() too severe for this? Perhaps dev_dbg() would be better?
Any preferences?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help