From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796319710; b=mrJ6Vy2wedTwpo3UrLMmV7WaUhMBJsma+Jz0SFqrF7RqdhWzGsBe7l0+4+HZczIFD6VQ L/8zlsUQpNhe2/PUQZSiA9rZSIagxrZEkkAN1LrOCWEzSF0tphe0RPU8z66zMU9EFlhrz SOjyj0sUxvx4quix9ipQuKxrl899nkvDlDXoXuQF/OLbkWgH68uFBCeEscs8bgzca3bj1 SbdpF3HZW2TxKl9nT9dCmpc2wD4Di6yTX1iucn3nBpQYTLcjMs2f5Lxoli4jV0kqO6KT4 a4hmHrhUznYfFWnHJ6qeVTRmpr3Jjvw7Nejh09rt06ThVaNn7G5Pqe9v+/6LN6hCmFg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796319710; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=2UXhwZiqZl6HcCmpPon+/G41xuXZplPBjeloRUHKQVs=; b=t+P8QmNLgu76z1rHT56QnGSXAS9XsTKbf5mNpH5l/2sRDNfDFkMl7VA2xnyW2kiZayl1 hdmA2s3AyMjwiPpbOwy0N8wWkcqbBgn70vs20b1TxrcjKxjrojy3GCIyVuK5+RQqFbtDF vJiT9ubnHWkbTcbHCD5FXzVMXENqnCQSeexXpn9Wve3IDuVt+/dTSEborO96bfTstpDyu xG2nPT9jDyJJ0wbhxeL9WsTZhie/FCG5NcwfvB53oyHZHstDlx4YRr6vGM5E5wD8+RpHP gttr9nZ7LWiiARVE1MYNSd7SENse3DfTK31gIVaxyE0GUe9wWIOVQOdkmdnQUzf4zEg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yXKrbxS+; arc=none smtp.remote-ip=209.85.214.174 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50400606A32D for ; Thu, 3 Dec 2026 17:41:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 50400606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=yXKrbxS+ Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2f05b465cd1so924445ad.3 for ; Thu, 03 Dec 2026 09:41:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796319709; x=1796924509; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=2UXhwZiqZl6HcCmpPon+/G41xuXZplPBjeloRUHKQVs=; b=yXKrbxS+pYJqS7UuFJj7E+JPS6m6+yGgr8UB1b/SSFG9c3MwyQLdcW6YvpNIE/fAL3 Q/osVDpqztAUyHJ/O8y4Hxb0WpTNF6zUzRUoauk+loJb+T0NJEqjcukD4TQAGNv+WVfV W3wTz5FBHTIGux1/QphDtSk/aslfwy7oPqbRQCyRAf9ZlBFW1V4ouH6hM6RWiWD4j+3F mS/IePfa2BzaHBVxj6VeyUUpxyIdGXbV/kUbg40nvp9lmRN70sIVD5P2g05r7UpMqurx FktaXxYvJIMlngIk3IEJisAtvuZUItI4+1T/bJ0Ysjms2yiuD+GKUu2V+ngWiZiO9qKn MgIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796319709; x=1796924509; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=2UXhwZiqZl6HcCmpPon+/G41xuXZplPBjeloRUHKQVs=; b=bbrfC9Ib0py4Vw/T6a2L/HIfpxn7liAHhbtxlN7BPAHbj1/aXRI9k46LWWKLaB7V29 QDi/R9g5Glb2S8JZt6PFVDZweJafmZGAND/tL0GFYK6kUhTJonHmMI+/5SyXjHsa7KOz H0JFZVv1PjC9cFXlcOrrHT2dxOc1MG2eJO1x0gc1Uxxt4MgphSDcfQM6hPCkXSTQpcBK XV0FS3v7/HKrkCpChQL5zP55RlsItsexijFqecrazEIbL6ku6SIB4t+tE5imgzsytsXn KzejvrlJzSce73+CNzCkYvLjCOLdIH+ll40Itsbz3IENXzc2sWhZD7MneMHhyuCy0nqb eKoQ== X-Forwarded-Encrypted: i=1; AL+hErHnkRAGU1L4LgdKukB+f7msIMw3A84Tu3TcD0TN7g8CeRwmx4FLzHQLEawIQm0ZPLiqX6nVysMCwklHXXg=@vger.kernel.org X-Gm-Message-State: APuU4Z/cUkL4dmI3KlE6Vbf+WoUcyGAXleFlPs1RaXTd/Bl6bPCn9PdI 2ydC6/ep1ILoRkbZ1lUE3WSov7DCx47i/gB2Lh9jeYtyPcL3nyRrTKbr X-Gm-Gg: AZFdTZcqUcbIXdw9KXs2HSICLeIFxMOxuDtTPSm2qePHHi7ULvc7OE415pwqh0j2/R0 DyaLCT71EUcFWSF2oB7V9AL4P0qChWCooIXQhkxY2BTN9Tjoa6lQviuDTJYx2X0R7DhCdy1Hrg/ ggXD8bQv6AcJLs+Uk9mrGrfe7gt87GIKS7hBy8bR/RyAlKHo2wPOGvOSHFHHRRFliGGYZFQ8boy FN81MhmUVwM80lxutXuqd437SBzmruuvkHLcksUGgcbbxAC142rHpv3HZ5I69RGPMskaUkM0WUK mainRY5K062DsPMLth84+C+XWZvvR61YBFEBPu9LuARY64iTA7DQduTgK0EXyftcKAAhHDduv8h fAwkCfCx6ZOKnHWu8rWobg3NfxHymE7icImCKQkR2oT8pfLwA/vO4NJeEQfGXGH2UuWlbX1WAiZ HMI53SrPJNj65WAmI2lirodYJa6gQqx3qUaoPAu0j+uJt0H2yk5O17kIzs+Mu+DKyuJdJ6We9iw 7r+IuMRkMgczogyjcdyKQa8eegZ+q3Epyrkgsam3W5j8Oh1mSa21OBgAohtJSrhYOEznoHiY4lQ qZBMJAJqrHrN9TKjNkzQM3ld0/4FYY+YS0ORLiiLCOMYG7lV X-Received: by 2002:a17:902:e80b:b0:2e9:9a19:c43 with SMTP id d9443c01a7336-2f03f118277mr465226915ad.15.1796319709313; Thu, 03 Dec 2026 09:41:49 -0800 (PST) Received: from localhost.localdomain ([115.73.20.187]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f07877d6afsm195753145ad.42.2026.12.03.09.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 09:41:48 -0800 (PST) From: Nhat Tran To: nm@ti.com, ssantosh@kernel.org Cc: afd@ti.com, linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, Nhat Tran , stable@vger.kernel.org Subject: [PATCH v2] soc: ti: wkup_m3_ipc: Fix NULL dereference when the M3 fails to boot Date: Fri, 4 Dec 2026 00:41:39 +0700 Message-Id: <20261203174139.55646-1-nhat.tranminhk2@gmail.com> X-Mailer: git-send-email 2.25.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit m3_ipc_state is set by the rproc boot thread only once rproc_boot() succeeds, while probe returns success regardless of the boot result. The pointer is used both to tell wkup_m3_ipc_get() that the M3 is available and as the only way remove() and the resume callback reach the driver state. 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 both resuming from system sleep and unbinding the driver dereference it. On a BeagleBone Black (AM335x) with the firmware missing: wkup_m3_ipc 44e11324.wkup_m3_ipc: rproc_boot failed # echo devices > /sys/power/pm_test # echo freeze > /sys/power/state Unable to handle kernel NULL pointer dereference at virtual address 00000060 when read Internal error: Oops: 5 [#1] SMP ARM PC is at wkup_m3_ipc_resume+0xc/0x44 [wkup_m3_ipc] LR is at dpm_run_callback+0x4c/0x208 Call trace: wkup_m3_ipc_resume [wkup_m3_ipc] from dpm_run_callback+0x4c/0x208 dpm_run_callback from device_resume+0xf0/0x298 device_resume from dpm_resume+0x178/0x2dc dpm_resume from dpm_resume_end+0xc/0x1c dpm_resume_end from suspend_devices_and_enter+0x25c/0x9d4 suspend_devices_and_enter from pm_suspend+0x2f8/0x340 pm_suspend from state_store+0x68/0xc8 Unbinding the driver, directly or through the mailbox it depends on, oopses the same way in wkup_m3_ipc_remove(). Split the two uses. Set m3_ipc_state at the end of probe so it is valid for as long as the driver is bound, and add an 'available' flag that the boot thread sets once the M3 is running and remove() clears. wkup_m3_ipc_get() checks the flag, so pm33xx still defers its probe until the M3 has booted. The boot thread sets the flag through its own pointer because it is started before probe assigns m3_ipc_state. wkup_m3_ipc_put() keeps checking only the pointer, as it has to drop the reference taken by wkup_m3_ipc_get() whether or not the M3 is still running. Tested on a BeagleBone Black: - firmware missing: s2idle with pm_test=devices resumes without an oops, and repeated unbind/bind cycles no longer oops - firmware present: the M3 boots, pm33xx probes, and s2idle still suspends and resumes Fixes: cdd5de500b2c ("soc: ti: Add wkup_m3_ipc driver") Cc: stable@vger.kernel.org Suggested-by: Andrew Davis Signed-off-by: Nhat Tran --- v1 -> v2: - Instead of passing the state to remove() as driver data, keep m3_ipc_state set from probe and track whether the M3 is running in a separate flag, as suggested by Andrew Davis. This also fixes the same NULL dereference in the resume callback, which v1 missed. - Retitled from "Use the device's own state in remove()". v1: https://lore.kernel.org/r/20261120141139.55783-1-nhat.tranminhk2@gmail.com --- drivers/soc/ti/wkup_m3_ipc.c | 8 ++++++-- include/linux/wkup_m3_ipc.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/soc/ti/wkup_m3_ipc.c b/drivers/soc/ti/wkup_m3_ipc.c index eb6074a67ba3..7f9d67115ebf 100644 --- a/drivers/soc/ti/wkup_m3_ipc.c +++ b/drivers/soc/ti/wkup_m3_ipc.c @@ -569,7 +569,7 @@ static struct wkup_m3_ipc_ops ipc_ops = { */ struct wkup_m3_ipc *wkup_m3_ipc_get(void) { - if (m3_ipc_state) + if (m3_ipc_state && m3_ipc_state->available) get_device(m3_ipc_state->dev); else return NULL; @@ -601,7 +601,7 @@ static int wkup_m3_rproc_boot_thread(void *arg) if (ret) dev_err(dev, "rproc_boot failed\n"); else - m3_ipc_state = m3_ipc; + m3_ipc->available = true; return 0; } @@ -695,6 +695,8 @@ static int wkup_m3_ipc_probe(struct platform_device *pdev) goto err_put_rproc; } + m3_ipc_state = m3_ipc; + wkup_m3_ipc_dbg_init(m3_ipc); return 0; @@ -708,6 +710,8 @@ static int wkup_m3_ipc_probe(struct platform_device *pdev) static void wkup_m3_ipc_remove(struct platform_device *pdev) { + m3_ipc_state->available = false; + wkup_m3_ipc_dbg_destroy(m3_ipc_state); mbox_free_channel(m3_ipc_state->mbox); diff --git a/include/linux/wkup_m3_ipc.h b/include/linux/wkup_m3_ipc.h index 5e1b26f988e2..f4a8ab45ee30 100644 --- a/include/linux/wkup_m3_ipc.h +++ b/include/linux/wkup_m3_ipc.h @@ -29,6 +29,7 @@ struct wkup_m3_ipc { int isolation_conf; int state; u32 halt; + bool available; unsigned long volt_scale_offsets; const char *sd_fw_name; -- 2.25.1