* [PATCH] Staging: gpib: iblib: iboffline check if board is in use
@ 2025-05-10 17:24 Thomas Andreatta
2025-05-12 9:16 ` Dave Penkler
2025-05-12 14:58 ` Dan Carpenter
0 siblings, 2 replies; 3+ messages in thread
From: Thomas Andreatta @ 2025-05-10 17:24 UTC (permalink / raw)
To: dpenkler; +Cc: gregkh, linux-kernel, linux-staging, Thomas Andreatta
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] Staging: gpib: iblib: iboffline check if board is in use
2025-05-10 17:24 [PATCH] Staging: gpib: iblib: iboffline check if board is in use Thomas Andreatta
@ 2025-05-12 9:16 ` Dave Penkler
2025-05-12 14:58 ` Dan Carpenter
1 sibling, 0 replies; 3+ messages in thread
From: Dave Penkler @ 2025-05-12 9:16 UTC (permalink / raw)
To: Thomas Andreatta; +Cc: gregkh, linux-kernel, linux-staging, Thomas Andreatta
On Sat, May 10, 2025 at 07:24:20PM +0200, Thomas Andreatta wrote:
> 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) {
use_count is never zero for an initialised board so this would always
return -EBUSY not allowing a board to be placed offline
> + 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
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] Staging: gpib: iblib: iboffline check if board is in use
2025-05-10 17:24 [PATCH] Staging: gpib: iblib: iboffline check if board is in use Thomas Andreatta
2025-05-12 9:16 ` Dave Penkler
@ 2025-05-12 14:58 ` Dan Carpenter
1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2025-05-12 14:58 UTC (permalink / raw)
To: Thomas Andreatta
Cc: dpenkler, gregkh, linux-kernel, linux-staging, Thomas Andreatta
On Sat, May 10, 2025 at 07:24:20PM +0200, Thomas Andreatta wrote:
> 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) {
We're not holding this mutex in ibopen() and not necessarily
in ibclose() either so this doesn't work. It's racy.
You'd have to change the ioctl as well.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-05-12 14:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-10 17:24 [PATCH] Staging: gpib: iblib: iboffline check if board is in use Thomas Andreatta
2025-05-12 9:16 ` Dave Penkler
2025-05-12 14:58 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox