Commit 16b0c0ce83ec3f8bf96de69b1c84214cacc39416

Authored by Axel Lin
Committed by Stefano Babic
1 parent 53940a5079

pwm: imx: Prevent NULL pointer dereference

pwm_id_to_reg() can return NULL, so add NULL testing to prevent NULL pointer
dereference.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Acked-by: Stefano Babic <sbabic@denx.de>
Acked-by: Heiko Schocher <hs@denx.de>

Showing 1 changed file with 12 additions and 0 deletions Side-by-side Diff

drivers/pwm/pwm-imx.c
... ... @@ -18,6 +18,9 @@
18 18 {
19 19 struct pwm_regs *pwm = (struct pwm_regs *)pwm_id_to_reg(pwm_id);
20 20  
  21 + if (!pwm)
  22 + return -1;
  23 +
21 24 writel(0, &pwm->ir);
22 25 return 0;
23 26 }
... ... @@ -28,6 +31,9 @@
28 31 unsigned long period_cycles, duty_cycles, prescale;
29 32 u32 cr;
30 33  
  34 + if (!pwm)
  35 + return -1;
  36 +
31 37 pwm_imx_get_parms(period_ns, duty_ns, &period_cycles, &duty_cycles,
32 38 &prescale);
33 39  
... ... @@ -47,6 +53,9 @@
47 53 {
48 54 struct pwm_regs *pwm = (struct pwm_regs *)pwm_id_to_reg(pwm_id);
49 55  
  56 + if (!pwm)
  57 + return -1;
  58 +
50 59 setbits_le32(&pwm->cr, PWMCR_EN);
51 60 return 0;
52 61 }
... ... @@ -54,6 +63,9 @@
54 63 void pwm_disable(int pwm_id)
55 64 {
56 65 struct pwm_regs *pwm = (struct pwm_regs *)pwm_id_to_reg(pwm_id);
  66 +
  67 + if (!pwm)
  68 + return;
57 69  
58 70 clrbits_le32(&pwm->cr, PWMCR_EN);
59 71 }