[PATCH net 1/2] liquidio: Fix an off by one in octeon_download_firmware()

From: Christophe JAILLET
Date: Sun Oct 22 2023 - 17:00:30 EST


In order to append the 'boottime' string to 'h->bootcmd', the final NULL
has to betaken into account when checking if there is enough space.

Fixes: 907aaa6babe1 ("liquidio: pass date and time info to NIC firmware")
Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
---
drivers/net/ethernet/cavium/liquidio/octeon_console.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_console.c b/drivers/net/ethernet/cavium/liquidio/octeon_console.c
index 67c3570f875f..bd6baf2872a5 100644
--- a/drivers/net/ethernet/cavium/liquidio/octeon_console.c
+++ b/drivers/net/ethernet/cavium/liquidio/octeon_console.c
@@ -899,13 +899,13 @@ int octeon_download_firmware(struct octeon_device *oct, const u8 *data,
ret = snprintf(boottime, MAX_BOOTTIME_SIZE,
" time_sec=%lld time_nsec=%ld",
(s64)ts.tv_sec, ts.tv_nsec);
- if ((sizeof(h->bootcmd) - strnlen(h->bootcmd, sizeof(h->bootcmd))) <
+ if ((sizeof(h->bootcmd) - strnlen(h->bootcmd, sizeof(h->bootcmd))) <=
ret) {
dev_err(&oct->pci_dev->dev, "Boot command buffer too small\n");
return -EINVAL;
}
strncat(h->bootcmd, boottime,
- sizeof(h->bootcmd) - strnlen(h->bootcmd, sizeof(h->bootcmd)));
+ sizeof(h->bootcmd) - strnlen(h->bootcmd, sizeof(h->bootcmd)) - 1);

dev_info(&oct->pci_dev->dev, "Writing boot command: %s\n",
h->bootcmd);
--
2.34.1