From: Yalagada Pavan Kumar <pavankumaryalagada(a)gmail.com>
Replace the existing usleep_range() and msleep() calls with
a single call to fsleep(), simplifying the code and letting
fsleep() select the appropriate delay method based on the
requested time.
For short delays, fsleep() allows up to 25% extra time instead
of the fixed 100 microseconds. For longer delays, the old code
rounds the requested time down to whole milliseconds, while
fsleep() rounds it up when using msleep().
These changes may affect the time between loopback operations
and the reported performance.
Suggested-by: Alex Elder <elder(a)riscstar.com>
Signed-off-by: Yalagada Pavan Kumar <pavankumaryalagada(a)gmail.com>
Reviewed-by: Alex Elder <elder(a)riscstar.com>
---
v3:
- Clarify the reason for using fsleep() in the commit message
v2:
- Add more details about how fsleep() affects delays.
- Update the subject to include the loopback module.
v1: https://lore.kernel.org/outreachy/c482704b-903e-413d-ba7b-5bf31c0a6104@risc…
---
drivers/staging/greybus/loopback.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/greybus/loopback.c b/drivers/staging/greybus/loopback.c
index efc69c10cffe..2fe845eaef29 100644
--- a/drivers/staging/greybus/loopback.c
+++ b/drivers/staging/greybus/loopback.c
@@ -898,12 +898,8 @@ static int gb_loopback_fn(void *data)
gb->send_count++;
mutex_unlock(&gb->mutex);
- if (us_wait) {
- if (us_wait < 20000)
- usleep_range(us_wait, us_wait + 100);
- else
- msleep(us_wait / 1000);
- }
+ if (us_wait)
+ fsleep(us_wait);
}
gb_pm_runtime_put_autosuspend(bundle);
--
2.43.0
From: Yalagada Pavan Kumar <pavankumaryalagada(a)gmail.com>
In the loopback function, usleep_range() is used for short delays
and msleep() for longer delays. This requires choosing the delay
function based on the requested time and converting microseconds
to milliseconds when using msleep().
Replace both functions with fsleep(), which chooses a delay
delay method based on the requested time. For short delays,
fsleep() allows up to 25% extra time instead of the fixed 100
microseconds. For longer delays, the old code rounds the
requested time down to whole milliseconds, while fsleep() rounds
it up when using msleep().
These changes may affect time between loopback operations and
the reported performance.
Suggested-by: Alex Elder <elder(a)riscstar.com>
Signed-off-by: Yalagada Pavan Kumar <pavankumaryalagada(a)gmail.com>
---
v2:
- Add more details about how fsleep() affects delays.
- Update the subject to include the loopback module.
v1: https://lore.kernel.org/outreachy/c482704b-903e-413d-ba7b-5bf31c0a6104@risc…
---
drivers/staging/greybus/loopback.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/greybus/loopback.c b/drivers/staging/greybus/loopback.c
index efc69c10cffe..2fe845eaef29 100644
--- a/drivers/staging/greybus/loopback.c
+++ b/drivers/staging/greybus/loopback.c
@@ -898,12 +898,8 @@ static int gb_loopback_fn(void *data)
gb->send_count++;
mutex_unlock(&gb->mutex);
- if (us_wait) {
- if (us_wait < 20000)
- usleep_range(us_wait, us_wait + 100);
- else
- msleep(us_wait / 1000);
- }
+ if (us_wait)
+ fsleep(us_wait);
}
gb_pm_runtime_put_autosuspend(bundle);
--
2.43.0
The audio manager module is created in a context that permits
sleeping. Its caller, gb_audio_manager_add(), already uses
GFP_KERNEL through ida_alloc(), and module creation subsequently
calls kobject_init_and_add().
GFP_ATOMIC is unnecessary in this context and restricts memory
reclaim. Remove the explicit flag to use the default GFP_KERNEL
allocation.
Signed-off-by: Torra Sowmya <sowmyatorra(a)gmail.com>
---
drivers/staging/greybus/audio_manager_module.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/greybus/audio_manager_module.c b/drivers/staging/greybus/audio_manager_module.c
index dc90cc2d2308..8a9f7e7d1766 100644
--- a/drivers/staging/greybus/audio_manager_module.c
+++ b/drivers/staging/greybus/audio_manager_module.c
@@ -187,7 +187,7 @@ int gb_audio_manager_module_create(struct gb_audio_manager_module **module,
int err;
struct gb_audio_manager_module *m;
- m = kzalloc_obj(*m, GFP_ATOMIC);
+ m = kzalloc_obj(*m);
if (!m)
return -ENOMEM;
--
2.47.3
From: Yalagada Pavan Kumar <pavankumaryalagada(a)gmail.com>
In the loopback function, usleep_range() is used for short delays
and msleep() for longer delays. This requires choosing the delay
function based on the requested time and converting microseconds
to milliseconds when using msleep().
Replace both functions with fsleep(), which selects a suitable
delay method based on the requested time. This avoids the need
to choose the delay function and convert the time manually.
Suggested-by: Alex Elder <elder(a)riscstar.com>
Signed-off-by: Yalagada Pavan Kumar <pavankumaryalagada(a)gmail.com>
---
drivers/staging/greybus/loopback.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/greybus/loopback.c b/drivers/staging/greybus/loopback.c
index efc69c10cffe..2fe845eaef29 100644
--- a/drivers/staging/greybus/loopback.c
+++ b/drivers/staging/greybus/loopback.c
@@ -898,12 +898,8 @@ static int gb_loopback_fn(void *data)
gb->send_count++;
mutex_unlock(&gb->mutex);
- if (us_wait) {
- if (us_wait < 20000)
- usleep_range(us_wait, us_wait + 100);
- else
- msleep(us_wait / 1000);
- }
+ if (us_wait)
+ fsleep(us_wait);
}
gb_pm_runtime_put_autosuspend(bundle);
--
2.43.0
An operation can complete after gb_message_send() returns but before
gb_operation_request_send() arms its timeout timer. The completion
worker then sees no active timer, finishes the callback, and drops its
operation reference. The request path may still arm the timer, so a later
final put frees an operation with an active timer.
Take a temporary reference before sending and keep it through timer
setup. After arming the timer, inspect the result under
gb_operations_lock. If the operation has already completed,
synchronously delete the timer before dropping the temporary reference.
OpenAI Codex assisted with the syzbot investigation, race analysis, patch,
and changelog. The syzbot C reproducer drove Greybus ES2 under ARM64 QEMU
but did not naturally trigger ODEBUG. In a test-only build, forcing
completion work to finish before timer setup left the timer pending when
the operation was destroyed before this change and inactive with this
change.
Fixes: dbec27298b0d ("staging: greybus: operation: add generic timeout support")
Reported-by: syzbot+61464b62b688791cc24c(a)syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=61464b62b688791cc24c
Reported-by: syzbot+a2e50fb40695811c2dab(a)syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=a2e50fb40695811c2dab
Signed-off-by: Eduard Zateev <hackerowskiy(a)gmail.com>
---
drivers/greybus/operation.c | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/drivers/greybus/operation.c b/drivers/greybus/operation.c
index 7e12ffb2dd6..5bfee8638c9 100644
--- a/drivers/greybus/operation.c
+++ b/drivers/greybus/operation.c
@@ -188,6 +188,18 @@ int gb_operation_result(struct gb_operation *operation)
}
EXPORT_SYMBOL_GPL(gb_operation_result);
+static bool gb_operation_is_in_progress(struct gb_operation *operation)
+{
+ unsigned long flags;
+ bool in_progress;
+
+ spin_lock_irqsave(&gb_operations_lock, flags);
+ in_progress = operation->errno == -EINPROGRESS;
+ spin_unlock_irqrestore(&gb_operations_lock, flags);
+
+ return in_progress;
+}
+
/*
* Looks up an outgoing operation on a connection and returns a refcounted
* pointer if found, or NULL otherwise.
@@ -766,18 +778,30 @@ int gb_operation_request_send(struct gb_operation *operation,
if (ret)
goto err_put;
+ /* Keep the operation alive while a fast completion races with send. */
+ gb_operation_get(operation);
ret = gb_message_send(operation->request, gfp);
if (ret)
- goto err_put_active;
+ goto err_put_send;
if (timeout) {
operation->timer.expires = jiffies + msecs_to_jiffies(timeout);
add_timer(&operation->timer);
+
+ /*
+ * Completion may have removed the timer before it was armed.
+ * If so, remove the newly armed timer before the operation can
+ * be released.
+ */
+ if (!gb_operation_is_in_progress(operation))
+ timer_delete_sync(&operation->timer);
}
+ gb_operation_put(operation);
return 0;
-err_put_active:
+err_put_send:
+ gb_operation_put(operation);
gb_operation_put_active(operation);
err_put:
gb_operation_put(operation);
--
2.55.0
The following has been changed:
- introduce mutex to C serdev tty port controller
- introduce a new C serdev API to fix race conditions and simplify rust
code. Should also be useful on the C side.
- fix race conditions
- simplify rust code
Signed-off-by: Markus Probst <markus.probst(a)posteo.de>
---
Changes in v4:
- fix issues reported by Sashiko:
- add receive_lock to prevent deadlocks
- Link to v3: https://patch.msgid.link/20260930-rust_serdev_probe_refactor-v3-0-d1b6e7713…
Changes in v3:
- add mutex
- Link to v2: https://patch.msgid.link/20260920-rust_serdev_probe_refactor-v2-0-43b855162…
Changes in v2:
- fix missing memory barriers in serdev apis
- use `tty_buffer_restart_work` instead of `tty_flip_buffer_push`
- use `tty_buffer_flush_work` instead of exclusively locking the mutex
- add `#[inline]` to `PrivateData::driver_data`
- remove patches for mutable references
- Link to v1: https://patch.msgid.link/20260906-rust_serdev_probe_refactor-v1-0-69cdae007…
---
Markus Probst (4):
tty: serdev: Add mutex lock
tty: serdev: Export functions to pause receive_buf callback calls
rust: serdev: Replace `active` mutex with receive pause
rust: serdev: Simplify callbacks
drivers/tty/serdev/core.c | 54 +++++++++++-
drivers/tty/serdev/serdev-ttyport.c | 84 ++++++++++++++++--
include/linux/serdev.h | 8 +-
rust/kernel/serdev.rs | 167 ++++++++++++------------------------
4 files changed, 188 insertions(+), 125 deletions(-)
---
base-commit: ec8bf8280261294a9b9b4520414b42704c7f9f6b
change-id: 20260905-rust_serdev_probe_refactor-0e2b044354a7