From patchwork Fri Apr 12 08:35:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mishin X-Patchwork-Id: 13627168 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 83CAFC00A94 for ; Fri, 12 Apr 2024 08:40:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B07E210E072; Fri, 12 Apr 2024 08:40:20 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=t-argos.ru header.i=@t-argos.ru header.b="iXeFh1Eq"; dkim-atps=neutral Received: from mx1.t-argos.ru (mx1.t-argos.ru [109.73.34.58]) by gabe.freedesktop.org (Postfix) with ESMTPS id C4F9910E072 for ; Fri, 12 Apr 2024 08:40:15 +0000 (UTC) Received: from mx1.t-argos.ru (localhost [127.0.0.1]) by mx1.t-argos.ru (Postfix) with ESMTP id 69B3D100002; Fri, 12 Apr 2024 11:39:57 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=t-argos.ru; s=mail; t=1712911197; bh=rjbo4UmWfdwF8R6/DF5Fmz37zbZJApM7uAaHW6mJOAY=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=iXeFh1EqZq8ZPAePYUl6mbxwrMGpyXIC1+9DRMFGc73/E573jzoGpC5Lx0+DONq3m ArhmsPc0O4i5twLUmUhy1AKQC5bDVXI0QMZU3yRj11y4Yj8H0QQc+mFZ2ub4ahGoVJ JGqbeZpZyEft8TOVtFfGqHQrktvOM7zHlMZIoHkJHy3VEgtyI8lEmgSJqAOTyi7MjG xI1l0tI/QclaAU5QSGcZUxQiN2L9uUc4IyRaX4pAoqsRmqWW9hqdFebFLktRr8XObx ib8mK9p1Jpmxhjrit1lHgY0iQAbkQTNGWkssh+K4XUF28RVnD+vlhqqrHcYx58SwdP sRGkDj7l1ZRLw== Received: from mx1.t-argos.ru.ru (ta-mail-02.ta.t-argos.ru [172.17.13.212]) by mx1.t-argos.ru (Postfix) with ESMTP; Fri, 12 Apr 2024 11:36:10 +0300 (MSK) Received: from localhost.localdomain (172.17.215.6) by ta-mail-02 (172.17.13.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Fri, 12 Apr 2024 11:35:50 +0300 From: Aleksandr Mishin To: Swapnil Jakhade CC: Aleksandr Mishin , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Tomi Valkeinen , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Nikhil Devshatwar , Aradhya Bhatia , Jani Nikula , Rob Herring , Zhu Wang , Yuti Amonkar , Jyri Sarha , Quentin Schulz , , , Subject: [PATCH v2] drm: bridge: cdns-mhdp8546: Fix possible null pointer dereference Date: Fri, 12 Apr 2024 11:35:32 +0300 Message-ID: <20240412083532.11540-1-amishin@t-argos.ru> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Originating-IP: [172.17.215.6] X-ClientProxiedBy: ta-mail-02.ta.t-argos.ru (172.17.13.212) To ta-mail-02 (172.17.13.212) X-KSMG-Rule-ID: 1 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 184683 [Apr 12 2024] X-KSMG-AntiSpam-Version: 6.1.0.4 X-KSMG-AntiSpam-Envelope-From: amishin@t-argos.ru X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 16 0.3.16 6e64c33514fcbd07e515710c86ba61de7f56194e, {Tracking_from_domain_doesnt_match_to}, 127.0.0.199:7.1.2; mx1.t-argos.ru.ru:7.1.1; t-argos.ru:7.1.1; d41d8cd98f00b204e9800998ecf8427e.com:7.1.1, FromAlignment: s X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean, bases: 2024/04/12 08:01:00 X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2024/04/12 05:40:00 #24753079 X-KSMG-AntiVirus-Status: Clean, skipped 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" In cdns_mhdp_atomic_enable(), the return value of drm_mode_duplicate() is assigned to mhdp_state->current_mode, and there is a dereference of it in drm_mode_set_name(), which will lead to a NULL pointer dereference on failure of drm_mode_duplicate(). Fix this bug by adding a check of mhdp_state->current_mode. Fixes: fb43aa0acdfd ("drm: bridge: Add support for Cadence MHDP8546 DPI/DP bridge") Signed-off-by: Aleksandr Mishin --- v2: Fix a mistake where the mutex remained locked drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c index e226acc5c15e..5b831d6d7764 100644 --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c @@ -2059,6 +2059,11 @@ static void cdns_mhdp_atomic_enable(struct drm_bridge *bridge, mhdp_state = to_cdns_mhdp_bridge_state(new_state); mhdp_state->current_mode = drm_mode_duplicate(bridge->dev, mode); + if (!mhdp_state->current_mode) { + ret = -EINVAL; + goto out; + } + drm_mode_set_name(mhdp_state->current_mode); dev_dbg(mhdp->dev, "%s: Enabling mode %s\n", __func__, mode->name);