From patchwork Fri Jul 17 14:02:03 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Albert Esteve X-Patchwork-Id: 302 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 54D711C2C22 for ; Fri, 17 Jul 2026 16:09:26 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=redhat.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-24488-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-24488-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sea.lore.kernel.org (Postfix) with ESMTP id 7A93630425A7 for ; Fri, 17 Jul 2026 14:04:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03EB6305676; Fri, 17 Jul 2026 14:04:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XEChtGs0" X-Original-To: linux-sunxi@lists.linux.dev Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77BFB1CEAC2 for ; Fri, 17 Jul 2026 14:03:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784297039; cv=none; b=rFRB+9I9cU4xc/mwxSYYeSdQ3QGJkriqf8DbiZ1UdzhysBKFr7S5hLY/10nuUc05hzVgSPrZF34CTq8705DqCFf1VjFqKN6KA56PIJxU/wf0WZML6tA9MheWVWRf5fWpf9K7KREHAXUQ23CSn1Jfqg0VRiOz8tc9rGk3G9WPzoE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784297039; c=relaxed/simple; bh=CBR1Ph2kUJjjkYaGrdkvqaa4iWlYMfiXDLEZXyTQZ1o=; h=From:Subject:Date:Message-Id:MIME-Version:To:Cc:Content-Type; b=qGNbvSqNvjzCN4wt4C9zXGNcF8uE51V303bRAMY6GIbir0HxlZFkFsLTKBwBaaez+1OoUnODKXqeMYuH9Nq7sxP6gUph9KCq4rOreVNngyufvOJmqb7lDP1W3WTqEd893ePSmDTCuaNCYtG8nOgEvbZ4oOK+ZlEtHpoACQBiz78= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XEChtGs0; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784297037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KXAKRwDTnzEg9ZBBk/oAwaIuZZpboPYGh9kDsncZq0U=; b=XEChtGs0gVhHVA4dZhDwiM5oNgLSAN+6QZKeYvb05RZfyRychjsySDdsUc4+ZQFRmgy1CB 0JBbeB9+DnPH4izZrGr6QpXr9g5/6Xskje/3m0hHQ6FRxduOh268bYi4Q4IPiAiigPE/8a pTs0ycapj2FPIrc0270FhR5IF2xVGlc= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-270-B9LWD_NdMFydwywJpNzkwg-1; Fri, 17 Jul 2026 10:02:47 -0400 X-MC-Unique: B9LWD_NdMFydwywJpNzkwg-1 X-Mimecast-MFC-AGG-ID: B9LWD_NdMFydwywJpNzkwg_1784296961 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B1AF018007F5; Fri, 17 Jul 2026 14:02:38 +0000 (UTC) Received: from [192.168.1.153] (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 342F318005B3; Fri, 17 Jul 2026 14:02:18 +0000 (UTC) From: Albert Esteve Subject: [PATCH v3 0/4] drm/panel: refcounting panel lookups and references Date: Fri, 17 Jul 2026 16:02:03 +0200 Message-Id: <20260717-drm_refcount_wiring-v3-0-023900c32e01@redhat.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAAAAAAAC/3XOyw6CMBAF0F8hXVvTF2105X8YQ/oYoAuKabFqC P9uwYUx0eWdzD0zM0oQPSR0rGYUIfvkx1AC31XI9jp0gL0rGTHCJKkpxy4OTYTWjrcwNXcffei wgBpUreBAhEKleS0L/rGp50vJvU/TGJ/bkUzX6duTTP70MsUEW6upVoYbB+0pguv1tLfjgFYws w+i/jyVWUEcN0bSVhgn3BeyLMsLlq5UcPwAAAA= X-Change-ID: 20260513-drm_refcount_wiring-4e5e757e9047 To: Neil Armstrong , Jessica Zhang , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Andrzej Hajda , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Luca Ceresoli , Inki Dae , Jagan Teki , Marek Szyprowski , Laurentiu Palcu , Lucas Stach , Frank Li , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Paul Cercueil , Linus Walleij , Marek Vasut , Stefan Agner , Tomi Valkeinen , Laurent Pinchart , Kieran Bingham , Geert Uytterhoeven , Magnus Damm , Biju Das , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Andy Yan , Yannick Fertre , Raphael Gallais-Pou , Philippe Cornu , Maxime Coquelin , Alexandre Torgue , Chen-Yu Tsai , Samuel Holland , Jyri Sarha , Jingoo Han , Seung-Woo Kim , Kyungmin Park , Krzysztof Kozlowski , Peter Griffin , Alim Akhtar , Alison Wang , Paul Kocialkowski , Alain Volmat , Raphael Gallais-Pou , Thierry Reding , Mikko Perttunen , Jonathan Hunter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@lists.linux.dev, linux-samsung-soc@vger.kernel.org, linux-tegra@vger.kernel.org, Albert Esteve X-Developer-Signature: v=1; a=ed25519-sha256; t=1784296938; l=6089; i=aesteve@redhat.com; s=20260303; h=from:subject:message-id; bh=CBR1Ph2kUJjjkYaGrdkvqaa4iWlYMfiXDLEZXyTQZ1o=; b=wkA63uP1ZKoAa4h64tde85ydj2YqROznD17VIE6GUQVqeRP94Romw2NP7XiRctsK48Czd8IKA egJVcLgipY8AlirQeQbG5HkLYCJmhqolZb8CsYQG+KwOXgQPNcCRePK X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=YSFz6sOHd2L45+Fr8DIvHTi6lSIjhLZ5T+rkxspJt1s= X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 4u--eli7Qjq6NFCncvaUtz1Pc0iOV7mWjSszz7H9Fm0_1784296961 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [3.34 / 15.00]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; MAILLIST(-0.15)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:rdns,sea.lore.kernel.org:helo]; FROM_HAS_DN(0.00)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc-20240116:i=1]; PRECEDENCE_BULK(0.00)[]; TAGGED_RCPT(0.00)[renesas]; R_DKIM_ALLOW(0.00)[redhat.com:s=mimecast20190719]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_NEQ_ENVFROM(0.00)[aesteve@redhat.com,linux-sunxi@lists.linux.dev]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; TAGGED_FROM(0.00)[bounces-24488-noreply=patchwork.local]; DKIM_TRACE(0.00)[redhat.com:+]; DMARC_POLICY_ALLOW(0.00)[redhat.com,quarantine]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10]; TO_DN_SOME(0.00)[]; RCVD_COUNT_SEVEN(0.00)[7]; RCPT_COUNT_GT_50(0.00)[68]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_TO(0.00)[linaro.org,gmail.com,linux.intel.com,kernel.org,suse.de,ffwll.ch,intel.com,ideasonboard.com,kwiboo.se,bootlin.com,samsung.com,amarulasolutions.com,oss.nxp.com,pengutronix.de,nxp.com,crapouillou.net,denx.de,agner.ch,glider.be,bp.renesas.com,rock-chips.com,sntech.de,foss.st.com,sholland.org,iki.fi,sys-base.io,nvidia.com]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; FORGED_SENDER_MAILLIST(0.00)[] X-Rspamd-Queue-Id: 54D711C2C22 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= The drm_panel subsystem provides kref-based reference counting [1] (drm_panel_get/put) but almost nothing in the tree actually uses it. This results in a systemic use-after-free pattern throughout the codebase. This series aims to close all those issues. Patches 1-2: fix the infrastructure. drm_panel_add/remove now keep a counted reference for the list entry. drm_panel_bridge_add_typed() now holds a counted reference for the lifetime of the panel_bridge. Patch 3: change the semantics of of_drm_find_panel(). It now acquires a reference before returning, under panel_lock. All in-tree callers of of_drm_find_panel() and drm_of_find_panel_or_bridge() are updated. Two patterns are common in these fixes: - Bridge-wrapping: the panel is passed to devm_drm_panel_bridge_add() or equivalent, which acquires its own reference. The caller (including devm_drm_of_get_bridge() and drmm_of_get_bridge()) releases its lookup reference immediately after. - Store-and-use: the panel pointer is kept in a driver struct and used directly for the device lifetime. The reference is released in the remove/unbind path, or via devm_add_action_or_reset() where no explicit teardown function exists. Patch 4: extend the same fix to find_panel_by_fwnode(), a static helper used internally by drm_panel_add_follower(). Since it has no external callers, the fix is self-contained: drm_panel_remove_follower() is updated to call drm_panel_put() to balance the reference. In order to catch all places in the tree that required releasing the reference, the search was assisted by an AI model. Specifically, a Coccinelle script was designed by the agent to address the trivial changes (not included in the series). Although a few required manual fixes, with goto labels or bracket additions. Additionally, the model helped to discern implicit teardown paths that were addressed with devm_add_action_or_reset() calls. Thus, these commits have the Assisted-by label following the project guidelines. No functional change is intended for any driver. The reference counting only affects object lifetime; panel operations are unaffected. [1] https://lore.kernel.org/all/20250331-b4-panel-refcounting-v4-0-dad50c60c6c9@redhat.com/ Signed-off-by: Albert Esteve --- Changes in v3: - Squashed patches 3 and 5 - Fix probe failure paths that leaked reference - Fix UAF and other smaller issues found by Sashiko - Add comment in tegra-dsi explaining why panel is always NULL in that path and so no early drm_panel_put() is required - Link to v2: https://lore.kernel.org/r/20260713-drm_refcount_wiring-v2-0-d3bb61f4bd4d@redhat.com Changes in v2: - Squash of_drm_find_panel() API change with its caller fixes - Split find_panel_by_fwnode() into its own commit - Update kernel-doc for drm_of_find_panel_or_bridge() - Link to v1: https://lore.kernel.org/r/20260626-drm_refcount_wiring-v1-0-cca1a7b3bdef@redhat.com --- Albert Esteve (4): drm/panel: have drm_panel_add/remove manage a list reference drm/bridge/panel: hold a reference to the wrapped panel drm/panel: of_drm_find_panel() return a counted reference drm/panel: find_panel_by_fwnode() return a counted reference drivers/gpu/drm/bridge/analogix/analogix-anx6345.c | 12 +++++++++++ drivers/gpu/drm/bridge/fsl-ldb.c | 1 + drivers/gpu/drm/bridge/lontium-lt9211.c | 1 + drivers/gpu/drm/bridge/lvds-codec.c | 1 + drivers/gpu/drm/bridge/panel.c | 20 ++++++++++++++---- drivers/gpu/drm/bridge/samsung-dsim.c | 1 + drivers/gpu/drm/bridge/ssd2825.c | 1 + drivers/gpu/drm/bridge/tc358767.c | 2 ++ drivers/gpu/drm/bridge/tc358768.c | 1 + drivers/gpu/drm/bridge/waveshare-dsi.c | 1 + drivers/gpu/drm/drm_of.c | 3 ++- drivers/gpu/drm/drm_panel.c | 24 +++++++++++++++++----- drivers/gpu/drm/exynos/exynos_dp.c | 19 ++++++++++++++++- drivers/gpu/drm/exynos/exynos_drm_dpi.c | 3 +++ drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c | 18 ++++++++++++++++ drivers/gpu/drm/imx/dcss/dcss-kms.c | 3 +++ drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 4 +++- drivers/gpu/drm/logicvc/logicvc_interface.c | 12 +++++++++++ drivers/gpu/drm/mcde/mcde_drv.c | 1 + drivers/gpu/drm/mcde/mcde_dsi.c | 1 + drivers/gpu/drm/mxsfb/mxsfb_drv.c | 1 + drivers/gpu/drm/omapdrm/dss/output.c | 1 + drivers/gpu/drm/pl111/pl111_drv.c | 1 + drivers/gpu/drm/renesas/rcar-du/rcar_du_encoder.c | 1 + drivers/gpu/drm/renesas/rcar-du/rcar_lvds.c | 1 + drivers/gpu/drm/renesas/rz-du/rzg2l_du_encoder.c | 1 + drivers/gpu/drm/rockchip/analogix_dp-rockchip.c | 11 ++++++++++ drivers/gpu/drm/rockchip/rockchip_lvds.c | 4 ++++ drivers/gpu/drm/rockchip/rockchip_rgb.c | 3 +++ drivers/gpu/drm/sti/sti_dvo.c | 3 +++ drivers/gpu/drm/stm/ltdc.c | 1 + drivers/gpu/drm/stm/lvds.c | 12 ++++++++--- drivers/gpu/drm/sun4i/sun4i_lvds.c | 13 ++++++++++++ drivers/gpu/drm/sun4i/sun4i_rgb.c | 13 ++++++++++++ drivers/gpu/drm/sun4i/sun4i_tcon.c | 2 ++ drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c | 6 +++++- drivers/gpu/drm/tegra/dsi.c | 5 +++++ drivers/gpu/drm/tegra/output.c | 24 +++++++++++++++++++--- drivers/gpu/drm/tidss/tidss_kms.c | 16 ++++++++++----- drivers/gpu/drm/tve200/tve200_drv.c | 1 + 40 files changed, 225 insertions(+), 24 deletions(-) --- base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda change-id: 20260513-drm_refcount_wiring-4e5e757e9047 Best regards,