Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp293607rdh; Thu, 26 Oct 2023 02:18:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFp1GgtgPcZInTrboWXrfS9bPIjvtLJfaN+JNOFMdFJySeYDjln8qJewT7R3uGSdzPHhkqy X-Received: by 2002:a5b:f4c:0:b0:d9a:3bf1:35e9 with SMTP id y12-20020a5b0f4c000000b00d9a3bf135e9mr16747396ybr.3.1698311909884; Thu, 26 Oct 2023 02:18:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698311909; cv=none; d=google.com; s=arc-20160816; b=k2uz/VeGEkhErDbaWQztxCBmgp9TYoatBPKEF48L7J9Pizf8QbINLjNnguufzKzFjx 4f5RlQSTvi/RS5V5+utXtW8y5U6rdoepOiSN4ioCZtAfywDeoJPuz1XOKt7Cf6g3FasE R/OLxxAPVxvgFsI0m6pWXg8w+8EfV2ODeNP7IQDeKZrH+/rj3EMYs+1IY7r1vLeTn4s3 TifPhgCvcEdWq9u0VGe3Ao3u8LNlH7PbINjkw8VCQOQ6kSW4jhC5/Haf6kI/iX/XXcCR DNUaV60fChzUz2yrovysdjxrW+umiG0wnb7I1WMCPq1ZCOVhU/mkVqTe/uzkwQYTqZ0a Jj4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=h1X+DNY/iTCC/RXz6gLmq3+0NTsUCCCQ/AZXabXabIc=; fh=OfD39iH5qdOGlMCV/6v6TKW7sIrATLmAQNO/RIJ1AvI=; b=Fy+npbSRXQ8LH6fR6EPVwjJzgD7oR15W6YhnCT4kE5vmdtvXvSwTA0CYZvZgaWyMNI utMWzX1WGSoyiRT8Pg+kM5E+45gETJcAINhG4+dtcI4YHrqorOVgSPp1beTnp4IO/LsV CmAZ3OoQgWH98znYUWO0MV73DkzIDkAFfWOa4gNqeduzBUPo+a/AFo1J4R4I91Gq/iaK kMBLzgPW2Y+VdtFQ+hfuc+N/DQTi6HvqDjLLyu6VOCpbvMcrASvHlDh6gxH2EgsBL73r JWnLa0eEGXj6DQPyNYnZQDYvCxhuNaI8FPjANFRhTc24iRkXD901jcJ/TVGO06g5MiDZ Bo7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id m130-20020a25d488000000b00d9a39b80f7dsi14150968ybf.656.2023.10.26.02.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 02:18:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 5672B8212A97; Thu, 26 Oct 2023 02:18:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344465AbjJZJSZ (ORCPT + 99 others); Thu, 26 Oct 2023 05:18:25 -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: 8bit X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 26 Oct 2023 02:18:28 -0700 (PDT) '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 --- 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; } -- 2.30.2