Skip to contentSkip to conversation

macsmc: check for missing SMC to avoid crash

PATCH In review Atharva Tiwari 2 participants 2 messages Oct 9, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 macsmc: check for missing SMC to avoid crash

Users might manually install these drivers
without the core SMC device, causing
a NULL deref. Add a guard and return -ENODEV.

---
 drivers/gpio/gpio-macsmc.c          | 3 +++
 drivers/power/reset/macsmc-reboot.c | 3 +++
 2 files changed, 6 insertions(+)
drivers/gpio/gpio-macsmc.c +3 -0
index 30ef258e7655..7048b45953bb 100644
@@ -238,6 +238,9 @@ static int macsmc_gpio_probe(struct platform_device *pdev)
 	smc_key key;
 	int ret;
 
+	if (!smc)
+		return -ENODEV;
+
 	smcgp = devm_kzalloc(&pdev->dev, sizeof(*smcgp), GFP_KERNEL);
 	if (!smcgp)
 		return -ENOMEM;
drivers/power/reset/macsmc-reboot.c +3 -0
index e9702acdd366..739f94e4ed7e 100644
@@ -205,6 +205,9 @@ static int macsmc_reboot_probe(struct platform_device *pdev)
 	struct macsmc_reboot *reboot;
 	int ret, i;
 
+	if (!smc)
+		return -ENODEV;
+
 	reboot = devm_kzalloc(&pdev->dev, sizeof(*reboot), GFP_KERNEL);
 	if (!reboot)
 		return -ENOMEM;
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 2 lines · Atharva Tiwari

Users might manually install these drivers
without the core SMC device, causing

Installing isn't enough; that's not gonna trigger probing any of these devices. Did you run into this issue?

Hitting this should require deliberately creating a broken dts file and booting with that one. But if I'm creating a broken dts file I can easily crash the kernel in various other ways.

Sven