linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: mcp795: remove VLA usage
@ 2018-03-12 23:13 Stefano Manni
  2018-03-12 23:31 ` Alexandre Belloni
  0 siblings, 1 reply; 4+ messages in thread
From: Stefano Manni @ 2018-03-12 23:13 UTC (permalink / raw)
  To: a.zummo, alexandre.belloni; +Cc: linux-rtc, linux-kernel, Stefano Manni

In preparation to enabling -Wvla, remove VLAs and replace them with
fixed-length arrays instead.

rtc-mcp795.c uses a variable-length array declaration to contain
the command to write the rtcc; this can be replaced by a fixed-
size array of length 2 (instruction, address) + 32 (data out),
assuming a maximum data length of 32 bytes before wrap up.

This was prompted by https://lkml.org/lkml/2018/3/7/621

Signed-off-by: Stefano Manni <stefano.manni@gmail.com>
---
 drivers/rtc/rtc-mcp795.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-mcp795.c b/drivers/rtc/rtc-mcp795.c
index 77f21331ae21..a5f504e2364c 100644
--- a/drivers/rtc/rtc-mcp795.c
+++ b/drivers/rtc/rtc-mcp795.c
@@ -61,6 +61,9 @@
 
 #define SEC_PER_DAY		(24 * 60 * 60)
 
+/* Maximum length for data out in write operation to RTCC */
+#define MCP795_MAX_DATAOUT_LEN	32
+
 static int mcp795_rtcc_read(struct device *dev, u8 addr, u8 *buf, u8 count)
 {
 	struct spi_device *spi = to_spi_device(dev);
@@ -82,7 +85,10 @@ static int mcp795_rtcc_write(struct device *dev, u8 addr, u8 *data, u8 count)
 {
 	struct spi_device *spi = to_spi_device(dev);
 	int ret;
-	u8 tx[2 + count];
+	u8 tx[2 + MCP795_MAX_DATAOUT_LEN];
+
+	if (count > MCP795_MAX_DATAOUT_LEN)
+		return -EINVAL;
 
 	tx[0] = MCP795_WRITE;
 	tx[1] = addr;
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-03-13 16:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-12 23:13 [PATCH] rtc: mcp795: remove VLA usage Stefano Manni
2018-03-12 23:31 ` Alexandre Belloni
2018-03-13  8:29   ` Stefano Manni
2018-03-13 16:28     ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).