Skip to contentSkip to conversation

nfc: trf7970a: power down on startup RX gain failure

PATCH In review Myeonghun Pak 2 participants 2 messages Sep 13 – Sep 14

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

PATCH 1/1 nfc: trf7970a: power down on startup RX gain failure

trf7970a_startup() powers up the device before applying the optional RX gain reduction. If the register read or write fails, it returns without undoing that power-up. Probe's unwind only drops the separate regulator references acquired by probe, leaving the additional VIN enable from startup unbalanced. The system resume caller also has no power-down on this error.

Call trf7970a_power_down() before returning the RX gain error to deassert the enable GPIOs, release the startup VIN reference and restore the powered-off state. Runtime PM has not been enabled yet, so the full shutdown helper is not appropriate here. Preserve the original SPI error.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 5d69351820ea ("NFC: trf7970a: Create device-tree parameter for RX gain reduction")
Assisted-by OpenAI:GPT-5.6
---
 drivers/nfc/trf7970a.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nfc/trf7970a.c +3 -1
index 60883001f..ddfc58c29 100644
@@ -1997,8 +1997,10 @@ static int trf7970a_startup(struct trf7970a *trf)
 		return ret;
 
 	ret = trf7970a_update_rx_gain_reduction(trf);
-	if (ret)
+	if (ret) {
+		trf7970a_power_down(trf);
 		return ret;
+	}
 
 	pm_runtime_set_active(trf->dev);
 	pm_runtime_enable(trf->dev);
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines

trf7970a_startup() powers up the device before applying the optional RX gain reduction. If the register read or write fails, it returns without undoing that power-up. Probe's unwind only drops the separate regulator references acquired by probe, leaving the additional VIN enable from startup unbalanced. The system resume caller also has no power-down on this error.

Quoted 7 lines

Call trf7970a_power_down() before returning the RX gain error to deassert the enable GPIOs, release the startup VIN reference and restore the powered-off state. Runtime PM has not been enabled yet, so the full shutdown helper is not appropriate here. Preserve the original SPI error.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Yes, we should do power_down here indeed.
Thanks!

br,
Paul