Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp3894711ooa; Mon, 13 Aug 2018 20:49:42 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzsIB2LVnBIU5M4jy+z55gJ34holOC4QWwLUvNdLvFuyw6oER+BJxRp6hfln2MyPuqksEfL X-Received: by 2002:a62:129a:: with SMTP id 26-v6mr21619543pfs.102.1534218582788; Mon, 13 Aug 2018 20:49:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534218582; cv=none; d=google.com; s=arc-20160816; b=EC+buhQQvS2O2GYpt8z4yTOmACtY8YoRr70+pYV+S5skVrzVIxrxLNP9jRxQt1duZv 8pzij8ZMqThAz6cexp6lDbIWgoJw6FVsROUQFaydcQqBmE+smYGtkUVGXs7xCnzi+5Cw Hyx9t2MZ2Bi/bBvwSOqqAxeCtFeKbpfMwodZ2J1Hpw0+yBPRCR2aR02m0COVO9xnJlH4 63ybFM4PljeJp+LHuTUuMfNtlAVV35Bcfki+i2FfjHKJgsnZ7IVdj2hRQgtOtzAq5Pja gMy7XVdGsW+3uE/5vuI1EwIPQabG+QkNS4iV1qdI7+jHvz3mdUxqmJbGiu61Jy1xCnqx jkXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=h3z96xJatzBoJwONfdtNQgm90qovpwIM2BJ3FzfFuT8=; b=n9KiJgTiFhnVHN8OH+lB/nEnm3/XyaO1YqRggkLEV8fQhHk0nPKSR6LTbkgpmMlWem Y6zao9NCttHgAY61hgPlZssY/OYiuEEBCIMT68cLJosIzURECvkTAdGRA1G1ApmKxp3b mM3Gw3SxNt4wQNep13oe07iHqMS1Z+7Si9mXC5HVEHT6wk81oGd4COQWtwB+s+z7jQcA HbIjS4iYfQyGkeYqIwAT2n3Snkd2R7WTyAdxIt2Ukwy3ZE+/uBH7Z3hr6qMyeZAv+8yC GwJ2as5ruYExPfnZ84lzIGe4L6pvxhRHXO734MgvuwYUv0j3IugH1w0991xiHkgRcqVd x1+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ps+Rbzuh; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z123-v6si21655561pfc.289.2018.08.13.20.49.28; Mon, 13 Aug 2018 20:49:42 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=ps+Rbzuh; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731308AbeHNGdW (ORCPT + 99 others); Tue, 14 Aug 2018 02:33:22 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:37892 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729443AbeHNGdV (ORCPT ); Tue, 14 Aug 2018 02:33:21 -0400 Received: by mail-lf1-f66.google.com with SMTP id a4-v6so12754427lff.5 for ; Mon, 13 Aug 2018 20:48:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=h3z96xJatzBoJwONfdtNQgm90qovpwIM2BJ3FzfFuT8=; b=ps+RbzuhG60PVMs/YtO0hzHsOXD2si9Z5D2UJHlqsQmw5aMkxZ4fSsU6cJXS29e4NJ viDIK984lnXpfrqRDIXBos3Qil3lEWCiYvJhZQuXaE6tH/vNDp2y1trKNPqxzDUUUkHO VTzG4xuwjYNY+oZ2h1gLS0jMgQzQam3BQcrc07m0xU7KVFH49xqgdpxjKl7cvPl5NF/g GsYO88mGvyuVvSkY9Mygo/CIgKCZYqxQrx1iAg01ahdGInT55SsqFob3dutaP9abbUBX OvJj6RIXmIHhpFFGpNMTRbsILp0Wib0TYmMbPP9nHztUcGeqq7y8kKRpMzOtvpv2jkKd SEdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=h3z96xJatzBoJwONfdtNQgm90qovpwIM2BJ3FzfFuT8=; b=cktJDfZY88x0w/Xc1ccnDO5elZvnx2VzW9nzyAyLXgOpVto0Bp9ZoE123dndd75CMg 9a16VgYXhx7JkoxkPhWPsP3t3lA6mupJ2NdAIwwySSMDbGz0gBgo4qAQ4ThtqzJyZHqH 0xgJqBVC4RF4atiZ+4mxc2344RbpLJpWNCIUZhzstvR+kawkRzVOiiOxtjMp4QxRYeSE wtSPcrgDcA3fepaatYuc2o4e9w/Mxme5ETm+5PjOthb77EOdtWwg4Z50jNaXaJ2vNICU gqz4Sn1r7LpSUotP7CBIL/nppjpknQ6AguIJ+EMxiagH0JoTISAB4AAe2CCzMlr0LDvW WwwA== X-Gm-Message-State: AOUpUlEXJBLY3EeIACtJe/i/CflYzumxpW6HMkMD3UAMuiqHsr+Np9wD 1WtEof6zWa8IrlIWl1zA7Wi6MwYWdCRxeOb3J2Drfw== X-Received: by 2002:a19:8f8f:: with SMTP id s15-v6mr12209487lfk.96.1534218486239; Mon, 13 Aug 2018 20:48:06 -0700 (PDT) MIME-Version: 1.0 References: <20180813233839.190855-1-rkir@google.com> <20180813233839.190855-6-rkir@google.com> In-Reply-To: From: Roman Kiryanov Date: Mon, 13 Aug 2018 20:47:54 -0700 Message-ID: Subject: Re: [PATCH 6/9] platform: goldfish: pipe: Fail compilation if structs are too large To: joe@perches.com Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, Todd Kjos Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, thank you for reviewing my patches. I decided to put BUILD_BUG_ON close to places where it is important that these structs fit into a memory page to give some context. Regards, Roman. On Mon, Aug 13, 2018 at 6:48 PM Joe Perches wrote: > > 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); >