Skip to contentSkip to conversation

gpio: rockchip: Fix bank clock leak in rockchip_get_bank_data()

PATCH In review Wentao Liang 2 participants 2 messages Sep 16

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

PATCH 1/1 gpio: rockchip: Fix bank clock leak in rockchip_get_bank_data()

rockchip_get_bank_data() obtains the bank clock with of_clk_get() and enables it before reading the GPIO version ID. The reference returned by of_clk_get() is never dropped on the error paths that follow:

When the debounce clock is missing, the bank clock is disabled with clk_disable_unprepare() but the reference is never released with clk_put(). When the version ID is unsupported, the function returns -ENODEV leaving the bank clock prepared, enabled and referenced.

Drop the reference with clk_put() on both error paths and disable and unprepare the bank clock on the unsupported version path so that probe failures no longer leak the clock.

Fixes 41209307cad7 ("gpio: rockchip: change the GPIO version judgment logic")
---
 drivers/gpio/gpio-rockchip.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpio/gpio-rockchip.c +3 -0
index 44d7ebd12724..69a7cd8c9a1a 100644
@@ -673,6 +673,7 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
 		if (IS_ERR(bank->db_clk)) {
 			dev_err(bank->dev, "cannot find debounce clk\n");
 			clk_disable_unprepare(bank->clk);
+			clk_put(bank->clk);
 			return -EINVAL;
 		}
 		break;
@@ -682,6 +683,8 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
 		break;
 	default:
 		dev_err(bank->dev, "unsupported version ID: 0x%08x\n", id);
+		clk_disable_unprepare(bank->clk);
+		clk_put(bank->clk);
 		return -ENODEV;
 	}
 
Signature · 1 line
2.34.1
#1 lore raw

Hi,

Quoted 9 lines · Wentao Liang

rockchip_get_bank_data() obtains the bank clock with of_clk_get() and enables it before reading the GPIO version ID. The reference returned by of_clk_get() is never dropped on the error paths that follow:

When the debounce clock is missing, the bank clock is disabled with clk_disable_unprepare() but the reference is never released with clk_put(). When the version ID is unsupported, the function returns -ENODEV leaving the bank clock prepared, enabled and referenced.

Quoted 8 lines

Drop the reference with clk_put() on both error paths and disable and unprepare the bank clock on the unsupported version path so that probe failures no longer leak the clock.

Fixes 41209307cad7 ("gpio: rockchip: change the GPIO version judgment logic")

---

This got fixed in 3e46c18d5d87 ("gpio: rockchip: convert bank->clk to devm_clk_get_enabled()") and 950007767823 ("gpio: rockchip:
teardown bugs and resource leaks") already. Please make sure to use latest kernel trees.

Greetings,

-- Sebastian

Quoted 27 lines
 drivers/gpio/gpio-rockchip.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpio/gpio-rockchip.c +3 -0
index 44d7ebd12724..69a7cd8c9a1a 100644
@@ -673,6 +673,7 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
 		if (IS_ERR(bank->db_clk)) {
 			dev_err(bank->dev, "cannot find debounce clk\n");
 			clk_disable_unprepare(bank->clk);
+			clk_put(bank->clk);
 			return -EINVAL;
 		}
 		break;
@@ -682,6 +683,8 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank)
 		break;
 	default:
 		dev_err(bank->dev, "unsupported version ID: 0x%08x\n", id);
+		clk_disable_unprepare(bank->clk);
+		clk_put(bank->clk);
 		return -ENODEV;
 	}
 
Signature · 1 line
2.34.1

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip