From mboxrd@z Thu Jan 1 00:00:00 1970 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 539463DCD9C for ; Fri, 26 Jun 2026 12:04:13 +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=1782475454; cv=none; b=j+MqAP69kVRcLsUFggnwV+PpDkQdBChjog1qbcmBbnBdkkFSBxS1cpV96WDOcvcIBz0+1xcUgWr2wAP8u2fXo1PwJwXjTGXYxuojdya1xBKSxT6Ipo8dTGSKQ5ks9ZWQNEfXBbtRHo6Jb9Z/ad77QL/8z/6qu9PYsPHRmVYSpmY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782475454; c=relaxed/simple; bh=orKWqDgf+p3yKjBR7Y3rK+A3gtMJHSHsy3pz0IxqEa8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RHdHHGjWqBt+b/atgys1bDHRIE2tnRbUWX71aTy4JzOdiVySJi1xPI3s37hHmvquKL8gfkuHHoZtbwOWsIW0PkaW093wclR2iga8ImIBCU30e0diiLfeNeC48+vKQ2LFGbRZXHJEGwg6Eblm2cL8KAcmsXMNFUXxfzXgtO2vQd4= 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=Y66EFTWz; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Y66EFTWz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782475452; 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: in-reply-to:in-reply-to:references:references; bh=FViDxx5winIJTx4A1LSm96AlpSugjn0hoKixmZIIAiQ=; b=Y66EFTWzmn4dITb44OUO/RpvsBmqGjyhd/ZyTSugmEixmAYgym8CfQjNEvs9Vwl8pcPvNe XlpVZnbKpWWUK9hafyidG4BUajLs7JwLO9vyfKmMFMZIG8fCb3owBK4LvUu3vuHk37KbQD Y0orLU0iCn4+1zp+xZMKOHHWLEDUmT4= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-7c2vqhWPPASsVPMehKOiHA-1; Fri, 26 Jun 2026 08:04:09 -0400 X-MC-Unique: 7c2vqhWPPASsVPMehKOiHA-1 X-Mimecast-MFC-AGG-ID: 7c2vqhWPPASsVPMehKOiHA_1782475446 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E7CBA19560AD; Fri, 26 Jun 2026 12:04:05 +0000 (UTC) Received: from [192.168.1.153] (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4AAFA18005B6; Fri, 26 Jun 2026 12:03:49 +0000 (UTC) From: Albert Esteve Date: Fri, 26 Jun 2026 14:03:23 +0200 Subject: [PATCH 1/5] drm/panel: have drm_panel_add/remove manage a list reference Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260626-drm_refcount_wiring-v1-1-cca1a7b3bdef@redhat.com> References: <20260626-drm_refcount_wiring-v1-0-cca1a7b3bdef@redhat.com> In-Reply-To: <20260626-drm_refcount_wiring-v1-0-cca1a7b3bdef@redhat.com> 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=1782475410; l=1528; i=aesteve@redhat.com; s=20260303; h=from:subject:message-id; bh=orKWqDgf+p3yKjBR7Y3rK+A3gtMJHSHsy3pz0IxqEa8=; b=lP43AsH/FBUNAw+g/vAGxmj6wle77hMQ+FEg934iAODxrHenTnoOgZ4wiFXO/xT0AQViPwIHO J92o4leGVQ0A3rA3e6xzgaxeW87HR9Tc8kvHmKBq2DTk8fvIcTt9gLP X-Developer-Key: i=aesteve@redhat.com; a=ed25519; pk=YSFz6sOHd2L45+Fr8DIvHTi6lSIjhLZ5T+rkxspJt1s= X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 The global panel_list holds raw pointers to drm_panel objects. Nothing prevents a panel from being freed while it is still linked in the list: if a driver's probe calls drm_panel_add() and then fails at a later step, panel->list remains in panel_list. Any subsequent call to of_drm_find_panel() that iterates the list will dereference freed memory. Have drm_panel_add() acquire a reference via drm_panel_get() before inserting the panel into the list, and have drm_panel_remove() drop it via drm_panel_put() after removing the panel from the list. The global registry now holds a counted reference for as long as the panel is listed, ensuring the object outlives any concurrent lookup. Signed-off-by: Albert Esteve --- drivers/gpu/drm/drm_panel.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c index 2c5649e433dfb..545fe93dc28fe 100644 --- a/drivers/gpu/drm/drm_panel.c +++ b/drivers/gpu/drm/drm_panel.c @@ -81,6 +81,7 @@ static void drm_panel_init(struct drm_panel *panel, struct device *dev, */ void drm_panel_add(struct drm_panel *panel) { + drm_panel_get(panel); mutex_lock(&panel_lock); list_add_tail(&panel->list, &panel_list); mutex_unlock(&panel_lock); @@ -98,6 +99,7 @@ void drm_panel_remove(struct drm_panel *panel) mutex_lock(&panel_lock); list_del_init(&panel->list); mutex_unlock(&panel_lock); + drm_panel_put(panel); } EXPORT_SYMBOL(drm_panel_remove); -- 2.54.0