Message ID | 1872639a.89.1843b5106aa.Coremail.wangkailong@jari.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp274435wru; Wed, 2 Nov 2022 19:37:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6s/LbZWtpsrRa/fkSAPTOUN1URkcR22mVdate8F8wFRf225rDGRjk5FHE+Ea8Pi4z4EiGb X-Received: by 2002:a17:907:2bd2:b0:7ad:9ada:a6ca with SMTP id gv18-20020a1709072bd200b007ad9adaa6camr25838839ejc.637.1667443054422; Wed, 02 Nov 2022 19:37:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667443054; cv=none; d=google.com; s=arc-20160816; b=DI+gBv3WquGeCt+7nEcuzvBmq1sggm5V7BrE9MKdEVtGMtR5OF1zAxFpQynH5az0hp 49PjST4f/oiIK1Wri2ninQ2SHbZ4zo9D+tAAiyS/u77gKo0VeX3XyhY5o9cRGpxuBguq FQ/7LWt7NjhQWL+z6W5zZEZuqCSgfxLv4xTSGhCUyhN7ppab1Xo2DKgMaEdczVkuSNfT cUbJ7YLd/nqm0d+/CsBJX9zgXs6HlIcaIC7XV4ZpFMPz0ODLZFyxQVkc9OHSwlWIqxll v4MxHr71zIkt3OHOXlA+HcWP5slJNhopEIcqkwx9teUJAggiRcGd8hNeONgylQCZdbq/ MY2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:mime-version :content-transfer-encoding:subject:cc:to:from:date; bh=TsEtt443Cr3NIij6gGdvzEE/9wPb5554DIB7BWsLG14=; b=Sb30gHkD06phozZ5ky0SRQxbzZ8MLqiIAozm2jXx6k9arEcwuy9hHh8GtW/H83Oc4q v0Ds50sJjE298t4KUZQLQjBNkCM4bDSGPbGv9jyIQ+Jck4k1RlRENXCB360J7W7tZ9xL oTA5Pqgim/edBjKyDnnI0QbJVGTbpIUAlClTo5Gk1MoiFIBuM4TIwECF6YTRZfvo3wm4 4zGyvou8RDoY6MwcfBh62rxcXn2KkJmioVsxxDse3i/rlvGIekwp47kIJC7PSG1MIOjl IgqmwDZO9aO8mc/y/OwaSIoM3opDWd2WbvwFMv2fXtd48wRjpmp4IL7K0RftL8pY/FVM f4Rw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s7-20020a508d07000000b0045d079c8f20si14622185eds.43.2022.11.02.19.37.10; Wed, 02 Nov 2022 19:37:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230297AbiKCCdz (ORCPT <rfc822;yves.mi.zy@gmail.com> + 99 others); Wed, 2 Nov 2022 22:33:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229992AbiKCCdx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 2 Nov 2022 22:33:53 -0400 X-Greylist: delayed 63 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 02 Nov 2022 19:33:47 PDT Received: from jari.cn (unknown [218.92.28.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8E59D12A98; Wed, 2 Nov 2022 19:33:47 -0700 (PDT) Received: by ajax-webmail-localhost.localdomain (Coremail) ; Thu, 3 Nov 2022 10:27:56 +0800 (GMT+08:00) X-Originating-IP: [182.148.15.109] Date: Thu, 3 Nov 2022 10:27:56 +0800 (GMT+08:00) X-CM-HeaderCharset: UTF-8 From: wangkailong@jari.cn To: jdelvare@suse.com, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] hwmon: (amc6821) Fix unsigned expression compared with zero X-Priority: 3 X-Mailer: Coremail Webmail Server Version XT6.0.1 build 20210329(c53f3fee) Copyright (c) 2002-2022 www.mailtech.cn mispb-4e503810-ca60-4ec8-a188-7102c18937cf-zhkzyfz.cn Content-Transfer-Encoding: base64 Content-Type: text/plain; charset=UTF-8 MIME-Version: 1.0 Message-ID: <1872639a.89.1843b5106aa.Coremail.wangkailong@jari.cn> X-Coremail-Locale: zh_CN X-CM-TRANSID: AQAAfwD3C+ItJ2NjvEEBAA--.41W X-CM-SenderInfo: 5zdqwypdlo00nj6mt2flof0/1tbiAQAOB2FEYx0BLQALs0 X-Coremail-Antispam: 1Ur529EdanIXcx71UUUUU7IcSsGvfJ3iIAIbVAYjsxI4VWxJw CS07vEb4IE77IF4wCS07vE1I0E4x80FVAKz4kxMIAIbVAFxVCaYxvI4VCIwcAKzIAtYxBI daVFxhVjvjDU= X-Spam-Status: No, score=3.6 required=5.0 tests=BAYES_05,RCVD_IN_PBL,RDNS_NONE, T_SPF_HELO_PERMERROR,T_SPF_PERMERROR,XPRIO autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: *** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748440768184666345?= X-GMAIL-MSGID: =?utf-8?q?1748440768184666345?= |
Series |
hwmon: (amc6821) Fix unsigned expression compared with zero
|
|
Commit Message
KaiLong Wang
Nov. 3, 2022, 2:27 a.m. UTC
Fix the following coccicheck warning:
drivers/hwmon/amc6821.c:215: WARNING: Unsigned expression compared
with zero: reg > 0
drivers/hwmon/amc6821.c:228: WARNING: Unsigned expression compared
with zero: reg > 0
Signed-off-by: KaiLong Wang <wangkailong@jari.cn>
---
drivers/hwmon/amc6821.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 11/2/22 19:27, wangkailong@jari.cn wrote: > Fix the following coccicheck warning: > > drivers/hwmon/amc6821.c:215: WARNING: Unsigned expression compared > with zero: reg > 0 > drivers/hwmon/amc6821.c:228: WARNING: Unsigned expression compared > with zero: reg > 0 > > Signed-off-by: KaiLong Wang <wangkailong@jari.cn> Hm. IDGI. What's wrong with comparing an unsigned value to > 0? I mean, it could be == 0 or > 0. Please explain. > --- > drivers/hwmon/amc6821.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c > index 3bfd12ff4b3c..1f5382f8d52b 100644 > --- a/drivers/hwmon/amc6821.c > +++ b/drivers/hwmon/amc6821.c > @@ -166,7 +166,7 @@ static struct amc6821_data *amc6821_update_device(struct device *dev) > struct amc6821_data *data = dev_get_drvdata(dev); > struct i2c_client *client = data->client; > int timeout = HZ; > - u8 reg; > + int reg; > int i; > > mutex_lock(&data->update_lock);
On Wed, Nov 02, 2022 at 07:59:06PM -0700, Randy Dunlap wrote: > > > On 11/2/22 19:27, wangkailong@jari.cn wrote: > > Fix the following coccicheck warning: > > > > drivers/hwmon/amc6821.c:215: WARNING: Unsigned expression compared > > with zero: reg > 0 > > drivers/hwmon/amc6821.c:228: WARNING: Unsigned expression compared > > with zero: reg > 0 > > > > Signed-off-by: KaiLong Wang <wangkailong@jari.cn> > > Hm. IDGI. What's wrong with comparing an unsigned value to > 0? > I mean, it could be == 0 or > 0. > Please explain. I don't get it either. The real problem with this driver is that error returns from i2c functions are not checked. However, that problem is not fixed by this patch. That means the patch would change behavior without fixing the actual problem. I wonder what kind of (broken) compiler or analyzer produces above errors. We'll have to watch out for similar broken "fixes". Guenter
On 11/3/22 07:17, Guenter Roeck wrote: > On Wed, Nov 02, 2022 at 07:59:06PM -0700, Randy Dunlap wrote: >> >> >> On 11/2/22 19:27, wangkailong@jari.cn wrote: >>> Fix the following coccicheck warning: >>> >>> drivers/hwmon/amc6821.c:215: WARNING: Unsigned expression compared >>> with zero: reg > 0 >>> drivers/hwmon/amc6821.c:228: WARNING: Unsigned expression compared >>> with zero: reg > 0 >>> >>> Signed-off-by: KaiLong Wang <wangkailong@jari.cn> >> >> Hm. IDGI. What's wrong with comparing an unsigned value to > 0? >> I mean, it could be == 0 or > 0. >> Please explain. > > I don't get it either. The real problem with this driver is that error > returns from i2c functions are not checked. However, that problem is not > fixed by this patch. That means the patch would change behavior without > fixing the actual problem. > > I wonder what kind of (broken) compiler or analyzer produces above errors. > We'll have to watch out for similar broken "fixes". It says above that it's a coccicheck warning.
On Thu, Nov 03, 2022 at 08:03:35AM -0700, Randy Dunlap wrote: > > > On 11/3/22 07:17, Guenter Roeck wrote: > > On Wed, Nov 02, 2022 at 07:59:06PM -0700, Randy Dunlap wrote: > >> > >> > >> On 11/2/22 19:27, wangkailong@jari.cn wrote: > >>> Fix the following coccicheck warning: > >>> > >>> drivers/hwmon/amc6821.c:215: WARNING: Unsigned expression compared > >>> with zero: reg > 0 > >>> drivers/hwmon/amc6821.c:228: WARNING: Unsigned expression compared > >>> with zero: reg > 0 > >>> > >>> Signed-off-by: KaiLong Wang <wangkailong@jari.cn> > >> > >> Hm. IDGI. What's wrong with comparing an unsigned value to > 0? > >> I mean, it could be == 0 or > 0. > >> Please explain. > > > > I don't get it either. The real problem with this driver is that error > > returns from i2c functions are not checked. However, that problem is not > > fixed by this patch. That means the patch would change behavior without > > fixing the actual problem. > > > > I wonder what kind of (broken) compiler or analyzer produces above errors. > > We'll have to watch out for similar broken "fixes". > > It says above that it's a coccicheck warning. > I see, unsigned_lesser_than_zero.cocci. It actually complains that an unsigned variable is used to hold the return code of a function which returns an int. In other words, it really tries to warn that the error return code from that function is not or not properly checked. The message is misleading for that situation. Guenter
diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index 3bfd12ff4b3c..1f5382f8d52b 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -166,7 +166,7 @@ static struct amc6821_data *amc6821_update_device(struct device *dev) struct amc6821_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; int timeout = HZ; - u8 reg; + int reg; int i; mutex_lock(&data->update_lock);