Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp3802517ooa; Mon, 13 Aug 2018 18:50:08 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyTThAoHyjXMvrY+8trn3jgiO9KK9Q32sVCV2xmE+PRx5zAAHy9nJNA10sWv6FJs/usmMEH X-Received: by 2002:a63:1810:: with SMTP id y16-v6mr1418696pgl.48.1534211408402; Mon, 13 Aug 2018 18:50:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534211408; cv=none; d=google.com; s=arc-20160816; b=YjKrv0iqCER/Ih8LF/ukljSm3puT6fe3tA0qlZuxfKUhbeNDnjCVPSfS9VfTqyacG7 Fq9mPtxlLHOCWV3ckgoHkIiF+VYN+9uQnAvk4O7VmLYe/iZgK1GTUfVhGnm7Tpu0+DdV RRd+rpkZfHCMgmOg1VV6lH+LhFslnwAq3JlYlauHddrUuO+tip/btR3D/4gBFwUditkI f6LcY58JhbACd7lRN5FMhWU1cbovxSPGINiC5/K2I3slNzCs1xYK/eTRKa9foPWTFzYY M+EccKtz367J/iB4syzB1YnG2jLRbFdCA45nK2o8Cfseu2NmfG23jAxtUWQTCF163HcM g+6w== 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=ew9Fz5rfZhpRnxK0MDfjIzTY+AutCTk3bc9Oc88J/8M=; b=t/TNhJxjOekWxA7BK6jCmWUt62Iq5PUcTGMT2KIPIipPOVV0vdx1Y2Nn4n7SuL60aG ZgtswcznQ+w1H5cGKq9vktoQt8OBSEF8F+7r4Dw6bbyv2XtyJ0/guLlndfaqwopGqIbw OFSgZEjVpIbnZY+pW4NRQ848rTLoD5LDcfVCtRoRi+EC9Lhdid6xASSLvNDoeIyJN1Js 7CyeybV0oiho8QVcChNjnBjaUtdtC2OmJY1SQ0HyjMO8Wg7N5xgJdtYjP+6OrFabmTPP eEkNPRe+4yyw5DLqBqxbRS9CwZW0xS/mR6PWQyppYCjvH67j+h13NV7nucYfFkku2ohA BWoA== 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 i61-v6si15083224plb.209.2018.08.13.18.49.50; Mon, 13 Aug 2018 18:50:08 -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 S1730126AbeHNEc6 (ORCPT + 99 others); Tue, 14 Aug 2018 00:32:58 -0400 Received: from smtprelay0123.hostedemail.com ([216.40.44.123]:60577 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725829AbeHNEc6 (ORCPT ); Tue, 14 Aug 2018 00:32:58 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay07.hostedemail.com (Postfix) with ESMTP id 4F025181D340F; Tue, 14 Aug 2018 01:48:05 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::,RULES_HIT:41:355:379:541:599:800:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2194:2196:2199:2200:2393:2559:2562:2828:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3870:3871:3872:4321:4385:5007:6119:7576:10004:10400:10848:11026:11232:11473:11658:11914:12043:12296:12438:12740:12760:12895:13069:13255:13311:13357:13439:14096:14097:14181:14659:14721:21080:21324:21627:21740:30054:30091,0,RBL:47.151.153.53:@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:29,LUA_SUMMARY:none X-HE-Tag: balls99_296431b65a958 X-Filterd-Recvd-Size: 2368 Received: from XPS-9350.home (unknown [47.151.153.53]) (Authenticated sender: joe@perches.com) by omf09.hostedemail.com (Postfix) with ESMTPA; Tue, 14 Aug 2018 01:48:04 +0000 (UTC) Message-ID: Subject: Re: [PATCH 6/9] platform: goldfish: pipe: Fail compilation if structs are too large From: Joe Perches To: rkir@google.com, gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, tkjos@google.com Date: Mon, 13 Aug 2018 18:48:02 -0700 In-Reply-To: <20180813233839.190855-6-rkir@google.com> References: <20180813233839.190855-1-rkir@google.com> <20180813233839.190855-6-rkir@google.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 Mon, 2018-08-13 at 16:38 -0700, rkir@google.com wrote: > From: Roman Kiryanov > > Since the driver provides no workaround prevent in cases if structs do > no fit into a memory page, it is better to fail complation to find about > the issue earlt instead of returning errors at runtime. Minor earlt/early typo > diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c [] > @@ -797,9 +798,7 @@ static int goldfish_pipe_device_init(struct platform_device *pdev) > * needs to be contained in a single physical page. The easiest choice > * is to just allocate a page and place the buffers in it. > */ > - if (WARN_ON(sizeof(*dev->buffers) > PAGE_SIZE)) > - return -ENOMEM; > - > + BUILD_BUG_ON(sizeof(*dev->buffers) > PAGE_SIZE); > page = (char *)__get_free_page(GFP_KERNEL); > if (!page) { > kfree(dev->pipes); > @@ -842,8 +841,7 @@ static int goldfish_pipe_probe(struct platform_device *pdev) > struct resource *r; > struct goldfish_pipe_dev *dev = pipe_dev; > > - if (WARN_ON(sizeof(struct goldfish_pipe_command) > PAGE_SIZE)) > - return -ENOMEM; > + BUILD_BUG_ON(sizeof(struct goldfish_pipe_command) > PAGE_SIZE); > > /* not thread safe, but this should not happen */ > WARN_ON(dev->base != NULL); Why separate these BUILD_BUG_ONs into 2 different functions? Why not just BUILD_BUG_ON(sizeof(struct goldfish_pipe_command) > PAGE_SIZE); BUILD_BUG_ON(sizeof(struct goldfish_pipe_dev_buffers) > PAGE_SIZE);