Skip to contentSkip to conversation

soc: ti: wkup_m3_ipc: Use the device's own state in remove()

PATCH New Nhat Tran 1 participant 1 message Nov 20

Subsystems (2)
lore
Share & tools
lore

Nhat Tran

author
#0 lore raw

PATCH 1/1 soc: ti: wkup_m3_ipc: Use the device's own state in remove()

wkup_m3_ipc_remove() tears down the driver through the global m3_ipc_state pointer. That pointer is only set by the rproc boot thread once rproc_boot() succeeds, while probe returns success regardless of the boot result. If the wkup_m3 firmware cannot be loaded, for example because the driver is built in and probes before the root filesystem holding am335x-pm-firmware.elf is mounted, m3_ipc_state stays NULL and unbinding the driver dereferences it.

On a BeagleBone Black (AM335x):

wkup_m3_ipc 44e11324.wkup_m3_ipc: rproc_boot failed

  # cd /sys/bus/platform/drivers/wkup_m3_ipc
  # echo 44e11324.wkup_m3_ipc > unbind
  Unable to handle kernel NULL pointer dereference at virtual address 00000064 when read
  Internal error: Oops: 5 [#1] SMP ARM
  PC is at wkup_m3_ipc_remove+0xc/0x48
  LR is at device_release_driver_internal+0xbc/0x144
  Call trace:
   wkup_m3_ipc_remove from device_release_driver_internal+0xbc/0x144
   device_release_driver_internal from unbind_store+0x50/0x74
   unbind_store from kernfs_fop_write_iter+0x11c/0x1d4
   kernfs_fop_write_iter from vfs_write+0x2a8/0x3f8
   vfs_write from ksys_write+0x60/0xe0
   ksys_write from ret_fast_syscall+0x0/0x54

The same happens when the mailbox the driver depends on is unbound.

Store the per-device state as driver data in probe and use it in remove(), so the debugfs entries, the mailbox channel and the rproc reference taken in probe are released whether or not the M3 was booted. rproc_shutdown() already returns -EINVAL for a remote processor that is not running.

Tested on a BeagleBone Black with the firmware not loaded at probe
time: unbinding the driver directly or through the mailbox no longer oopses, and repeated unbind/bind cycles rebind and boot the M3 again.

Fixes cdd5de500b2c ("soc: ti: Add wkup_m3_ipc driver")
---
 drivers/soc/ti/wkup_m3_ipc.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/soc/ti/wkup_m3_ipc.c +7 -4
index eb6074a67ba3..224651955cda 100644
@@ -695,6 +695,7 @@ static int wkup_m3_ipc_probe(struct platform_device *pdev)
 		goto err_put_rproc;
 	}
 
+	platform_set_drvdata(pdev, m3_ipc);
 	wkup_m3_ipc_dbg_init(m3_ipc);
 
 	return 0;
@@ -708,12 +709,14 @@ static int wkup_m3_ipc_probe(struct platform_device *pdev)
 
 static void wkup_m3_ipc_remove(struct platform_device *pdev)
 {
-	wkup_m3_ipc_dbg_destroy(m3_ipc_state);
+	struct wkup_m3_ipc *m3_ipc = platform_get_drvdata(pdev);
 
-	mbox_free_channel(m3_ipc_state->mbox);
+	wkup_m3_ipc_dbg_destroy(m3_ipc);
 
-	rproc_shutdown(m3_ipc_state->rproc);
-	rproc_put(m3_ipc_state->rproc);
+	mbox_free_channel(m3_ipc->mbox);
+
+	rproc_shutdown(m3_ipc->rproc);
+	rproc_put(m3_ipc->rproc);
 
 	m3_ipc_state = NULL;
 }
Signature · 1 line
2.25.1