public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpiolib: put gpio_suffixes in a single compilation unit
@ 2024-06-12 18:48 Bartosz Golaszewski
  2024-06-13  4:54 ` Mika Westerberg
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-06-12 18:48 UTC (permalink / raw)
  To: Mika Westerberg, Andy Shevchenko, Linus Walleij
  Cc: linux-gpio, linux-acpi, linux-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

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.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpiolib-acpi.c | 4 ++--
 drivers/gpio/gpiolib-of.c   | 4 ++--
 drivers/gpio/gpiolib.c      | 4 ++++
 drivers/gpio/gpiolib.h      | 3 ++-
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index bb063b81cee6..69cd2be9c7f3 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -976,7 +976,7 @@ __acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int
 	int i;
 
 	/* Try first from _DSD */
-	for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
+	for (i = 0; i < gpio_suffix_count; i++) {
 		if (con_id) {
 			snprintf(propname, sizeof(propname), "%s-%s",
 				 con_id, gpio_suffixes[i]);
@@ -1453,7 +1453,7 @@ int acpi_gpio_count(const struct fwnode_handle *fwnode, const char *con_id)
 	unsigned int i;
 
 	/* Try first from _DSD */
-	for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
+	for (i = 0; i < gpio_suffix_count; i++) {
 		if (con_id)
 			snprintf(propname, sizeof(propname), "%s-%s",
 				 con_id, gpio_suffixes[i]);
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index d75f6ee37028..49d533df2cd9 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -103,7 +103,7 @@ int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id)
 	if (ret > 0)
 		return ret;
 
-	for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
+	for (i = 0; i < gpio_suffix_count; i++) {
 		if (con_id)
 			snprintf(propname, sizeof(propname), "%s-%s",
 				 con_id, gpio_suffixes[i]);
@@ -676,7 +676,7 @@ struct gpio_desc *of_find_gpio(struct device_node *np, const char *con_id,
 	unsigned int i;
 
 	/* Try GPIO property "foo-gpios" and "foo-gpio" */
-	for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
+	for (i = 0; i < gpio_suffix_count; i++) {
 		if (con_id)
 			snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id,
 				 gpio_suffixes[i]);
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 0ec82ac7f0f4..ed620442f32c 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 
 #include <linux/acpi.h>
+#include <linux/array_size.h>
 #include <linux/bitmap.h>
 #include <linux/cleanup.h>
 #include <linux/compat.h>
@@ -89,6 +90,9 @@ DEFINE_STATIC_SRCU(gpio_devices_srcu);
 static DEFINE_MUTEX(gpio_machine_hogs_mutex);
 static LIST_HEAD(gpio_machine_hogs);
 
+const char *const gpio_suffixes[] = { "gpios", "gpio" };
+const size_t gpio_suffix_count = ARRAY_SIZE(gpio_suffixes);
+
 static void gpiochip_free_hogs(struct gpio_chip *gc);
 static int gpiochip_add_irqchip(struct gpio_chip *gc,
 				struct lock_class_key *lock_key,
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 48e086c2f416..a75635891c6f 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -90,7 +90,8 @@ static inline struct gpio_device *to_gpio_device(struct device *dev)
 }
 
 /* gpio suffixes used for ACPI and device tree lookup */
-static __maybe_unused const char * const gpio_suffixes[] = { "gpios", "gpio" };
+extern const char *const gpio_suffixes[];
+extern const size_t gpio_suffix_count;
 
 /**
  * struct gpio_array - Opaque descriptor for a structure of GPIO array attributes
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpiolib: put gpio_suffixes in a single compilation unit
  2024-06-12 18:48 [PATCH] gpiolib: put gpio_suffixes in a single compilation unit Bartosz Golaszewski
@ 2024-06-13  4:54 ` Mika Westerberg
  2024-06-14  7:15 ` Bartosz Golaszewski
  2024-08-09 12:29 ` Andy Shevchenko
  2 siblings, 0 replies; 5+ messages in thread
From: Mika Westerberg @ 2024-06-13  4:54 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Andy Shevchenko, Linus Walleij, linux-gpio, linux-acpi,
	linux-kernel, Bartosz Golaszewski

On Wed, Jun 12, 2024 at 08:48:21PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> 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.
> 
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpiolib: put gpio_suffixes in a single compilation unit
  2024-06-12 18:48 [PATCH] gpiolib: put gpio_suffixes in a single compilation unit Bartosz Golaszewski
  2024-06-13  4:54 ` Mika Westerberg
@ 2024-06-14  7:15 ` Bartosz Golaszewski
  2024-08-09 12:29   ` Andy Shevchenko
  2024-08-09 12:29 ` Andy Shevchenko
  2 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-06-14  7:15 UTC (permalink / raw)
  To: Mika Westerberg, Andy Shevchenko, Linus Walleij,
	Bartosz Golaszewski
  Cc: Bartosz Golaszewski, linux-gpio, linux-acpi, linux-kernel

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


On Wed, 12 Jun 2024 20:48:21 +0200, Bartosz Golaszewski wrote:
> 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.
> 
> 

Applied, thanks!

[1/1] gpiolib: put gpio_suffixes in a single compilation unit
      commit: 7e92061f1e9d1f6d3bfa6113719534f2c773b041

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpiolib: put gpio_suffixes in a single compilation unit
  2024-06-12 18:48 [PATCH] gpiolib: put gpio_suffixes in a single compilation unit Bartosz Golaszewski
  2024-06-13  4:54 ` Mika Westerberg
  2024-06-14  7:15 ` Bartosz Golaszewski
@ 2024-08-09 12:29 ` Andy Shevchenko
  2 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2024-08-09 12:29 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Mika Westerberg, Linus Walleij, linux-gpio, linux-acpi,
	linux-kernel, Bartosz Golaszewski

On Wed, Jun 12, 2024 at 08:48:21PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> 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.

Instead of having two exported variables you may just make the arrays be NULL
terminated. That's how, for example, ID tables are done.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gpiolib: put gpio_suffixes in a single compilation unit
  2024-06-14  7:15 ` Bartosz Golaszewski
@ 2024-08-09 12:29   ` Andy Shevchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2024-08-09 12:29 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Mika Westerberg, Linus Walleij, Bartosz Golaszewski, linux-gpio,
	linux-acpi, linux-kernel

On Fri, Jun 14, 2024 at 09:15:31AM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> 
> On Wed, 12 Jun 2024 20:48:21 +0200, Bartosz Golaszewski wrote:
> > 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.
> 
> Applied, thanks!
> 
> [1/1] gpiolib: put gpio_suffixes in a single compilation unit
>       commit: 7e92061f1e9d1f6d3bfa6113719534f2c773b041

Urgh... :-(

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-08-09 12:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-12 18:48 [PATCH] gpiolib: put gpio_suffixes in a single compilation unit Bartosz Golaszewski
2024-06-13  4:54 ` Mika Westerberg
2024-06-14  7:15 ` Bartosz Golaszewski
2024-08-09 12:29   ` Andy Shevchenko
2024-08-09 12:29 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox