Skip to content

Commit

Permalink
gpio: constify opaque pointer in gpio_device_find() match function
Browse files Browse the repository at this point in the history
The match function used in gpio_device_find() should not modify the
contents of passed opaque pointer, because such modification would not
be necessary for actual matching and it could lead to quite unreadable,
spaghetti code.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
[Bartosz: fix coding style in header]
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
  • Loading branch information
Krzysztof Kozlowski authored and Bartosz Golaszewski committed Feb 12, 2024
1 parent 104e00b commit faf6efd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion drivers/gpio/gpiolib-acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static DEFINE_MUTEX(acpi_gpio_deferred_req_irqs_lock);
static LIST_HEAD(acpi_gpio_deferred_req_irqs_list);
static bool acpi_gpio_deferred_req_irqs_done;

static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
static int acpi_gpiochip_find(struct gpio_chip *gc, const void *data)
{
return device_match_acpi_handle(&gc->gpiodev->dev, data);
}
Expand Down
7 changes: 4 additions & 3 deletions drivers/gpio/gpiolib-of.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ int of_gpio_get_count(struct device *dev, const char *con_id)
return ret ? ret : -ENOENT;
}

static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data)
static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip,
const void *data)
{
struct of_phandle_args *gpiospec = data;
const struct of_phandle_args *gpiospec = data;

return device_match_of_node(&chip->gpiodev->dev, gpiospec->np) &&
chip->of_xlate &&
Expand Down Expand Up @@ -852,7 +853,7 @@ static void of_gpiochip_remove_hog(struct gpio_chip *chip,
gpiochip_free_own_desc(desc);
}

static int of_gpiochip_match_node(struct gpio_chip *chip, void *data)
static int of_gpiochip_match_node(struct gpio_chip *chip, const void *data)
{
return device_match_of_node(&chip->gpiodev->dev, data);
}
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ EXPORT_SYMBOL_GPL(gpiochip_remove);
*/
struct gpio_device *gpio_device_find(void *data,
int (*match)(struct gpio_chip *gc,
void *data))
const void *data))
{
struct gpio_device *gdev;

Expand All @@ -1141,7 +1141,7 @@ struct gpio_device *gpio_device_find(void *data,
}
EXPORT_SYMBOL_GPL(gpio_device_find);

static int gpio_chip_match_by_label(struct gpio_chip *gc, void *label)
static int gpio_chip_match_by_label(struct gpio_chip *gc, const void *label)
{
return gc->label && !strcmp(gc->label, label);
}
Expand All @@ -1161,7 +1161,7 @@ struct gpio_device *gpio_device_find_by_label(const char *label)
}
EXPORT_SYMBOL_GPL(gpio_device_find_by_label);

static int gpio_chip_match_by_fwnode(struct gpio_chip *gc, void *fwnode)
static int gpio_chip_match_by_fwnode(struct gpio_chip *gc, const void *fwnode)
{
return device_match_fwnode(&gc->gpiodev->dev, fwnode);
}
Expand Down
3 changes: 2 additions & 1 deletion include/linux/gpio/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,8 @@ int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip *gc,
struct lock_class_key *request_key);

struct gpio_device *gpio_device_find(void *data,
int (*match)(struct gpio_chip *gc, void *data));
int (*match)(struct gpio_chip *gc,
const void *data));
struct gpio_device *gpio_device_find_by_label(const char *label);
struct gpio_device *gpio_device_find_by_fwnode(const struct fwnode_handle *fwnode);

Expand Down

0 comments on commit faf6efd

Please sign in to comment.