From nobody Mon Jun 8 20:53:15 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 9570A2D0C62; Tue, 26 May 2026 17:11:08 +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=1779815470; cv=none; b=TUFuEWjzdQiS7XT1Vbyc/qLIV9YFPv+I+cOeTHbh/P+Sr7iQjwCYc3VhQ3gTr5kgIv+jiK1+F4sfMKokmK4uEXgjaZh3jq8dzYrgwUA+giace5rhRBoexN7xNP8ZNcUt0bRfxRZgGV2AR+ZhieWdls7maRl/l2CuJF3Y8OGTrYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779815470; c=relaxed/simple; bh=XdAOWq8GGsIdFr4SLIxKKpxOgKgyrzPl7v4EErdEiPY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mXTdY+yBcCn9f4DImjIZdGRTj6M7cDiKUmhK+mkq0nfC7SlwlNp2lGch/SxfBhrnasxhN+EBx+HoXk1gJVpKfOCN5/CCfMM5bHxkOL12pvbcIougN0FH1CxNh2TdDBnhTT/z0AnovCUQM7uKmgg/PojaPAcAGXEj3Lq/VYKgxsc= 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=YvY47lyb; 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="YvY47lyb" Received: from mail01.disroot.lan (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 4AD0F26F8E; Tue, 26 May 2026 19:11:07 +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 WwX45KF2v4_W; Tue, 26 May 2026 19:11:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1779815466; bh=XdAOWq8GGsIdFr4SLIxKKpxOgKgyrzPl7v4EErdEiPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YvY47lybVuABgoIIJo3mtGYHdx+Dhyl7GsDFT6RCpU/MhGw4R7FYyC9XDGQd4peCX cJ08ca/3HaJP5VXxBKZLSz9A4pgR7yjHyXNhsQksk/IZo7OH/cInX4r/Yu5ho/IFxa Z74y/Ye3RO1BVUDGDFtgf5KKEx0oXD0zZ6pvd+Oj49WaN+ciZ1/1Pal7CKiOND0wkN Tipb0bqz13qWVhMMYCk47hr2kbSGymDNldymyi0M52vJ85KPAPkF1nK8Ipk7aH3cEw ZW4cTgnHzk8HgSVPpOWNAt+IwMZ8DRqHFepe7+HK040S5Pe6wWIyOCFT41quzGubGy orjbUFwVNddLQ== From: Marco Scardovi To: brgl@kernel.org Cc: heiko@sntech.de, linusw@kernel.org, linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, scardracs@disroot.org Subject: [PATCH v2 1/2] gpio: rockchip: convert bank->clk to devm_clk_get_enabled() Date: Tue, 26 May 2026 19:02:45 +0200 Message-ID: <20260526171050.12785-2-scardracs@disroot.org> In-Reply-To: <20260526171050.12785-1-scardracs@disroot.org> References: <20260526171050.12785-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. Fix the reference leak and simplify the code by removing the manual clk_disable_unprepare() calls in the probe error paths and in the remove function. Fixes: 936ee2675eee ("gpio/rockchip: add driver for rockchip gpio") 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 20:53:15 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 31439CA45; Tue, 26 May 2026 17:11:08 +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=1779815470; cv=none; b=ZTxeN4nc6j0pkT6imiRGRgb6eLBv0ezoswp0/9xzPogfRuR/rfzzc/Y5qM9fOGsyRm+FREM9b+sf+FgbfQhmw+flkWE51qDXXGnY3egMktu12wqE16YmsiIqmvaDpQ6VbQaYIQ3HRltqj7CuLpOsZus0zBplJPzIrPtizfQtArU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779815470; c=relaxed/simple; bh=nG8T2sDyMTvq1VTUzB4uTiqI65Ywba/cU0io/fgNHAM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JItAKsar9fpLmrmknymjGBFeZvXxbqIbai/ebpO254Kr2FHp0vuoT2gbjSAy9Yuno81AHzzLBUk8l5DyFq5Jec8rwaNql8cZJJm0PYpCwYUj1J3xUZhAMQx6qle0C7Nb3iJTYqMLCbqeN3lXV4bRsP5Wsyqm8OjtqqBxXvqFCBY= 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=brMpP/3u; 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="brMpP/3u" Received: from mail01.disroot.lan (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id C740A26FB1; Tue, 26 May 2026 19:11:07 +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 KdRAlyE6vvhA; Tue, 26 May 2026 19:11:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1779815467; bh=nG8T2sDyMTvq1VTUzB4uTiqI65Ywba/cU0io/fgNHAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=brMpP/3uRaqBFyS/3FuWaqj1LkIPLM+tFUWQRmjORbIzViIkjkFoIPeTkRbUS8zKs T1lRwi0t99btr6XxUHAVG4C867WQISraNMZIsSq24o+dcwB1tXcVQIAz46Yh2bvpCu JgxJHhkG4XyFoYHChl+8F6RP/G28Wj3wGQdNDiVyYd1q2i5OeRYb4N44AuWaxPU8wV cDiG69QFl4XFcpm8RbK5qeD/h/21HpPgUfOryzfzHg3bFWUz6ZGXaYH3ODantIsYCH jZeX0y86TV0PKcZeFCmMbsqNpvYcwszxdeD/c5Uy6Cgotvehm5IEut3i+vkoFwoctl 9CYvG703MaCow== From: Marco Scardovi To: brgl@kernel.org Cc: heiko@sntech.de, linusw@kernel.org, linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, scardracs@disroot.org Subject: [PATCH v2 2/2] gpio: rockchip: teardown bugs and resource leaks Date: Tue, 26 May 2026 19:02:46 +0200 Message-ID: <20260526171050.12785-3-scardracs@disroot.org> In-Reply-To: <20260526171050.12785-1-scardracs@disroot.org> References: <20260526171050.12785-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" Address 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) is obtained using of_clk_get() which increments the clock's reference count, but clk_put() is never called. Register a devm action 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 is not disconnected in remove(). If a stray interrupt fires after the driver is removed, the kernel attempts to execute a stale handler, leading to a panic. Fix this by clearing the handler in remove(). 3. IRQ domain leak: The linear IRQ domain and its generic chips are allocated manually during probe but never removed. Remove the IRQ domain during driver teardown to free the associated generic chips and mappings. Fixes: 936ee2675eee ("gpio/rockchip: add driver for rockchip gpio") 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