From patchwork Thu Oct 26 09:18:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Su Hui X-Patchwork-Id: 13437393 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 3C721C25B48 for ; Thu, 26 Oct 2023 09:18:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8A84010E10F; Thu, 26 Oct 2023 09:18:23 +0000 (UTC) Received: from mail.nfschina.com (unknown [42.101.60.195]) by gabe.freedesktop.org (Postfix) with SMTP id 60CDF10E10F for ; Thu, 26 Oct 2023 09:18:21 +0000 (UTC) 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 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 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: Su Hui , kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Jim.Qu@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" '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 bound GPU id") Signed-off-by: Su Hui Reviewed-by: Dan Carpenter --- v2: - add check of VGA_SWITCHEROO_UNKNOWN_ID(Dan's suggestion). By the way, all functions of 'get_client_id' will never return error code or VGA_SWITCHEROO_UNKNOWN_ID,should 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_switcheroo.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 = vgasr_priv.handler->get_client_id(vga_dev); - if (id < 0) { + if ((int)id < 0 || id == VGA_SWITCHEROO_UNKNOWN_ID) { mutex_unlock(&vgasr_mutex); return -EINVAL; }