public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
From: Baran Arda <baran9arda@gmail.com>
To: gregkh@linuxfoundation.org
Cc: ovidiu.panait.oss@gmail.com, gshahrouzi@gmail.com,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
	baran9arda@gmail.com
Subject: [PATCH v2] staging: axis-fifo: fix sleep while holding mutex
Date: Tue,  3 Feb 2026 14:48:58 +0300	[thread overview]
Message-ID: <20260203114858.28278-1-baran9arda@gmail.com> (raw)

The driver calls wait_event_interruptible_timeout() while holding a mutex. This can lead to a deadlock or poor performance as the mutex is held while the process is sleeping, preventing other processes from accessing the device. This patch moves the wait_event call outside of the mutex lock in both read and write operations.

Signed-off-by: Baran Arda <baran9arda@gmail.com>
---
 drivers/staging/axis-fifo/axis-fifo.c | 30 +++++++++++++--------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/axis-fifo/axis-fifo.c b/drivers/staging/axis-fifo/axis-fifo.c
index 509d620d6ce7..a651c59a80ea 100644
--- a/drivers/staging/axis-fifo/axis-fifo.c
+++ b/drivers/staging/axis-fifo/axis-fifo.c
@@ -197,11 +197,10 @@ static ssize_t axis_fifo_read(struct file *f, char __user *buf,
 			goto end_unlock;
 		}
 	} else {
-		/* opened in blocking mode
-		 * wait for a packet available interrupt (or timeout)
-		 * if nothing is currently available
+		/*
+		 * Opened in blocking mode. Wait for a packet available
+		 * interrupt (or timeout) before acquiring the lock.
 		 */
-		mutex_lock(&fifo->read_lock);
 		ret = wait_event_interruptible_timeout(fifo->read_queue,
 						       ioread32(fifo->base_addr + XLLF_RDFO_OFFSET),
 						       read_timeout);
@@ -214,8 +213,10 @@ static ssize_t axis_fifo_read(struct file *f, char __user *buf,
 					ret);
 			}
 
-			goto end_unlock;
+			return ret;
 		}
+
+		mutex_lock(&fifo->read_lock);
 	}
 
 	bytes_available = ioread32(fifo->base_addr + XLLF_RLR_OFFSET);
@@ -340,27 +341,26 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf,
 			goto end_unlock;
 		}
 	} else {
-		/* opened in blocking mode */
-
-		/* wait for an interrupt (or timeout) if there isn't
-		 * currently enough room in the fifo
+		/*
+		 * Opened in blocking mode. Wait for enough room in the FIFO
+		 * (or timeout) before acquiring the lock.
 		 */
-		mutex_lock(&fifo->write_lock);
 		ret = wait_event_interruptible_timeout(fifo->write_queue,
 						       ioread32(fifo->base_addr + XLLF_TDFV_OFFSET)
-								>= words_to_write,
+						       >= words_to_write,
 						       write_timeout);
 
 		if (ret <= 0) {
-			if (ret == 0) {
+			if (ret == 0)
 				ret = -EAGAIN;
-			} else if (ret != -ERESTARTSYS) {
+			else if (ret != -ERESTARTSYS)
 				dev_err(fifo->dt_device, "wait_event_interruptible_timeout() error in write (ret=%i)\n",
 					ret);
-			}
 
-			goto end_unlock;
+			return ret;
 		}
+
+		mutex_lock(&fifo->write_lock);
 	}
 
 	txbuf = vmemdup_user(buf, len);
-- 
2.39.5 (Apple Git-154)


             reply	other threads:[~2026-02-03 11:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-03 11:48 Baran Arda [this message]
2026-02-03 12:00 ` [PATCH v2] staging: axis-fifo: fix sleep while holding mutex Greg KH
2026-02-03 12:02 ` Greg KH
2026-02-03 13:44   ` Baran Arda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260203114858.28278-1-baran9arda@gmail.com \
    --to=baran9arda@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gshahrouzi@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=ovidiu.panait.oss@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox