pwm: Manage owner assignment implicitly for drivers
[linux-2.6-microblaze.git] / drivers / pwm / core.c
index dc66e34..a2824eb 100644 (file)
@@ -89,13 +89,13 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label)
        if (test_bit(PWMF_REQUESTED, &pwm->flags))
                return -EBUSY;
 
-       if (!try_module_get(pwm->chip->ops->owner))
+       if (!try_module_get(pwm->chip->owner))
                return -ENODEV;
 
        if (pwm->chip->ops->request) {
                err = pwm->chip->ops->request(pwm->chip, pwm);
                if (err) {
-                       module_put(pwm->chip->ops->owner);
+                       module_put(pwm->chip->owner);
                        return err;
                }
        }
@@ -253,14 +253,16 @@ static bool pwm_ops_check(const struct pwm_chip *chip)
 }
 
 /**
- * pwmchip_add() - register a new PWM chip
+ * __pwmchip_add() - register a new PWM chip
  * @chip: the PWM chip to add
+ * @owner: reference to the module providing the chip.
  *
- * Register a new PWM chip.
+ * Register a new PWM chip. @owner is supposed to be THIS_MODULE, use the
+ * pwmchip_add wrapper to do this right.
  *
  * Returns: 0 on success or a negative error code on failure.
  */
-int pwmchip_add(struct pwm_chip *chip)
+int __pwmchip_add(struct pwm_chip *chip, struct module *owner)
 {
        struct pwm_device *pwm;
        unsigned int i;
@@ -272,6 +274,8 @@ int pwmchip_add(struct pwm_chip *chip)
        if (!pwm_ops_check(chip))
                return -EINVAL;
 
+       chip->owner = owner;
+
        chip->pwms = kcalloc(chip->npwm, sizeof(*pwm), GFP_KERNEL);
        if (!chip->pwms)
                return -ENOMEM;
@@ -306,7 +310,7 @@ int pwmchip_add(struct pwm_chip *chip)
 
        return 0;
 }
-EXPORT_SYMBOL_GPL(pwmchip_add);
+EXPORT_SYMBOL_GPL(__pwmchip_add);
 
 /**
  * pwmchip_remove() - remove a PWM chip
@@ -338,17 +342,17 @@ static void devm_pwmchip_remove(void *data)
        pwmchip_remove(chip);
 }
 
-int devm_pwmchip_add(struct device *dev, struct pwm_chip *chip)
+int __devm_pwmchip_add(struct device *dev, struct pwm_chip *chip, struct module *owner)
 {
        int ret;
 
-       ret = pwmchip_add(chip);
+       ret = __pwmchip_add(chip, owner);
        if (ret)
                return ret;
 
        return devm_add_action_or_reset(dev, devm_pwmchip_remove, chip);
 }
-EXPORT_SYMBOL_GPL(devm_pwmchip_add);
+EXPORT_SYMBOL_GPL(__devm_pwmchip_add);
 
 /**
  * pwm_request_from_chip() - request a PWM device relative to a PWM chip
@@ -979,7 +983,7 @@ void pwm_put(struct pwm_device *pwm)
        pwm_set_chip_data(pwm, NULL);
        pwm->label = NULL;
 
-       module_put(pwm->chip->ops->owner);
+       module_put(pwm->chip->owner);
 out:
        mutex_unlock(&pwm_lock);
 }