From patchwork Mon Jan 2 12:01:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 13086726 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 B7828C3DA7A for ; Mon, 2 Jan 2023 12:01:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D45BD10E344; Mon, 2 Jan 2023 12:01:31 +0000 (UTC) Received: from new2-smtp.messagingengine.com (new2-smtp.messagingengine.com [66.111.4.224]) by gabe.freedesktop.org (Postfix) with ESMTPS id 72DAD10E344 for ; Mon, 2 Jan 2023 12:01:29 +0000 (UTC) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailnew.nyi.internal (Postfix) with ESMTP id D003B580C7A; Mon, 2 Jan 2023 07:01:26 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 02 Jan 2023 07:01:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:sender:subject:subject:to:to; s=fm3; t=1672660886; x=1672668086; bh=uEKmG+6dNXPgUJX+bG2DQMjEj SeELmo5mzB+Sfe2Ijs=; b=aH9ptOHGgwDqNDOWzPlQI3GzhncviGWnhB09eGkVA 7mQUfbSPn/AgZHfrWwiUPvTpsTIdLGh7WgOawj82EqHKG8Z5MhtcMWJ+wN1agZYP zQQiiVc/GKEUsVzkmIQTDb9pQVLS7WswWksVXflggl8tke2SLrK0VrSlWuKXB1YM yYDMSMzNeSeUqAAWFFrsICZj4qtvb7N2XBhAPMvj1ZpXNw2n08gcGUt7JbaEIw6H DtaDpzyDj55jJeloo1SsNlzm3VqGRuEZrp7TVn1+RnpMI4jZhLoP1CmIcMt+mSJd ZSCkFrt+JAoQ9Scv60yRo15WIjFi6ME2vNk6cT1DJAeCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1672660886; x=1672668086; bh=uEKmG+6dNXPgUJX+bG2DQMjEjSeELmo5mzB +Sfe2Ijs=; b=Ey02JA7ym7ZhluUrnVsLJphnMC8hixoTHKKZUZ0Lrr8kwKBe+6e uj2GUVQ0sIpPXGdlapXhku1KWfA3KtwfqK32k2TxKacrPkdWVwi7eVgKmJjY5uPi /Gt8FcsxjZrvvngbKW8FeXuiWEHLgcJHIikbvs4qT5toj0BpfmATbzCYb/KpNlLN VM8rm/z+AbAUpgihxy36NeMO1/phtAutMuB9mhh4ISKMXkulfMe4WSHHJRRej0vJ 7zkWQ0skeEHk6FkWIfFbsy9vEuT/aXFOdmiJwL6qLyMO6pD416QOwTJIXZzlPHXw VWFAMNH/8ioMcd9MXnDLJ0JpvearWFY7C5A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrjedvgdefiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffoggfgsedtkeertdertddtnecuhfhrohhmpeforgigihhmvgcu tfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrfgrthhtvg hrnhepkeetudejieejfefhjeeutddugedtjeffffdvtedtieegkeffieelleegvefgvddv necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhgrgi himhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 2 Jan 2023 07:01:25 -0500 (EST) From: Maxime Ripard To: Maarten Lankhorst , Thomas Zimmermann , Maxime Ripard , Daniel Vetter , David Airlie , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec Subject: [PATCH] drm/bridge: panel: Prevent ERR_PTR Dereference Date: Mon, 2 Jan 2023 13:01:23 +0100 Message-Id: <20230102120123.19062-1-maxime@cerno.tech> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 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: , Cc: Dan Carpenter , kernel test robot , dri-devel@lists.freedesktop.org, Dave Stevenson Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Commit 5ea6b1702781 ("drm/panel: Add prepare_prev_first flag to drm_panel") introduced an access to the bridge pointer in the devm_drm_panel_bridge_add_typed() function. However, due to the unusual ERR_PTR check when getting that pointer, the pointer access is done even though the pointer might be an error pointer. Rework the function for a more traditional design that will return immediately if it gets an ERR_PTR so that we never access the pointer in that case. Fixes: 5ea6b1702781 ("drm/panel: Add prepare_prev_first flag to drm_panel") Reported-by: kernel test robot Reported-by: Dan Carpenter Signed-off-by: Maxime Ripard Reviewed-by: Laurent Pinchart Reviewed-by: Andrzej Hajda --- drivers/gpu/drm/bridge/panel.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/bridge/panel.c b/drivers/gpu/drm/bridge/panel.c index 1708098fba6d..e8aae3cdc73d 100644 --- a/drivers/gpu/drm/bridge/panel.c +++ b/drivers/gpu/drm/bridge/panel.c @@ -357,15 +357,16 @@ struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev, return ERR_PTR(-ENOMEM); bridge = drm_panel_bridge_add_typed(panel, connector_type); - if (!IS_ERR(bridge)) { - *ptr = bridge; - devres_add(dev, ptr); - } else { + if (IS_ERR(bridge)) { devres_free(ptr); + return bridge; } bridge->pre_enable_prev_first = panel->prepare_prev_first; + *ptr = bridge; + devres_add(dev, ptr); + return bridge; } EXPORT_SYMBOL(devm_drm_panel_bridge_add_typed);