From patchwork Sat Mar 23 06:39:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Shumilin X-Patchwork-Id: 13600640 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 DBD08CD1282 for ; Sat, 23 Mar 2024 12:53:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7D7E310F692; Sat, 23 Mar 2024 12:53:26 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=nppct.ru header.i=@nppct.ru header.b="XluqJj4f"; dkim-atps=neutral Received: from mail.nppct.ru (mail.nppct.ru [195.133.245.4]) by gabe.freedesktop.org (Postfix) with ESMTPS id B3832112B26 for ; Sat, 23 Mar 2024 06:39:42 +0000 (UTC) Received: from mail.nppct.ru (localhost [127.0.0.1]) by mail.nppct.ru (Postfix) with ESMTP id 136091C1396 for ; Sat, 23 Mar 2024 09:39:38 +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=1711175976; x= 1712039977; bh=8Ru1KtR1m4ULexCA5WK3GVpaEyvcpR5jkF1JflcEVtQ=; b=X luqJj4fPGYa3u0mMu9e+EXQyqAdwwur150el+3a6bd8z1l4wKBuzx3s897y2mU/C HiRxyxWVaRZNg6dSV517/A4CEchiMRUhfaHCgLdPNuLmSLLt3FHf1HQIGKE9OGeZ jFLQ7P5rHLPSEfK8+qdJJexpCvbhEabzp+OqyXcC+4= 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 1j_abhGrDk48 for ; Sat, 23 Mar 2024 09:39:36 +0300 (MSK) Received: from localhost.localdomain (mail.dev-ai-melanoma.ru [185.130.227.204]) by mail.nppct.ru (Postfix) with ESMTPSA id 1C6961C11FE; Sat, 23 Mar 2024 09:39:35 +0300 (MSK) From: Andrey Shumilin To: Karol Herbst Cc: Andrey Shumilin , Lyude Paul , Danilo Krummrich , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, khoroshilov@ispras.ru, ykarpov@ispras.ru, vmerzlyakov@ispras.ru, vefanov@ispras.ru Subject: [PATCH] therm.c: Adding an array index check before accessing an element. Date: Sat, 23 Mar 2024 09:39:33 +0300 Message-Id: <20240323063933.665695-1-shum.sdl@nppct.ru> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Mailman-Approved-At: Sat, 23 Mar 2024 12:53:03 +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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" It is possible to access an element at index -1 if at the first iteration of the loop the result of switch is equal to 0x25 Added variable checking. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Andrey Shumilin --- drivers/gpu/drm/nouveau/nvkm/subdev/bios/therm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/therm.c b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/therm.c index 5babc5a7c7d5..78387053f214 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/bios/therm.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bios/therm.c @@ -180,6 +180,8 @@ nvbios_therm_fan_parse(struct nvkm_bios *bios, struct nvbios_therm_fan *fan) cur_trip->fan_duty = duty_lut[(value & 0xf000) >> 12]; break; case 0x25: + if (fan->nr_fan_trip == 0) + fan->nr_fan_trip++; cur_trip = &fan->trip[fan->nr_fan_trip - 1]; cur_trip->fan_duty = value; break;