diff options
author | Boris Brezillon <boris.brezillon@free-electrons.com> | 2016-05-17 08:27:25 -0400 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2016-05-17 08:41:18 -0400 |
commit | fbd45a12988e75a48d392feb8b0e5feb5d612513 (patch) | |
tree | 67d84a279f38b1582fb0345a9d81cd474cfa7965 | |
parent | e39c0df1be5a97e0910b09af1530bdf3de057a06 (diff) |
pwm: Fix pwm_apply_args() call sites
pwm_apply_args() is supposed to initialize a PWM device according to the
arguments provided by the DT or the PWM lookup, but this function was
called inside pwm_device_request(), which in turn was called before the
core had a chance to initialize the pwm->args fields.
Fix that by calling pwm_apply_args directly in pwm_get() and of_pwm_get()
after initializing pwm->args field.
This commit also fixes an invalid pointer dereference introduced by
commit e39c0df1be5a ("pwm: Introduce the pwm_args concept").
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Fixes: e39c0df1be5a ("pwm: Introduce the pwm_args concept")
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
-rw-r--r-- | drivers/pwm/core.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 680fbc795a0a..22cf3959041c 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c | |||
@@ -128,13 +128,6 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label) | |||
128 | set_bit(PWMF_REQUESTED, &pwm->flags); | 128 | set_bit(PWMF_REQUESTED, &pwm->flags); |
129 | pwm->label = label; | 129 | pwm->label = label; |
130 | 130 | ||
131 | /* | ||
132 | * FIXME: This should be removed once all PWM users properly make use | ||
133 | * of struct pwm_args to initialize the PWM device. As long as this is | ||
134 | * here, the PWM state and hardware state can get out of sync. | ||
135 | */ | ||
136 | pwm_apply_args(pwm); | ||
137 | |||
138 | return 0; | 131 | return 0; |
139 | } | 132 | } |
140 | 133 | ||
@@ -627,6 +620,13 @@ struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id) | |||
627 | 620 | ||
628 | pwm->label = con_id; | 621 | pwm->label = con_id; |
629 | 622 | ||
623 | /* | ||
624 | * FIXME: This should be removed once all PWM users properly make use | ||
625 | * of struct pwm_args to initialize the PWM device. As long as this is | ||
626 | * here, the PWM state and hardware state can get out of sync. | ||
627 | */ | ||
628 | pwm_apply_args(pwm); | ||
629 | |||
630 | put: | 630 | put: |
631 | of_node_put(args.np); | 631 | of_node_put(args.np); |
632 | 632 | ||
@@ -754,13 +754,20 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id) | |||
754 | if (!chip) | 754 | if (!chip) |
755 | goto out; | 755 | goto out; |
756 | 756 | ||
757 | pwm->args.period = chosen->period; | ||
758 | pwm->args.polarity = chosen->polarity; | ||
759 | |||
760 | pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id); | 757 | pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id); |
761 | if (IS_ERR(pwm)) | 758 | if (IS_ERR(pwm)) |
762 | goto out; | 759 | goto out; |
763 | 760 | ||
761 | pwm->args.period = chosen->period; | ||
762 | pwm->args.polarity = chosen->polarity; | ||
763 | |||
764 | /* | ||
765 | * FIXME: This should be removed once all PWM users properly make use | ||
766 | * of struct pwm_args to initialize the PWM device. As long as this is | ||
767 | * here, the PWM state and hardware state can get out of sync. | ||
768 | */ | ||
769 | pwm_apply_args(pwm); | ||
770 | |||
764 | out: | 771 | out: |
765 | mutex_unlock(&pwm_lookup_lock); | 772 | mutex_unlock(&pwm_lookup_lock); |
766 | return pwm; | 773 | return pwm; |