perf probe: Fix memory leak when synthesizing SDT probes
[linux-2.6-microblaze.git] / drivers / gpio / gpiolib-devres.c
index 7dbce4c..4a517e5 100644 (file)
@@ -246,10 +246,8 @@ struct gpio_desc *__must_check devm_gpiod_get_index_optional(struct device *dev,
        struct gpio_desc *desc;
 
        desc = devm_gpiod_get_index(dev, con_id, index, flags);
-       if (IS_ERR(desc)) {
-               if (PTR_ERR(desc) == -ENOENT)
-                       return NULL;
-       }
+       if (gpiod_not_found(desc))
+               return NULL;
 
        return desc;
 }
@@ -308,7 +306,7 @@ devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
        struct gpio_descs *descs;
 
        descs = devm_gpiod_get_array(dev, con_id, flags);
-       if (PTR_ERR(descs) == -ENOENT)
+       if (gpiod_not_found(descs))
                return NULL;
 
        return descs;
@@ -479,9 +477,9 @@ void devm_gpio_free(struct device *dev, unsigned int gpio)
 }
 EXPORT_SYMBOL_GPL(devm_gpio_free);
 
-static void devm_gpio_chip_release(struct device *dev, void *res)
+static void devm_gpio_chip_release(void *data)
 {
-       struct gpio_chip *gc = *(struct gpio_chip **)res;
+       struct gpio_chip *gc = data;
 
        gpiochip_remove(gc);
 }
@@ -507,23 +505,12 @@ int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc, vo
                                    struct lock_class_key *lock_key,
                                    struct lock_class_key *request_key)
 {
-       struct gpio_chip **ptr;
        int ret;
 
-       ptr = devres_alloc(devm_gpio_chip_release, sizeof(*ptr),
-                            GFP_KERNEL);
-       if (!ptr)
-               return -ENOMEM;
-
        ret = gpiochip_add_data_with_key(gc, data, lock_key, request_key);
-       if (ret < 0) {
-               devres_free(ptr);
+       if (ret < 0)
                return ret;
-       }
 
-       *ptr = gc;
-       devres_add(dev, ptr);
-
-       return 0;
+       return devm_add_action_or_reset(dev, devm_gpio_chip_release, gc);
 }
 EXPORT_SYMBOL_GPL(devm_gpiochip_add_data_with_key);