From cef602586cd3b7acbd944dfd4b4ab69801c7f6f6 Mon Sep 17 00:00:00 2001 From: Florian Pose Date: Thu, 23 Jun 2022 11:26:20 +0200 Subject: [PATCH] Applied 0017-Master-locks-to-avoid-corrupted-datagram-queue.patch --- master/ioctl.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/master/ioctl.c b/master/ioctl.c index afd8e902..64c411f7 100755 --- a/master/ioctl.c +++ b/master/ioctl.c @@ -57,6 +57,16 @@ #define ATTRIBUTES #endif +/** Ioctl locking is disabled for RTDM as the RT app needs to use RTAI locks. + */ +#ifdef EC_IOCTL_RTDM +#define ec_ioctl_lock_down_interruptible(p) 0 +#define ec_ioctl_lock_up(p) do {} while (0) +#else +#define ec_ioctl_lock_down_interruptible(p) ec_lock_down_interruptible(p) +#define ec_ioctl_lock_up(p) ec_lock_up(p) +#endif + /*****************************************************************************/ /** Copies a string to an ioctl structure. @@ -2100,8 +2110,15 @@ static ATTRIBUTES int ec_ioctl_send( return -EPERM; } + /* Locking added as send is likely to be used by more than + one application tasks */ + if (ec_ioctl_lock_down_interruptible(&master->master_sem)) + return -EINTR; + sent_bytes = ecrt_master_send(master); + ec_ioctl_lock_up(&master->master_sem); + if (copy_to_user((void __user *) arg, &sent_bytes, sizeof(sent_bytes))) { return -EFAULT; } @@ -2125,7 +2142,14 @@ static ATTRIBUTES int ec_ioctl_receive( return -EPERM; } + /* Locking added as receive is likely to be used by more than + one application tasks */ + if (ec_ioctl_lock_down_interruptible(&master->master_sem)) + return -EINTR; + ecrt_master_receive(master); + + ec_ioctl_lock_up(&master->master_sem); return 0; } @@ -3441,14 +3465,19 @@ static ATTRIBUTES int ec_ioctl_domain_process( if (unlikely(!ctx->requested)) return -EPERM; - /* no locking of master_sem needed, because domain will not be deleted in - * the meantime. */ + /* Locking added as domain processing is likely to be used by more than + one application tasks */ + if (ec_ioctl_lock_down_interruptible(&master->master_sem)) { + return -EINTR; + } if (!(domain = ec_master_find_domain(master, (unsigned long) arg))) { + ec_ioctl_lock_up(&master->master_sem); return -ENOENT; } ecrt_domain_process(domain); + ec_ioctl_lock_up(&master->master_sem); return 0; } @@ -3469,14 +3498,20 @@ static ATTRIBUTES int ec_ioctl_domain_queue( if (unlikely(!ctx->requested)) return -EPERM; - /* no locking of master_sem needed, because domain will not be deleted in - * the meantime. */ + /* Locking added as domain queing is likely to be used by more than + one application tasks */ + if (ec_ioctl_lock_down_interruptible(&master->master_sem)) + return -EINTR; if (!(domain = ec_master_find_domain(master, (unsigned long) arg))) { + ec_ioctl_lock_up(&master->master_sem); return -ENOENT; } ecrt_domain_queue(domain); + + ec_ioctl_lock_up(&master->master_sem); + return 0; }