[v2] spmi: hisi-spmi-controller: Fix kernel panic on rmmod

Message ID 20240228190523.8377-1-vamshigajjela@google.com
State New
Headers
Series [v2] spmi: hisi-spmi-controller: Fix kernel panic on rmmod |

Commit Message

Vamshi Gajjela Feb. 28, 2024, 7:05 p.m. UTC
  Ensure consistency in spmi_controller pointers between
spmi_controller_remove/put and driver spmi_del_controller functions.
The former requires a pointer to struct spmi_controller, while the
latter passes a pointer of struct spmi_controller_dev, leading to a
"Null pointer exception".

Signed-off-by: Vamshi Gajjela <vamshigajjela@google.com>
Fixes: 70f59c90c819 ("staging: spmi: add Hikey 970 SPMI controller driver")
Cc: stable@vger.kernel.org
---
v2:
- Split into two separate patches
- add Fixes and Cc stable

 drivers/spmi/hisi-spmi-controller.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Johan Hovold Feb. 29, 2024, 8:05 a.m. UTC | #1
On Thu, Feb 29, 2024 at 12:35:23AM +0530, Vamshi Gajjela wrote:
> Ensure consistency in spmi_controller pointers between
> spmi_controller_remove/put and driver spmi_del_controller functions.
> The former requires a pointer to struct spmi_controller, while the
> latter passes a pointer of struct spmi_controller_dev, leading to a
> "Null pointer exception".
> 
> Signed-off-by: Vamshi Gajjela <vamshigajjela@google.com>
> Fixes: 70f59c90c819 ("staging: spmi: add Hikey 970 SPMI controller driver")
> Cc: stable@vger.kernel.org
> ---
> v2:
> - Split into two separate patches
> - add Fixes and Cc stable

You need to mark this patch more clearly as a stable backport (e.g.
using a "[PATCH-stable]" prefix), and explain that the corresponding
issue has already been fixed upstream by commits:

	490d88ef548d ("spmi: hisi-spmi-controller: Use devm_spmi_controller_add()")
	ffdfbafdc4f4 ("spmi: Use devm_spmi_controller_alloc()")

but that those commits (and their dependencies) are too intrusive to
backport.

Johan
  

Patch

diff --git a/drivers/spmi/hisi-spmi-controller.c b/drivers/spmi/hisi-spmi-controller.c
index 9cbd473487cb..4b6189d8cc4d 100644
--- a/drivers/spmi/hisi-spmi-controller.c
+++ b/drivers/spmi/hisi-spmi-controller.c
@@ -326,7 +326,8 @@  static int spmi_controller_probe(struct platform_device *pdev)
 
 static void spmi_del_controller(struct platform_device *pdev)
 {
-	struct spmi_controller *ctrl = platform_get_drvdata(pdev);
+	struct spmi_controller_dev *spmi_controller = platform_get_drvdata(pdev);
+	struct spmi_controller *ctrl = spmi_controller->controller;
 
 	spmi_controller_remove(ctrl);
 	spmi_controller_put(ctrl);