[PATCH 4/5] staging: nvec: fix pm_power_off teardown in tegra_nvec_remove()

From: Alexandru Hossu

Date: Sun Apr 12 2026 - 16:52:59 EST


The remove() function unconditionally sets pm_power_off to NULL regardless
of whether this driver instance was the one that set it. There is even a
FIXME comment acknowledging this. Additionally, nvec_power_handle is never
cleared on removal, leaving a dangling pointer to freed device data.

Fix both issues: check that pm_power_off still points to nvec_power_off
before clearing it, and also clear nvec_power_handle at the same time.

Signed-off-by: Alexandru Hossu <hossu.alexandru@xxxxxxxxx>
---
drivers/staging/nvec/nvec.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c
index 75877038847f..9fe9b7a3491d 100644
--- a/drivers/staging/nvec/nvec.c
+++ b/drivers/staging/nvec/nvec.c
@@ -907,8 +907,10 @@ static void tegra_nvec_remove(struct platform_device *pdev)
nvec_unregister_notifier(nvec, &nvec->nvec_status_notifier);
cancel_work_sync(&nvec->rx_work);
cancel_work_sync(&nvec->tx_work);
- /* FIXME: needs check whether nvec is responsible for power off */
- pm_power_off = NULL;
+ if (pm_power_off == nvec_power_off) {
+ pm_power_off = NULL;
+ nvec_power_handle = NULL;
+ }
}

#ifdef CONFIG_PM_SLEEP
--
2.53.0