Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp6200101imm; Mon, 27 Aug 2018 11:25:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaGg0PRqjPpenXjdx27YGmx459nBThkINEKVUxhsD6lTJbBIu07DvJixMadhJz4Jbeq1YqW X-Received: by 2002:a62:3184:: with SMTP id x126-v6mr15357495pfx.49.1535394359360; Mon, 27 Aug 2018 11:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535394359; cv=none; d=google.com; s=arc-20160816; b=cbXWFN8CnnkXpRCF1pmA1nPp+GicnCOqH+4uXUWAEo6CIzWrAIXRZ7oDcdenrJCU5Y HctoWFDUoWwbyYUYysGNmUbCl/kgu99ZVe7k+27k8DlnRUe2Yi3DKDRFLPMGJpdqsgWW txzSi2loF5j4DI04cVHn8d47inx5YXLeMMX+ut9ZAbzol+8cCvgkvWlys8gWlGCvLynT fqskuGN1DNnQxqevjtxMCeQ59IY4xMtC5HW7UYXfYjfv0K4HbDcj+FAYeLoQyD2nXDIl Jf+dQV3gQOS2PyBu+AUlI1o+q/h9odgiBVfhYYpAFic+NwWNnWjSVqtKBWgmnPPfNx9r 3XVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature :arc-authentication-results; bh=aMsh+OhO3+eG0eAe2tB3C0wZmw5Mkk207ICLxJgOd18=; b=RenGSH4wxdOlsKLa6J8gqAPRfsnQaz5Ia8irYhnh5Qabv5UVuTWQSEUDO2GFHk3d48 I5/OndzBnathFdiYXftEKozVBariYG+rqAw91h5zAFK/rlF/y+Wq1SxavhW8YTMUFhUV J6XJGrdqZX27sNvsbcgrH35Pk1JuENII4ycZgHRnmCsHZ290N9HGsvebvafKYAFyt2AN XX7U6Hxzk8hyv8Ynra8fnSDOY2r0P/gzwzAjLYf+gifSEME8fqGfY6DG5bgwKdWfIC3A wsusvmQmJxVh+YMz6xMmetZOlnBS0YYwhK4oPFFUwqsPKfh497WGJouk+4tCQznWplrT MGsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eFHQBhzF; 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 d129-v6si16328919pfd.113.2018.08.27.11.25.43; Mon, 27 Aug 2018 11:25:59 -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=eFHQBhzF; 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 S1727563AbeH0WLd (ORCPT + 99 others); Mon, 27 Aug 2018 18:11:33 -0400 Received: from mail-vk0-f73.google.com ([209.85.213.73]:34163 "EHLO mail-vk0-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726895AbeH0WLd (ORCPT ); Mon, 27 Aug 2018 18:11:33 -0400 Received: by mail-vk0-f73.google.com with SMTP id o62-v6so6834974vko.1 for ; Mon, 27 Aug 2018 11:23:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=aMsh+OhO3+eG0eAe2tB3C0wZmw5Mkk207ICLxJgOd18=; b=eFHQBhzFgLByMEu8elt/2yO0FxyOc2MeYlq1rooPm6Yao3BkTvGE37q1tSyfNE8VHG GMQRb2Xa7Fj6UCQBKwyfDLMXMQ4cmi+of+HqiKIm2f5xx/zg4/W97K7Wfo7uHTC6YtQl y4f65n+15GEz1bujrVr2FxruznfHtD7/2a4wjA/LlfleQGPllJqIArQ2mj9TDw+5uz/K Fxs6zYWqJAvAfIH6fChRntS2rolg169HtL+KjziXty+FM3tryuaEuDWXcuN8Av0GWqlG 10SVZo/KTaG+ITSGDSY7wLIB9+DE5nYiaHMlwn7U6ozAoDDljn7P6pyKyXSdQiH+lt06 42Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=aMsh+OhO3+eG0eAe2tB3C0wZmw5Mkk207ICLxJgOd18=; b=tldOu5XHrj/+Y+pPjTX/WyQCH+pZ6sdx2UiN/lJHOAmsqmhTtqXllvXX/WMER21X6n c1nzRLWHMy2ZmX5zK6XukeqA4ybuAsbBzU59/Kpxmkaz5BbZHvBXNlJq+r7no2I1vbfb xio3Cc2vUvt9wP6kKb0kfHRxdPZRiTyMVmy8SSAUsZ6IjYPvm8eV+0HjXseBdeYReRUM rDnJiGqJOjGciv1DyIzq2CDK+bXGiFONDkGpKYgP2c1Q3cxphytVfSe8UXPkh+M+raZk zDBprhFgRnd+0GAY2CKjf9rU1b8220J4j/evMMTaMbYnieJtnsULBTw06rZ8rjrGZ2W7 VT/Q== X-Gm-Message-State: APzg51BpiC/PXSOOxuendAIkb9iW4u+CCIXnBNvXUNHVBb6r7T40fh7C myHqpnzX2RZSUH6fSNAxRQPMG6Pw X-Received: by 2002:ab0:492b:: with SMTP id z40-v6mr7329597uac.67.1535394230619; Mon, 27 Aug 2018 11:23:50 -0700 (PDT) Date: Mon, 27 Aug 2018 11:23:01 -0700 In-Reply-To: <20180827182315.126345-1-rkir@google.com> Message-Id: <20180827182315.126345-6-rkir@google.com> Mime-Version: 1.0 References: <20180827182315.126345-1-rkir@google.com> X-Mailer: git-send-email 2.19.0.rc0.228.g281dcd1b4d0-goog Subject: [PATCH 06/20] platform: goldfish: pipe: Fail compilation if structs are too large From: rkir@google.com To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, tkjos@google.com, Roman Kiryanov 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 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. Signed-off-by: Roman Kiryanov --- drivers/platform/goldfish/goldfish_pipe.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c index 0c55e657da5a..24e40deb98cc 100644 --- a/drivers/platform/goldfish/goldfish_pipe.c +++ b/drivers/platform/goldfish/goldfish_pipe.c @@ -64,6 +64,7 @@ #include #include #include +#include #include "goldfish_pipe_qemu.h" /* @@ -689,6 +690,7 @@ static int goldfish_pipe_open(struct inode *inode, struct file *file) * Command buffer needs to be allocated on its own page to make sure * it is physically contiguous in host's address space. */ + BUILD_BUG_ON(sizeof(struct goldfish_pipe_command) > PAGE_SIZE); pipe->command_buffer = (struct goldfish_pipe_command *)__get_free_page(GFP_KERNEL); if (!pipe->command_buffer) { @@ -798,9 +800,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(struct goldfish_pipe_dev_buffers) > PAGE_SIZE); page = (char *)__get_free_page(GFP_KERNEL); if (!page) { kfree(dev->pipes); @@ -843,9 +843,6 @@ 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; - /* not thread safe, but this should not happen */ WARN_ON(dev->base != NULL); -- 2.19.0.rc0.228.g281dcd1b4d0-goog