[PATCH v2 1/2] remoteproc: qcom: Handle reserved-memory allocation issues

From: Stephan Gerhold
Date: Wed Jun 14 2023 - 12:32:20 EST


If Linux fails to allocate the dynamic reserved memory specified in the
device tree, the size of the reserved_mem will be 0. Add a check for
this to avoid using an invalid reservation.

Signed-off-by: Stephan Gerhold <stephan@xxxxxxxxxxx>
---
New patch in v2, I wasn't aware of this until Bjorn posted a similar
patch for rmtfs:
https://lore.kernel.org/linux-arm-msm/20230530233643.4044823-4-quic_bjorande@xxxxxxxxxxx/
---
drivers/remoteproc/qcom_q6v5_mss.c | 2 +-
drivers/remoteproc/qcom_q6v5_wcss.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c
index 70bffc9f33f6..a35ab6e860f3 100644
--- a/drivers/remoteproc/qcom_q6v5_mss.c
+++ b/drivers/remoteproc/qcom_q6v5_mss.c
@@ -1932,7 +1932,7 @@ static int q6v5_alloc_memory_region(struct q6v5 *qproc)
return 0;

rmem = of_reserved_mem_lookup(node);
- if (!rmem) {
+ if (!rmem || !rmem->size) {
dev_err(qproc->dev, "unable to resolve metadata region\n");
return -EINVAL;
}
diff --git a/drivers/remoteproc/qcom_q6v5_wcss.c b/drivers/remoteproc/qcom_q6v5_wcss.c
index b437044aa126..9edab9d60c21 100644
--- a/drivers/remoteproc/qcom_q6v5_wcss.c
+++ b/drivers/remoteproc/qcom_q6v5_wcss.c
@@ -882,7 +882,7 @@ static int q6v5_alloc_memory_region(struct q6v5_wcss *wcss)
rmem = of_reserved_mem_lookup(node);
of_node_put(node);

- if (!rmem) {
+ if (!rmem || !rmem->size) {
dev_err(dev, "unable to acquire memory-region\n");
return -EINVAL;
}

--
2.40.1