Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4849291imm; Tue, 26 Jun 2018 01:22:53 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIyfaAu8e/B3/e5URx3YtN+clsDZx1n95D3OWXihiRR5F6QBr+2hE+jOnKa2A947F058pfM X-Received: by 2002:a17:902:8a95:: with SMTP id p21-v6mr582462plo.91.1530001373261; Tue, 26 Jun 2018 01:22:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530001373; cv=none; d=google.com; s=arc-20160816; b=rrVkkEORNBE8EGmwMCY/muWt+TnjqHg4AV7TzkFutxHPlhsZa7lDHXqE+x+SGUc9Of a44vZswliq5ynIA1gtC5BGiDRKwfVcTGe4hQniFqWCIQiJ+liiDmb/fGq5EAGtfqhmUx XmlZxczvj+xUP5tcnC7gkxs0ngZvj/Ftcx1HzIgtoSRyzQG001csgtDi/E44IU7sHoZx wxBZCvzdcjkzTAKzTWJSZ1+OLs+Sz0xi2Tfweu39sHM9SetFt/AfDGNDAPeINAQWa+eS xe9uy9hAah3L5ygoiPAuMeS3o6YREBBZXuSxJENjSJ6hzCJYZXBWRqsPLLyVmAWRxwS5 PHJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=A+tBBWJRNtsYwdlex2UQpAkezKegEZloKUNTDFvY2MM=; b=uM0iZEHcxk4SrW8bHLTY+IoTJfF4Gy1nH3UH9ekqTznmgLSsXuFytLD2enaQ1ZVOoa EBpcAK7Jp46a1A9j+yrF9QZGgnHRP1KxFy+Y1xTr5C7VKArcRj0rWMzBiDqpkDqr1t8v hNTblROa0eMkvMMFRbK0QwwOSlbcQ7ebXEJHd7Sps8qI/liExejySTjS4868eL+9a8LW 3Jehwyn2AO85IN4NuZgJjYlmtcDeRd0z2eEo7XU31YSWtaxhkhnhqA6eNYtm1LD0bka7 xRBu6gr8eLvcGZKVnuYArX+ytmSfnN6d1omaVJHG49TTe7O4UdAIQrT2LUt4vOJlhYxK FtgQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1-v6si963210pgb.101.2018.06.26.01.22.39; Tue, 26 Jun 2018 01:22:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932560AbeFZIVh (ORCPT + 99 others); Tue, 26 Jun 2018 04:21:37 -0400 Received: from mout.gmx.net ([212.227.15.15]:48593 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752706AbeFZIVe (ORCPT ); Tue, 26 Jun 2018 04:21:34 -0400 Received: from [172.17.46.209] ([122.224.77.194]) by mail.gmx.com (mrgmx002 [212.227.17.184]) with ESMTPSA (Nemesis) id 0LqQzp-1g25y611Iv-00e2Fd; Tue, 26 Jun 2018 10:21:23 +0200 Subject: Re: [PATCH v2 net] nfp: cast sizeof() to int when comparing with error code To: Julia Lawall Cc: Joe Perches , jakub.kicinski@netronome.com, davem@davemloft.net, LKML , cocci , oss-drivers@netronome.com, netdev@vger.kernel.org, Dmitry Torokhov , linux-input , linux-s390 References: <20180626011631.22717-1-cgxu519@gmx.com> From: cgxu519 Message-ID: Date: Tue, 26 Jun 2018 16:21:10 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Provags-ID: V03:K1:2ioQTmi2mIk7Q5IZKqPXZXFlyiCTquiiyMoHmOm1+fLBYAHk/Cd /a1pPjL6ZaTgKnvUU/tCC1oIoi7yBwnXxhP33nFEIZ7pxGO8hs/r8fUOnqfK0oyn20ls3UN tsOPIhON0lu3TN6LKit7DNWUe0wLaEbL/ijRt5naTXcmskXEOewoUSRM4p8rjzBsseI3BUG PwgjnmyTeG859ZhqZuw3w== X-UI-Out-Filterresults: notjunk:1;V01:K0:UN/tP1SvHtc=:K4rIOsvgSO+kxcGUjcQIJb dYCQwNccW61Xru5ZStvGWKBxoeARzFgxKzA51f85LSq1Z8WP2iGqyEJSeRcEsNhtViJ5XtQYj PE5GPI+aqN64m2c02tYt6QHTICTNvd+irYzMGMFDKB3+VIHKiGUnlFpRM6kwWspuDTy6piTDE p687Yk4XSDfm9jBMf5tvdxHwdUsUuCxBy/Vs82JlquOGh/ryLOmxmkYd7SDoFFUj/y7PITsXe TdYuSfd1JZezZ23Z8OHqFM92uhpijS+1Z+6m7zPhvYcITOsq5IZ9cmKnN2PGi6gDBhLLCyj5y 1J7tlIj1oL7IFwKnSgEANcZk6rfushhbMkwWZEf5ejVVfy7y+q0ZAwLt/LUpKmK0hlbM8wVDv IRv/NRIjjxr0+9cKUod7IoBnoalW8Nt17HptDa1d3y1bfYPRRXpahtiLOO1gVH52hTf8RcZDi 4qPbL7gdBCmvjrbxV5VM2uMzd4gA7MD35xLq3RbtKKpJxLEMxJhktK8s3Xq3UU+2/5yfQHgV9 1KpkBq6ss9L/NTcCLjZhmXj3g+0181Kqu7oBrYFWaopv7pjR8vf30+0ay5KA+H57Q3aukuDoI KTf3ZVURTQ4uR/Bkj1Y6O8EjsFKsLjVZBF6Sl61BRDdzMcBm9K2Y6u57fY0veLJ1hmNAvblnT 3miYoFtav4AYTLh0NYIwGBPqNImzTjYxv9busxW2u7m82D6QbD4nu4nptmF8V3BojxsfARKKm FpQZSQVBZvHWkxVw2k5IT3j3W4Vb7B2IX6WfFFzLjmwSO/itknzSt8WjsqG558Lof8jO2LIaD +9RWKR0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/26/2018 04:06 PM, Julia Lawall wrote: > > On Mon, 25 Jun 2018, Joe Perches wrote: > >> On Tue, 2018-06-26 at 09:16 +0800, Chengguang Xu wrote: >>> sizeof() will return unsigned value so in the error check >>> negative error code will be always larger than sizeof(). >> This looks like a general class of error in the kernel >> where a signed result that could be returning a -errno >> is tested against < or <= sizeof() >> >> A couple examples: >> >> drivers/input/mouse/elan_i2c_smbus.c: >> >> len = i2c_smbus_read_block_data(client, >> ETP_SMBUS_IAP_PASSWORD_READ, >> val); >> if (len < sizeof(u16)) { >> >> i2c_smbus_read_block_data can return a negative errno >> >> >> net/smc/smc_clc.c: >> >> len = kernel_sendmsg(smc->clcsock, &msg, &vec, 1, >> sizeof(struct smc_clc_msg_decline)); >> if (len < sizeof(struct smc_clc_msg_decline)) >> >> where kernel_sendmsg can return a negative errno >> >> There are probably others, I didn't look hard. >> >> Perhaps a cocci script to find these could be generated? > Here's another one: > > drivers/usb/serial/ir-usb.c > @@ -126,13 +126,8 @@ irda_usb_find_class_desc(struct usb_seri > if (!desc) > return NULL; > > - ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), > - USB_REQ_CS_IRDA_GET_CLASS_DESC, > - USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, > - 0, ifnum, desc, sizeof(*desc), 1000); > > dev_dbg(&serial->dev->dev, "%s - ret=%d\n", __func__, ret); > - if (ret < sizeof(*desc)) { > dev_dbg(&serial->dev->dev, > "%s - class descriptor read %s (%d)\n", __func__, > (ret < 0) ? "failed" : "too short", ret); > > There are other results, but I haven't checked all of them. Hi Julia, Thanks for your check. I posted a patch yesterday to fix three places in usb subsystem and the patch is just in queue now, so you can skip these places. The detail of patch. --- diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c index 24b06c7e5e2d..7643716b5299 100644 --- a/drivers/usb/serial/ir-usb.c +++ b/drivers/usb/serial/ir-usb.c @@ -132,7 +132,7 @@ irda_usb_find_class_desc(struct usb_serial *serial, unsigned int ifnum) 0, ifnum, desc, sizeof(*desc), 1000); dev_dbg(&serial->dev->dev, "%s - ret=%d\n", __func__, ret); - if (ret < sizeof(*desc)) { + if (ret < (int)sizeof(*desc)) { dev_dbg(&serial->dev->dev, "%s - class descriptor read %s (%d)\n", __func__, (ret < 0) ? "failed" : "too short", ret); diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c index 958e12e1e7c7..ff2322ea5e14 100644 --- a/drivers/usb/serial/quatech2.c +++ b/drivers/usb/serial/quatech2.c @@ -194,7 +194,7 @@ static inline int qt2_getregister(struct usb_device *dev, ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), QT_SET_GET_REGISTER, 0xc0, reg, uart, data, sizeof(*data), QT2_USB_TIMEOUT); - if (ret < sizeof(*data)) { + if (ret < (int)sizeof(*data)) { if (ret >= 0) ret = -EIO; } diff --git a/drivers/usb/serial/ssu100.c b/drivers/usb/serial/ssu100.c index 2083c267787b..0900b47b5f57 100644 --- a/drivers/usb/serial/ssu100.c +++ b/drivers/usb/serial/ssu100.c @@ -104,7 +104,7 @@ static inline int ssu100_getregister(struct usb_device *dev, ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), QT_SET_GET_REGISTER, 0xc0, reg, uart, data, sizeof(*data), 300); - if (ret < sizeof(*data)) { + if (ret < (int)sizeof(*data)) { if (ret >= 0) ret = -EIO; } --- Thanks, Chengguang.