From patchwork Thu Nov 16 06:51:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Shumilin X-Patchwork-Id: 13457718 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 725A5C197A0 for ; Thu, 16 Nov 2023 09:06:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7848710E250; Thu, 16 Nov 2023 09:06:55 +0000 (UTC) Received: from mail.nppct.ru (mail.nppct.ru [195.133.245.4]) by gabe.freedesktop.org (Postfix) with ESMTPS id EDF3F10E0FE for ; Thu, 16 Nov 2023 06:52:13 +0000 (UTC) Received: from mail.nppct.ru (localhost [127.0.0.1]) by mail.nppct.ru (Postfix) with ESMTP id 051511C0DA7 for ; Thu, 16 Nov 2023 09:52:11 +0300 (MSK) Authentication-Results: mail.nppct.ru (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=nppct.ru DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nppct.ru; h= content-transfer-encoding:mime-version:x-mailer:message-id:date :date:subject:subject:to:from:from; s=dkim; t=1700117529; x= 1700981530; bh=K3YRmKofc6N6uINNSmeFkKZnxYRW32B+l0K9TQS6g74=; b=i nMMJ0bQJaJANR3cyvZIDtllai0Jb3wM2NMR6v0N44d1he6CesRdVEz4LV1xwVaid yR6vSF3dOYhgTbBb0WbbzgHFO577pOdVVNpkTzsQ4MxkRohc6/5KtvnVM4nbfdoF 7EkecHOTEsvOp/0SH9ZuZnt9fz/4iSjkE9vDSixOZo= X-Virus-Scanned: Debian amavisd-new at mail.nppct.ru Received: from mail.nppct.ru ([127.0.0.1]) by mail.nppct.ru (mail.nppct.ru [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id U5nqlVVJNTOH for ; Thu, 16 Nov 2023 09:52:09 +0300 (MSK) Received: from localhost.localdomain (mail.dev-ai-melanoma.ru [185.130.227.204]) by mail.nppct.ru (Postfix) with ESMTPSA id D04BC1C061A; Thu, 16 Nov 2023 09:52:07 +0300 (MSK) From: Andrey Shumilin To: Karol Herbst Subject: [PATCH] tvnv17.c: Adding a NULL pointer check. Date: Thu, 16 Nov 2023 09:51:59 +0300 Message-Id: <20231116065159.37876-1-shum.sdl@nppct.ru> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 16 Nov 2023 09:06:53 +0000 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: Thomas Zimmermann , Jani Nikula , nouveau@lists.freedesktop.org, Andrey Shumilin , linux-kernel@vger.kernel.org, Maxime Ripard , vefanov@ispras.ru, ykarpov@ispras.ru, =?utf-8?q?Noralf_Tr=C3=B8nnes?= , Danilo Krummrich , dri-devel@lists.freedesktop.org, vmerzlyakov@ispras.ru, khoroshilov@ispras.ru Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" It is possible to dereference a null pointer if drm_mode_duplicate() returns NULL. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Andrey Shumilin Reviewed-by: Alexey Khoroshilov --- drivers/gpu/drm/nouveau/dispnv04/tvnv17.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c b/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c index 670c9739e5e1..1f0c5f4a5fd2 100644 --- a/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c +++ b/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c @@ -209,7 +209,8 @@ static int nv17_tv_get_ld_modes(struct drm_encoder *encoder, struct drm_display_mode *mode; mode = drm_mode_duplicate(encoder->dev, tv_mode); - + if (mode == NULL) + continue; mode->clock = tv_norm->tv_enc_mode.vrefresh * mode->htotal / 1000 * mode->vtotal / 1000; @@ -258,6 +259,8 @@ static int nv17_tv_get_hd_modes(struct drm_encoder *encoder, if (modes[i].hdisplay == output_mode->hdisplay && modes[i].vdisplay == output_mode->vdisplay) { mode = drm_mode_duplicate(encoder->dev, output_mode); + if (mode == NULL) + continue; mode->type |= DRM_MODE_TYPE_PREFERRED; } else {