0/4] Fix build issues against kernel 6.4, modernize some API usage
PATCH 1/1 0/4] Fix build issues against kernel 6.4, modernize some API usage
[repost, first attempt triggered some spam filters for unknown reasons]
The goal of this series is to allow building against upcoming 6.4. Along that, it gets rid of legacy Linux semaphore usage and replaces gpio_export with gpiod_export. See patches for more details.
Jan
Jan Kiszka (4):
kernel: Account for signature change of class_create in 6.4 cobalt/registry: Convert export_mutex to real mutex drivers/can: Convert rtcan_devices_nrt_lock to real mutex drivers/gpio: Ensure compatibility with kernel 6.4
kernel/cobalt/pipe.c | 4 ++++ kernel/cobalt/registry.c | 7 ++++--- kernel/cobalt/rtdm/device.c | 4 ++++ kernel/drivers/can/rtcan_dev.c | 18 +++++++++--------- kernel/drivers/can/rtcan_dev.h | 4 ++-- kernel/drivers/can/rtcan_module.c | 12 ++++++------ kernel/drivers/gpio/gpio-core.c | 7 ++++++- kernel/drivers/net/stack/rtnet_module.c | 4 ++++ kernel/drivers/spi/spi-master.c | 7 +++++-- 9 files changed, 44 insertions(+), 23 deletions(-)
Signature · 1 line
2.35.3
PATCH 1/1 1/4] kernel: Account for signature change of class_create in 6.4
From: Jan Kiszka <[email protected]>
--- kernel/cobalt/pipe.c | 4 ++++ kernel/cobalt/rtdm/device.c | 4 ++++ kernel/drivers/gpio/gpio-core.c | 4 ++++ kernel/drivers/net/stack/rtnet_module.c | 4 ++++ kernel/drivers/spi/spi-master.c | 7 +++++-- 5 files changed, 21 insertions(+), 2 deletions(-)
kernel/cobalt/pipe.c +4 -0
@@ -1149,7 +1149,11 @@ int xnpipe_mount(void) state->nroutq =0 ; } +#if LINUX_VERSION_CODE >=KERNEL_VERSION (6 ,4 ,0 ) + xnpipe_class =class_create ("rtpipe" ); +#else xnpipe_class =class_create (THIS_MODULE ,"rtpipe" ); +#endif if (IS_ERR (xnpipe_class)) {printk (XENO_ERR "error creating rtpipe class, err=%ld\n" ,PTR_ERR (xnpipe_class));
kernel/cobalt/rtdm/device.c +4 -0
@@ -630,7 +630,11 @@ int __init rtdm_init(void) {xntree_init (&protocol_devices); +#if LINUX_VERSION_CODE >=KERNEL_VERSION (6 ,4 ,0 ) + rtdm_class =class_create ("rtdm" ); +#else rtdm_class =class_create (THIS_MODULE ,"rtdm" ); +#endif if (IS_ERR (rtdm_class)) {printk (XENO_ERR "cannot create RTDM sysfs class\n" );return PTR_ERR (rtdm_class);
kernel/drivers/gpio/gpio-core.c +4 -0
@@ -415,7 +415,11 @@ int rtdm_gpiochip_add(struct rtdm_gpio_chip *rgc, {int ret; +#if LINUX_VERSION_CODE >=KERNEL_VERSION (6 ,4 ,0 ) + rgc->devclass =class_create (gc->label); +#else rgc->devclass =class_create (gc->owner, gc->label); +#endif if (IS_ERR (rgc->devclass)) {printk (XENO_ERR "cannot create sysfs class\n" );return PTR_ERR (rgc->devclass);
kernel/drivers/net/stack/rtnet_module.c +4 -0
@@ -324,7 +324,11 @@ int __init rtnet_init(void)printk ("\n*** RTnet for Xenomai v" XENO_VERSION_STRING " ***\n\n" );printk ("RTnet: initialising real-time networking\n" ); +#if LINUX_VERSION_CODE >=KERNEL_VERSION (6 ,4 ,0 ) + rtnet_class =class_create ("rtnet" ); +#else rtnet_class =class_create (THIS_MODULE ,"rtnet" ); +#endif if (IS_ERR (rtnet_class))return PTR_ERR (rtnet_class);
kernel/drivers/spi/spi-master.c +5 -2
@@ -372,8 +372,11 @@ int __rtdm_spi_setup_driver(struct rtdm_spi_master *master) { master->classname =kstrdup (dev_name (&master->controller->dev),GFP_KERNEL ); - master->devclass =class_create (THIS_MODULE , - master->classname); +#if LINUX_VERSION_CODE >=KERNEL_VERSION (6 ,4 ,0 ) + master->devclass =class_create (master->classname); +#else + master->devclass =class_create (THIS_MODULE , master->classname); +#endif if (IS_ERR (master->devclass)) {kfree (master->classname);printk (XENO_ERR "cannot create sysfs class\n" );
Signature · 1 line
2.35.3
PATCH 1/1 2/4] cobalt/registry: Convert export_mutex to real mutex
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
A semaphore is semantically not a mutex, plus there are now changes in its definition in 6.4. Therefore, just convert the export_mutex to a real one.
--- kernel/cobalt/registry.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
kernel/cobalt/registry.c +4 -3
@@ -16,6 +16,7 @@* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include <linux/mutex.h> #include <linux/slab.h> #include <cobalt/kernel/sched.h> #include <cobalt/kernel/heap.h>
@@ -209,7 +210,7 @@ void xnregistry_cleanup(void)#ifdef CONFIG_XENO_OPT_VFILE -static DEFINE_SEMAPHORE (export_mutex); +static DEFINE_MUTEX (export_mutex);/* * The following stuff implements the mechanism for delegating
@@ -232,7 +233,7 @@ static void proc_callback(struct work_struct *work)int ret;spl_t s; -down (&export_mutex); +mutex_lock (&export_mutex);xnlock_get_irqsave (&nklock, s);
@@ -324,7 +325,7 @@ static void proc_callback(struct work_struct *work)xnlock_put_irqrestore (&nklock, s); -up (&export_mutex); +mutex_unlock (&export_mutex); }static irqreturn_t registry_proc_schedule (int virq,void *dev_id)
Signature · 1 line
2.35.3
PATCH 1/1 4/4] drivers/gpio: Ensure compatibility with kernel 6.4
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
One include was missing, and gpio_export is now history. The latter can be safely replaced by modern gpiod_export.
--- kernel/drivers/gpio/gpio-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/drivers/gpio/gpio-core.c +2 -1
@@ -22,6 +22,7 @@#include <linux/irq.h> #include <linux/slab.h> #include <linux/err.h> +#include <linux/gpio/driver.h> #include <rtdm/gpio.h> struct rtdm_gpio_chan {
@@ -78,7 +79,7 @@ static int request_gpio_irq(unsigned int gpio, struct rtdm_gpio_pin *pin, } chan->has_direction = true; -gpio_export (gpio, true); +gpiod_export (pin->desc, true);rtdm_event_clear (&pin->event);
Signature · 1 line
2.35.3
PATCH 1/1 3/4] drivers/can: Convert rtcan_devices_nrt_lock to real mutex
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
No need to use a semaphore here which is semantically not a real mutex anyway. Also avoids to adjust to the kernel changes coming in with 6.4.
--- kernel/drivers/can/rtcan_dev.c | 18 +++++++++--------- kernel/drivers/can/rtcan_dev.h | 4 ++-- kernel/drivers/can/rtcan_module.c | 12 ++++++------ 3 files changed, 17 insertions(+), 17 deletions(-)
kernel/drivers/can/rtcan_dev.c +9 -9
@@ -36,7 +36,7 @@static struct rtcan_device *rtcan_devices[RTCAN_MAX_DEVICES ];static DEFINE_RTDM_LOCK (rtcan_devices_rt_lock); -DEFINE_SEMAPHORE (rtcan_devices_nrt_lock); +DEFINE_MUTEX (rtcan_devices_nrt_lock);/* Spinlock for all reception lists and also for some members in * struct rtcan_socket */
@@ -210,10 +210,10 @@ int rtcan_dev_register(struct rtcan_device *dev)rtdm_lockctx_t context;int ret; -down (&rtcan_devices_nrt_lock); +mutex_lock (&rtcan_devices_nrt_lock);if ((ret =__rtcan_dev_new_index ()) <0 ) { -up (&rtcan_devices_nrt_lock); +mutex_unlock (&rtcan_devices_nrt_lock);return ret; } dev->ifindex = ret;
@@ -222,7 +222,7 @@ int rtcan_dev_register(struct rtcan_device *dev)rtcan_dev_alloc_name (dev, dev->name);if (__rtcan_dev_get_by_name (dev->name) !=NULL ) { -up (&rtcan_devices_nrt_lock); +mutex_unlock (&rtcan_devices_nrt_lock);return -EEXIST ; }
@@ -233,7 +233,7 @@ int rtcan_dev_register(struct rtcan_device *dev)rtdm_lock_put_irqrestore (&rtcan_devices_rt_lock, context);rtcan_dev_create_proc (dev); -up (&rtcan_devices_nrt_lock); +mutex_unlock (&rtcan_devices_nrt_lock);printk ("rtcan: registered %s\n" , dev->name);
@@ -254,7 +254,7 @@ int rtcan_dev_unregister(struct rtcan_device *dev)if (CAN_STATE_OPERATING (dev->state))return -EBUSY ; -down (&rtcan_devices_nrt_lock); +mutex_lock (&rtcan_devices_nrt_lock);rtcan_dev_remove_proc (dev);
@@ -263,21 +263,21 @@ int rtcan_dev_unregister(struct rtcan_device *dev)#ifdef RTCAN_USE_REFCOUNT while (atomic_read (&dev->refcount) >0 ) {rtdm_lock_put_irqrestore (&rtcan_devices_rt_lock, context); -up (&rtcan_devices_nrt_lock); +mutex_unlock (&rtcan_devices_nrt_lock);RTCAN_DBG ("RTCAN: unregistering %s deferred (refcount = %d)\n" , dev->name,atomic_read (&dev->refcount));set_current_state (TASK_UNINTERRUPTIBLE );schedule_timeout (1 *HZ );/* wait a second */ -down (&rtcan_devices_nrt_lock); +mutex_lock (&rtcan_devices_nrt_lock);rtdm_lock_get_irqsave (&rtcan_devices_rt_lock, context); }#endif rtcan_devices[dev->ifindex -1 ] =NULL ;rtdm_lock_put_irqrestore (&rtcan_devices_rt_lock, context); -up (&rtcan_devices_nrt_lock); +mutex_unlock (&rtcan_devices_nrt_lock);#ifdef RTCAN_USE_REFCOUNT RTCAN_ASSERT(atomic_read(&dev->refcount) == 0,
kernel/drivers/can/rtcan_dev.h +2 -2
@@ -30,8 +30,8 @@#ifdef __KERNEL__#include <asm/atomic.h> +#include <linux/mutex.h> #include <linux/netdevice.h> -#include <linux/semaphore.h> #include "rtcan_list.h" #include "rtcan_ethtool.h"
@@ -169,7 +169,7 @@ struct rtcan_device { }; -extern struct semaphore rtcan_devices_nrt_lock; +extern struct mutex rtcan_devices_nrt_lock;void rtcan_dev_free (struct rtcan_device *dev);
kernel/drivers/can/rtcan_module.c +6 -6
@@ -125,7 +125,7 @@ static int rtcan_read_proc_devices(struct seq_file *p, void *data)struct rtcan_device *dev;char state_name[20 ], baudrate_name[20 ]; -if (down_interruptible (&rtcan_devices_nrt_lock)) +if (mutex_lock_interruptible (&rtcan_devices_nrt_lock))return -ERESTARTSYS ;/* Name___________ _Baudrate State___ _TX_Counts _TX_Counts ____Errors
@@ -149,7 +149,7 @@ static int rtcan_read_proc_devices(struct seq_file *p, void *data) } } -up (&rtcan_devices_nrt_lock); +mutex_unlock (&rtcan_devices_nrt_lock);return 0 ; }
@@ -175,7 +175,7 @@ static int rtcan_read_proc_sockets(struct seq_file *p, void *data)rtdm_lockctx_t lock_ctx;int ifindex; -if (down_interruptible (&rtcan_devices_nrt_lock)) +if (mutex_lock_interruptible (&rtcan_devices_nrt_lock))return -ERESTARTSYS ;/* Name___________ Filter ErrMask RX_Timeout TX_Timeout RX_BufFull TX_Lo
@@ -211,7 +211,7 @@ static int rtcan_read_proc_sockets(struct seq_file *p, void *data)rtdm_lock_put_irqrestore (&rtcan_recv_list_lock, lock_ctx); -up (&rtcan_devices_nrt_lock); +mutex_unlock (&rtcan_devices_nrt_lock);return 0 ; }
@@ -233,7 +233,7 @@ static int rtcan_read_proc_info(struct seq_file *p, void *data)char state_name[20 ], baudrate_name[20 ];char ctrlmode_name[80 ], bittime_name[80 ]; -if (down_interruptible (&rtcan_devices_nrt_lock)) +if (mutex_lock_interruptible (&rtcan_devices_nrt_lock))return -ERESTARTSYS ; rtcan_dev_get_state_name(dev->state,
@@ -260,7 +260,7 @@ static int rtcan_read_proc_info(struct seq_file *p, void *data)seq_printf (p,"Refcount %d\n" ,atomic_read (&dev->refcount));#endif -up (&rtcan_devices_nrt_lock); +mutex_unlock (&rtcan_devices_nrt_lock);return 0 ; }
Signature · 1 line
2.35.3