From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 F2F8C34D4F9; Tue, 28 Apr 2026 15:31:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777390289; cv=none; b=ViBVG1VdRwg5S+wrSiEyIWj0yvJryr04dsJtgTYi8gSG4UpT2EwerYsS7ciTwLCLMu9Mm5fdv17jzE98wsuMokGiFch/GRNz/FrvMFdgQlXeoYzFF1jlaJymKyDdx3MDxrC/0tDwM7xzz50YhaP6TWufep0r8qAg/kSwg+lkW+w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777390289; c=relaxed/simple; bh=/6i+I+Ahqcaw0hEVyXO/+NoRSgZfkn3GsxAfKifHV7c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UoTQajJFLB2HcqfFQJw7ktd2l/1TesH8bDgdnY3fMtU5vn1fc0wGc7u3LbEtmYxmzz2p0soKjT5r4hHbYvyIkEtoO720E5fktduV3DqdeoVeymbZ29FHMd0lBJpxFpZj3CSsXeq9ItmKgzaOEV2IRJN9iXemKNy90YqkBJOH0n8= 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=WB8l9OWe; arc=none smtp.client-ip=185.171.202.116 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="WB8l9OWe" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 0A240C5EF13; Tue, 28 Apr 2026 15:32:10 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 552F8601D0; Tue, 28 Apr 2026 15:31:26 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id C96E910728E18; Tue, 28 Apr 2026 17:31:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1777390284; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=2BvOzWo5y7iu3ogjGuvFlqMhxWThTnHYQLmqfAhkhSI=; b=WB8l9OWelMoWKonXJmNPEosw6UmTjMyDvYMFiv/ZdIvZ4c6MGQcKzq18C2w1A8bXXr8vgI nVjEYs4aT+s2bQ60RJMG00r/kY/Frg5dC3GxgIb5Gj75D0J7PzKJn+DLNlC/c50/YDOhc3 ohEdTqbZepBi+gLbNS8J/XHz+sPbssxw+Hj+fPmiCwwLHZzKXD4lUHT7mVewpLsJQCrExU Sx0cVc7E87qv5/pLQXSPuzuWbJ4Gq7QqeMAa2F/2bQ0VAcf9IghwVpRk61SAAxFb7zj8O9 C0Jtlr5MFFwxo9VZqwbxpc/dazjgPtenP27VYlYAPc+QgfnzjiWUAELitWcxCg== From: Luca Ceresoli Date: Tue, 28 Apr 2026 17:30:50 +0200 Subject: [PATCH v3 01/11] drm/bridge: drm_bridge_get/put(): ignore ERR_PTR 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: <20260428-drm-bridge-alloc-getput-panel_or_bridge-v3-1-a537b5567add@bootlin.com> References: <20260428-drm-bridge-alloc-getput-panel_or_bridge-v3-0-a537b5567add@bootlin.com> In-Reply-To: <20260428-drm-bridge-alloc-getput-panel_or_bridge-v3-0-a537b5567add@bootlin.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Rob Clark , Dmitry Baryshkov , Abhinav Kumar , Jessica Zhang , Sean Paul , Marijn Suijten , Xinliang Liu , Sumit Semwal , Yongqin Liu , John Stultz , Tomi Valkeinen , Michal Simek Cc: Hui Pu , Ian Ray , Thomas Petazzoni , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, Luca Ceresoli , Laurent Pinchart , Dmitry Baryshkov X-Mailer: b4 0.15.2 X-Last-TLS-Session-Version: TLSv1.3 Most functions returning a struct drm_bridge pointer currently return a valid pointer or NULL, but this restricts their ability to return an error code describing the error kind. In preparation to have new APIs that can return a struct drm_bridge pointer holding an ERR_PTR (and for those which already do) make drm_bridge_get() and drm_bridge_put() ignore ERR_PTR values, just like they ignore NULL pointers. This will avoid annoying error checking in many places and the risk of missing error checks. Suggested-by: Laurent Pinchart Link: https://lore.kernel.org/all/20260318152533.GA633439@killaraus.ideasonboard.com/ Suggested-by: Dmitry Baryshkov Link: https://lore.kernel.org/all/omlnswxukeqgnatzdvooaashgkfcacjevkvbkm6xt33itgua2k@jcmzll2w6kdq/ Reviewed-by: Dmitry Baryshkov Signed-off-by: Luca Ceresoli --- Patch added in v2 --- drivers/gpu/drm/drm_bridge.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index 986e4c79a4e0..cea5babbe99e 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -282,7 +282,7 @@ static void __drm_bridge_free(struct kref *kref) /** * drm_bridge_get - Acquire a bridge reference - * @bridge: DRM bridge; if NULL this function does nothing + * @bridge: DRM bridge; if NULL or an ERR_PTR this function does nothing * * This function increments the bridge's refcount. * @@ -291,7 +291,7 @@ static void __drm_bridge_free(struct kref *kref) */ struct drm_bridge *drm_bridge_get(struct drm_bridge *bridge) { - if (bridge) + if (!IS_ERR_OR_NULL(bridge)) kref_get(&bridge->refcount); return bridge; @@ -300,7 +300,7 @@ EXPORT_SYMBOL(drm_bridge_get); /** * drm_bridge_put - Release a bridge reference - * @bridge: DRM bridge; if NULL this function does nothing + * @bridge: DRM bridge; if NULL or an ERR_PTR this function does nothing * * This function decrements the bridge's reference count and frees the * object if the reference count drops to zero. @@ -310,7 +310,7 @@ EXPORT_SYMBOL(drm_bridge_get); */ void drm_bridge_put(struct drm_bridge *bridge) { - if (bridge) + if (!IS_ERR_OR_NULL(bridge)) kref_put(&bridge->refcount, __drm_bridge_free); } EXPORT_SYMBOL(drm_bridge_put); @@ -319,8 +319,8 @@ EXPORT_SYMBOL(drm_bridge_put); * drm_bridge_clear_and_put - Given a bridge pointer, clear the pointer * then put the bridge * @bridge_pp: pointer to pointer to a struct drm_bridge; ``bridge_pp`` - * must be non-NULL; if ``*bridge_pp`` is NULL this function - * does nothing + * must be non-NULL; if ``*bridge_pp`` is NULL or an ERR_PTR + * this function does nothing * * Helper to put a DRM bridge, but only after setting its pointer to * NULL. Useful when a struct drm_bridge reference must be dropped without -- 2.53.0