return 0;
  }
  
 -static void pwm_fan_pwm_disable(void *data)
+ static void pwm_fan_regulator_disable(void *data)
+ {
+       regulator_disable(data);
+ }
+ 
 -      pwm_disable(data);
++static void pwm_fan_pwm_disable(void *__ctx)
+ {
++      struct pwm_fan_ctx *ctx = __ctx;
++      pwm_disable(ctx->pwm);
++      del_timer_sync(&ctx->rpm_timer);
+ }
+ 
  static int pwm_fan_probe(struct platform_device *pdev)
  {
        struct thermal_cooling_device *cdev;
        struct device *hwmon;
        int ret;
        struct pwm_state state = { };
 +      u32 ppr = 2;
  
-       ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
+       ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
        if (!ctx)
                return -ENOMEM;
  
  
        platform_set_drvdata(pdev, ctx);
  
-       ctx->reg_en = devm_regulator_get_optional(&pdev->dev, "fan");
 +      ctx->irq = platform_get_irq(pdev, 0);
 +      if (ctx->irq == -EPROBE_DEFER)
 +              return ctx->irq;
 +
+       ctx->reg_en = devm_regulator_get_optional(dev, "fan");
        if (IS_ERR(ctx->reg_en)) {
                if (PTR_ERR(ctx->reg_en) != -ENODEV)
                        return PTR_ERR(ctx->reg_en);
  
        ret = pwm_apply_state(ctx->pwm, &state);
        if (ret) {
-               dev_err(&pdev->dev, "Failed to configure PWM: %d\n", ret);
-               goto err_reg_disable;
 -              dev_err(dev, "Failed to configure PWM\n");
++              dev_err(dev, "Failed to configure PWM: %d\n", ret);
+               return ret;
        }
- 
 -      devm_add_action_or_reset(dev, pwm_fan_pwm_disable, ctx->pwm);
 +      timer_setup(&ctx->rpm_timer, sample_timer, 0);
++      devm_add_action_or_reset(dev, pwm_fan_pwm_disable, ctx);
 +
-       of_property_read_u32(pdev->dev.of_node, "pulses-per-revolution", &ppr);
++      of_property_read_u32(dev->of_node, "pulses-per-revolution", &ppr);
 +      ctx->pulses_per_revolution = ppr;
 +      if (!ctx->pulses_per_revolution) {
-               dev_err(&pdev->dev, "pulses-per-revolution can't be zero.\n");
-               ret = -EINVAL;
-               goto err_pwm_disable;
++              dev_err(dev, "pulses-per-revolution can't be zero.\n");
++              return -EINVAL;
 +      }
 +
 +      if (ctx->irq > 0) {
-               ret = devm_request_irq(&pdev->dev, ctx->irq, pulse_handler, 0,
++              ret = devm_request_irq(dev, ctx->irq, pulse_handler, 0,
 +                                     pdev->name, ctx);
 +              if (ret) {
-                       dev_err(&pdev->dev,
-                               "Failed to request interrupt: %d\n", ret);
-                       goto err_pwm_disable;
++                      dev_err(dev, "Failed to request interrupt: %d\n", ret);
++                      return ret;
 +              }
 +              ctx->sample_start = ktime_get();
 +              mod_timer(&ctx->rpm_timer, jiffies + HZ);
 +      }
  
-       hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, "pwmfan",
+       hwmon = devm_hwmon_device_register_with_groups(dev, "pwmfan",
                                                       ctx, pwm_fan_groups);
        if (IS_ERR(hwmon)) {
-               ret = PTR_ERR(hwmon);
-               dev_err(&pdev->dev,
-                       "Failed to register hwmon device: %d\n", ret);
-               goto err_del_timer;
+               dev_err(dev, "Failed to register hwmon device\n");
+               return PTR_ERR(hwmon);
        }
  
-       ret = pwm_fan_of_get_cooling_data(&pdev->dev, ctx);
+       ret = pwm_fan_of_get_cooling_data(dev, ctx);
        if (ret)
-               goto err_del_timer;
+               return ret;
  
        ctx->pwm_fan_state = ctx->pwm_fan_max_state;
        if (IS_ENABLED(CONFIG_THERMAL)) {
-               cdev = thermal_of_cooling_device_register(pdev->dev.of_node,
-                                                         "pwm-fan", ctx,
-                                                         &pwm_fan_cooling_ops);
+               cdev = devm_thermal_of_cooling_device_register(dev,
+                       dev->of_node, "pwm-fan", ctx, &pwm_fan_cooling_ops);
                if (IS_ERR(cdev)) {
-                       dev_err(&pdev->dev,
 +                      ret = PTR_ERR(cdev);
 -                              "Failed to register pwm-fan as cooling device");
 -                      return PTR_ERR(cdev);
+                       dev_err(dev,
-                       goto err_del_timer;
 +                              "Failed to register pwm-fan as cooling device: %d\n",
 +                              ret);
++                      return ret;
                }
                ctx->cdev = cdev;
                thermal_cdev_update(cdev);