mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] i2c: muxes: pca954x: switch to device_get_match_data
@ 2025-03-28  8:35 Ahmad Fatoum
  2025-03-28  8:35 ` [PATCH 2/3] treewide: export symbols needed for i2c-mux-pca954x.ko Ahmad Fatoum
  2025-03-28  8:35 ` [PATCH 3/3] kbuild: compile *.mod.c files with -fshort-wchar Ahmad Fatoum
  0 siblings, 2 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2025-03-28  8:35 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

dev_get_drvdata has other semantics in barebox than in Linux and should
be removed eventually. Drop it in favor of device_get_match_data, which
avoids common bugs with pointer width difference casts.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/i2c/muxes/i2c-mux-pca954x.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index 6c21b92860f0..4a926fb92b17 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -186,7 +186,6 @@ static int pca954x_probe(struct device *dev)
 	struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent);
 	int num;
 	struct pca954x *data;
-	uintptr_t tmp;
 	int ret = -ENODEV;
 	int gpio;
 	bool idle_disconnect;
@@ -210,10 +209,7 @@ static int pca954x_probe(struct device *dev)
 	if (i2c_smbus_write_byte(client, 0) < 0)
 		goto exit_free;
 
-	ret = dev_get_drvdata(dev, (const void **)&tmp);
-	data->type = tmp;
-	if (ret)
-		goto exit_free;
+	data->type = (uintptr_t)device_get_match_data(dev);
 
 	idle_disconnect = of_property_read_bool(dev->of_node,
 						"i2c-mux-idle-disconnect");
-- 
2.39.5




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

* [PATCH 2/3] treewide: export symbols needed for i2c-mux-pca954x.ko
  2025-03-28  8:35 [PATCH 1/3] i2c: muxes: pca954x: switch to device_get_match_data Ahmad Fatoum
@ 2025-03-28  8:35 ` Ahmad Fatoum
  2025-03-28 16:54   ` David Dgien
  2025-03-28  8:35 ` [PATCH 3/3] kbuild: compile *.mod.c files with -fshort-wchar Ahmad Fatoum
  1 sibling, 1 reply; 4+ messages in thread
From: Ahmad Fatoum @ 2025-03-28  8:35 UTC (permalink / raw)
  To: barebox; +Cc: David Dgien, Ahmad Fatoum

The module support in barebox is an experimental feature, but it can
prove useful in some situations.

Building most drivers as modules currently fails, because e.g. pr_print
and dev_printf are not exported.

Add EXPORT_SYMBOL annotations for all symbols currently used
by i2c-mux-pca954x.

Cc: David Dgien <dgienda125@gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
David, are you still using the module support? We have added an
allyesconfig build to CI and an allmodconfig build may be added as well
if there are users.
---
 common/console_common.c | 2 ++
 drivers/base/driver.c   | 1 +
 drivers/dma/map.c       | 6 ++++++
 drivers/i2c/i2c.c       | 1 +
 4 files changed, 10 insertions(+)

diff --git a/common/console_common.c b/common/console_common.c
index a8527eee1e5a..5b7a64c99c29 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -135,6 +135,7 @@ int pr_print(int level, const char *fmt, ...)
 
 	return i;
 }
+EXPORT_SYMBOL(pr_print);
 
 int dev_printf(int level, const struct device *dev, const char *format, ...)
 {
@@ -161,6 +162,7 @@ int dev_printf(int level, const struct device *dev, const char *format, ...)
 
 	return ret;
 }
+EXPORT_SYMBOL(dev_printf);
 
 #ifdef CONFIG_CONSOLE_ALLOW_COLOR
 static unsigned int __console_allow_color = 1;
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 6363b3948f1d..edba037fa2dd 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -725,6 +725,7 @@ const void *device_get_match_data(struct device *dev)
 
 	return NULL;
 }
+EXPORT_SYMBOL(device_get_match_data);
 
 static void device_set_deferred_probe_reason(struct device *dev,
 					     const struct va_format *vaf)
diff --git a/drivers/dma/map.c b/drivers/dma/map.c
index cd0f5c3d3497..2980d4c2e790 100644
--- a/drivers/dma/map.c
+++ b/drivers/dma/map.c
@@ -7,6 +7,7 @@ void *dma_alloc(size_t size)
 {
 	return xmemalign(DMA_ALIGNMENT, ALIGN(size, DMA_ALIGNMENT));
 }
+EXPORT_SYMBOL(dma_alloc);
 
 void *dma_zalloc(size_t size)
 {
@@ -18,6 +19,7 @@ void *dma_zalloc(size_t size)
 
 	return buf;
 }
+EXPORT_SYMBOL(dma_zalloc);
 
 void dma_sync_single_for_cpu(struct device *dev, dma_addr_t address,
 			     size_t size, enum dma_data_direction dir)
@@ -29,6 +31,7 @@ void dma_sync_single_for_cpu(struct device *dev, dma_addr_t address,
 	if (!dev_is_dma_coherent(dev))
 		arch_sync_dma_for_cpu(ptr, size, dir);
 }
+EXPORT_SYMBOL(dma_sync_single_for_cpu);
 
 void dma_sync_single_for_device(struct device *dev, dma_addr_t address,
 					      size_t size, enum dma_data_direction dir)
@@ -40,6 +43,7 @@ void dma_sync_single_for_device(struct device *dev, dma_addr_t address,
 	if (!dev_is_dma_coherent(dev))
 		arch_sync_dma_for_device(ptr, size, dir);
 }
+EXPORT_SYMBOL(dma_sync_single_for_device);
 
 dma_addr_t dma_map_single(struct device *dev, void *ptr,
 					size_t size, enum dma_data_direction dir)
@@ -53,6 +57,7 @@ dma_addr_t dma_map_single(struct device *dev, void *ptr,
 
 	return dma_addr;
 }
+EXPORT_SYMBOL(dma_map_single);
 
 void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
 				    size_t size, enum dma_data_direction dir)
@@ -62,3 +67,4 @@ void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
 
 	debug_dma_unmap(dev, dma_addr, size, dir);
 }
+EXPORT_SYMBOL(dma_unmap_single);
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 7df645ba1c3f..49b87bb47c00 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -765,6 +765,7 @@ struct bus_type i2c_bus = {
 	.name = "i2c",
 	.match = device_match_of_modalias,
 };
+EXPORT_SYMBOL(i2c_bus);
 
 static int i2c_bus_init(void)
 {
-- 
2.39.5




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

* [PATCH 3/3] kbuild: compile *.mod.c files with -fshort-wchar
  2025-03-28  8:35 [PATCH 1/3] i2c: muxes: pca954x: switch to device_get_match_data Ahmad Fatoum
  2025-03-28  8:35 ` [PATCH 2/3] treewide: export symbols needed for i2c-mux-pca954x.ko Ahmad Fatoum
