]> git.karo-electronics.de Git - linux-beck.git/commitdiff
pwm: Check for negative duty-cycle and period
authorThierry Reding <thierry.reding@avionic-design.de>
Sun, 2 Sep 2012 20:13:40 +0000 (22:13 +0200)
committerThierry Reding <thierry.reding@avionic-design.de>
Fri, 5 Oct 2012 18:56:43 +0000 (20:56 +0200)
Make sure the duty-cycle and period passed in are not negative. This
should eventually be made implicit by making them unsigned. While at
it, the drivers' .config() implementations can have the equivalent
checks removed.

Signed-off-by: Thierry Reding <thierry.reding@avionic-design.de>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Sachin Kamat <sachin.kamat@linaro.org>
Cc: Axel Lin <axel.lin@gmail.com>
Cc: Kukjin Kim <kgene.kim@samsung.com>
Cc: Jingoo Han <jg1.han@samsung.com>
Cc: Jonghwan Choi <jhbird.choi@samsung.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: "Philip, Avinash" <avinashphilip@ti.com>
Cc: Vaibhav Bedia <vaibhav.bedia@ti.com>
Acked-by: Jingoo Han <jg1.han@samsung.com>
drivers/pwm/core.c
drivers/pwm/pwm-bfin.c
drivers/pwm/pwm-pxa.c
drivers/pwm/pwm-samsung.c
drivers/pwm/pwm-tiecap.c
drivers/pwm/pwm-tiehrpwm.c

index 92b1782d0d8ef7e25ca08796db6939d7f05de9d8..f5acdaa527077bc1e6e4bd8f67a52b21c5310dfb 100644 (file)
@@ -371,7 +371,7 @@ EXPORT_SYMBOL_GPL(pwm_free);
  */
 int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
 {
-       if (!pwm || period_ns == 0 || duty_ns > period_ns)
+       if (!pwm || duty_ns < 0 || period_ns <= 0 || duty_ns > period_ns)
                return -EINVAL;
 
        return pwm->chip->ops->config(pwm->chip, pwm, duty_ns, period_ns);
index d53c4e7941ef4364f9cf06975e19132e86bf817a..5da8e185e838c111676fb40a9d159619a846cdc7 100644 (file)
@@ -69,9 +69,6 @@ static int bfin_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
        unsigned long period, duty;
        unsigned long long val;
 
-       if (duty_ns < 0 || duty_ns > period_ns)
-               return -EINVAL;
-
        val = (unsigned long long)get_sclk() * period_ns;
        do_div(val, NSEC_PER_SEC);
        period = val;
index bd5867a1c70064db164836630b7f126c2eeb4afb..260c3a88564d2a59e51d9c780d2d45517a54dbbd 100644 (file)
@@ -70,9 +70,6 @@ static int pxa_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
        unsigned long offset;
        int rc;
 
-       if (period_ns == 0 || duty_ns > period_ns)
-               return -EINVAL;
-
        offset = pwm->hwpwm ? 0x10 : 0;
 
        c = clk_get_rate(pc->clk);
index e5187c0ade9fdde4a4cfd4e8ba55c8b2d337173a..023a3bee76e7d04e9a76922d46c95addcf418086 100644 (file)
@@ -126,9 +126,6 @@ static int s3c_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
        if (period_ns > NS_IN_HZ || duty_ns > NS_IN_HZ)
                return -ERANGE;
 
-       if (duty_ns > period_ns)
-               return -EINVAL;
-
        if (period_ns == s3c->period_ns &&
            duty_ns == s3c->duty_ns)
                return 0;
index 081471fbb097e27a2e754c060251b4a0f9ba7217..d6d4cf05565ef0975ca149e03ece75964f74baf6 100644 (file)
@@ -60,7 +60,7 @@ static int ecap_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
        unsigned long period_cycles, duty_cycles;
        unsigned int reg_val;
 
-       if (period_ns < 0 || duty_ns < 0 || period_ns > NSEC_PER_SEC)
+       if (period_ns > NSEC_PER_SEC)
                return -ERANGE;
 
        c = pc->clk_rate;
index caf00feadc666cf4976620bb33a321586a3e2e90..d3c1dff0a0dc7a5a3eceb7e7c15fa1af10012afa 100644 (file)
@@ -221,7 +221,7 @@ static int ehrpwm_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
        unsigned short ps_divval, tb_divval;
        int i, cmp_reg;
 
-       if (period_ns < 0 || duty_ns < 0 || period_ns > NSEC_PER_SEC)
+       if (period_ns > NSEC_PER_SEC)
                return -ERANGE;
 
        c = pc->clk_rate;