Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pwm: sl28cpld: fix getting driver data in pwm callbacks

Currently .get_state() and .apply() use dev_get_drvdata() on the struct
device related to the pwm chip. This only works after .probe() called
platform_set_drvdata() which in this driver happens only after
pwmchip_add() and so comes possibly too late.

Instead of setting the driver data earlier use the traditional
container_of approach as this way the driver data is conceptually and
computational nearer.

Fixes: 9db33d221efc ("pwm: Add support for sl28cpld PWM controller")
Tested-by: Michael Walle <michael@walle.cc>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Uwe Kleine-König and committed by
Linus Torvalds
062c9cdf 4f134b89

+4 -2
+4 -2
drivers/pwm/pwm-sl28cpld.c
··· 84 84 struct regmap *regmap; 85 85 u32 offset; 86 86 }; 87 + #define sl28cpld_pwm_from_chip(_chip) \ 88 + container_of(_chip, struct sl28cpld_pwm, pwm_chip) 87 89 88 90 static void sl28cpld_pwm_get_state(struct pwm_chip *chip, 89 91 struct pwm_device *pwm, 90 92 struct pwm_state *state) 91 93 { 92 - struct sl28cpld_pwm *priv = dev_get_drvdata(chip->dev); 94 + struct sl28cpld_pwm *priv = sl28cpld_pwm_from_chip(chip); 93 95 unsigned int reg; 94 96 int prescaler; 95 97 ··· 120 118 static int sl28cpld_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, 121 119 const struct pwm_state *state) 122 120 { 123 - struct sl28cpld_pwm *priv = dev_get_drvdata(chip->dev); 121 + struct sl28cpld_pwm *priv = sl28cpld_pwm_from_chip(chip); 124 122 unsigned int cycle, prescaler; 125 123 bool write_duty_cycle_first; 126 124 int ret;