Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4801791imm; Tue, 26 Jun 2018 00:23:38 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdhecpoJZ/HIHmC/TCkQ5dUd6rzKhyCJA5RAF7BNlAu1yhKShWB4jTLmkiq/goWEX/HwATO X-Received: by 2002:a62:c20e:: with SMTP id l14-v6mr376692pfg.185.1529997818610; Tue, 26 Jun 2018 00:23:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529997818; cv=none; d=google.com; s=arc-20160816; b=CeH+cPu84sRInmdWpTMXOccLGjnHCE1vx2dZT8eLV7nMN8EOxecDSd5EQtmaLrmu3Z nS5E2e00ijPiUIAKG2+zjJd0xLyZTCIT6tLP13PiiGLOAMQ/WPnJVnd7P0Rc/BLK76aS mHXPSnd4ay6EWHTo71I0Vj78bl7SKjzmp85VuALDJJb11z81HfYyve+NDmjzAwzoO320 6ufUv9E6VRnSPYuFCh1pSyUTLN1EJsrJAMTnJKYVcQjPKOG97s63EFBOZlj+tmdOB3NW M0UJMlWXlA9ZmJoIEM63r+/55mnTWXuQskCwLu6sLyk/ngtWVX9ge8LiEOXa5CBmL1fo v1RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=evCTxZFqtKXoxBto4ORuBzVBJHO7U/5lkY7W1TYb+JI=; b=hm3TMmSH1aurxv+7Ksw0Mm3z928GeqdR9JsI7QjDUb10ACdSuZUYPZRomfjyIFU1mG aQA1J8HHSdEmHbgGgvsVl1FycnAz/w2103JCZy2/ypOsAS25YDBS8PLy1vCsnRHXWKZ8 jopMgRSvWhvz26kcbO/8TZh0c7O6RzqB8EbHk12KVYTjJx1aL/MR3EGI+yJ8EWhysjnv V9MC7upljKDFsZPYzTgDhHNAzGf8bnlwNhceZ3iAi9ln82VVhlaO22KiOCrFQb2lszJC Cg5JT5N04w/zALxqdTV1ofTnq13WoCuuItVLVruHOMo7k2obQ3STa+9LBBs11xIwcubk DXkw== 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 h33-v6si969496plh.117.2018.06.26.00.23.24; Tue, 26 Jun 2018 00:23:38 -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 S1752529AbeFZHV5 (ORCPT + 99 others); Tue, 26 Jun 2018 03:21:57 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:28913 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751905AbeFZHVz (ORCPT ); Tue, 26 Jun 2018 03:21:55 -0400 X-IronPort-AV: E=Sophos;i="5.51,273,1526335200"; d="scan'208";a="333290168" Received: from dhcp-64-47.ens-lyon.fr ([140.77.64.47]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jun 2018 09:21:52 +0200 Date: Tue, 26 Jun 2018 09:21:52 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Joe Perches cc: Chengguang Xu , jakub.kicinski@netronome.com, davem@davemloft.net, LKML , cocci , oss-drivers@netronome.com, netdev@vger.kernel.org, Dmitry Torokhov , linux-input , linux-s390 Subject: Re: [PATCH v2 net] nfp: cast sizeof() to int when comparing with error code In-Reply-To: Message-ID: References: <20180626011631.22717-1-cgxu519@gmx.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? Currently there is a rule for comparison of unsigneds to 0. It would be reasonable to extend it for sizes. I will see what it gives. julia