@ 2025-03-28  8:35 ` Ahmad Fatoum
  1 sibling, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2025-03-28  8:35 UTC (permalink / raw)
  To: barebox; +Cc: David Dgien, Ahmad Fatoum

We use wchar_t in USB and EFI code, both of which expect 2-byte wide
strings. Thus, like Linux, we set -fshort-wchar in KBUILD_CFLAGS.

This flag is not passed through to the build of *.mod.c files that are
generated in a module build, leading to a linker warning.

Add it to fix this.

Cc: David Dgien <dgienda125@gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 5c9fce83123c..4ee9780abeac 100644
--- a/Makefile
+++ b/Makefile
@@ -459,7 +459,7 @@ XZ		= xz
 CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise $(CF)
 CFLAGS_KERNEL	=
 AFLAGS_KERNEL	=
-CFLAGS_MODULE	=
+CFLAGS_MODULE	= -fshort-wchar
 AFLAGS_MODULE	=
 
 LDFLAGS_MODULE  = -T common/module.lds
-- 
2.39.5




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

* Re: [PATCH 2/3] treewide: export symbols needed for i2c-mux-pca954x.ko
  2025-03-28  8:35 ` [PATCH 2/3] treewide: export symbols needed for i2c-mux-pca954x.ko Ahmad Fatoum
