From nobody Sun Nov 24 12:11:17 2024 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 C0D6F1DED76 for ; Wed, 6 Nov 2024 10:48:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730890129; cv=none; b=nEJ1t5Y39SvEjN2X2O0sBYQ+m+dwNUTqMbbqPhGQCZSRoa4P/E/BJ2ItXQ69O23midaNI+76O/86qkDo6t6VTAbD/OfPjpT6ojYbDEhsk0Fj/t7aK66w6MH+dLDBuU67sU9eP93o9CzOVTyeHyfGnPS4LwHhvI71XMSmVaR9HiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730890129; c=relaxed/simple; bh=pudTfM36kFQMq2RWVOPHfAT6VK0+RurGw7EGVRZsQII=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mm+FQ/e5ToXtbMl23BnifW3mUNfJCepEj9f38LFAxEDzKfVlsLsfhrUf+uE181AJQxcad7fQNTJjz18W3ceKk/h/cgVPkJnfcknoSXHfl6buoYq4BP9NtjdvsZ3YipQHwgk4WyfBHInWcv9+ic88I1fYn5PRXMzsmOcdiNotX0I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=kaUmYTxC; arc=none smtp.client-ip=217.70.183.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="kaUmYTxC" Received: by mail.gandi.net (Postfix) with ESMTPSA id 6DAC160003; Wed, 6 Nov 2024 10:48:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1730890125; 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=ZWsYONnEgvEeIa9tipWPBTuf84MWmW0KPLgHIvkZDok=; b=kaUmYTxCnAY2Yaz8+lF+h/n9rzbIibLHfOtbjYi0RxCWz7kJHEgqIzosrye/v3wAiLSPLW gO9t/5T1tl6xNTSs2mPVzehbbookhUgglKSomQsH7cMyi+oTmW7jhhYhmKo8xYKRGsT7vQ lM81A82fyV1da9oFru9YDUO9/fIIOVB1h++XisPbFFxHmc9O7c78qxbpzwbYSCYbVD2/kV 3yUPLJw07eInHnS1s2gLJ8F2QK8kmW01qB5Gwy/2GOIb6wVy9EB0EzHSXbB4/F5kwkSvTO rAdLAmsK2Beluk6zyorHqG8v54mwsNjHmEUwfihpS+VpYxgbzWfK5mVI2gC+Tg== From: Luca Ceresoli Date: Wed, 06 Nov 2024 11:48:27 +0100 Subject: [PATCH v2 4/4] drm/connector: warn when cleaning up a refcounted connector 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: quoted-printable Message-Id: <20241106-drm-small-improvements-v2-4-f6e2aef86719@bootlin.com> References: <20241106-drm-small-improvements-v2-0-f6e2aef86719@bootlin.com> In-Reply-To: <20241106-drm-small-improvements-v2-0-f6e2aef86719@bootlin.com> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter Cc: 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 Calling drm_connector_cleanup() should only be done via the free_cb =3D> .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. Signed-off-by: Luca Ceresoli Reviewed-by: Dmitry Baryshkov --- 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_connecto= r.c index fc35f47e2849ed6786d6223ac9c69e1c359fc648..e0bf9c490af43055de4caaee158= 0a4befbd608c5 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 *conne= ctor) struct drm_device *dev =3D connector->dev; struct drm_display_mode *mode, *t; =20 + /* + * Cleanup must happen when the last ref is put, via the + * drm_connector_free() callback. + */ + WARN_ON(drm_mode_object_read_refcount(&connector->base) !=3D 0); + /* The connector should have been removed from userspace long before * it is finally destroyed. */ --=20 2.34.1