From: Josh Law <hlcj1234567@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
Josh Law <objecting@objecting.org>
Subject: [PATCH] staging: axis-fifo: minimize lock duration in write
Date: Sun, 1 Mar 2026 00:58:36 +0000 [thread overview]
Message-ID: <20260301005836.2513391-1-objecting@objecting.org> (raw)
Memory allocation and copy from user space with vmemdup_user() is relatively slow and can sleep. Move it outside the lock to minimize the time the mutex is held, reducing contention for concurrent accesses.
Signed-off-by: Josh Law <objecting@objecting.org>
---
drivers/staging/axis-fifo/axis-fifo.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/drivers/staging/axis-fifo/axis-fifo.c b/drivers/staging/axis-fifo/axis-fifo.c
index aad2206b481a..d5533235cefc 100644
--- a/drivers/staging/axis-fifo/axis-fifo.c
+++ b/drivers/staging/axis-fifo/axis-fifo.c
@@ -233,9 +233,15 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf,
(words_to_write > (fifo->tx_fifo_depth - 4)))
return -EINVAL;
+ txbuf = vmemdup_user(buf, len);
+ if (IS_ERR(txbuf))
+ return PTR_ERR(txbuf);
+
if (f->f_flags & O_NONBLOCK) {
- if (!mutex_trylock(&fifo->write_lock))
- return -EAGAIN;
+ if (!mutex_trylock(&fifo->write_lock)) {
+ ret = -EAGAIN;
+ goto err_free;
+ }
if (words_to_write > ioread32(fifo->base_addr +
XLLF_TDFV_OFFSET)) {
@@ -252,21 +258,17 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf,
goto end_unlock;
}
- txbuf = vmemdup_user(buf, len);
- if (IS_ERR(txbuf)) {
- ret = PTR_ERR(txbuf);
- goto end_unlock;
- }
-
for (int i = 0; i < words_to_write; ++i)
iowrite32(txbuf[i], fifo->base_addr + XLLF_TDFD_OFFSET);
iowrite32(len, fifo->base_addr + XLLF_TLR_OFFSET);
ret = len;
- kvfree(txbuf);
+
end_unlock:
mutex_unlock(&fifo->write_lock);
+err_free:
+ kvfree(txbuf);
return ret;
}
--
2.43.0
next reply other threads:[~2026-03-01 0:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-01 0:58 Josh Law [this message]
2026-03-01 18:39 ` [PATCH] staging: axis-fifo: minimize lock duration in write Ethan Tidmore
2026-03-09 16:07 ` Greg Kroah-Hartman
2026-03-09 16:11 ` Josh Law
2026-03-09 16:56 ` Greg Kroah-Hartman
2026-03-09 17:04 ` Josh Law
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=20260301005836.2513391-1-objecting@objecting.org \
--to=hlcj1234567@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=objecting@objecting.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.