[PATCH] Staging: gpib: iblib: iboffline check if board is in use
From: Thomas Andreatta
Date: Sat May 10 2025 - 13:25:30 EST
Ensures that a board cannot be taken offline while it's still in use.
Signed-off-by: Thomas Andreatta <thomas.andreatta2000@xxxxxxxxx>
---
drivers/staging/gpib/common/iblib.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/gpib/common/iblib.c b/drivers/staging/gpib/common/iblib.c
index 7a44517464ab..0ab5680457ac 100644
--- a/drivers/staging/gpib/common/iblib.c
+++ b/drivers/staging/gpib/common/iblib.c
@@ -240,7 +240,6 @@ int ibonline(struct gpib_board *board)
return 0;
}
-/* XXX need to make sure board is generally not in use (grab board lock?) */
int iboffline(struct gpib_board *board)
{
int retval;
@@ -250,6 +249,15 @@ int iboffline(struct gpib_board *board)
if (!board->interface)
return -ENODEV;
+ /* Ensure board is not in use */
+ if (mutex_lock_interruptible(&board->user_mutex))
+ return -ERESTARTSYS;
+
+ if (board->use_count > 0) {
+ mutex_unlock(&board->user_mutex);
+ return -EBUSY;
+ }
+
if (board->autospoll_task && !IS_ERR(board->autospoll_task)) {
retval = kthread_stop(board->autospoll_task);
if (retval)
@@ -262,6 +270,7 @@ int iboffline(struct gpib_board *board)
board->online = 0;
dev_dbg(board->gpib_dev, "board offline\n");
+ mutex_unlock(&board->user_mutex);
return 0;
}
--
2.34.1