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 B74FDC433EF for ; Tue, 7 Jun 2022 17:57:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 429C310F361; Tue, 7 Jun 2022 17:57:46 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2B5D110F1B9; Tue, 7 Jun 2022 17:57:45 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A2F49617A8; Tue, 7 Jun 2022 17:57:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BB35C385A5; Tue, 7 Jun 2022 17:57:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654624664; bh=14TsCn54a3xzE/a5cVI/njMjihJEWCBEFwfM8vZP8RI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qF2H5lbWAc/w9pBhA1GYOkIrHZS77y9rnzzBIsmt+5vvduX3RRk0t0FEnpKgd24Zs rVwx7Tp89agDu2r5omD2YmQ68dIN4YifFfiiLONp1HaCMrLLTOt5a2ejaBTFI4+8HX iyX22WsrO5FegrxD1fRM0P5ys/MnsPsyqQs7mYV4MMEUfykohBGUGjg6zWN5pFTuBm R1OjZwu5VNt2YWiimE4xuIB/bwYO3LlU1FAmsTLQr2M41PvxbNxv3TVu6571TEM5Gn sdubRh++L/7JzcLbjoz+Ti9wrAihdAE6dYyHMLQ/0Sx4OqmqX1BMwLA1nCtkNiqKVv xLUvvou3+kg/g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 38/51] drm/radeon: fix a possible null pointer dereference Date: Tue, 7 Jun 2022 13:55:37 -0400 Message-Id: <20220607175552.479948-38-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220607175552.479948-1-sashal@kernel.org> References: <20220607175552.479948-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sasha Levin , airlied@linux.ie, Xinhui.Pan@amd.com, amd-gfx@lists.freedesktop.org, Gong Yuanjun , dri-devel@lists.freedesktop.org, daniel@ffwll.ch, Alex Deucher , christian.koenig@amd.com Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" From: Gong Yuanjun [ Upstream commit a2b28708b645c5632dc93669ab06e97874c8244f ] In radeon_fp_native_mode(), the return value of drm_mode_duplicate() is assigned to mode, which will lead to a NULL pointer dereference on failure of drm_mode_duplicate(). Add a check to avoid npd. The failure status of drm_cvt_mode() on the other path is checked too. Signed-off-by: Gong Yuanjun Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/radeon/radeon_connectors.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c index 1546abcadacf..d157bb9072e8 100644 --- a/drivers/gpu/drm/radeon/radeon_connectors.c +++ b/drivers/gpu/drm/radeon/radeon_connectors.c @@ -473,6 +473,8 @@ static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encode native_mode->vdisplay != 0 && native_mode->clock != 0) { mode = drm_mode_duplicate(dev, native_mode); + if (!mode) + return NULL; mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER; drm_mode_set_name(mode); @@ -487,6 +489,8 @@ static struct drm_display_mode *radeon_fp_native_mode(struct drm_encoder *encode * simpler. */ mode = drm_cvt_mode(dev, native_mode->hdisplay, native_mode->vdisplay, 60, true, false, false); + if (!mode) + return NULL; mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER; DRM_DEBUG_KMS("Adding cvt approximation of native panel mode %s\n", mode->name); } -- 2.35.1