1 From 01995961823e4185f687c02cf326d78ba1b6b7bf Mon Sep 17 00:00:00 2001
2 From: James Hughes <JamesH65@users.noreply.github.com>
3 Date: Tue, 13 Nov 2018 17:27:00 +0000
4 Subject: [PATCH 206/806] Mailbox firmware calls now use kmalloc (#2749)
6 A previous change moved away from variable stack
7 allocation of a data buffer to a fixed maximum size.
8 However, some mailbox calls use larger data buffers
9 than the maximum allowed. This change moves from
10 stack storage to kmalloc to ensure all sizes are
13 Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
15 drivers/firmware/raspberrypi.c | 35 +++++++++++++++++-----------------
16 1 file changed, 18 insertions(+), 17 deletions(-)
18 --- a/drivers/firmware/raspberrypi.c
19 +++ b/drivers/firmware/raspberrypi.c
21 #include <linux/of_platform.h>
22 #include <linux/platform_device.h>
23 #include <linux/reboot.h>
24 +#include <linux/slab.h>
25 #include <soc/bcm2835/raspberrypi-firmware.h>
27 #define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
29 #define MBOX_DATA28(msg) ((msg) & ~0xf)
30 #define MBOX_CHAN_PROPERTY 8
32 -#define MAX_RPI_FW_PROP_BUF_SIZE 48
34 static struct platform_device *rpi_hwmon;
37 @@ -149,28 +148,28 @@ EXPORT_SYMBOL_GPL(rpi_firmware_property_
38 int rpi_firmware_property(struct rpi_firmware *fw,
39 u32 tag, void *tag_data, size_t buf_size)
41 - /* Single tags are very small (generally 8 bytes), so the
42 - * stack should be safe.
44 - u8 data[sizeof(struct rpi_firmware_property_tag_header) +
45 - MAX_RPI_FW_PROP_BUF_SIZE];
46 - struct rpi_firmware_property_tag_header *header =
47 - (struct rpi_firmware_property_tag_header *)data;
49 + struct rpi_firmware_property_tag_header *header;
51 - if (WARN_ON(buf_size > sizeof(data) - sizeof(*header)))
53 + /* Some mailboxes can use over 1k bytes. Rather than checking
54 + * size and using stack or kmalloc depending on requirements,
55 + * just use kmalloc. Mailboxes don't get called enough to worry
56 + * too much about the time taken in the allocation.
58 + void *data = kmalloc(sizeof(*header) + buf_size, GFP_KERNEL);
65 header->buf_size = buf_size;
66 header->req_resp_size = 0;
67 - memcpy(data + sizeof(struct rpi_firmware_property_tag_header),
68 - tag_data, buf_size);
69 + memcpy(data + sizeof(*header), tag_data, buf_size);
71 - ret = rpi_firmware_property_list(fw, &data, buf_size + sizeof(*header));
73 - data + sizeof(struct rpi_firmware_property_tag_header),
75 + ret = rpi_firmware_property_list(fw, data, buf_size + sizeof(*header));
77 + memcpy(tag_data, data + sizeof(*header), buf_size);
79 if ((tag == RPI_FIRMWARE_GET_THROTTLED) &&
80 memcmp(&fw->get_throttled, tag_data, sizeof(fw->get_throttled))) {
81 @@ -178,6 +177,8 @@ int rpi_firmware_property(struct rpi_fir
82 sysfs_notify(&fw->cl.dev->kobj, NULL, "get_throttled");
89 EXPORT_SYMBOL_GPL(rpi_firmware_property);