Skip to content

Commit

Permalink
gpiolib: define gpio suffixes globally
Browse files Browse the repository at this point in the history
Avoid multiple identical definitions of the gpio suffix strings by putting
them into a global constant array.

Signed-off-by: Rojhalat Ibrahim <imr@rtschenk.de>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Rojhalat Ibrahim authored and Linus Walleij committed Mar 5, 2015
1 parent 1feb57a commit 7f2e553
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 6 additions & 8 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1662,19 +1662,18 @@ static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
unsigned int idx,
enum gpio_lookup_flags *flags)
{
static const char * const suffixes[] = { "gpios", "gpio" };
char prop_name[32]; /* 32 is max size of property name */
enum of_gpio_flags of_flags;
struct gpio_desc *desc;
unsigned int i;

for (i = 0; i < ARRAY_SIZE(suffixes); i++) {
for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
if (con_id)
snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id,
suffixes[i]);
gpio_suffixes[i]);
else
snprintf(prop_name, sizeof(prop_name), "%s",
suffixes[i]);
gpio_suffixes[i]);

desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx,
&of_flags);
Expand All @@ -1695,21 +1694,20 @@ static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id,
unsigned int idx,
enum gpio_lookup_flags *flags)
{
static const char * const suffixes[] = { "gpios", "gpio" };
struct acpi_device *adev = ACPI_COMPANION(dev);
struct acpi_gpio_info info;
struct gpio_desc *desc;
char propname[32];
int i;

/* Try first from _DSD */
for (i = 0; i < ARRAY_SIZE(suffixes); i++) {
for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
if (con_id && strcmp(con_id, "gpios")) {
snprintf(propname, sizeof(propname), "%s-%s",
con_id, suffixes[i]);
con_id, gpio_suffixes[i]);
} else {
snprintf(propname, sizeof(propname), "%s",
suffixes[i]);
gpio_suffixes[i]);
}

desc = acpi_get_gpiod_by_index(adev, propname, idx, &info);
Expand Down
3 changes: 3 additions & 0 deletions drivers/gpio/gpiolib.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ struct acpi_gpio_info {
bool active_low;
};

/* gpio suffixes used for ACPI and device tree lookup */
static const char * const gpio_suffixes[] = { "gpios", "gpio" };

#ifdef CONFIG_ACPI
void acpi_gpiochip_add(struct gpio_chip *chip);
void acpi_gpiochip_remove(struct gpio_chip *chip);
Expand Down

0 comments on commit 7f2e553

Please sign in to comment.