Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4572863imm; Mon, 25 Jun 2018 19:12:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIvpjyZcgoAUt8MSrSZffL5ipB9RZVd6Slz3UO9UuR5HB8aibuO6x05zF7ubkjbGJQVByen X-Received: by 2002:a17:902:1127:: with SMTP id d36-v6mr14937282pla.267.1529979120979; Mon, 25 Jun 2018 19:12:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529979120; cv=none; d=google.com; s=arc-20160816; b=pALqr67uLeTZJi4SDDL9rxCE20/GrXRTvp3US9kgBIFl3992gKZRg4olzO9G0GIV87 8ycwIJg0+IVH4f/03OGEZtDLR5Z6DE385pbViCCPpruCD1gkOrp3Lmit2/gAisZhUm1e TgUaGA1nHQf4iq/5b8nDkuAaoLWUBHS2+VAbPkSB42VhD23ZjXFZ+8IUdNhRLRZHEx/w PeWqHDWM6ekZ7pI8IDTvM9BKemqdchfmmtOGlqMRO8Dm/TthHf+TWLCqsp63X635x2W0 jpKNuUru81fV1rxXd5DjlX0CyZqB6ozWCqKJVupDyOukpKw8Fu2T0xWtgKzJB/vusxik mb1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=GxtIBJKRe/BZkYP+PNtk0PBSdD/eA+UNmzb4VSPoaPI=; b=dEIiBWdwbuPYAETiuszGozB6mneCYdCN3WX3L5mvd0Wwn7+qMwfJtL90PGFAp1EPRl hjzeYwvx1Ku9kHLJhLMD2SqnOvlSV9/7IBor/nTLqPGPJj9A6iOn8+swWw2tuU3JG7ye yTx4my/QBK2MErj7V6UvUsQlZoBL7Vx5gztuHsVBis3spQZcgTBVeL1/bIqBFzZYA4LG LhVrwGilIpLVGUCegggoBgJ1R8HJDl1nuGAUX/0s/HrjFWWXgtZnZgZv/8nwOlb8uRCm kAimMs8FbxRMv6WUs6xgVNfWlLsxAZm6B/giI1+2nq7DH4m98vj6ob3gOQwTvNlXzh4y 3XFA== 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 b8-v6si429355ple.469.2018.06.25.19.11.45; Mon, 25 Jun 2018 19:12:00 -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 S965241AbeFZCLE (ORCPT + 99 others); Mon, 25 Jun 2018 22:11:04 -0400 Received: from smtprelay0126.hostedemail.com ([216.40.44.126]:59427 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965190AbeFZCLD (ORCPT ); Mon, 25 Jun 2018 22:11:03 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id 5495F18224D7A; Tue, 26 Jun 2018 02:11:02 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::,RULES_HIT:41:355:379:541:599:960:973:982:988:989:1256:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1540:1593:1594:1711:1714:1730:1747:1777:1792:2393:2559:2562:2693:2828:3138:3139:3140:3141:3142:3350:3622:3865:3866:3867:3870:3871:3874:4321:5007:10004:10400:10848:11026:11473:11658:11914:12043:12048:12296:12438:12679:12740:12760:12895:13069:13161:13229:13311:13357:13439:14096:14097:14659:14721:21080:21324:21627:30012:30054:30070:30091,0,RBL:47.151.150.235:@perches.com:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:26,LUA_SUMMARY:none X-HE-Tag: scent76_8cd89f294c4f X-Filterd-Recvd-Size: 1964 Received: from XPS-9350.home (unknown [47.151.150.235]) (Authenticated sender: joe@perches.com) by omf12.hostedemail.com (Postfix) with ESMTPA; Tue, 26 Jun 2018 02:11:00 +0000 (UTC) Message-ID: Subject: Re: [PATCH v2 net] nfp: cast sizeof() to int when comparing with error code From: Joe Perches To: Chengguang Xu , jakub.kicinski@netronome.com, davem@davemloft.net, LKML , Julia Lawall , cocci Cc: oss-drivers@netronome.com, netdev@vger.kernel.org, Dmitry Torokhov , linux-input , linux-s390 Date: Mon, 25 Jun 2018 19:10:59 -0700 In-Reply-To: <20180626011631.22717-1-cgxu519@gmx.com> References: <20180626011631.22717-1-cgxu519@gmx.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.28.1-2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?