From: Thomas Andreatta <thomasandreatta2000@gmail.com>
To: dpenkler@gmail.com
Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
linux-staging@lists.linux.dev,
Thomas Andreatta <thomas.andreatta2000@gmail.com>
Subject: [PATCH] Staging: gpib: iblib: iboffline check if board is in use
Date: Sat, 10 May 2025 19:24:20 +0200 [thread overview]
Message-ID: <20250510172419.274616-1-thomas.andreatta2000@gmail.com> (raw)
Ensures that a board cannot be taken offline while it's still in use.
Signed-off-by: Thomas Andreatta <thomas.andreatta2000@gmail.com>
---
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
next reply other threads:[~2025-05-10 17:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-10 17:24 Thomas Andreatta [this message]
2025-05-12 9:16 ` [PATCH] Staging: gpib: iblib: iboffline check if board is in use Dave Penkler
2025-05-12 14:58 ` Dan Carpenter
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=20250510172419.274616-1-thomas.andreatta2000@gmail.com \
--to=thomasandreatta2000@gmail.com \
--cc=dpenkler@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=thomas.andreatta2000@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