Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp279013rdh; Thu, 26 Oct 2023 01:46:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHrfftrzC2Q//3V3nfF8G7o7cRmnJla9QgpsCnHpK+4XSJ+LXV4uLVbRfxM6y6pNv/aTijp X-Received: by 2002:a05:620a:444e:b0:767:923:48e7 with SMTP id w14-20020a05620a444e00b00767092348e7mr21462566qkp.5.1698310017004; Thu, 26 Oct 2023 01:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698310016; cv=none; d=google.com; s=arc-20160816; b=BMiq13ac83cly+DE83yEsCQD3XhtY/1UkCQ+ZBBBWeJSvGCeHw48SDvjgd4MjktOIh FDuGowu42OJ9BLK9lyOP0ywBE+shg3mr0JMllmmpx3fNtr+WuRUyvNaTlevSC9nggQbL PX7EHsjS45V+WTdtQk7pH0IhQzepqG7B+AZLMp45EhAvLKnfyvYn6g7dJTT/sBoU8zm7 eVBhNZtygmlB5KJPFvd+qYRhRsTeqZTl/9SO21WFUFIo8jxU+mBcFoiZVviDwW7NgRRG FDzhmLJVAtPNAQNmtlbC56q5gH52sJUl9gL0HqiYHUpW9maQwN5JBRt0XpqlIedds3GL +bbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from:cc:to :content-language:subject:user-agent:mime-version:date:message-id; bh=aXwIh+C5Mo+gm5TTOuzQY5+6/3SGU13o608GN7b3cEw=; fh=hpC608wx0YC6/wSOp9VGWf+U2K+CAgf7nP4csomjstk=; b=a84c61NViRfG5vTJ9DkRUYqtsusEwjVipeOo2wARzi05Qt40nyxIA1gbRR9pFy5Z25 OqDBcJCpknXOtajm2Jt6Hd9YT1tO1n5yGZ4EyrBHP5mUpYSxmzZqPl3GstpdXmPO/Xm7 xt2wTt4woieS9RcrYMbEHr5lNzI4iaye9qnOTge8HWeHqGuE0UgYA9lg2tCzwOoRWgf2 P/0bDRUG6PQmPMr6Kumj8/j0wbroXW/poxLCHq3fo+dyl3/DHeEDZSudJeOc4BW64ZnM gNUxtxcz33bF92G+76vDm7H6UDTwaxw4EIRilyjQ0DSgDNlil606VCm19o9QOBrDcpuw T4qw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id v127-20020a252f85000000b00da0352438dbsi7585986ybv.590.2023.10.26.01.46.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 01:46:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 7B4AE8242989; Thu, 26 Oct 2023 01:46:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344496AbjJZIqo (ORCPT + 99 others); Thu, 26 Oct 2023 04:46:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjJZIqm (ORCPT ); Thu, 26 Oct 2023 04:46:42 -0400 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 0CCBC10E; Thu, 26 Oct 2023 01:46:39 -0700 (PDT) Received: from [172.30.11.106] (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPSA id AF3DB60863911; Thu, 26 Oct 2023 16:46:30 +0800 (CST) Message-ID: <54d21280-6e1e-780c-372d-d630630a4fe9@nfschina.com> Date: Thu, 26 Oct 2023 16:46:29 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH] vga_switcheroo: Fix impossible judgment condition Content-Language: en-US To: Dan Carpenter Cc: lukas@wunner.de, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, daniel@ffwll.ch, tiwai@suse.de, Jim.Qu@amd.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui In-Reply-To: <4ec2b80b-f042-4abf-b799-0a9ef364f0fa@kadam.mountain> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Thu, 26 Oct 2023 01:46:54 -0700 (PDT) On 2023/10/26 12:44, Dan Carpenter wrote: > On Thu, Oct 26, 2023 at 10:10:57AM +0800, Su Hui wrote: >> 'id' is enum type like unsigned int, so it will never be less than zero. >> >> Fixes: 4aaf448fa975 ("vga_switcheroo: set audio client id according to bound GPU id") >> Signed-off-by: Su Hui >> --- >> 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..d3064466fd3a 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) { > Hi, > > I feel like you're using Smatch? Which is great! Fantastic! Yep, Smatch helps meĀ  a lot to find these bugs! I really like this excellent tool! > > Have you built the cross function database? If you have there is a > command that's useful. Not yet, bu I want to build this. > $ ~/smatch/smatch_db/smdb.py functions vga_switcheroo_handler get_client_id | tee where > drivers/gpu/drm/nouveau/nouveau_acpi.c | (struct vga_switcheroo_handler)->get_client_id | nouveau_dsm_get_client_id | 1 > drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c | (struct vga_switcheroo_handler)->get_client_id | amdgpu_atpx_get_client_id | 1 > drivers/gpu/drm/radeon/radeon_atpx_handler.c | (struct vga_switcheroo_handler)->get_client_id | radeon_atpx_get_client_id | 1 > drivers/platform/x86/apple-gmux.c | (struct vga_switcheroo_handler)->get_client_id | gmux_get_client_id | 1 > $ make cscope > $ vim where > Use cscope to jump to each of those four functions. Move the cursor to > the nouveau_dsm_get_client_id and hit CTRL-]. Sounds great! I must try this! > > They never return negatives. The enum vga_switcheroo_client_id has a > VGA_SWITCHEROO_UNKNOWN_ID define which I guess these functions are > supposed to return on error. They never do return that, but I bet > that's what we are supposed to check for. It honestly might be good > to check for both... > > if ((int)id < 0 || id == VGA_SWITCHEROO_UNKNOWN_ID) { > mutex_unlock(&vgasr_mutex); > return -EINVAL; > } Agreed, I will send v2 patch soon. Really thanks for your wonderful suggestion! :) Su Hui > regards, > dan carpenter >