[PATCH] NFC: trf7970a: Fix runtime PM leak in trf7970a_switch_rf_on()

Wentao Liang posted 1 patch 1 week ago
drivers/nfc/trf7970a.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] NFC: trf7970a: Fix runtime PM leak in trf7970a_switch_rf_on()
Posted by Wentao Liang 1 week ago
pm_runtime_get_sync() unconditionally increments the runtime PM usage
counter, so the reference taken at the top of trf7970a_switch_rf_on()
has to be dropped on every exit path. The two error paths return
without doing so, and since the chip is left in TRF7970A_ST_RF_OFF they
are not balanced by trf7970a_switch_rf_off() either.

Release the reference the same way trf7970a_switch_rf_off() does.

Fixes: e6403b7c756f9 ("NFC: trf7970a: Add pm_runtime support")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/nfc/trf7970a.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c
index 08c27bb438b5..07bc336c6505 100644
--- a/drivers/nfc/trf7970a.c
+++ b/drivers/nfc/trf7970a.c
@@ -1155,12 +1155,14 @@ static int trf7970a_switch_rf_on(struct trf7970a *trf)
 	if (trf->state != TRF7970A_ST_RF_OFF) {	/* Power on, RF off */
 		dev_err(trf->dev, "%s - Incorrect state: %d\n", __func__,
 			trf->state);
+		pm_runtime_put_autosuspend(trf->dev);
 		return -EINVAL;
 	}
 
 	ret = trf7970a_init(trf);
 	if (ret) {
 		dev_err(trf->dev, "%s - Can't initialize: %d\n", __func__, ret);
+		pm_runtime_put_autosuspend(trf->dev);
 		return ret;
 	}
 
-- 
2.34.1