From nobody Tue Dec 16 16:41:17 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B850CC25B6B for ; Thu, 26 Oct 2023 09:18:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344557AbjJZJS0 (ORCPT ); Thu, 26 Oct 2023 05:18:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjJZJSY (ORCPT ); Thu, 26 Oct 2023 05:18:24 -0400 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 49173187; Thu, 26 Oct 2023 02:18:20 -0700 (PDT) Received: from localhost.localdomain (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPA id 5036A608E52BE; Thu, 26 Oct 2023 17:18:17 +0800 (CST) X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui To: dan.carpenter@linaro.org, lukas@wunner.de, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, daniel@ffwll.ch Cc: Su Hui , tiwai@suse.de, Jim.Qu@amd.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH v2] vga_switcheroo: Fix impossible judgment condition Date: Thu, 26 Oct 2023 17:18:04 +0800 Message-Id: <20231026091804.967960-1-suhui@nfschina.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 'id' is enum type like unsigned int, so it will never be less than zero. It's better to check VGA_SWITCHEROO_UNKNOWN_ID too. Fixes: 4aaf448fa975 ("vga_switcheroo: set audio client id according to boun= d GPU id") Signed-off-by: Su Hui Reviewed-by: Dan Carpenter --- v2: - add check of VGA_SWITCHEROO_UNKNOWN_ID(Dan's suggestion).=20 By the way, all functions of 'get_client_id' will never return error code or VGA_SWITCHEROO_UNKNOWN_ID=EF=BC=8Cshould we remove this check or keep it= for future. drivers/gpu/vga/vga_switcheroo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switche= roo.c index 365e6ddbe90f..cf530094f929 100644 --- a/drivers/gpu/vga/vga_switcheroo.c +++ b/drivers/gpu/vga/vga_switcheroo.c @@ -375,7 +375,7 @@ int vga_switcheroo_register_audio_client(struct pci_dev= *pdev, mutex_lock(&vgasr_mutex); if (vgasr_priv.active) { id =3D vgasr_priv.handler->get_client_id(vga_dev); - if (id < 0) { + if ((int)id < 0 || id =3D=3D VGA_SWITCHEROO_UNKNOWN_ID) { mutex_unlock(&vgasr_mutex); return -EINVAL; } --=20 2.30.2