Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4837745imm; Tue, 26 Jun 2018 01:08:56 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdaBkW8ysIoB/kzZ5OK46tbioaIDG0txgq7tTIh97RkZZCPLiixUTCgmBsTRwieiVIhVaR5 X-Received: by 2002:a62:2942:: with SMTP id p63-v6mr549457pfp.62.1530000536480; Tue, 26 Jun 2018 01:08:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530000536; cv=none; d=google.com; s=arc-20160816; b=wEW1Og42g8ZEP3lEO5CjwMCgr+V/lUYycHl+iGjC9mkLhd+KmL/hlQ/nX1bYBPIY4C JJBESFj/NQjhPOUhbrfpr7Zhb8R6zezhQDJ0nNRCDaSxveM73UibY57mvhcg7KCueC4c XJ+LTxlSuqOjhynxBfIfyEjkjp+bdtrUMMH57m6e+EFZAmTYkeJCwTpMfkkhzfQIfycg 2/8dfJCFpSTZu9tIrApfBBuWbPSELPyPZworG6My2SahuJPDCmFF9pMDYBByUtSTGEUs orvFTzZCKNjGXCe64ttnm1dbK+Gef2bhSaq7l0fws8XTchNsv3IIbXU8MG64osB3bPMr PRvQ== 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=9jD3nwMZgN0U/FYsVquEKeSq9nfcpyZ0z+xq/SRIbuU=; b=DU6jRy6kHafSpXrtXACArqgwVKpfT2mVZsU4S6cHYnx9Ens2zuadRtqS0WGE4uboih 6aGfAaJ43bnTa9Qo7BTfm+PwbaXgkcDa2ckoYBsh84Q8TayBXt8P9MjdTDg0Njd/ViL5 +/K7Nom5jujtmiUk+QBHRSTGLcJ1y++TzkcNi0lxEy+lGnI0EEC+feptxShQn3Kgz6DG Bw14FZhAxlZ4KgnXqN6krQTxW7vWag6YvQmqJsl3svwIArDSIBSow12mcvs7TUq6C85a tpMTFBSNPtOrODq9QtWnIZSrGZa3H7JPpOXjxN7TlPUWyV33AZ3Zbo77C4PiMR3V5wCY E+JQ== 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 r12-v6si927872pgt.384.2018.06.26.01.08.42; Tue, 26 Jun 2018 01:08:56 -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 S1752708AbeFZIGy (ORCPT + 99 others); Tue, 26 Jun 2018 04:06:54 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:54150 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751869AbeFZIGv (ORCPT ); Tue, 26 Jun 2018 04:06:51 -0400 X-IronPort-AV: E=Sophos;i="5.51,274,1526335200"; d="scan'208";a="269949661" Received: from dhcp-64-47.ens-lyon.fr ([140.77.64.47]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jun 2018 10:06:48 +0200 Date: Tue, 26 Jun 2018 10:06:48 +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? 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. julia