backports: add devm_gpio_free()
authorJohannes Berg <johannes.berg@intel.com>
Tue, 7 Feb 2017 14:05:48 +0000 (15:05 +0100)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 7 Feb 2017 14:56:55 +0000 (15:56 +0100)
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
backport/backport-include/linux/gpio.h
backport/compat/compat-3.5.c

index 8fb7211d9f13b066d7946fd3efe89a9de843a2f2..964f1f3683de0fa2edf3730baca4befb0b074428 100644 (file)
@@ -9,6 +9,7 @@
 int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
 int devm_gpio_request_one(struct device *dev, unsigned gpio,
                          unsigned long flags, const char *label);
+void devm_gpio_free(struct device *dev, unsigned int gpio);
 #else
 static inline int devm_gpio_request(struct device *dev, unsigned gpio,
                                    const char *label)
@@ -23,6 +24,11 @@ static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
        WARN_ON(1);
        return -EINVAL;
 }
+
+static inline void devm_gpio_free(struct device *dev, unsigned int gpio)
+{
+       WARN_ON(1);
+}
 #endif /* CONFIG_GPIOLIB */
 #endif
 
index 13f64768ccaed674a0fd188b541aec620bdc52a4..1b8f7874db13561d9ce9cd61c29600835436bb46 100644 (file)
@@ -149,4 +149,19 @@ int devm_gpio_request_one(struct device *dev, unsigned gpio,
        return 0;
 }
 EXPORT_SYMBOL_GPL(devm_gpio_request_one);
+
+static int devm_gpio_match(struct device *dev, void *res, void *data)
+{
+       unsigned *this = res, *gpio = data;
+
+       return *this == *gpio;
+}
+
+void devm_gpio_free(struct device *dev, unsigned int gpio)
+{
+       WARN_ON(devres_destroy(dev, devm_gpio_release, devm_gpio_match,
+               &gpio));
+       gpio_free(gpio);
+}
+EXPORT_SYMBOL_GPL(devm_gpio_free);
 #endif /* CONFIG_GPIOLIB */