Skip to content

Commit 7e92061

Browse files
author
Bartosz Golaszewski
committed
gpiolib: put gpio_suffixes in a single compilation unit
The gpio_suffixes array is defined in the gpiolib.h header. This means the array is stored in .rodata of every compilation unit that includes it. Put the definition for the array in gpiolib.c and export just the symbol in the header. We need the size of the array so expose it too. Reviewed-by: Mika Westerberg <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 08d94c7 commit 7e92061

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

drivers/gpio/gpiolib-acpi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ __acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int
976976
int i;
977977

978978
/* Try first from _DSD */
979-
for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
979+
for (i = 0; i < gpio_suffix_count; i++) {
980980
if (con_id) {
981981
snprintf(propname, sizeof(propname), "%s-%s",
982982
con_id, gpio_suffixes[i]);
@@ -1453,7 +1453,7 @@ int acpi_gpio_count(const struct fwnode_handle *fwnode, const char *con_id)
14531453
unsigned int i;
14541454

14551455
/* Try first from _DSD */
1456-
for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
1456+
for (i = 0; i < gpio_suffix_count; i++) {
14571457
if (con_id)
14581458
snprintf(propname, sizeof(propname), "%s-%s",
14591459
con_id, gpio_suffixes[i]);

drivers/gpio/gpiolib-of.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id)
103103
if (ret > 0)
104104
return ret;
105105

106-
for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
106+
for (i = 0; i < gpio_suffix_count; i++) {
107107
if (con_id)
108108
snprintf(propname, sizeof(propname), "%s-%s",
109109
con_id, gpio_suffixes[i]);
@@ -676,7 +676,7 @@ struct gpio_desc *of_find_gpio(struct device_node *np, const char *con_id,
676676
unsigned int i;
677677

678678
/* Try GPIO property "foo-gpios" and "foo-gpio" */
679-
for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
679+
for (i = 0; i < gpio_suffix_count; i++) {
680680
if (con_id)
681681
snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id,
682682
gpio_suffixes[i]);

drivers/gpio/gpiolib.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22

33
#include <linux/acpi.h>
4+
#include <linux/array_size.h>
45
#include <linux/bitmap.h>
56
#include <linux/cleanup.h>
67
#include <linux/compat.h>
@@ -89,6 +90,9 @@ DEFINE_STATIC_SRCU(gpio_devices_srcu);
8990
static DEFINE_MUTEX(gpio_machine_hogs_mutex);
9091
static LIST_HEAD(gpio_machine_hogs);
9192

93+
const char *const gpio_suffixes[] = { "gpios", "gpio" };
94+
const size_t gpio_suffix_count = ARRAY_SIZE(gpio_suffixes);
95+
9296
static void gpiochip_free_hogs(struct gpio_chip *gc);
9397
static int gpiochip_add_irqchip(struct gpio_chip *gc,
9498
struct lock_class_key *lock_key,

drivers/gpio/gpiolib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ static inline struct gpio_device *to_gpio_device(struct device *dev)
9090
}
9191

9292
/* gpio suffixes used for ACPI and device tree lookup */
93-
static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" };
93+
extern const char *const gpio_suffixes[];
94+
extern const size_t gpio_suffix_count;
9495

9596
/**
9697
* struct gpio_array - Opaque descriptor for a structure of GPIO array attributes

0 commit comments

Comments
 (0)