From patchwork Mon Nov 11 12:36:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 13870679 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 7B261D2E9E5 for ; Mon, 11 Nov 2024 12:36:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A035810E4A6; Mon, 11 Nov 2024 12:36:30 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="ik/UjZ5k"; 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 A34B410E49F for ; Mon, 11 Nov 2024 12:36:29 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 7BCFD1BF206; Mon, 11 Nov 2024 12:36:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1731328588; 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=J90J1NyXaKoXccZe2X72ycchhXTtGFZ2PH6GpQkBJsQ=; b=ik/UjZ5kr0Ad8hjStoOIneAgh2ZLiENJBEpnLMi+S8NqjvfpY0KieoBs+OZnU1Zk5hJ0C5 VYH1y8+uGfLFccje9VR5csfmr8SU5+rrE4Kx4IqVhcdDqhWh+C2Lyuvye5K2zBf8ffNYQa rNXGKsWsDEN8qvCUFa0eHQrvbatX31gPKYcVMIkJelOKnNZwiKDh/Hp742tv51ApX3cJuZ +GWZuOKU4/RvIqDCCNiZkfuHmimrd4RHvtUSMS+W9NjKmMyd4ikKgEIjhZez/W1bVFZ4zb bAObfeKbIPuXoPPIGSV0PcaDl5NdOPApsGonT+Spe5vy4zwen7pn/YYQcur54g== From: Luca Ceresoli Date: Mon, 11 Nov 2024 13:36:22 +0100 Subject: [PATCH v3 3/4] drm/mode_object: add drm_mode_object_read_refcount() MIME-Version: 1.0 Message-Id: <20241111-drm-small-improvements-v3-3-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" Add a wrapper to kref_read() just like the ones already in place for kref_get() and kref_put(). This will be used for sanity checks on object lifetime. Signed-off-by: Luca Ceresoli --- Changed in v3: * use conventions for 'Returns' doc syntax * ditch DRM_DEBUG() and as a consequence rework and simplify the entire function * fix function name in kerneldoc --- drivers/gpu/drm/drm_mode_object.c | 17 +++++++++++++++++ include/drm/drm_mode_object.h | 1 + 2 files changed, 18 insertions(+) diff --git a/drivers/gpu/drm/drm_mode_object.c b/drivers/gpu/drm/drm_mode_object.c index df4cc0e8e263d5887a799cf1a61d998234be7158..b9a16aceb926782eb033434eb6967ce9fd2e94f7 100644 --- a/drivers/gpu/drm/drm_mode_object.c +++ b/drivers/gpu/drm/drm_mode_object.c @@ -217,6 +217,23 @@ void drm_mode_object_get(struct drm_mode_object *obj) } EXPORT_SYMBOL(drm_mode_object_get); +/** + * drm_mode_object_read_refcount - read the refcount for a mode object + * @obj: DRM mode object + * + * Returns: + * The current object refcount if it is a refcounted modeset object, or 0 + * for any other object. + */ +unsigned int drm_mode_object_read_refcount(struct drm_mode_object *obj) +{ + if (obj->free_cb) + return kref_read(&obj->refcount); + + return 0; +} +EXPORT_SYMBOL(drm_mode_object_read_refcount); + /** * drm_object_attach_property - attach a property to a modeset object * @obj: drm modeset object diff --git a/include/drm/drm_mode_object.h b/include/drm/drm_mode_object.h index c68edbd126d04d51221f50aa2b4166475543b59f..3d2c739e703888bf4520c61594d480f128d50e56 100644 --- a/include/drm/drm_mode_object.h +++ b/include/drm/drm_mode_object.h @@ -123,6 +123,7 @@ struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, uint32_t id, uint32_t type); void drm_mode_object_get(struct drm_mode_object *obj); void drm_mode_object_put(struct drm_mode_object *obj); +unsigned int drm_mode_object_read_refcount(struct drm_mode_object *obj); int drm_object_property_set_value(struct drm_mode_object *obj, struct drm_property *property,