@ 2025-03-28 16:54   ` David Dgien
  0 siblings, 0 replies; 4+ messages in thread
From: David Dgien @ 2025-03-28 16:54 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Fri, Mar 28, 2025 at 4:35 AM Ahmad Fatoum <a.fatoum@pengutronix.de> wrote:
>
> The module support in barebox is an experimental feature, but it can
> prove useful in some situations.
>
> Building most drivers as modules currently fails, because e.g. pr_print
> and dev_printf are not exported.
>
> Add EXPORT_SYMBOL annotations for all symbols currently used
> by i2c-mux-pca954x.
>
> Cc: David Dgien <dgienda125@gmail.com>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> David, are you still using the module support? We have added an
> allyesconfig build to CI and an allmodconfig build may be added as well
> if there are users.

No, the program that had been using module support stopped
development, so we have no active users of module support.

There is another program considering using module support, but that
would require fixing modules for aarch64,
and that hasn't been a priority yet, nor do I know if/when it might be.

Thanks,
David Dgien

> ---
>  common/console_common.c | 2 ++
>  drivers/base/driver.c   | 1 +
>  drivers/dma/map.c       | 6 ++++++
>  drivers/i2c/i2c.c       | 1 +
>  4 files changed, 10 insertions(+)
>
> diff --git a/common/console_common.c b/common/console_common.c
> index a8527eee1e5a..5b7a64c99c29 100644
> --- a/common/console_common.c
> +++ b/common/console_common.c
> @@ -135,6 +135,7 @@ int pr_print(int level, const char *fmt, ...)
>
>         return i;
>  }
> +EXPORT_SYMBOL(pr_print);
>
>  int dev_printf(int level, const struct device *dev, const char *format, ...)
>  {
> @@ -161,6 +162,7 @@ int dev_printf(int level, const struct device *dev, const char *format, ...)
>
>         return ret;
>  }
> +EXPORT_SYMBOL(dev_printf);
>
>  #ifdef CONFIG_CONSOLE_ALLOW_COLOR
>  static unsigned int __console_allow_color = 1;
> diff --git a/drivers/base/driver.c b/drivers/base/driver.c
> index 6363b3948f1d..edba037fa2dd 100644
> --- a/drivers/base/driver.c
> +++ b/drivers/base/driver.c
> @@ -725,6 +725,7 @@ const void *device_get_match_data(struct device *dev)
>
>         return NULL;
>  }
> +EXPORT_SYMBOL(device_get_match_data);
>
>  static void device_set_deferred_probe_reason(struct device *dev,
>                                              const struct va_format *vaf)
> diff --git a/drivers/dma/map.c b/drivers/dma/map.c
> index cd0f5c3d3497..2980d4c2e790 100644
> --- a/drivers/dma/map.c
> +++ b/drivers/dma/map.c
> @@ -7,6 +7,7 @@ void *dma_alloc(size_t size)
>  {
>         return xmemalign(DMA_ALIGNMENT, ALIGN(size, DMA_ALIGNMENT));
>  }
> +EXPORT_SYMBOL(dma_alloc);
>
>  void *dma_zalloc(size_t size)
>  {
> @@ -18,6 +19,7 @@ void *dma_zalloc(size_t size)
>
>         return buf;
>  }
> +EXPORT_SYMBOL(dma_zalloc);
>
>  void dma_sync_single_for_cpu(struct device *dev, dma_addr_t address,
>                              size_t size, enum dma_data_direction dir)
> @@ -29,6 +31,7 @@ void dma_sync_single_for_cpu(struct device *dev, dma_addr_t address,
>         if (!dev_is_dma_coherent(dev))
>                 arch_sync_dma_for_cpu(ptr, size, dir);
>  }
> +EXPORT_SYMBOL(dma_sync_single_for_cpu);
>
>  void dma_sync_single_for_device(struct device *dev, dma_addr_t address,
>                                               size_t size, enum dma_data_direction dir)
> @@ -40,6 +43,7 @@ void dma_sync_single_for_device(struct device *dev, dma_addr_t address,
>         if (!dev_is_dma_coherent(dev))
>                 arch_sync_dma_for_device(ptr, size, dir);
>  }
> +EXPORT_SYMBOL(dma_sync_single_for_device);
>
>  dma_addr_t dma_map_single(struct device *dev, void *ptr,
>                                         size_t size, enum dma_data_direction dir)
> @@ -53,6 +57,7 @@ dma_addr_t dma_map_single(struct device *dev, void *ptr,
>
>         return dma_addr;
>  }
> +EXPORT_SYMBOL(dma_map_single);
>
>  void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
>                                     size_t size, enum dma_data_direction dir)
> @@ -62,3 +67,4 @@ void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
>
>         debug_dma_unmap(dev, dma_addr, size, dir);
>  }
> +EXPORT_SYMBOL(dma_unmap_single);
> diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
> index 7df645ba1c3f..49b87bb47c00 100644
> --- a/drivers/i2c/i2c.c
> +++ b/drivers/i2c/i2c.c
> @@ -765,6 +765,7 @@ struct bus_type i2c_bus = {
>         .name = "i2c",
>         .match = device_match_of_modalias,
>  };
> +EXPORT_SYMBOL(i2c_bus);
>
>  static int i2c_bus_init(void)
>  {
> --
> 2.39.5
>



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

end of thread, other threads:[~2025-03-28 16:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-28  8:35 [PATCH 1/3] i2c: muxes: pca954x: switch to device_get_match_data Ahmad Fatoum
2025-03-28  8:35 ` [PATCH 2/3] treewide: export symbols needed for i2c-mux-pca954x.ko Ahmad Fatoum
2025-03-28 16:54   ` David Dgien
2025-03-28  8:35 ` [PATCH 3/3] kbuild: compile *.mod.c files with -fshort-wchar Ahmad Fatoum

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