Linux kernel -stable discussions
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 6.12-stable tree
@ 2026-05-01 10:58 gregkh
  2026-05-01 13:56 ` [PATCH 6.12.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
  0 siblings, 1 reply; 35+ messages in thread
From: gregkh @ 2026-05-01 10:58 UTC (permalink / raw)
  To: corey, 252270051; +Cc: stable


The patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026050146-duckbill-exile-3382@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..

Possible dependencies:



thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4 Mon Sep 17 00:00:00 2001
From: Corey Minyard <corey@minyard.net>
Date: Mon, 13 Apr 2026 08:00:23 -0500
Subject: [PATCH] ipmi:ssif: Clean up kthread on errors

If an error occurs after the ssif kthread is created, but before the
main IPMI code starts the ssif interface, the ssif kthread will not
be stopped.

So make sure the kthread is stopped on an error condition if it is
running.

Fixes: 259307074bfc ("ipmi: Add SMBus interface driver (SSIF)")
Reported-by: Li Xiao <<252270051@hdu.edu.cn>
Cc: stable@vger.kernel.org
Reviewed-by: Li Xiao <252270051@hdu.edu.cn>
Signed-off-by: Corey Minyard <corey@minyard.net>

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index ce918fe987c6..b49500a1bd36 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1268,8 +1268,10 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	timer_delete_sync(&ssif_info->watch_timer);
 	timer_delete_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread)
+	if (ssif_info->thread) {
 		kthread_stop(ssif_info->thread);
+		ssif_info->thread = NULL;
+	}
 }
 
 static void ssif_remove(struct i2c_client *client)
@@ -1912,6 +1914,15 @@ static int ssif_probe(struct i2c_client *client)
 
  out:
 	if (rv) {
+		/*
+		 * If ipmi_register_smi() starts the interface, it will
+		 * call shutdown and that will free the thread and set
+		 * it to NULL.  Otherwise it must be freed here.
+		 */
+		if (ssif_info->thread) {
+			kthread_stop(ssif_info->thread);
+			ssif_info->thread = NULL;
+		}
 		if (addr_info)
 			addr_info->client = NULL;
 


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 6.6-stable tree
@ 2026-05-01 10:58 gregkh
  2026-05-01 14:06 ` [PATCH 6.6.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
  0 siblings, 1 reply; 35+ messages in thread
From: gregkh @ 2026-05-01 10:58 UTC (permalink / raw)
  To: corey, 252270051; +Cc: stable


The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026050147-kinfolk-perennial-0e04@gregkh' --subject-prefix 'PATCH 6.6.y' HEAD^..

Possible dependencies:



thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4 Mon Sep 17 00:00:00 2001
From: Corey Minyard <corey@minyard.net>
Date: Mon, 13 Apr 2026 08:00:23 -0500
Subject: [PATCH] ipmi:ssif: Clean up kthread on errors

If an error occurs after the ssif kthread is created, but before the
main IPMI code starts the ssif interface, the ssif kthread will not
be stopped.

So make sure the kthread is stopped on an error condition if it is
running.

Fixes: 259307074bfc ("ipmi: Add SMBus interface driver (SSIF)")
Reported-by: Li Xiao <<252270051@hdu.edu.cn>
Cc: stable@vger.kernel.org
Reviewed-by: Li Xiao <252270051@hdu.edu.cn>
Signed-off-by: Corey Minyard <corey@minyard.net>

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index ce918fe987c6..b49500a1bd36 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1268,8 +1268,10 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	timer_delete_sync(&ssif_info->watch_timer);
 	timer_delete_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread)
+	if (ssif_info->thread) {
 		kthread_stop(ssif_info->thread);
+		ssif_info->thread = NULL;
+	}
 }
 
 static void ssif_remove(struct i2c_client *client)
