aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorGustavo A. R. Silva <garsilva@embeddedor.com>2018-03-07 21:27:56 -0500
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2018-03-17 09:20:56 -0400
commitfed9b18611f75110d5b26d650819665d528038da (patch)
treebca711325de4c186d2e3d42320211fc758b828e8 /drivers/rtc
parent83bbc5ac63326433755592829caf02920b3d8dc0 (diff)
rtc: remove VLA usage
In preparation to enabling -Wvla, remove VLA and replace it with a fixed-length array instead. >From a security viewpoint, the use of Variable Length Arrays can be a vector for stack overflow attacks. Also, in general, as the code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having segfaults that are hard to debug. Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621 Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-bq32k.c6
-rw-r--r--drivers/rtc/rtc-mcp795.c2
2 files changed, 6 insertions, 2 deletions
diff --git a/drivers/rtc/rtc-bq32k.c b/drivers/rtc/rtc-bq32k.c
index e8698e9870fe..ef52741000a8 100644
--- a/drivers/rtc/rtc-bq32k.c
+++ b/drivers/rtc/rtc-bq32k.c
@@ -36,6 +36,10 @@
36#define BQ32K_CFG2 0x09 /* Trickle charger control */ 36#define BQ32K_CFG2 0x09 /* Trickle charger control */
37#define BQ32K_TCFE BIT(6) /* Trickle charge FET bypass */ 37#define BQ32K_TCFE BIT(6) /* Trickle charge FET bypass */
38 38
39#define MAX_LEN 10 /* Maximum number of consecutive
40 * register for this particular RTC.
41 */
42
39struct bq32k_regs { 43struct bq32k_regs {
40 uint8_t seconds; 44 uint8_t seconds;
41 uint8_t minutes; 45 uint8_t minutes;
@@ -74,7 +78,7 @@ static int bq32k_read(struct device *dev, void *data, uint8_t off, uint8_t len)
74static int bq32k_write(struct device *dev, void *data, uint8_t off, uint8_t len) 78static int bq32k_write(struct device *dev, void *data, uint8_t off, uint8_t len)
75{ 79{
76 struct i2c_client *client = to_i2c_client(dev); 80 struct i2c_client *client = to_i2c_client(dev);
77 uint8_t buffer[len + 1]; 81 uint8_t buffer[MAX_LEN + 1];
78 82
79 buffer[0] = off; 83 buffer[0] = off;
80 memcpy(&buffer[1], data, len); 84 memcpy(&buffer[1], data, len);
diff --git a/drivers/rtc/rtc-mcp795.c b/drivers/rtc/rtc-mcp795.c
index 79e24eadbe99..00e11c1b2186 100644
--- a/drivers/rtc/rtc-mcp795.c
+++ b/drivers/rtc/rtc-mcp795.c
@@ -82,7 +82,7 @@ static int mcp795_rtcc_write(struct device *dev, u8 addr, u8 *data, u8 count)
82{ 82{
83 struct spi_device *spi = to_spi_device(dev); 83 struct spi_device *spi = to_spi_device(dev);
84 int ret; 84 int ret;
85 u8 tx[2 + count]; 85 u8 tx[257];
86 86
87 tx[0] = MCP795_WRITE; 87 tx[0] = MCP795_WRITE;
88 tx[1] = addr; 88 tx[1] = addr;