summaryrefslogtreecommitdiffstats
path: root/drivers/mfd/rave-sp.c
diff options
context:
space:
mode:
authorKyle Spiers <ksspiers@google.com>2018-04-27 15:30:23 -0700
committerLee Jones <lee.jones@linaro.org>2018-05-16 09:21:48 +0100
commit7169483ce4570bd2918cb7b1ab04c3e095a22713 (patch)
tree6d733e984373eff7973cb484ae1d33e3e317bbe3 /drivers/mfd/rave-sp.c
parentac1886165cd1201c5793099b6fbad1876bf98dfe (diff)
downloadblackbird-obmc-linux-7169483ce4570bd2918cb7b1ab04c3e095a22713.tar.gz
blackbird-obmc-linux-7169483ce4570bd2918cb7b1ab04c3e095a22713.zip
mfd: rave-sp: Remove VLA
As part of the effort to remove VLAs from the kernel[1], this creates constants for the checksum lengths of CCITT and 8B2C and changes crc_calculated to be the maximum size of a checksum. https://lkml.org/lkml/2018/3/7/621 Signed-off-by: Kyle Spiers <ksspiers@google.com> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Lee Jones <lee.jones@linaro.org>
Diffstat (limited to 'drivers/mfd/rave-sp.c')
-rw-r--r--drivers/mfd/rave-sp.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/drivers/mfd/rave-sp.c b/drivers/mfd/rave-sp.c
index cb0cc9d509a0..36dcd98977d6 100644
--- a/drivers/mfd/rave-sp.c
+++ b/drivers/mfd/rave-sp.c
@@ -45,7 +45,9 @@
#define RAVE_SP_DLE 0x10
#define RAVE_SP_MAX_DATA_SIZE 64
-#define RAVE_SP_CHECKSUM_SIZE 2 /* Worst case scenario on RDU2 */
+#define RAVE_SP_CHECKSUM_8B2C 1
+#define RAVE_SP_CHECKSUM_CCITT 2
+#define RAVE_SP_CHECKSUM_SIZE RAVE_SP_CHECKSUM_CCITT
/*
* We don't store STX, ETX and unescaped bytes, so Rx is only
* DATA + CSUM
@@ -449,7 +451,12 @@ static void rave_sp_receive_frame(struct rave_sp *sp,
const size_t payload_length = length - checksum_length;
const u8 *crc_reported = &data[payload_length];
struct device *dev = &sp->serdev->dev;
- u8 crc_calculated[checksum_length];
+ u8 crc_calculated[RAVE_SP_CHECKSUM_SIZE];
+
+ if (unlikely(checksum_length > sizeof(crc_calculated))) {
+ dev_warn(dev, "Checksum too long, dropping\n");
+ return;
+ }
print_hex_dump_debug("rave-sp rx: ", DUMP_PREFIX_NONE,
16, 1, data, length, false);
OpenPOWER on IntegriCloud