From c6fc7597ada64ab5c742ca89ad8e409e3f33cd78 Mon Sep 17 00:00:00 2001 From: Jorge Marques Date: Mon, 4 Aug 2025 15:57:36 +0200 Subject: [PATCH 1/2] drivers/misc/mathworks: Use wrapper mathods for devm To solve cast from 'void (*)(struct device *)' to 'devm_action_fn' (aka 'void (*)(void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict] on strict compile Signed-off-by: Jorge Marques --- drivers/misc/mathworks/mathworks_generic_of.c | 39 ++++++++++++++++--- drivers/misc/mathworks/mw_mm_iio_channel.c | 9 ++++- .../misc/mathworks/mw_sharedmem_iio_channel.c | 20 +++++++--- drivers/misc/mathworks/mw_stream_channel.c | 29 ++++++++++++-- .../misc/mathworks/mw_stream_iio_channel.c | 9 ++++- include/linux/mathworks/mathworks_ip.h | 1 - 6 files changed, 89 insertions(+), 18 deletions(-) diff --git a/drivers/misc/mathworks/mathworks_generic_of.c b/drivers/misc/mathworks/mathworks_generic_of.c index 61ee37145e1d74..9052e85f4df6fe 100755 --- a/drivers/misc/mathworks/mathworks_generic_of.c +++ b/drivers/misc/mathworks/mathworks_generic_of.c @@ -19,11 +19,31 @@ #define DRIVER_NAME "mathworks_generic_of" -static void mwgen_of_unlink_i2c_device(struct mathworks_ip_info *thisIpcore){ +static inline void mwgen_of_node_put(void *data) +{ + struct device_node *node = data; + + of_node_put(node); +} + +static inline void mwgen_put_device(void *data) +{ + struct device *dev = data; + + put_device(dev); +} + +static inline void mwgen_of_unlink_i2c_device(void *data) +{ + struct mathworks_ip_info *thisIpcore = data; + sysfs_remove_link(&thisIpcore->char_device->kobj, "i2c_device"); } -static void mwgen_of_unlink_i2c_adapter(struct mathworks_ip_info *thisIpcore){ +static inline void mwgen_of_unlink_i2c_adapter(void *data) +{ + struct mathworks_ip_info *thisIpcore = data; + sysfs_remove_link(&thisIpcore->char_device->kobj, "i2c_adapter"); } @@ -34,7 +54,8 @@ static int mathworks_generic_of_i2c_init(struct mathworks_ip_info *thisIpcore){ slave_node = of_parse_phandle(nodePointer, "i2c-controller", 0); if (slave_node) { - status = devm_add_action_helper(thisIpcore->dev, (devm_action_fn)of_node_put, slave_node); + status = devm_add_action_helper(thisIpcore->dev, + mwgen_of_node_put, slave_node); if(status) return status; @@ -45,7 +66,9 @@ static int mathworks_generic_of_i2c_init(struct mathworks_ip_info *thisIpcore){ dev_err(thisIpcore->dev, "could not find i2c device\n"); return -ENODEV; } - status = devm_add_action_helper(thisIpcore->dev, (devm_action_fn)put_device, &thisIpcore->i2c->dev); + status = devm_add_action_helper(thisIpcore->dev, + mwgen_put_device, + &thisIpcore->i2c->dev); if(status) return status; @@ -55,7 +78,9 @@ static int mathworks_generic_of_i2c_init(struct mathworks_ip_info *thisIpcore){ status = sysfs_create_link(&thisIpcore->char_device->kobj, &thisIpcore->i2c->dev.kobj, "i2c_device"); if (status) return status; - status = devm_add_action_helper(thisIpcore->dev, (devm_action_fn)mwgen_of_unlink_i2c_device, thisIpcore); + status = devm_add_action_helper(thisIpcore->dev, + mwgen_of_unlink_i2c_device, + thisIpcore); if(status) return status; @@ -63,7 +88,9 @@ static int mathworks_generic_of_i2c_init(struct mathworks_ip_info *thisIpcore){ status = sysfs_create_link(&thisIpcore->char_device->kobj, &thisIpcore->i2c->adapter->dev.kobj, "i2c_adapter"); if (status) return status; - status = devm_add_action_helper(thisIpcore->dev, (devm_action_fn)mwgen_of_unlink_i2c_adapter, thisIpcore); + status = devm_add_action_helper(thisIpcore->dev, + mwgen_of_unlink_i2c_adapter, + thisIpcore); if(status) return status; diff --git a/drivers/misc/mathworks/mw_mm_iio_channel.c b/drivers/misc/mathworks/mw_mm_iio_channel.c index e2c95c308855b8..8c2a26e9fe5d5f 100644 --- a/drivers/misc/mathworks/mw_mm_iio_channel.c +++ b/drivers/misc/mathworks/mw_mm_iio_channel.c @@ -192,6 +192,13 @@ static void mw_mm_iio_channel_release(struct device *dev) { } +static inline void mw_device_unregister(void *data) +{ + struct device *dev = data; + + device_unregister(dev); +} + static struct iio_dev *devm_mw_mm_iio_alloc( struct mathworks_ipcore_dev *mwdev, struct device_node *node, @@ -253,7 +260,7 @@ static struct iio_dev *devm_mw_mm_iio_alloc( if (status) return ERR_PTR(status); - status = devm_add_action(IP2DEVP(mwdev), (devm_action_fn)device_unregister, &mwchan->dev); + status = devm_add_action(IP2DEVP(mwdev), mw_device_unregister, &mwchan->dev); if (status) { device_unregister(&mwchan->dev); return ERR_PTR(status); diff --git a/drivers/misc/mathworks/mw_sharedmem_iio_channel.c b/drivers/misc/mathworks/mw_sharedmem_iio_channel.c index 4b90054a638452..eb28535a901be7 100755 --- a/drivers/misc/mathworks/mw_sharedmem_iio_channel.c +++ b/drivers/misc/mathworks/mw_sharedmem_iio_channel.c @@ -332,8 +332,10 @@ static struct iio_buffer *mw_sharedmem_buffer_alloc(struct device *dev, return &sharedmem_buff->buffer; } -static void mw_sharedmem_buffer_free(struct iio_buffer *buffer) +static void mw_sharedmem_buffer_free(void *data) { + struct iio_buffer *buffer = data; + iio_buffer_put(buffer); } @@ -528,7 +530,7 @@ static int devm_mw_sharedmem_configure_buffer(struct iio_dev *indio_dev, enum ii buffer->direction = direction; - status = devm_add_action(indio_dev->dev.parent,(devm_action_fn)mw_sharedmem_buffer_free, buffer); + status = devm_add_action(indio_dev->dev.parent, mw_sharedmem_buffer_free, buffer); if(status){ mw_sharedmem_buffer_free(buffer); return status; @@ -657,7 +659,15 @@ static int mw_sharedmem_setup_offset_channel(struct iio_dev *indio_dev, struct i return 0; } -static void mw_sharedmem_iio_unregister(void *opaque) { +static inline void mw_device_unregister(void *data) +{ + struct device *dev = data; + + device_unregister(dev); +} + +static inline void mw_sharedmem_iio_unregister(void *opaque) +{ struct device *dev = opaque; /* Unregister the IIO device */ @@ -818,7 +828,7 @@ static struct iio_dev *devm_mw_sharedmem_iio_alloc( if (status) return ERR_PTR(status); - status = devm_add_action(IP2DEVP(mwdev), (devm_action_fn)device_unregister, &mwchan->dev); + status = devm_add_action(IP2DEVP(mwdev), mw_device_unregister, &mwchan->dev); if (status) { device_unregister(&mwchan->dev); return ERR_PTR(status); @@ -986,7 +996,7 @@ static struct mw_sharedmem_region_dev *devm_mw_sharedmem_region_alloc( if (status) return ERR_PTR(status); - status = devm_add_action(IP2DEVP(mwdev), (devm_action_fn)device_unregister, &mwregion->dev); + status = devm_add_action(IP2DEVP(mwdev), mw_device_unregister, &mwregion->dev); if (status) { device_unregister(&mwregion->dev); return ERR_PTR(status); diff --git a/drivers/misc/mathworks/mw_stream_channel.c b/drivers/misc/mathworks/mw_stream_channel.c index fb348faf887dc9..f79a2e42611522 100644 --- a/drivers/misc/mathworks/mw_stream_channel.c +++ b/drivers/misc/mathworks/mw_stream_channel.c @@ -1087,6 +1087,27 @@ static void mw_stream_chan_release(struct device *dev) } } +static inline void mw_dma_release_channel(void *data) +{ + struct dma_chan *chan = data; + + dma_release_channel(chan); +} + +static inline void mw_device_unregister(void *data) +{ + struct device *dev = data; + + device_unregister(dev); +} + +static inline void mw_sysfs_put(void *data) +{ + struct kernfs_node *kn = data; + + sysfs_put(kn); +} + static struct mwadma_chan* __must_check mw_stream_chan_probe( struct mwadma_dev *mwdev, enum dma_transfer_direction direction, @@ -1111,7 +1132,7 @@ static struct mwadma_chan* __must_check mw_stream_chan_probe( return (void *)chan; } /* Create the cleanup action */ - status = devm_add_action(IP2DEVP(mwdev), (devm_action_fn)dma_release_channel, chan); + status = devm_add_action(IP2DEVP(mwdev), mw_dma_release_channel, chan); if(status){ dma_release_channel(chan); return ERR_PTR(status); @@ -1135,7 +1156,7 @@ static struct mwadma_chan* __must_check mw_stream_chan_probe( if (mwchan->dev.id < 0) { return ERR_PTR(mwchan->dev.id); } - status = devm_add_action(IP2DEVP(mwdev),mw_stream_chan_ida_remove, mwchan); + status = devm_add_action(IP2DEVP(mwdev), mw_stream_chan_ida_remove, mwchan); if(status){ ida_simple_remove(&mw_stream_channel_ida, mwchan->dev.id); return ERR_PTR(status); @@ -1148,7 +1169,7 @@ static struct mwadma_chan* __must_check mw_stream_chan_probe( status = device_add(&mwchan->dev); if (status) return ERR_PTR(status); - status = devm_add_action(IP2DEVP(mwdev), (devm_action_fn)device_unregister, &mwchan->dev); + status = devm_add_action(IP2DEVP(mwdev), mw_device_unregister, &mwchan->dev); if(status){ device_unregister(&mwchan->dev); return ERR_PTR(status); @@ -1159,7 +1180,7 @@ static struct mwadma_chan* __must_check mw_stream_chan_probe( if(!mwchan->irq_kn){ return ERR_PTR(-ENODEV); } - status = devm_add_action(&mwchan->dev, (devm_action_fn)sysfs_put, mwchan->irq_kn); + status = devm_add_action(&mwchan->dev, mw_sysfs_put, mwchan->irq_kn); if(status) { sysfs_put(mwchan->irq_kn); return ERR_PTR(status); diff --git a/drivers/misc/mathworks/mw_stream_iio_channel.c b/drivers/misc/mathworks/mw_stream_iio_channel.c index 768e5840aec7e0..c4516dc0339cf0 100644 --- a/drivers/misc/mathworks/mw_stream_iio_channel.c +++ b/drivers/misc/mathworks/mw_stream_iio_channel.c @@ -490,6 +490,13 @@ static void mw_stream_iio_channel_release(struct device *dev) { } +static inline void mw_device_unregister(void *data) +{ + struct device *dev = data; + + device_unregister(dev); +} + static struct iio_dev *devm_mw_stream_iio_alloc( struct mathworks_ipcore_dev *mwdev, struct device_node *node, @@ -565,7 +572,7 @@ static struct iio_dev *devm_mw_stream_iio_alloc( if (status) return ERR_PTR(status); - status = devm_add_action(IP2DEVP(mwdev), (devm_action_fn)device_unregister, &mwchan->dev); + status = devm_add_action(IP2DEVP(mwdev), mw_device_unregister, &mwchan->dev); if (status) { device_unregister(&mwchan->dev); return ERR_PTR(status); diff --git a/include/linux/mathworks/mathworks_ip.h b/include/linux/mathworks/mathworks_ip.h index 1eea40d31b5293..e787ba731f3f39 100755 --- a/include/linux/mathworks/mathworks_ip.h +++ b/include/linux/mathworks/mathworks_ip.h @@ -34,7 +34,6 @@ /********************************************************* * Devm Helpers *********************************************************/ -typedef void (*devm_action_fn)(void *); static inline int devm_add_action_helper(struct device *dev, void (*action)(void *), void *data){ int status; From d2196a2493cd6a43efee607f92c439574b9e8320 Mon Sep 17 00:00:00 2001 From: Jorge Marques Date: Mon, 4 Aug 2025 16:49:20 +0200 Subject: [PATCH 2/2] drivers/misc/mathworks: Extend ifdef CONFIG_I2C To avoid unused warnings. Signed-off-by: Jorge Marques --- drivers/misc/mathworks/mathworks_generic_of.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/misc/mathworks/mathworks_generic_of.c b/drivers/misc/mathworks/mathworks_generic_of.c index 9052e85f4df6fe..e36da469d097ed 100755 --- a/drivers/misc/mathworks/mathworks_generic_of.c +++ b/drivers/misc/mathworks/mathworks_generic_of.c @@ -19,6 +19,7 @@ #define DRIVER_NAME "mathworks_generic_of" +#if defined(CONFIG_I2C) static inline void mwgen_of_node_put(void *data) { struct device_node *node = data; @@ -100,6 +101,7 @@ static int mathworks_generic_of_i2c_init(struct mathworks_ip_info *thisIpcore){ return 0; } +#endif static int mathworks_generic_of_get_param(struct mathworks_ip_info *thisIpcore, void *arg) {