From nobody Mon Jun 8 22:53:30 2026 Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 980203F65EB; Mon, 25 May 2026 16:42:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.21.23.139 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779727370; cv=none; b=RH3MSOMCoXwDx79uB6Fy9SBLTiAbpE8lAsui5ewCI+8AJKi0c1Vs/zTIlSN8b7VJN6oyFy4eFahh9bm/9zZ/zujgxCWlW3uiXBB7NNVDaRl78LQnNKfLOdulpHsdPrOWyPde6fkf+r/5MdiriQxcFUga4vwcD9ETze5Mbb1V36Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779727370; c=relaxed/simple; bh=2OF8js3j011GkbvGK5yHUNv8z+itCdsM0bZhVVbT3Gs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=paE075nEThYHzb0qG0jOgorE3/oUMaN2OAsOUblJtZyRsXfmtCKW2d4bMApJwB4Fymrz0/LLgLnOXWqZlT61WMbtyr6KeAcCGlHR1YjSATjjeIuMSCcREeU+VcGQYGrRBv1htNwo9leQgGjWeaSytrOmRxQxgUe3JJSu0P2jQ5k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=disroot.org; spf=pass smtp.mailfrom=disroot.org; dkim=pass (2048-bit key) header.d=disroot.org header.i=@disroot.org header.b=jyx8dljb; arc=none smtp.client-ip=178.21.23.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=disroot.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=disroot.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=disroot.org header.i=@disroot.org header.b="jyx8dljb" Received: from mail01.disroot.lan (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 56D8D271DC; Mon, 25 May 2026 18:42:46 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id ZOP0gYfiY2U5; Mon, 25 May 2026 18:42:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1779727365; bh=2OF8js3j011GkbvGK5yHUNv8z+itCdsM0bZhVVbT3Gs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jyx8dljb0o9X2Zu8q11qd/9fDwiFed/WZj5YPpRnlTa5LWwS92gCuM8dPAVnNa2qs W2I/M6J7OoYAidzZAURRqswTyyYX9lHiyZdA9k7vQpZF4fd+HgOoIdDANwQwtV6aH5 AN3ZganVnzUAZl/EZ+zvlcrYqjSQTTKiRkpd4viPHE3ZQNw1Nj4CLeBJwcXyICboG5 QVVEyRi5cEg8EYV/F121Y2bahwrO9Glgyr9hJ+GWSLEdDbf3tzWbl+a2n9TvG4DBhG vTDdjMI8UlDY6FuvpaqU0/zBxEJLYBa1SsLwd86C7FLKOPzIWu62QInGQd1pxpQBgT rpNAZrzE/Nuxg== From: "Marco Scardovi (scardracs)" To: linusw@kernel.org, brgl@kernel.org, heiko@sntech.de Cc: linux-gpio@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "Marco Scardovi (scardracs)" Subject: [PATCH 1/2] gpio: rockchip: convert bank->clk to devm_clk_get_enabled() Date: Mon, 25 May 2026 18:39:38 +0200 Message-ID: <20260525164230.43307-2-scardracs@disroot.org> In-Reply-To: <20260525164230.43307-1-scardracs@disroot.org> References: <20260525164230.43307-1-scardracs@disroot.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The bank->clk was previously obtained via of_clk_get() and manually prepared/enabled. However, it was missing a corresponding clk_put() in both the error paths and the remove function, leading to a reference leak. Convert the allocation to devm_clk_get_enabled(), which also properly propagates failures from clk_prepare_enable() that were previously ignored. The GPIO bank device uses the same OF node as the previous of_clk_get() call, so devm_clk_get_enabled(dev, NULL) correctly resolves the same clock provider entry. This change fixes the reference leak and simplifies the code by removing the manual clk_disable_unprepare() calls in the probe error paths and in the remove function. Assisted-by: Antigravity:gemini-3.5-flash Signed-off-by: Marco Scardovi --- drivers/gpio/gpio-rockchip.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 44d7ebd12724..33580093a4e7 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -656,11 +656,10 @@ static int rockchip_get_bank_data(struct rockchip_pin= _bank *bank) if (!bank->irq) return -EINVAL; =20 - bank->clk =3D of_clk_get(bank->of_node, 0); + bank->clk =3D devm_clk_get_enabled(bank->dev, NULL); if (IS_ERR(bank->clk)) return PTR_ERR(bank->clk); =20 - clk_prepare_enable(bank->clk); id =3D readl(bank->reg_base + gpio_regs_v2.version_id); =20 switch (id) { @@ -672,7 +671,6 @@ static int rockchip_get_bank_data(struct rockchip_pin_b= ank *bank) bank->db_clk =3D of_clk_get(bank->of_node, 1); if (IS_ERR(bank->db_clk)) { dev_err(bank->dev, "cannot find debounce clk\n"); - clk_disable_unprepare(bank->clk); return -EINVAL; } break; @@ -751,7 +749,6 @@ static int rockchip_gpio_probe(struct platform_device *= pdev) =20 ret =3D rockchip_gpiolib_register(bank); if (ret) { - clk_disable_unprepare(bank->clk); mutex_unlock(&bank->deferred_lock); return ret; } @@ -792,7 +789,6 @@ static void rockchip_gpio_remove(struct platform_device= *pdev) { struct rockchip_pin_bank *bank =3D platform_get_drvdata(pdev); =20 - clk_disable_unprepare(bank->clk); gpiochip_remove(&bank->gpio_chip); } =20 --=20 2.54.0 From nobody Mon Jun 8 22:53:30 2026 Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C45F3F65EC; Mon, 25 May 2026 16:42:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.21.23.139 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779727369; cv=none; b=hotyV1QcnI2+7Qb6nVBSZlQJIiidFHjsUU6F+LTCaUhvvA/QdUttOGITCOOoC0xRtIvl+vPYvlt+1JNqeGOaL3IyeaKhk1ceYc2+KgLSKfw6yYfNMV9NN1tWD8pklKEAzpxodgOaJruGYsqxqxaeq1GejtpDxA6IY1G7eEHau4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779727369; c=relaxed/simple; bh=tYb7EiJrA7HY9h6NF25A/246WD8DV5q9e0H5fLjg+M4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VRsXiVmTJ7BqjrqyediAufnroy5EVpDZHXsbcQ+6++J9YA5fDUBlOIfdPQPOy29cJ/thlyszP5TeoYXx4TpGKlhfSm644eTmxF94vMrm2db38lMwWLz6hK9vFML4u+/0DOoQrJ4joyZgahSMVL9rgynX20Ht7hH8/iEsNnLycpQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=disroot.org; spf=pass smtp.mailfrom=disroot.org; dkim=pass (2048-bit key) header.d=disroot.org header.i=@disroot.org header.b=hp0HLQvq; arc=none smtp.client-ip=178.21.23.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=disroot.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=disroot.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=disroot.org header.i=@disroot.org header.b="hp0HLQvq" Received: from mail01.disroot.lan (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id E0B2A27202; Mon, 25 May 2026 18:42:46 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id lNK1EPbJY_67; Mon, 25 May 2026 18:42:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1779727366; bh=tYb7EiJrA7HY9h6NF25A/246WD8DV5q9e0H5fLjg+M4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hp0HLQvqO1mb5Dsk6KPITtG7rPvFkpEOi2o/Oru9pe0b0MeolFOwfLECjLDA//ZGp fTVwOWbtCJyskqQEmqg2jDO3pF7ULnA4nzf458Ai0aFExLs77d0UrOiedpeHU8s5+j Imb5RzFMtBIJ6w0fqxyUp7H+2IYSybOsv33d7S5sVBy4PQvX49ohnjkycTfGvKJoim 1Dixd7VCGjW5/UHi1JPGQWXqatHABzYyZ1MPQBoKve+qgz2cvWBhOUaD3a995YCgJ7 Wcp/ji0TLGbQwZZhHUWdbNiqF1oHX0zndh+mI0j7T+GnhLQ8gakq64DhKk15KTpO9/ 0580b2POZm1zQ== From: "Marco Scardovi (scardracs)" To: linusw@kernel.org, brgl@kernel.org, heiko@sntech.de Cc: linux-gpio@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "Marco Scardovi (scardracs)" Subject: [PATCH 2/2] gpio: rockchip: fix teardown bugs and resource leaks Date: Mon, 25 May 2026 18:39:39 +0200 Message-ID: <20260525164230.43307-3-scardracs@disroot.org> In-Reply-To: <20260525164230.43307-1-scardracs@disroot.org> References: <20260525164230.43307-1-scardracs@disroot.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit addresses several teardown issues and resource leaks in the driver's remove path and error handling: 1. Debounce clock reference leak: The debounce clock (bank->db_clk) was obtained using of_clk_get() which increments the clock's reference count, but clk_put() was never called. A devm action is now registered to cleanly release it on unbind. Note that of_clk_get(..., 1) remains necessary over devm_clk_get() because the DT binding does not define clock-names, precluding name-based lookup. 2. Unregistered chained IRQ handler: The chained IRQ handler was not disconnected in remove(). If a stray interrupt fired after the driver was removed, the kernel would attempt to execute a stale handler, leading to a panic. This is fixed by clearing the handler in remove(). 3. IRQ domain leak: The linear IRQ domain and its generic chips were allocated manually during probe but never removed. The IRQ domain is now removed during driver teardown to free the associated generic chips and mappings. Assisted-by: Antigravity:gemini-3.5-flash Signed-off-by: Marco Scardovi --- drivers/gpio/gpio-rockchip.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 33580093a4e7..c804f970d823 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -638,10 +638,17 @@ static int rockchip_gpiolib_register(struct rockchip_= pin_bank *bank) return ret; } =20 +static void rockchip_clk_put(void *data) +{ + struct clk *clk =3D data; + + clk_put(clk); +} + static int rockchip_get_bank_data(struct rockchip_pin_bank *bank) { struct resource res; - int id =3D 0; + int id =3D 0, ret; =20 if (of_address_to_resource(bank->of_node, 0, &res)) { dev_err(bank->dev, "cannot find IO resource for bank\n"); @@ -673,6 +680,13 @@ static int rockchip_get_bank_data(struct rockchip_pin_= bank *bank) dev_err(bank->dev, "cannot find debounce clk\n"); return -EINVAL; } + + ret =3D devm_add_action_or_reset(bank->dev, rockchip_clk_put, + bank->db_clk); + if (ret) { + dev_err(bank->dev, "failed to register debounce clk action\n"); + return ret; + } break; case GPIO_TYPE_V1: bank->gpio_regs =3D &gpio_regs_v1; @@ -789,6 +803,9 @@ static void rockchip_gpio_remove(struct platform_device= *pdev) { struct rockchip_pin_bank *bank =3D platform_get_drvdata(pdev); =20 + irq_set_chained_handler_and_data(bank->irq, NULL, NULL); + if (bank->domain) + irq_domain_remove(bank->domain); gpiochip_remove(&bank->gpio_chip); } =20 --=20 2.54.0