Skip to contentSkip to conversation

power: reset: tdx-ec-poweroff: fix return value on command failure

PATCH New Emanuele Ghidoli 1 participant 1 message Nov 27

Subsystems (4)
lore
Share & tools
lore

Emanuele Ghidoli

author maintainer
#0 lore raw

PATCH 1/1 power: reset: tdx-ec-poweroff: fix return value on command failure

From: Emanuele Ghidoli <[email protected]>

When the power-off or restart command cannot be sent to the embedded controller, the handlers return NOTIFY_BAD. NOTIFY_BAD includes NOTIFY_STOP_MASK, so the sys-off notifier chain stops and lower priority handlers are never called. The system then halts instead of powering off or restarting.

Fix this by returning NOTIFY_DONE in the error path too, so the next handler can take over.

A failed write does not guarantee that the EC did not receive the command. To avoid running the next handler while the EC may still be acting on it, wait EC_CMD_TIMEOUT_MS unconditionally.

Fixes 18672fe12367 ("power: reset: add Toradex Embedded Controller")
---
 drivers/power/reset/tdx-ec-poweroff.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/power/reset/tdx-ec-poweroff.c +10 -12
index b4f1c87f5651..5d025a724392 100644
@@ -79,14 +79,13 @@ static int tdx_ec_power_off(struct sys_off_data *data)
 
 	err = tdx_ec_cmd(regmap, EC_CMD_POWEROFF);
 
-	if (err) {
+	if (err)
 		dev_err(data->dev, "Failed to send power off command\n");
-	} else {
-		mdelay(EC_CMD_TIMEOUT_MS);
-		WARN_ONCE(1, "Unable to power off system\n");
-	}
 
-	return err ? NOTIFY_BAD : NOTIFY_DONE;
+	mdelay(EC_CMD_TIMEOUT_MS);
+	WARN_ONCE(!err, "Unable to power off system\n");
+
+	return NOTIFY_DONE;
 }
 
 static int tdx_ec_restart(struct sys_off_data *data)
@@ -96,14 +95,13 @@ static int tdx_ec_restart(struct sys_off_data *data)
 
 	err = tdx_ec_cmd(regmap, EC_CMD_RESET);
 
-	if (err) {
+	if (err)
 		dev_err(data->dev, "Failed to send restart command\n");
-	} else {
-		mdelay(EC_CMD_TIMEOUT_MS);
-		WARN_ONCE(1, "Unable to restart system\n");
-	}
 
-	return err ? NOTIFY_BAD : NOTIFY_DONE;
+	mdelay(EC_CMD_TIMEOUT_MS);
+	WARN_ONCE(!err, "Unable to restart system\n");
+
+	return NOTIFY_DONE;
 }
 
 static int tdx_ec_register_power_off_restart(struct device *dev, struct regmap *regmap)
Signature · 1 line
2.53.0