platform: goldfish: pipe: Fail compilation if structs are too large

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 <rkir@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Roman Kiryanov 2018-08-27 11:23:01 -07:00 коммит произвёл Greg Kroah-Hartman
Родитель 84ae527aa5
Коммит d23069a5a5
1 изменённых файлов: 3 добавлений и 6 удалений

Просмотреть файл

@ -64,6 +64,7 @@
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/acpi.h> #include <linux/acpi.h>
#include <linux/bug.h>
#include "goldfish_pipe_qemu.h" #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 * Command buffer needs to be allocated on its own page to make sure
* it is physically contiguous in host's address space. * it is physically contiguous in host's address space.
*/ */
BUILD_BUG_ON(sizeof(struct goldfish_pipe_command) > PAGE_SIZE);
pipe->command_buffer = pipe->command_buffer =
(struct goldfish_pipe_command *)__get_free_page(GFP_KERNEL); (struct goldfish_pipe_command *)__get_free_page(GFP_KERNEL);
if (!pipe->command_buffer) { 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 * needs to be contained in a single physical page. The easiest choice
* is to just allocate a page and place the buffers in it. * is to just allocate a page and place the buffers in it.
*/ */
if (WARN_ON(sizeof(*dev->buffers) > PAGE_SIZE)) BUILD_BUG_ON(sizeof(struct goldfish_pipe_dev_buffers) > PAGE_SIZE);
return -ENOMEM;
page = (char *)__get_free_page(GFP_KERNEL); page = (char *)__get_free_page(GFP_KERNEL);
if (!page) { if (!page) {
kfree(dev->pipes); kfree(dev->pipes);
@ -843,9 +843,6 @@ static int goldfish_pipe_probe(struct platform_device *pdev)
struct resource *r; struct resource *r;
struct goldfish_pipe_dev *dev = pipe_dev; 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 */ /* not thread safe, but this should not happen */
WARN_ON(dev->base != NULL); WARN_ON(dev->base != NULL);