From 9b09f136f74e7d4faca8327aa0ca4f38ced9ae6b Mon Sep 17 00:00:00 2001 From: Ioannis Glaropoulos Date: Tue, 5 May 2020 16:42:44 +0200 Subject: [PATCH] bluetooth: hci_rpmsg: check SHM_SIZE against shared mem size using DT Add a build-time assert to check that the configured SHM_SIZE does not exceed the memory allocated as shared memory. USe DT to extract the shared memory size. Signed-off-by: Ioannis Glaropoulos --- drivers/bluetooth/hci/rpmsg_nrf53.c | 4 ++++ samples/bluetooth/hci_rpmsg/src/main.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/drivers/bluetooth/hci/rpmsg_nrf53.c b/drivers/bluetooth/hci/rpmsg_nrf53.c index 04d90f25f5d..6a5d497981d 100644 --- a/drivers/bluetooth/hci/rpmsg_nrf53.c +++ b/drivers/bluetooth/hci/rpmsg_nrf53.c @@ -36,6 +36,10 @@ static struct device *ipm_rx_handle; #define SHM_SIZE 0x7c00 #define SHM_DEVICE_NAME "sram0.shm" +BUILD_ASSERT((SHM_START_ADDR + SHM_SIZE - SHM_BASE_ADDRESS) + <= DT_REG_SIZE(SHM_NODE), + "Allocated size exceeds available shared memory reserved for IPC"); + #define VRING_COUNT 2 #define VRING_TX_ADDRESS (SHM_START_ADDR + SHM_SIZE - 0x400) #define VRING_RX_ADDRESS (VRING_TX_ADDRESS - 0x400) diff --git a/samples/bluetooth/hci_rpmsg/src/main.c b/samples/bluetooth/hci_rpmsg/src/main.c index 8815b49f43a..26f6abc4297 100644 --- a/samples/bluetooth/hci_rpmsg/src/main.c +++ b/samples/bluetooth/hci_rpmsg/src/main.c @@ -43,6 +43,10 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #define SHM_SIZE 0x7c00 #define SHM_DEVICE_NAME "sram0.shm" +BUILD_ASSERT((SHM_START_ADDR + SHM_SIZE - SHM_BASE_ADDRESS) + <= DT_REG_SIZE(SHM_NODE), + "Allocated size exceeds available shared memory reserved for IPC"); + #define VRING_COUNT 2 #define VRING_TX_ADDRESS (SHM_START_ADDR + SHM_SIZE - 0x400) #define VRING_RX_ADDRESS (VRING_TX_ADDRESS - 0x400)