@@ -1912,6 +1914,15 @@ static int ssif_probe(struct i2c_client *client)
 
  out:
 	if (rv) {
+		/*
+		 * If ipmi_register_smi() starts the interface, it will
+		 * call shutdown and that will free the thread and set
+		 * it to NULL.  Otherwise it must be freed here.
+		 */
+		if (ssif_info->thread) {
+			kthread_stop(ssif_info->thread);
+			ssif_info->thread = NULL;
+		}
 		if (addr_info)
 			addr_info->client = NULL;
 


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 6.1-stable tree
@ 2026-05-01 10:58 gregkh
  2026-05-01 14:19 ` [PATCH 6.1.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
  0 siblings, 1 reply; 35+ messages in thread
From: gregkh @ 2026-05-01 10:58 UTC (permalink / raw)
  To: corey, 252270051; +Cc: stable


The patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026050147-trio-dangling-a9ed@gregkh' --subject-prefix 'PATCH 6.1.y' HEAD^..

Possible dependencies:



thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4 Mon Sep 17 00:00:00 2001
From: Corey Minyard <corey@minyard.net>
Date: Mon, 13 Apr 2026 08:00:23 -0500
Subject: [PATCH] ipmi:ssif: Clean up kthread on errors

If an error occurs after the ssif kthread is created, but before the
main IPMI code starts the ssif interface, the ssif kthread will not
be stopped.

So make sure the kthread is stopped on an error condition if it is
running.

Fixes: 259307074bfc ("ipmi: Add SMBus interface driver (SSIF)")
Reported-by: Li Xiao <<252270051@hdu.edu.cn>
Cc: stable@vger.kernel.org
Reviewed-by: Li Xiao <252270051@hdu.edu.cn>
Signed-off-by: Corey Minyard <corey@minyard.net>

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index ce918fe987c6..b49500a1bd36 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1268,8 +1268,10 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	timer_delete_sync(&ssif_info->watch_timer);
 	timer_delete_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread)
+	if (ssif_info->thread) {
 		kthread_stop(ssif_info->thread);
+		ssif_info->thread = NULL;
+	}
 }
 
 static void ssif_remove(struct i2c_client *client)
@@ -1912,6 +1914,15 @@ static int ssif_probe(struct i2c_client *client)
 
  out:
 	if (rv) {
+		/*
+		 * If ipmi_register_smi() starts the interface, it will
+		 * call shutdown and that will free the thread and set
+		 * it to NULL.  Otherwise it must be freed here.
+		 */
+		if (ssif_info->thread) {
+			kthread_stop(ssif_info->thread);
+			ssif_info->thread = NULL;
+		}
 		if (addr_info)
 			addr_info->client = NULL;
 


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 5.10-stable tree
@ 2026-05-01 10:58 gregkh
  2026-05-01 14:54 ` [PATCH 5.10.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
                   ` (2 more replies)
  0 siblings, 3 replies; 35+ messages in thread
From: gregkh @ 2026-05-01 10:58 UTC (permalink / raw)
  To: corey, 252270051; +Cc: stable


The patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026050148-irregular-kite-7f24@gregkh' --subject-prefix 'PATCH 5.10.y' HEAD^..

Possible dependencies:



thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4 Mon Sep 17 00:00:00 2001
From: Corey Minyard <corey@minyard.net>
Date: Mon, 13 Apr 2026 08:00:23 -0500
Subject: [PATCH] ipmi:ssif: Clean up kthread on errors

If an error occurs after the ssif kthread is created, but before the
main IPMI code starts the ssif interface, the ssif kthread will not
be stopped.

So make sure the kthread is stopped on an error condition if it is
running.

Fixes: 259307074bfc ("ipmi: Add SMBus interface driver (SSIF)")
Reported-by: Li Xiao <<252270051@hdu.edu.cn>
Cc: stable@vger.kernel.org
Reviewed-by: Li Xiao <252270051@hdu.edu.cn>
Signed-off-by: Corey Minyard <corey@minyard.net>

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index ce918fe987c6..b49500a1bd36 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1268,8 +1268,10 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	timer_delete_sync(&ssif_info->watch_timer);
 	timer_delete_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread)
+	if (ssif_info->thread) {
 		kthread_stop(ssif_info->thread);
+		ssif_info->thread = NULL;
+	}
 }
 
 static void ssif_remove(struct i2c_client *client)
@@ -1912,6 +1914,15 @@ static int ssif_probe(struct i2c_client *client)
 
  out:
 	if (rv) {
+		/*
+		 * If ipmi_register_smi() starts the interface, it will
+		 * call shutdown and that will free the thread and set
+		 * it to NULL.  Otherwise it must be freed here.
+		 */
+		if (ssif_info->thread) {
+			kthread_stop(ssif_info->thread);
+			ssif_info->thread = NULL;
+		}
 		if (addr_info)
 			addr_info->client = NULL;
 


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 5.15-stable tree
@ 2026-05-01 10:58 gregkh
  2026-05-01 14:27 ` [PATCH 5.15.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
                   ` (2 more replies)
  0 siblings, 3 replies; 35+ messages in thread
From: gregkh @ 2026-05-01 10:58 UTC (permalink / raw)
  To: corey, 252270051; +Cc: stable


The patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026050148-politely-tabloid-3059@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^..

Possible dependencies:



thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4 Mon Sep 17 00:00:00 2001
From: Corey Minyard <corey@minyard.net>
Date: Mon, 13 Apr 2026 08:00:23 -0500
Subject: [PATCH] ipmi:ssif: Clean up kthread on errors

If an error occurs after the ssif kthread is created, but before the
main IPMI code starts the ssif interface, the ssif kthread will not
be stopped.

So make sure the kthread is stopped on an error condition if it is
running.

Fixes: 259307074bfc ("ipmi: Add SMBus interface driver (SSIF)")
Reported-by: Li Xiao <<252270051@hdu.edu.cn>
Cc: stable@vger.kernel.org
Reviewed-by: Li Xiao <252270051@hdu.edu.cn>
Signed-off-by: Corey Minyard <corey@minyard.net>

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index ce918fe987c6..b49500a1bd36 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1268,8 +1268,10 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	timer_delete_sync(&ssif_info->watch_timer);
 	timer_delete_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread)
+	if (ssif_info->thread) {
 		kthread_stop(ssif_info->thread);
+		ssif_info->thread = NULL;
+	}
 }
 
 static void ssif_remove(struct i2c_client *client)
@@ -1912,6 +1914,15 @@ static int ssif_probe(struct i2c_client *client)
 
  out:
 	if (rv) {
+		/*
+		 * If ipmi_register_smi() starts the interface, it will
+		 * call shutdown and that will free the thread and set
+		 * it to NULL.  Otherwise it must be freed here.
+		 */
+		if (ssif_info->thread) {
+			kthread_stop(ssif_info->thread);
+			ssif_info->thread = NULL;
+		}
 		if (addr_info)
 			addr_info->client = NULL;
 


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 6.12.y 1/2] ipmi:ssif: Fix a shutdown race
  2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 6.12-stable tree gregkh
@ 2026-05-01 13:56 ` Corey Minyard
  2026-05-01 13:56   ` [PATCH 6.12.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
  2026-05-03 18:19   ` [PATCH 6.12.y/6.6.y/6.1.y/5.15.y/5.10.y 1-2/2] ipmi:ssif: shutdown race + kthread cleanup Sasha Levin
  0 siblings, 2 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-01 13:56 UTC (permalink / raw)
  To: stable; +Cc: Corey Minyard, Corey Minyard

It was possible for the SSIF thread to stop and quit before the
kthread_stop() call because ssif->stopping was set before the
stop.  So only exit the SSIF thread is kthread_should_stop()
returns true.

There is no need to wake the thread, as the wait will be interrupted
by kthread_stop().

Signed-off-by: Corey Minyard <cminyard@mvista.com>
(cherry picked from commit 6bd0eb6d759b9a22c5509ea04e19c2e8407ba418)
---
 drivers/char/ipmi/ipmi_ssif.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index d04b391048fb..cce4d9c00566 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -481,8 +481,6 @@ static int ipmi_ssif_thread(void *data)
 		/* Wait for something to do */
 		result = wait_for_completion_interruptible(
 						&ssif_info->wake_thread);
-		if (ssif_info->stopping)
-			break;
 		if (result == -ERESTARTSYS)
 			continue;
 		init_completion(&ssif_info->wake_thread);
@@ -1270,10 +1268,8 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	del_timer_sync(&ssif_info->watch_timer);
 	del_timer_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread) {
-		complete(&ssif_info->wake_thread);
+	if (ssif_info->thread)
 		kthread_stop(ssif_info->thread);
-	}
 }
 
 static void ssif_remove(struct i2c_client *client)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 6.12.y 2/2] ipmi:ssif: Clean up kthread on errors
  2026-05-01 13:56 ` [PATCH 6.12.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
@ 2026-05-01 13:56   ` Corey Minyard
  2026-05-03 18:19   ` [PATCH 6.12.y/6.6.y/6.1.y/5.15.y/5.10.y 1-2/2] ipmi:ssif: shutdown race + kthread cleanup Sasha Levin
  1 sibling, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-01 13:56 UTC (permalink / raw)
  To: stable; +Cc: Corey Minyard, Li Xiao

If an error occurs after the ssif kthread is created, but before the
main IPMI code starts the ssif interface, the ssif kthread will not
be stopped.

So make sure the kthread is stopped on an error condition if it is
running.

Fixes: 259307074bfc ("ipmi: Add SMBus interface driver (SSIF)")
Reported-by: Li Xiao <<252270051@hdu.edu.cn>
Cc: stable@vger.kernel.org
Reviewed-by: Li Xiao <252270051@hdu.edu.cn>
Signed-off-by: Corey Minyard <corey@minyard.net>
(cherry picked from commit 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4)
---
 drivers/char/ipmi/ipmi_ssif.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index cce4d9c00566..347446b165a9 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1268,8 +1268,10 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	del_timer_sync(&ssif_info->watch_timer);
 	del_timer_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread)
+	if (ssif_info->thread) {
 		kthread_stop(ssif_info->thread);
+		ssif_info->thread = NULL;
+	}
 }
 
 static void ssif_remove(struct i2c_client *client)
@@ -1916,6 +1918,15 @@ static int ssif_probe(struct i2c_client *client)
 
  out:
 	if (rv) {
+		/*
+		 * If ipmi_register_smi() starts the interface, it will
+		 * call shutdown and that will free the thread and set
+		 * it to NULL.  Otherwise it must be freed here.
+		 */
+		if (ssif_info->thread) {
+			kthread_stop(ssif_info->thread);
+			ssif_info->thread = NULL;
+		}
 		if (addr_info)
 			addr_info->client = NULL;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 6.6.y 1/2] ipmi:ssif: Fix a shutdown race
  2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 6.6-stable tree gregkh
@ 2026-05-01 14:06 ` Corey Minyard
  2026-05-01 14:06   ` [PATCH 6.6.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
  0 siblings, 1 reply; 35+ messages in thread
From: Corey Minyard @ 2026-05-01 14:06 UTC (permalink / raw)
  To: stable; +Cc: Corey Minyard, Corey Minyard

It was possible for the SSIF thread to stop and quit before the
kthread_stop() call because ssif->stopping was set before the
stop.  So only exit the SSIF thread is kthread_should_stop()
returns true.

There is no need to wake the thread, as the wait will be interrupted
by kthread_stop().

Signed-off-by: Corey Minyard <cminyard@mvista.com>
(cherry picked from commit 6bd0eb6d759b9a22c5509ea04e19c2e8407ba418)
---
 drivers/char/ipmi/ipmi_ssif.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index df8dd50b4cbe..3c4aa87d6bd4 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -481,8 +481,6 @@ static int ipmi_ssif_thread(void *data)
 		/* Wait for something to do */
 		result = wait_for_completion_interruptible(
 						&ssif_info->wake_thread);
-		if (ssif_info->stopping)
-			break;
 		if (result == -ERESTARTSYS)
 			continue;
 		init_completion(&ssif_info->wake_thread);
@@ -1270,10 +1268,8 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	del_timer_sync(&ssif_info->watch_timer);
 	del_timer_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread) {
-		complete(&ssif_info->wake_thread);
+	if (ssif_info->thread)
 		kthread_stop(ssif_info->thread);
-	}
 }
 
 static void ssif_remove(struct i2c_client *client)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 6.6.y 2/2] ipmi:ssif: Clean up kthread on errors
  2026-05-01 14:06 ` [PATCH 6.6.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
@ 2026-05-01 14:06   ` Corey Minyard
  0 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-01 14:06 UTC (permalink / raw)
  To: stable; +Cc: Corey Minyard, Li Xiao

If an error occurs after the ssif kthread is created, but before the
main IPMI code starts the ssif interface, the ssif kthread will not
be stopped.

So make sure the kthread is stopped on an error condition if it is
running.

Fixes: 259307074bfc ("ipmi: Add SMBus interface driver (SSIF)")
Reported-by: Li Xiao <<252270051@hdu.edu.cn>
Cc: stable@vger.kernel.org
Reviewed-by: Li Xiao <252270051@hdu.edu.cn>
Signed-off-by: Corey Minyard <corey@minyard.net>
(cherry picked from commit 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4)
---
 drivers/char/ipmi/ipmi_ssif.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index 3c4aa87d6bd4..6665cf1891b8 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1268,8 +1268,10 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	del_timer_sync(&ssif_info->watch_timer);
 	del_timer_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread)
+	if (ssif_info->thread) {
 		kthread_stop(ssif_info->thread);
+		ssif_info->thread = NULL;
+	}
 }
 
 static void ssif_remove(struct i2c_client *client)
@@ -1894,6 +1896,15 @@ static int ssif_probe(struct i2c_client *client)
 
  out:
 	if (rv) {
+		/*
+		 * If ipmi_register_smi() starts the interface, it will
+		 * call shutdown and that will free the thread and set
+		 * it to NULL.  Otherwise it must be freed here.
+		 */
+		if (ssif_info->thread) {
+			kthread_stop(ssif_info->thread);
+			ssif_info->thread = NULL;
+		}
 		if (addr_info)
 			addr_info->client = NULL;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 6.1.y 1/2] ipmi:ssif: Fix a shutdown race
  2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 6.1-stable tree gregkh
@ 2026-05-01 14:19 ` Corey Minyard
  2026-05-01 14:19   ` [PATCH 6.1.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
  0 siblings, 1 reply; 35+ messages in thread
From: Corey Minyard @ 2026-05-01 14:19 UTC (permalink / raw)
  To: stable; +Cc: Corey Minyard, Corey Minyard

It was possible for the SSIF thread to stop and quit before the
kthread_stop() call because ssif->stopping was set before the
stop.  So only exit the SSIF thread is kthread_should_stop()
returns true.

There is no need to wake the thread, as the wait will be interrupted
by kthread_stop().

Signed-off-by: Corey Minyard <cminyard@mvista.com>
(cherry picked from commit 6bd0eb6d759b9a22c5509ea04e19c2e8407ba418)
---
 drivers/char/ipmi/ipmi_ssif.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index 248459f97c67..fbc870ffff6a 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -481,8 +481,6 @@ static int ipmi_ssif_thread(void *data)
 		/* Wait for something to do */
 		result = wait_for_completion_interruptible(
 						&ssif_info->wake_thread);
-		if (ssif_info->stopping)
-			break;
 		if (result == -ERESTARTSYS)
 			continue;
 		init_completion(&ssif_info->wake_thread);
@@ -1270,10 +1268,8 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	del_timer_sync(&ssif_info->watch_timer);
 	del_timer_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread) {
-		complete(&ssif_info->wake_thread);
+	if (ssif_info->thread)
 		kthread_stop(ssif_info->thread);
-	}
 }
 
 static void ssif_remove(struct i2c_client *client)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 6.1.y 2/2] ipmi:ssif: Clean up kthread on errors
  2026-05-01 14:19 ` [PATCH 6.1.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
@ 2026-05-01 14:19   ` Corey Minyard
  0 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-01 14:19 UTC (permalink / raw)
  To: stable; +Cc: Corey Minyard, Li Xiao

If an error occurs after the ssif kthread is created, but before the
main IPMI code starts the ssif interface, the ssif kthread will not
be stopped.

So make sure the kthread is stopped on an error condition if it is
running.

Fixes: 259307074bfc ("ipmi: Add SMBus interface driver (SSIF)")
Reported-by: Li Xiao <<252270051@hdu.edu.cn>
Cc: stable@vger.kernel.org
Reviewed-by: Li Xiao <252270051@hdu.edu.cn>
Signed-off-by: Corey Minyard <corey@minyard.net>
(cherry picked from commit 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4)
---
 drivers/char/ipmi/ipmi_ssif.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index fbc870ffff6a..4d68c7a451ba 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1268,8 +1268,10 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	del_timer_sync(&ssif_info->watch_timer);
 	del_timer_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread)
+	if (ssif_info->thread) {
 		kthread_stop(ssif_info->thread);
+		ssif_info->thread = NULL;
+	}
 }
 
 static void ssif_remove(struct i2c_client *client)
@@ -1897,6 +1899,15 @@ static int ssif_probe(struct i2c_client *client)
 
  out:
 	if (rv) {
+		/*
+		 * If ipmi_register_smi() starts the interface, it will
+		 * call shutdown and that will free the thread and set
+		 * it to NULL.  Otherwise it must be freed here.
+		 */
+		if (ssif_info->thread) {
+			kthread_stop(ssif_info->thread);
+			ssif_info->thread = NULL;
+		}
 		if (addr_info)
 			addr_info->client = NULL;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 5.15.y 1/2] ipmi:ssif: Fix a shutdown race
  2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 5.15-stable tree gregkh
@ 2026-05-01 14:27 ` Corey Minyard
  2026-05-01 14:27   ` [PATCH 5.15.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
  2026-05-01 16:11 ` [PATCH 5.15.y] ipmi:ssif: Fix a thread shutdown issue Corey Minyard
  2026-05-06  2:18 ` [PATCH 5.15.y] ipmi:ssif: Clean up kthread on errors Corey Minyard
  2 siblings, 1 reply; 35+ messages in thread
From: Corey Minyard @ 2026-05-01 14:27 UTC (permalink / raw)
  To: stable; +Cc: Corey Minyard, Corey Minyard

It was possible for the SSIF thread to stop and quit before the
kthread_stop() call because ssif->stopping was set before the
stop.  So only exit the SSIF thread is kthread_should_stop()
returns true.

There is no need to wake the thread, as the wait will be interrupted
by kthread_stop().

Signed-off-by: Corey Minyard <cminyard@mvista.com>
(cherry picked from commit 6bd0eb6d759b9a22c5509ea04e19c2e8407ba418)
---
 drivers/char/ipmi/ipmi_ssif.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index 30f757249c5c..22074f23c06a 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -487,8 +487,6 @@ static int ipmi_ssif_thread(void *data)
 		/* Wait for something to do */
 		result = wait_for_completion_interruptible(
 						&ssif_info->wake_thread);
-		if (ssif_info->stopping)
-			break;
 		if (result == -ERESTARTSYS)
 			continue;
 		init_completion(&ssif_info->wake_thread);
@@ -1279,10 +1277,8 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	del_timer_sync(&ssif_info->watch_timer);
 	del_timer_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread) {
-		complete(&ssif_info->wake_thread);
+	if (ssif_info->thread)
 		kthread_stop(ssif_info->thread);
-	}
 }
 
 static int ssif_remove(struct i2c_client *client)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 5.15.y 2/2] ipmi:ssif: Clean up kthread on errors
  2026-05-01 14:27 ` [PATCH 5.15.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
@ 2026-05-01 14:27   ` Corey Minyard
  0 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-01 14:27 UTC (permalink / raw)
  To: stable; +Cc: Corey Minyard, Li Xiao

If an error occurs after the ssif kthread is created, but before the
main IPMI code starts the ssif interface, the ssif kthread will not
be stopped.

So make sure the kthread is stopped on an error condition if it is
running.

Fixes: 259307074bfc ("ipmi: Add SMBus interface driver (SSIF)")
Reported-by: Li Xiao <<252270051@hdu.edu.cn>
Cc: stable@vger.kernel.org
Reviewed-by: Li Xiao <252270051@hdu.edu.cn>
Signed-off-by: Corey Minyard <corey@minyard.net>
(cherry picked from commit 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4)
---
 drivers/char/ipmi/ipmi_ssif.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index 22074f23c06a..ce0f20cac88d 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1277,8 +1277,10 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	del_timer_sync(&ssif_info->watch_timer);
 	del_timer_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread)
+	if (ssif_info->thread) {
 		kthread_stop(ssif_info->thread);
+		ssif_info->thread = NULL;
+	}
 }
 
 static int ssif_remove(struct i2c_client *client)
@@ -1908,6 +1910,15 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
 
  out:
 	if (rv) {
+		/*
+		 * If ipmi_register_smi() starts the interface, it will
+		 * call shutdown and that will free the thread and set
+		 * it to NULL.  Otherwise it must be freed here.
+		 */
+		if (ssif_info->thread) {
+			kthread_stop(ssif_info->thread);
+			ssif_info->thread = NULL;
+		}
 		if (addr_info)
 			addr_info->client = NULL;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 5.10.y 1/2] ipmi:ssif: Fix a shutdown race
  2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 5.10-stable tree gregkh
@ 2026-05-01 14:54 ` Corey Minyard
  2026-05-01 14:54   ` [PATCH 5.10.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
  2026-05-01 16:20 ` [PATCH 5.10.y] ipmi:ssif: Fix a thread shutdown issue Corey Minyard
  2026-05-06  2:20 ` [PATCH 5.10.y] ipmi:ssif: Clean up kthread on errors Corey Minyard
  2 siblings, 1 reply; 35+ messages in thread
From: Corey Minyard @ 2026-05-01 14:54 UTC (permalink / raw)
  To: stable; +Cc: Corey Minyard, Corey Minyard

It was possible for the SSIF thread to stop and quit before the
kthread_stop() call because ssif->stopping was set before the
stop.  So only exit the SSIF thread is kthread_should_stop()
returns true.

There is no need to wake the thread, as the wait will be interrupted
by kthread_stop().

Signed-off-by: Corey Minyard <cminyard@mvista.com>
(cherry picked from commit 6bd0eb6d759b9a22c5509ea04e19c2e8407ba418)
---
 drivers/char/ipmi/ipmi_ssif.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index 30f757249c5c..22074f23c06a 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -487,8 +487,6 @@ static int ipmi_ssif_thread(void *data)
 		/* Wait for something to do */
 		result = wait_for_completion_interruptible(
 						&ssif_info->wake_thread);
-		if (ssif_info->stopping)
-			break;
 		if (result == -ERESTARTSYS)
 			continue;
 		init_completion(&ssif_info->wake_thread);
@@ -1279,10 +1277,8 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	del_timer_sync(&ssif_info->watch_timer);
 	del_timer_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread) {
-		complete(&ssif_info->wake_thread);
+	if (ssif_info->thread)
 		kthread_stop(ssif_info->thread);
-	}
 }
 
 static int ssif_remove(struct i2c_client *client)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 5.10.y 2/2] ipmi:ssif: Clean up kthread on errors
  2026-05-01 14:54 ` [PATCH 5.10.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
@ 2026-05-01 14:54   ` Corey Minyard
  0 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-01 14:54 UTC (permalink / raw)
  To: stable; +Cc: Corey Minyard, Li Xiao

If an error occurs after the ssif kthread is created, but before the
main IPMI code starts the ssif interface, the ssif kthread will not
be stopped.

So make sure the kthread is stopped on an error condition if it is
running.

Fixes: 259307074bfc ("ipmi: Add SMBus interface driver (SSIF)")
Reported-by: Li Xiao <<252270051@hdu.edu.cn>
Cc: stable@vger.kernel.org
Reviewed-by: Li Xiao <252270051@hdu.edu.cn>
Signed-off-by: Corey Minyard <corey@minyard.net>
(cherry picked from commit 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4)
---
 drivers/char/ipmi/ipmi_ssif.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index 22074f23c06a..ce0f20cac88d 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1277,8 +1277,10 @@ static void shutdown_ssif(void *send_info)
 	ssif_info->stopping = true;
 	del_timer_sync(&ssif_info->watch_timer);
 	del_timer_sync(&ssif_info->retry_timer);
-	if (ssif_info->thread)
+	if (ssif_info->thread) {
 		kthread_stop(ssif_info->thread);
+		ssif_info->thread = NULL;
+	}
 }
 
 static int ssif_remove(struct i2c_client *client)
@@ -1908,6 +1910,15 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
 
  out:
 	if (rv) {
+		/*
+		 * If ipmi_register_smi() starts the interface, it will
+		 * call shutdown and that will free the thread and set
+		 * it to NULL.  Otherwise it must be freed here.
+		 */
+		if (ssif_info->thread) {
+			kthread_stop(ssif_info->thread);
+			ssif_info->thread = NULL;
+		}
 		if (addr_info)
 			addr_info->client = NULL;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 5.15.y] ipmi:ssif: Fix a thread shutdown issue
  2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 5.15-stable tree gregkh
  2026-05-01 14:27 ` [PATCH 5.15.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
@ 2026-05-01 16:11 ` Corey Minyard
  2026-05-06  2:18 ` [PATCH 5.15.y] ipmi:ssif: Clean up kthread on errors Corey Minyard
  2 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-01 16:11 UTC (permalink / raw)
  To: stable; +Cc: Corey Minyard

The kthread used by ssif had a shutdown issue that was fixed by
6bd0eb6d759b ("ipmi:ssif: Fix a shutdown race").  That was backported to
an older kernel in the process of fixing another issue,
2105b70be84d ("ipmi:ssif: Clean up kthread on errors") as it would
not have worked correctly without the shutdown race fix.

Kernel version 6.1 has a fix to kthread stop to cause interruptible
waits to return -ERESTARTSYS on a stop.  This has not been backported
to older kernels, and that would probably be a bad idea.  But not
having this means that the completion in the SSIF driver will
not wake up on kthread_stop(), thus the driver hangs on unload.

We can't cause the interrupt before calling kthread_stop() because
the task stop bit need to be set before causing the interrupt.

So re-introduce the code removed by 6bd0eb6d759b ("ipmi:ssif: Fix a
shutdown race") but add a wait at the end of the thread so it
doesn't exit until kthread_should_stop() is set.

Fixes: 6bd0eb6d759b ("ipmi:ssif: Fix a shutdown race")
Signed-off-by: Corey Minyard <corey@minyard.net>
---
I realized I hadn't done an unload test on this on the older kernels.
But why wouldn't that work?  Well, it didn't.  One more patch for this
on top of the previous two.  Sorry :(.


 drivers/char/ipmi/ipmi_ssif.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index ce0f20cac88d..b884bfae7fa6 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -487,6 +487,8 @@ static int ipmi_ssif_thread(void *data)
 		/* Wait for something to do */
 		result = wait_for_completion_interruptible(
 						&ssif_info->wake_thread);
+		if (ssif_info->stopping)
+			break;
 		if (result == -ERESTARTSYS)
 			continue;
 		init_completion(&ssif_info->wake_thread);
@@ -511,6 +513,16 @@ static int ipmi_ssif_thread(void *data)
 		}
 	}
 
+	/*
+	 * The thread can break out of the loop if stopping is set,
+	 * and this can be before kthread_stop() gets called and thus
+	 * kthread_should_stop() will not be set.  This can cause
+	 * spinning calling this function and other bad things.  So
+	 * wait for kthread_should_stop() to be set.
+	 */
+	while (!kthread_should_stop())
+		msleep_interruptible(1);
+
 	return 0;
 }
 
@@ -1278,6 +1290,7 @@ static void shutdown_ssif(void *send_info)
 	del_timer_sync(&ssif_info->watch_timer);
 	del_timer_sync(&ssif_info->retry_timer);
 	if (ssif_info->thread) {
+		complete(&ssif_info->wake_thread);
 		kthread_stop(ssif_info->thread);
 		ssif_info->thread = NULL;
 	}
@@ -1916,6 +1929,8 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
 		 * it to NULL.  Otherwise it must be freed here.
 		 */
 		if (ssif_info->thread) {
+			ssif_info->stopping = true;
+			complete(&ssif_info->wake_thread);
 			kthread_stop(ssif_info->thread);
 			ssif_info->thread = NULL;
 		}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 5.10.y] ipmi:ssif: Fix a thread shutdown issue
  2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 5.10-stable tree gregkh
  2026-05-01 14:54 ` [PATCH 5.10.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
@ 2026-05-01 16:20 ` Corey Minyard
  2026-05-06  2:20 ` [PATCH 5.10.y] ipmi:ssif: Clean up kthread on errors Corey Minyard
  2 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-01 16:20 UTC (permalink / raw)
  To: stable; +Cc: Corey Minyard

The kthread used by ssif had a shutdown issue that was fixed by
6bd0eb6d759b ("ipmi:ssif: Fix a shutdown race").  That was backported to
an older kernel in the process of fixing another issue,
2105b70be84d ("ipmi:ssif: Clean up kthread on errors") as it would
not have worked correctly without the shutdown race fix.

Kernel version 6.1 has a fix to kthread stop to cause interruptible
waits to return -ERESTARTSYS on a stop.  This has not been backported
to older kernels, and that would probably be a bad idea.  But not
having this means that the completion in the SSIF driver will
not wake up on kthread_stop(), thus the driver hangs on unload.

We can't cause the interrupt before calling kthread_stop() because
the task stop bit need to be set before causing the interrupt.

So re-introduce the code removed by 6bd0eb6d759b ("ipmi:ssif: Fix a
shutdown race") but add a wait at the end of the thread so it
doesn't exit until kthread_should_stop() is set.

Fixes: 6bd0eb6d759b ("ipmi:ssif: Fix a shutdown race")
Signed-off-by: Corey Minyard <corey@minyard.net>
---
I realized I hadn't done an unload test on this on the older kernels.
But why wouldn't that work?  Well, it didn't.  One more patch for this
on top of the previous two.  Sorry :(.

 drivers/char/ipmi/ipmi_ssif.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index ce0f20cac88d..b884bfae7fa6 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -487,6 +487,8 @@ static int ipmi_ssif_thread(void *data)
 		/* Wait for something to do */
 		result = wait_for_completion_interruptible(
 						&ssif_info->wake_thread);
+		if (ssif_info->stopping)
+			break;
 		if (result == -ERESTARTSYS)
 			continue;
 		init_completion(&ssif_info->wake_thread);
@@ -511,6 +513,16 @@ static int ipmi_ssif_thread(void *data)
 		}
 	}
 
+	/*
+	 * The thread can break out of the loop if stopping is set,
+	 * and this can be before kthread_stop() gets called and thus
+	 * kthread_should_stop() will not be set.  This can cause
+	 * spinning calling this function and other bad things.  So
+	 * wait for kthread_should_stop() to be set.
+	 */
+	while (!kthread_should_stop())
+		msleep_interruptible(1);
+
 	return 0;
 }
 
@@ -1278,6 +1290,7 @@ static void shutdown_ssif(void *send_info)
 	del_timer_sync(&ssif_info->watch_timer);
 	del_timer_sync(&ssif_info->retry_timer);
 	if (ssif_info->thread) {
+		complete(&ssif_info->wake_thread);
 		kthread_stop(ssif_info->thread);
 		ssif_info->thread = NULL;
 	}
@@ -1916,6 +1929,8 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
 		 * it to NULL.  Otherwise it must be freed here.
 		 */
 		if (ssif_info->thread) {
+			ssif_info->stopping = true;
+			complete(&ssif_info->wake_thread);
 			kthread_stop(ssif_info->thread);
 			ssif_info->thread = NULL;
 		}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH 6.12.y/6.6.y/6.1.y/5.15.y/5.10.y 1-2/2] ipmi:ssif: shutdown race + kthread cleanup
  2026-05-01 13:56 ` [PATCH 6.12.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
  2026-05-01 13:56   ` [PATCH 6.12.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
@ 2026-05-03 18:19   ` Sasha Levin
  2026-05-04 11:04     ` Corey Minyard
  1 sibling, 1 reply; 35+ messages in thread
From: Sasha Levin @ 2026-05-03 18:19 UTC (permalink / raw)
  To: Corey Minyard; +Cc: Corey Minyard, stable

Hi Corey,

I queued the 2-patch series across 6.12.y / 6.6.y / 6.1.y / 5.15.y /
5.10.y but had to drop them all again before pushing to stable-queue.

Patch 2/2 (cherry-pick of upstream 75c486cb1bca, "ipmi:ssif: Clean up
kthread on errors") has a real bug in upstream itself: in ssif_probe()'s
out: label,

	if (ssif_info->thread)
		kthread_stop(ssif_info->thread);

runs even when kthread_run() failed, in which case ssif_info->thread is
an ERR_PTR rather than NULL, so kthread_stop() ends up being called on
an error pointer. The check needs to be IS_ERR_OR_NULL(), or
ssif_info->thread needs to be reset to NULL on the kthread_run() error
path before goto out.

The same upstream bug propagates to all five LTS submissions, so I had
to drop them all rather than just the older trees. Could you send a
fixed version (an upstream follow-up that flips through the LTS trees
would be ideal)?

For 5.15 and 5.10 specifically, I'd also like to fold in your standalone
"ipmi:ssif: Fix a thread shutdown issue" follow-up
(<20260501161407.1106914-1-corey@minyard.net> for 5.15,
<20260501162131.1165570-1-corey@minyard.net> for 5.10) when you resend.
Those branches lack the kthread_stop ERESTARTSYS behaviour that 6.1+
has, and your follow-up addresses exactly that. A 3-patch series for
5.15/5.10 (plus the 2-patch series for 6.12/6.6/6.1) with the ERR_PTR
fix folded in would let me requeue the whole set in one pass.

--
Thanks,
Sasha

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 6.12.y/6.6.y/6.1.y/5.15.y/5.10.y 1-2/2] ipmi:ssif: shutdown race + kthread cleanup
  2026-05-03 18:19   ` [PATCH 6.12.y/6.6.y/6.1.y/5.15.y/5.10.y 1-2/2] ipmi:ssif: shutdown race + kthread cleanup Sasha Levin
@ 2026-05-04 11:04     ` Corey Minyard
  0 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-04 11:04 UTC (permalink / raw)
  To: Sasha Levin; +Cc: Corey Minyard, stable

On Sun, May 03, 2026 at 02:19:56PM -0400, Sasha Levin wrote:
> Hi Corey,
> 
> I queued the 2-patch series across 6.12.y / 6.6.y / 6.1.y / 5.15.y /
> 5.10.y but had to drop them all again before pushing to stable-queue.
> 
> Patch 2/2 (cherry-pick of upstream 75c486cb1bca, "ipmi:ssif: Clean up
> kthread on errors") has a real bug in upstream itself: in ssif_probe()'s
> out: label,
> 
> 	if (ssif_info->thread)
> 		kthread_stop(ssif_info->thread);
> 
> runs even when kthread_run() failed, in which case ssif_info->thread is
> an ERR_PTR rather than NULL, so kthread_stop() ends up being called on
> an error pointer. The check needs to be IS_ERR_OR_NULL(), or
> ssif_info->thread needs to be reset to NULL on the kthread_run() error
> path before goto out.
> 
> The same upstream bug propagates to all five LTS submissions, so I had
> to drop them all rather than just the older trees. Could you send a
> fixed version (an upstream follow-up that flips through the LTS trees
> would be ideal)?

There is already a fix for this queued in the next tree that I was about
to submit.  Fixing it here would add to the confusion.

> 
> For 5.15 and 5.10 specifically, I'd also like to fold in your standalone
> "ipmi:ssif: Fix a thread shutdown issue" follow-up
> (<20260501161407.1106914-1-corey@minyard.net> for 5.15,
> <20260501162131.1165570-1-corey@minyard.net> for 5.10) when you resend.
> Those branches lack the kthread_stop ERESTARTSYS behaviour that 6.1+
> has, and your follow-up addresses exactly that. A 3-patch series for
> 5.15/5.10 (plus the 2-patch series for 6.12/6.6/6.1) with the ERR_PTR
> fix folded in would let me requeue the whole set in one pass.

Ok, I'll fold that in to 5.10 and 5.15 as you request, that makes sense.

Can you add the 6.1/6.6/6.12 ones as they are and I'll submit the queue
to fix I have to Linus?

-corey

> 
> --
> Thanks,
> Sasha

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 5.15.y] ipmi:ssif: Clean up kthread on errors
  2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 5.15-stable tree gregkh
  2026-05-01 14:27 ` [PATCH 5.15.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
  2026-05-01 16:11 ` [PATCH 5.15.y] ipmi:ssif: Fix a thread shutdown issue Corey Minyard
@ 2026-05-06  2:18 ` Corey Minyard
  2026-05-09 12:46   ` Sasha Levin
  2 siblings, 1 reply; 35+ messages in thread
From: Corey Minyard @ 2026-05-06  2:18 UTC (permalink / raw)
  To: stable; +Cc: Corey Minyard, Li Xiao

If an error occurs after the ssif kthread is created, but before the
main IPMI code starts the ssif interface, the ssif kthread will not
be stopped.

So make sure the kthread is stopped on an error condition if it is
running.

Fixes: 259307074bfc ("ipmi: Add SMBus interface driver (SSIF)")
Reported-by: Li Xiao <<252270051@hdu.edu.cn>
Cc: stable@vger.kernel.org
Reviewed-by: Li Xiao <252270051@hdu.edu.cn>
[Adjusted for stopping flag and complete operation still being present.]
Signed-off-by: Corey Minyard <corey@minyard.net>
(cherry picked from commit 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4)
---
Version 2 of this patch, not taking a patch and then doing the fix
for it later, but just doing the patch.  The fix for setting the
thread to NULL on an ERR_PTR() error return is already in the main
kernel and should be coming to stable.

 drivers/char/ipmi/ipmi_ssif.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index 430302d2da6e..b884bfae7fa6 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1292,6 +1292,7 @@ static void shutdown_ssif(void *send_info)
 	if (ssif_info->thread) {
 		complete(&ssif_info->wake_thread);
 		kthread_stop(ssif_info->thread);
+		ssif_info->thread = NULL;
 	}
 }
 
@@ -1922,6 +1923,17 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
 
  out:
 	if (rv) {
+		/*
+		 * If ipmi_register_smi() starts the interface, it will
+		 * call shutdown and that will free the thread and set
+		 * it to NULL.  Otherwise it must be freed here.
+		 */
+		if (ssif_info->thread) {
+			ssif_info->stopping = true;
+			complete(&ssif_info->wake_thread);
+			kthread_stop(ssif_info->thread);
+			ssif_info->thread = NULL;
+		}
 		if (addr_info)
 			addr_info->client = NULL;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 5.10.y] ipmi:ssif: Clean up kthread on errors
  2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 5.10-stable tree gregkh
  2026-05-01 14:54 ` [PATCH 5.10.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
  2026-05-01 16:20 ` [PATCH 5.10.y] ipmi:ssif: Fix a thread shutdown issue Corey Minyard
@ 2026-05-06  2:20 ` Corey Minyard
  2 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-06  2:20 UTC (permalink / raw)
  To: stable; +Cc: Corey Minyard, Li Xiao

If an error occurs after the ssif kthread is created, but before the
main IPMI code starts the ssif interface, the ssif kthread will not
be stopped.

So make sure the kthread is stopped on an error condition if it is
running.

Fixes: 259307074bfc ("ipmi: Add SMBus interface driver (SSIF)")
Reported-by: Li Xiao <<252270051@hdu.edu.cn>
Cc: stable@vger.kernel.org
Reviewed-by: Li Xiao <252270051@hdu.edu.cn>
[Adjusted for stopping flag and complete operation still being present.]
Signed-off-by: Corey Minyard <corey@minyard.net>
(cherry picked from commit 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4)
---
Version 2 of this patch, not taking a patch and then doing the fix
for it later, but just doing the patch.  The fix for setting the
thread to NULL on an ERR_PTR() error return is already in the main
kernel and should be coming to stable.

 drivers/char/ipmi/ipmi_ssif.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index 430302d2da6e..b884bfae7fa6 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1292,6 +1292,7 @@ static void shutdown_ssif(void *send_info)
 	if (ssif_info->thread) {
 		complete(&ssif_info->wake_thread);
 		kthread_stop(ssif_info->thread);
+		ssif_info->thread = NULL;
 	}
 }
 
@@ -1922,6 +1923,17 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
 
  out:
 	if (rv) {
+		/*
+		 * If ipmi_register_smi() starts the interface, it will
+		 * call shutdown and that will free the thread and set
+		 * it to NULL.  Otherwise it must be freed here.
+		 */
+		if (ssif_info->thread) {
+			ssif_info->stopping = true;
+			complete(&ssif_info->wake_thread);
+			kthread_stop(ssif_info->thread);
+			ssif_info->thread = NULL;
+		}
 		if (addr_info)
 			addr_info->client = NULL;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH 5.15.y] ipmi:ssif: Clean up kthread on errors
  2026-05-06  2:18 ` [PATCH 5.15.y] ipmi:ssif: Clean up kthread on errors Corey Minyard
@ 2026-05-09 12:46   ` Sasha Levin
  2026-05-11 13:09     ` [PATCH 5.15.y v3 0/4] Fix error in IPMI SSIF shutdown Corey Minyard
  2026-05-11 13:19     ` [PATCH 5.10.y v3 1/4] " Corey Minyard
  0 siblings, 2 replies; 35+ messages in thread
From: Sasha Levin @ 2026-05-09 12:46 UTC (permalink / raw)
  To: stable; +Cc: Sasha Levin, Corey Minyard, Li Xiao

> [PATCH 5.15.y] ipmi:ssif: Clean up kthread on errors

Thanks for the explicit backports. I'm holding both the 5.15.y and
5.10.y submissions for now.

The folded v2 here calls complete(&ssif_info->wake_thread) before
kthread_stop and sets stopping=true on the error path, which folds
in the fix from upstream a8aebe93a493 ("ipmi:ssif: NULL thread on
error"). However, a8aebe93a493 itself is not yet in 5.15.y or 5.10.y
either, and given how the two upstream commits interact I'd rather not
take the folded form without that follow-up landed first via the
normal route. Could you also send 5.15.y/5.10.y backports of
a8aebe93a493?

--
Sasha

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 5.15.y v3 0/4] Fix error in IPMI SSIF shutdown
  2026-05-09 12:46   ` Sasha Levin
@ 2026-05-11 13:09     ` Corey Minyard
  2026-05-11 13:09       ` [PATCH 5.15.y v3 1/4] ipmi:ssif: Fix a shutdown race Corey Minyard
                         ` (4 more replies)
  2026-05-11 13:19     ` [PATCH 5.10.y v3 1/4] " Corey Minyard
  1 sibling, 5 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-11 13:09 UTC (permalink / raw)
  To: Sasha Levin, stable; +Cc: Li Xiao

This is a backport of 75c486cb1bca ("ipmi:ssif: Clean up kthread on
errors") and other necessary patches with it.

Version 2: Don't take the "ipmi:ssif: Fix a shutdown race" and then
remove it and fix it later.  Just do the fix.

Version 3: Include a8aebe93a493 ("ipmi:ssif: NULL thread on error")
in the patch set.


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 5.15.y v3 1/4] ipmi:ssif: Fix a shutdown race
  2026-05-11 13:09     ` [PATCH 5.15.y v3 0/4] Fix error in IPMI SSIF shutdown Corey Minyard
@ 2026-05-11 13:09       ` Corey Minyard
  2026-05-11 13:09       ` [PATCH 5.15.y v3 2/4] ipmi:ssif: Clean up kthread on errors Corey Minyard
                         ` (3 subsequent siblings)
  4 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-11 13:09 UTC (permalink / raw)
  To: Sasha Levin, stable; +Cc: Li Xiao, Corey Minyard, Corey Minyard

It was possible for the SSIF thread to stop and quit before the
kthread_stop() call because ssif->stopping was set before the
stop.  So only exit the SSIF thread is kthread_should_stop()
returns true.

In the mainstream kernel this was fixed in 6bd0eb6d759b ("ipmi:ssif:
Fix a shutdown race").  However, that requires a fix in kernel
version 6.1 has a fix to kthread stop to cause interruptible waits
to return -ERESTARTSYS on a stop.  This has not been backported to
older kernels, and that would probably be a bad idea.  But it means
that the mainstrem kernel fix for this will not work.

Instead, wait for kthread_should_stop() to return true before exiting
the thread.

Signed-off-by: Corey Minyard <cminyard@mvista.com>
---
 drivers/char/ipmi/ipmi_ssif.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index 30f757249c5c..430302d2da6e 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -513,6 +513,16 @@ static int ipmi_ssif_thread(void *data)
 		}
 	}
 
+	/*
+	 * The thread can break out of the loop if stopping is set,
+	 * and this can be before kthread_stop() gets called and thus
+	 * kthread_should_stop() will not be set.  This can cause
+	 * spinning calling this function and other bad things.  So
+	 * wait for kthread_should_stop() to be set.
+	 */
+	while (!kthread_should_stop())
+		msleep_interruptible(1);
+
 	return 0;
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 5.15.y v3 2/4] ipmi:ssif: Clean up kthread on errors
  2026-05-11 13:09     ` [PATCH 5.15.y v3 0/4] Fix error in IPMI SSIF shutdown Corey Minyard
  2026-05-11 13:09       ` [PATCH 5.15.y v3 1/4] ipmi:ssif: Fix a shutdown race Corey Minyard
@ 2026-05-11 13:09       ` Corey Minyard
  2026-05-11 13:09       ` [PATCH 5.15.y v3 3/4] ipmi:ssif: Remove unnecessary indention Corey Minyard
                         ` (2 subsequent siblings)
  4 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-11 13:09 UTC (permalink / raw)
  To: Sasha Levin, stable; +Cc: Li Xiao, Corey Minyard

If an error occurs after the ssif kthread is created, but before the
main IPMI code starts the ssif interface, the ssif kthread will not
be stopped.

So make sure the kthread is stopped on an error condition if it is
running.

Fixes: 259307074bfc ("ipmi: Add SMBus interface driver (SSIF)")
Reported-by: Li Xiao <<252270051@hdu.edu.cn>
Cc: stable@vger.kernel.org
Reviewed-by: Li Xiao <252270051@hdu.edu.cn>
[Adjusted for stopping flag and complete operation still being present.]
Signed-off-by: Corey Minyard <corey@minyard.net>
(cherry picked from commit 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4)
---
 drivers/char/ipmi/ipmi_ssif.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index 430302d2da6e..b884bfae7fa6 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1292,6 +1292,7 @@ static void shutdown_ssif(void *send_info)
 	if (ssif_info->thread) {
 		complete(&ssif_info->wake_thread);
 		kthread_stop(ssif_info->thread);
+		ssif_info->thread = NULL;
 	}
 }
 
@@ -1922,6 +1923,17 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
 
  out:
 	if (rv) {
+		/*
+		 * If ipmi_register_smi() starts the interface, it will
+		 * call shutdown and that will free the thread and set
+		 * it to NULL.  Otherwise it must be freed here.
+		 */
+		if (ssif_info->thread) {
+			ssif_info->stopping = true;
+			complete(&ssif_info->wake_thread);
+			kthread_stop(ssif_info->thread);
+			ssif_info->thread = NULL;
+		}
 		if (addr_info)
 			addr_info->client = NULL;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 5.15.y v3 3/4] ipmi:ssif: Remove unnecessary indention
  2026-05-11 13:09     ` [PATCH 5.15.y v3 0/4] Fix error in IPMI SSIF shutdown Corey Minyard
  2026-05-11 13:09       ` [PATCH 5.15.y v3 1/4] ipmi:ssif: Fix a shutdown race Corey Minyard
  2026-05-11 13:09       ` [PATCH 5.15.y v3 2/4] ipmi:ssif: Clean up kthread on errors Corey Minyard
@ 2026-05-11 13:09       ` Corey Minyard
  2026-05-11 13:09       ` [PATCH 5.15.y v3 4/4] ipmi:ssif: NULL thread on error Corey Minyard
  2026-05-12  0:17       ` [PATCH 5.15.y v3 0/4] Fix error in IPMI SSIF shutdown Sasha Levin
  4 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-11 13:09 UTC (permalink / raw)
  To: Sasha Levin, stable; +Cc: Li Xiao, Corey Minyard

A section was in {} that didn't need to be, move the variable
definition to the top and set th eindentino properly.

Signed-off-by: Corey Minyard <corey@minyard.net>
---
 drivers/char/ipmi/ipmi_ssif.c | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index b884bfae7fa6..c973c0d92319 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1675,6 +1675,7 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	int               len;
 	int               i;
 	u8		  slave_addr = 0;
+	unsigned int      thread_num;
 	struct ssif_addr_info *addr_info = NULL;
 
 	mutex_lock(&ssif_infos_mutex);
@@ -1883,22 +1884,17 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	ssif_info->handlers.request_events = request_events;
 	ssif_info->handlers.set_need_watch = ssif_set_need_watch;
 
-	{
-		unsigned int thread_num;
-
-		thread_num = ((i2c_adapter_id(ssif_info->client->adapter)
-			       << 8) |
-			      ssif_info->client->addr);
-		init_completion(&ssif_info->wake_thread);
-		ssif_info->thread = kthread_run(ipmi_ssif_thread, ssif_info,
-					       "kssif%4.4x", thread_num);
-		if (IS_ERR(ssif_info->thread)) {
-			rv = PTR_ERR(ssif_info->thread);
-			dev_notice(&ssif_info->client->dev,
-				   "Could not start kernel thread: error %d\n",
-				   rv);
-			goto out;
-		}
+	thread_num = ((i2c_adapter_id(ssif_info->client->adapter) << 8) |
+		      ssif_info->client->addr);
+	init_completion(&ssif_info->wake_thread);
+	ssif_info->thread = kthread_run(ipmi_ssif_thread, ssif_info,
+					"kssif%4.4x", thread_num);
+	if (IS_ERR(ssif_info->thread)) {
+		rv = PTR_ERR(ssif_info->thread);
+		dev_notice(&ssif_info->client->dev,
+			   "Could not start kernel thread: error %d\n",
+			   rv);
+		goto out;
 	}
 
 	dev_set_drvdata(&ssif_info->client->dev, ssif_info);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 5.15.y v3 4/4] ipmi:ssif: NULL thread on error
  2026-05-11 13:09     ` [PATCH 5.15.y v3 0/4] Fix error in IPMI SSIF shutdown Corey Minyard
                         ` (2 preceding siblings ...)
  2026-05-11 13:09       ` [PATCH 5.15.y v3 3/4] ipmi:ssif: Remove unnecessary indention Corey Minyard
@ 2026-05-11 13:09       ` Corey Minyard
  2026-05-12  0:17       ` [PATCH 5.15.y v3 0/4] Fix error in IPMI SSIF shutdown Sasha Levin
  4 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-11 13:09 UTC (permalink / raw)
  To: Sasha Levin, stable; +Cc: Li Xiao, Corey Minyard

Cleanup code was checking the thread for NULL, but it was possibly
a PTR_ERR() in one spot.

Spotted with static analysis.

Link: https://sourceforge.net/p/openipmi/mailman/message/59324676/
Fixes: 75c486cb1bca ("ipmi:ssif: Clean up kthread on errors")
Cc: <stable@vger.kernel.org> # 91eb7ec72612: ipmi:ssif: Remove unnecessary indention
Cc: stable@vger.kernel.org
Signed-off-by: Corey Minyard <corey@minyard.net>
---
 drivers/char/ipmi/ipmi_ssif.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index c973c0d92319..43c4863e7b03 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1891,6 +1891,7 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
 					"kssif%4.4x", thread_num);
 	if (IS_ERR(ssif_info->thread)) {
 		rv = PTR_ERR(ssif_info->thread);
+		ssif_info->thread = NULL;
 		dev_notice(&ssif_info->client->dev,
 			   "Could not start kernel thread: error %d\n",
 			   rv);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 5.10.y v3 1/4] Fix error in IPMI SSIF shutdown
  2026-05-09 12:46   ` Sasha Levin
  2026-05-11 13:09     ` [PATCH 5.15.y v3 0/4] Fix error in IPMI SSIF shutdown Corey Minyard
@ 2026-05-11 13:19     ` Corey Minyard
  2026-05-11 13:19       ` [PATCH 5.10.y v3 1/4] ipmi:ssif: Fix a shutdown race Corey Minyard
                         ` (4 more replies)
  1 sibling, 5 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-11 13:19 UTC (permalink / raw)
  To: Sasha Levin, stable; +Cc: Li Xiao

This is a backport of 75c486cb1bca ("ipmi:ssif: Clean up kthread on
errors") and other necessary patches with it.

Version 2: Don't take the "ipmi:ssif: Fix a shutdown race" and then
remove it and fix it later.  Just do the fix.

Version 3: Include a8aebe93a493 ("ipmi:ssif: NULL thread on error")
in the patch set.


^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH 5.10.y v3 1/4] ipmi:ssif: Fix a shutdown race
  2026-05-11 13:19     ` [PATCH 5.10.y v3 1/4] " Corey Minyard
@ 2026-05-11 13:19       ` Corey Minyard
  2026-05-11 13:19       ` [PATCH 5.10.y v3 2/4] ipmi:ssif: Clean up kthread on errors Corey Minyard
                         ` (3 subsequent siblings)
  4 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-11 13:19 UTC (permalink / raw)
  To: Sasha Levin, stable; +Cc: Li Xiao, Corey Minyard, Corey Minyard

It was possible for the SSIF thread to stop and quit before the
kthread_stop() call because ssif->stopping was set before the
stop.  So only exit the SSIF thread is kthread_should_stop()
returns true.

In the mainstream kernel this was fixed in 6bd0eb6d759b ("ipmi:ssif:
Fix a shutdown race").  However, that requires a fix in kernel
version 6.1 has a fix to kthread stop to cause interruptible waits
to return -ERESTARTSYS on a stop.  This has not been backported to
older kernels, and that would probably be a bad idea.  But it means
that the mainstrem kernel fix for this will not work.

Instead, wait for kthread_should_stop() to return true before exiting
the thread.

Signed-off-by: Corey Minyard <cminyard@mvista.com>
---
 drivers/char/ipmi/ipmi_ssif.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index 30f757249c5c..430302d2da6e 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -513,6 +513,16 @@ static int ipmi_ssif_thread(void *data)
 		}
 	}
 
+	/*
+	 * The thread can break out of the loop if stopping is set,
+	 * and this can be before kthread_stop() gets called and thus
+	 * kthread_should_stop() will not be set.  This can cause
+	 * spinning calling this function and other bad things.  So
+	 * wait for kthread_should_stop() to be set.
+	 */
+	while (!kthread_should_stop())
+		msleep_interruptible(1);
+
 	return 0;
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 5.10.y v3 2/4] ipmi:ssif: Clean up kthread on errors
  2026-05-11 13:19     ` [PATCH 5.10.y v3 1/4] " Corey Minyard
  2026-05-11 13:19       ` [PATCH 5.10.y v3 1/4] ipmi:ssif: Fix a shutdown race Corey Minyard
@ 2026-05-11 13:19       ` Corey Minyard
  2026-05-11 13:19       ` [PATCH 5.10.y v3 3/4] ipmi:ssif: Remove unnecessary indention Corey Minyard
                         ` (2 subsequent siblings)
  4 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-11 13:19 UTC (permalink / raw)
  To: Sasha Levin, stable; +Cc: Li Xiao, Corey Minyard

If an error occurs after the ssif kthread is created, but before the
main IPMI code starts the ssif interface, the ssif kthread will not
be stopped.

So make sure the kthread is stopped on an error condition if it is
running.

Fixes: 259307074bfc ("ipmi: Add SMBus interface driver (SSIF)")
Reported-by: Li Xiao <<252270051@hdu.edu.cn>
Cc: stable@vger.kernel.org
Reviewed-by: Li Xiao <252270051@hdu.edu.cn>
[Adjusted for stopping flag and complete operation still being present.]
Signed-off-by: Corey Minyard <corey@minyard.net>
(cherry picked from commit 75c486cb1bcaa1a3ec3a6438498176a3a4998ae4)
---
 drivers/char/ipmi/ipmi_ssif.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index 430302d2da6e..b884bfae7fa6 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1292,6 +1292,7 @@ static void shutdown_ssif(void *send_info)
 	if (ssif_info->thread) {
 		complete(&ssif_info->wake_thread);
 		kthread_stop(ssif_info->thread);
+		ssif_info->thread = NULL;
 	}
 }
 
@@ -1922,6 +1923,17 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
 
  out:
 	if (rv) {
+		/*
+		 * If ipmi_register_smi() starts the interface, it will
+		 * call shutdown and that will free the thread and set
+		 * it to NULL.  Otherwise it must be freed here.
+		 */
+		if (ssif_info->thread) {
+			ssif_info->stopping = true;
+			complete(&ssif_info->wake_thread);
+			kthread_stop(ssif_info->thread);
+			ssif_info->thread = NULL;
+		}
 		if (addr_info)
 			addr_info->client = NULL;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 5.10.y v3 3/4] ipmi:ssif: Remove unnecessary indention
  2026-05-11 13:19     ` [PATCH 5.10.y v3 1/4] " Corey Minyard
  2026-05-11 13:19       ` [PATCH 5.10.y v3 1/4] ipmi:ssif: Fix a shutdown race Corey Minyard
  2026-05-11 13:19       ` [PATCH 5.10.y v3 2/4] ipmi:ssif: Clean up kthread on errors Corey Minyard
@ 2026-05-11 13:19       ` Corey Minyard
  2026-05-11 13:19       ` [PATCH 5.10.y v3 4/4] ipmi:ssif: NULL thread on error Corey Minyard
  2026-05-12  0:17       ` [PATCH 5.10.y v3 1/4] Fix error in IPMI SSIF shutdown Sasha Levin
  4 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-11 13:19 UTC (permalink / raw)
  To: Sasha Levin, stable; +Cc: Li Xiao, Corey Minyard

A section was in {} that didn't need to be, move the variable
definition to the top and set th eindentino properly.

Signed-off-by: Corey Minyard <corey@minyard.net>
---
 drivers/char/ipmi/ipmi_ssif.c | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index b884bfae7fa6..c973c0d92319 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1675,6 +1675,7 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	int               len;
 	int               i;
 	u8		  slave_addr = 0;
+	unsigned int      thread_num;
 	struct ssif_addr_info *addr_info = NULL;
 
 	mutex_lock(&ssif_infos_mutex);
@@ -1883,22 +1884,17 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	ssif_info->handlers.request_events = request_events;
 	ssif_info->handlers.set_need_watch = ssif_set_need_watch;
 
-	{
-		unsigned int thread_num;
-
-		thread_num = ((i2c_adapter_id(ssif_info->client->adapter)
-			       << 8) |
-			      ssif_info->client->addr);
-		init_completion(&ssif_info->wake_thread);
-		ssif_info->thread = kthread_run(ipmi_ssif_thread, ssif_info,
-					       "kssif%4.4x", thread_num);
-		if (IS_ERR(ssif_info->thread)) {
-			rv = PTR_ERR(ssif_info->thread);
-			dev_notice(&ssif_info->client->dev,
-				   "Could not start kernel thread: error %d\n",
-				   rv);
-			goto out;
-		}
+	thread_num = ((i2c_adapter_id(ssif_info->client->adapter) << 8) |
+		      ssif_info->client->addr);
+	init_completion(&ssif_info->wake_thread);
+	ssif_info->thread = kthread_run(ipmi_ssif_thread, ssif_info,
+					"kssif%4.4x", thread_num);
+	if (IS_ERR(ssif_info->thread)) {
+		rv = PTR_ERR(ssif_info->thread);
+		dev_notice(&ssif_info->client->dev,
+			   "Could not start kernel thread: error %d\n",
+			   rv);
+		goto out;
 	}
 
 	dev_set_drvdata(&ssif_info->client->dev, ssif_info);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH 5.10.y v3 4/4] ipmi:ssif: NULL thread on error
  2026-05-11 13:19     ` [PATCH 5.10.y v3 1/4] " Corey Minyard
                         ` (2 preceding siblings ...)
  2026-05-11 13:19       ` [PATCH 5.10.y v3 3/4] ipmi:ssif: Remove unnecessary indention Corey Minyard
@ 2026-05-11 13:19       ` Corey Minyard
  2026-05-12  0:17       ` [PATCH 5.10.y v3 1/4] Fix error in IPMI SSIF shutdown Sasha Levin
  4 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-11 13:19 UTC (permalink / raw)
  To: Sasha Levin, stable; +Cc: Li Xiao, Corey Minyard

Cleanup code was checking the thread for NULL, but it was possibly
a PTR_ERR() in one spot.

Spotted with static analysis.

Link: https://sourceforge.net/p/openipmi/mailman/message/59324676/
Fixes: 75c486cb1bca ("ipmi:ssif: Clean up kthread on errors")
Cc: <stable@vger.kernel.org> # 91eb7ec72612: ipmi:ssif: Remove unnecessary indention
Cc: stable@vger.kernel.org
Signed-off-by: Corey Minyard <corey@minyard.net>
---
 drivers/char/ipmi/ipmi_ssif.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c
index c973c0d92319..43c4863e7b03 100644
--- a/drivers/char/ipmi/ipmi_ssif.c
+++ b/drivers/char/ipmi/ipmi_ssif.c
@@ -1891,6 +1891,7 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
 					"kssif%4.4x", thread_num);
 	if (IS_ERR(ssif_info->thread)) {
 		rv = PTR_ERR(ssif_info->thread);
+		ssif_info->thread = NULL;
 		dev_notice(&ssif_info->client->dev,
 			   "Could not start kernel thread: error %d\n",
 			   rv);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH 5.15.y v3 0/4] Fix error in IPMI SSIF shutdown
  2026-05-11 13:09     ` [PATCH 5.15.y v3 0/4] Fix error in IPMI SSIF shutdown Corey Minyard
                         ` (3 preceding siblings ...)
  2026-05-11 13:09       ` [PATCH 5.15.y v3 4/4] ipmi:ssif: NULL thread on error Corey Minyard
@ 2026-05-12  0:17       ` Sasha Levin
  4 siblings, 0 replies; 35+ messages in thread
From: Sasha Levin @ 2026-05-12  0:17 UTC (permalink / raw)
  To: stable; +Cc: Sasha Levin, Li Xiao, Corey Minyard

On Mon, May 11, 2026 at 08:09:22AM -0500, Corey Minyard wrote:
> This is a backport of 75c486cb1bca ("ipmi:ssif: Clean up kthread on
> errors") and other necessary patches with it.
>
> Version 3: Include a8aebe93a493 ("ipmi:ssif: NULL thread on error")
> in the patch set.

Queued all four for 5.15, thanks.

-- 
Thanks,
Sasha

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 5.10.y v3 1/4] Fix error in IPMI SSIF shutdown
  2026-05-11 13:19     ` [PATCH 5.10.y v3 1/4] " Corey Minyard
                         ` (3 preceding siblings ...)
  2026-05-11 13:19       ` [PATCH 5.10.y v3 4/4] ipmi:ssif: NULL thread on error Corey Minyard
@ 2026-05-12  0:17       ` Sasha Levin
  2026-05-12  2:06         ` Corey Minyard
  4 siblings, 1 reply; 35+ messages in thread
From: Sasha Levin @ 2026-05-12  0:17 UTC (permalink / raw)
  To: stable; +Cc: Sasha Levin, Li Xiao, Corey Minyard

On Mon, May 11, 2026 at 08:19:38AM -0500, Corey Minyard wrote:
> This is a backport of 75c486cb1bca ("ipmi:ssif: Clean up kthread on
> errors") and other necessary patches with it.
>
> Version 3: Include a8aebe93a493 ("ipmi:ssif: NULL thread on error")
> in the patch set.

Queued all four for 5.10 too, thanks.

-- 
Thanks,
Sasha

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH 5.10.y v3 1/4] Fix error in IPMI SSIF shutdown
  2026-05-12  0:17       ` [PATCH 5.10.y v3 1/4] Fix error in IPMI SSIF shutdown Sasha Levin
@ 2026-05-12  2:06         ` Corey Minyard
  0 siblings, 0 replies; 35+ messages in thread
From: Corey Minyard @ 2026-05-12  2:06 UTC (permalink / raw)
  To: Sasha Levin; +Cc: stable, Li Xiao

On Mon, May 11, 2026 at 08:17:56PM -0400, Sasha Levin wrote:
> On Mon, May 11, 2026 at 08:19:38AM -0500, Corey Minyard wrote:
> > This is a backport of 75c486cb1bca ("ipmi:ssif: Clean up kthread on
> > errors") and other necessary patches with it.
> >
> > Version 3: Include a8aebe93a493 ("ipmi:ssif: NULL thread on error")
> > in the patch set.
> 
> Queued all four for 5.10 too, thanks.

Thanks for getting this in.

-corey

> 
> -- 
> Thanks,
> Sasha

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2026-05-12  2:06 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 5.15-stable tree gregkh
2026-05-01 14:27 ` [PATCH 5.15.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
2026-05-01 14:27   ` [PATCH 5.15.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
2026-05-01 16:11 ` [PATCH 5.15.y] ipmi:ssif: Fix a thread shutdown issue Corey Minyard
2026-05-06  2:18 ` [PATCH 5.15.y] ipmi:ssif: Clean up kthread on errors Corey Minyard
2026-05-09 12:46   ` Sasha Levin
2026-05-11 13:09     ` [PATCH 5.15.y v3 0/4] Fix error in IPMI SSIF shutdown Corey Minyard
2026-05-11 13:09       ` [PATCH 5.15.y v3 1/4] ipmi:ssif: Fix a shutdown race Corey Minyard
2026-05-11 13:09       ` [PATCH 5.15.y v3 2/4] ipmi:ssif: Clean up kthread on errors Corey Minyard
2026-05-11 13:09       ` [PATCH 5.15.y v3 3/4] ipmi:ssif: Remove unnecessary indention Corey Minyard
2026-05-11 13:09       ` [PATCH 5.15.y v3 4/4] ipmi:ssif: NULL thread on error Corey Minyard
2026-05-12  0:17       ` [PATCH 5.15.y v3 0/4] Fix error in IPMI SSIF shutdown Sasha Levin
2026-05-11 13:19     ` [PATCH 5.10.y v3 1/4] " Corey Minyard
2026-05-11 13:19       ` [PATCH 5.10.y v3 1/4] ipmi:ssif: Fix a shutdown race Corey Minyard
2026-05-11 13:19       ` [PATCH 5.10.y v3 2/4] ipmi:ssif: Clean up kthread on errors Corey Minyard
2026-05-11 13:19       ` [PATCH 5.10.y v3 3/4] ipmi:ssif: Remove unnecessary indention Corey Minyard
2026-05-11 13:19       ` [PATCH 5.10.y v3 4/4] ipmi:ssif: NULL thread on error Corey Minyard
2026-05-12  0:17       ` [PATCH 5.10.y v3 1/4] Fix error in IPMI SSIF shutdown Sasha Levin
2026-05-12  2:06         ` Corey Minyard
  -- strict thread matches above, loose matches on Subject: below --
2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 5.10-stable tree gregkh
2026-05-01 14:54 ` [PATCH 5.10.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
2026-05-01 14:54   ` [PATCH 5.10.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
2026-05-01 16:20 ` [PATCH 5.10.y] ipmi:ssif: Fix a thread shutdown issue Corey Minyard
2026-05-06  2:20 ` [PATCH 5.10.y] ipmi:ssif: Clean up kthread on errors Corey Minyard
2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 6.6-stable tree gregkh
2026-05-01 14:06 ` [PATCH 6.6.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
2026-05-01 14:06   ` [PATCH 6.6.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 6.1-stable tree gregkh
2026-05-01 14:19 ` [PATCH 6.1.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
2026-05-01 14:19   ` [PATCH 6.1.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
2026-05-01 10:58 FAILED: patch "[PATCH] ipmi:ssif: Clean up kthread on errors" failed to apply to 6.12-stable tree gregkh
2026-05-01 13:56 ` [PATCH 6.12.y 1/2] ipmi:ssif: Fix a shutdown race Corey Minyard
2026-05-01 13:56   ` [PATCH 6.12.y 2/2] ipmi:ssif: Clean up kthread on errors Corey Minyard
2026-05-03 18:19   ` [PATCH 6.12.y/6.6.y/6.1.y/5.15.y/5.10.y 1-2/2] ipmi:ssif: shutdown race + kthread cleanup Sasha Levin
2026-05-04 11:04     ` Corey Minyard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox