From patchwork Mon Nov 11 12:36:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 13870680 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9F74ED2E9E3 for ; Mon, 11 Nov 2024 12:36:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EAB7C10E4A4; Mon, 11 Nov 2024 12:36:33 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="LDGfpUG3"; dkim-atps=neutral Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5A2C710E4A2 for ; Mon, 11 Nov 2024 12:36:30 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 5BBA01BF209; Mon, 11 Nov 2024 12:36:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1731328589; 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=qW3wdr4EeYIZ0MLaRPPuH3cK65j246cHF8/ZPxNc2Bo=; b=LDGfpUG3r6SAvyB0iHpIkXFrP9CQ12QOeFNpf5UcYXU+t6/9WL1alKBVgF+NqLVOzt5HkI RJGaFAVgeOIrLylJ7JwiznbRhkMNuvvocphw1ONk+1dThmEvpatSqBARiAb25/GwZ4a1GR YrfybiCo/WwijUlYAx1GtV9kqRV5SKTESGb8JvTzm0iKsz8DKnl6/1rfwc3+I+zI7XgXfl I7Qo4HPnnGUrvbtY96L33pXfpABVFDglcVRP4l1bm7I8061+PnNU4oo6E//UVFw9KhHZpN 0PwWzNw0s3X0htqCFXO6GvAL7MY/qW08qiShxEX04p93lqO2wA0c1TyWBsKdkg== From: Luca Ceresoli Date: Mon, 11 Nov 2024 13:36:23 +0100 Subject: [PATCH v3 4/4] drm/connector: warn when cleaning up a refcounted connector MIME-Version: 1.0 Message-Id: <20241111-drm-small-improvements-v3-4-a9f576111b41@bootlin.com> References: <20241111-drm-small-improvements-v3-0-a9f576111b41@bootlin.com> In-Reply-To: <20241111-drm-small-improvements-v3-0-a9f576111b41@bootlin.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter Cc: Dmitry Baryshkov , Jani Nikula , Thomas Petazzoni , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Luca Ceresoli X-Mailer: b4 0.14.2 X-GND-Sasl: luca.ceresoli@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Calling drm_connector_cleanup() should only be done via the free_cb => .destroy path, which cleans up the struct drm_connector only when the refcount drops to zero. A cleanup done with a refcount higher than 0 can result from buggy code, e.g. by doing cleanup directly in the drivers teardown code. Serious trouble can happen if this happens, so warn about it. Reviewed-by: Dmitry Baryshkov Signed-off-by: Luca Ceresoli --- drivers/gpu/drm/drm_connector.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index fc35f47e2849ed6786d6223ac9c69e1c359fc648..e0bf9c490af43055de4caaee1580a4befbd608c5 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -624,6 +624,12 @@ void drm_connector_cleanup(struct drm_connector *connector) struct drm_device *dev = connector->dev; struct drm_display_mode *mode, *t; + /* + * Cleanup must happen when the last ref is put, via the + * drm_connector_free() callback. + */ + WARN_ON(drm_mode_object_read_refcount(&connector->base) != 0); + /* The connector should have been removed from userspace long before * it is finally destroyed. */