pwm: sl28cpld: Set driver data before registering the PWM chip
authorThierry Reding <thierry.reding@gmail.com>
Fri, 4 Dec 2020 12:44:35 +0000 (13:44 +0100)
committerThierry Reding <thierry.reding@gmail.com>
Thu, 17 Dec 2020 13:19:02 +0000 (14:19 +0100)
It is good practice to set the driver data before registering a device
with a subsystem because the subsystem or the driver core may call back
into the driver implementation. This is not currently an issue, but to
prevent future changes from causing this to break unexpectedly, make
sure that the driver data is set before the PWM chip registration.

Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/pwm-sl28cpld.c

index 5046b6b..c5866a2 100644 (file)
@@ -230,6 +230,8 @@ static int sl28cpld_pwm_probe(struct platform_device *pdev)
        chip->base = -1;
        chip->npwm = 1;
 
+       platform_set_drvdata(pdev, priv);
+
        ret = pwmchip_add(&priv->pwm_chip);
        if (ret) {
                dev_err(&pdev->dev, "failed to add PWM chip (%pe)",
@@ -237,8 +239,6 @@ static int sl28cpld_pwm_probe(struct platform_device *pdev)
                return ret;
        }
 
-       platform_set_drvdata(pdev, priv);
-
        return 0;
 }