[PATCH 1/2] platform/raspberrypi: vc-sm-cma: Fix get_kernel_id check, pass NULL for pointer

From: Jai Luthra

Date: Mon Nov 16 2026 - 08:33:27 EST


Fix a couple of issues reported by sparse on the vc-sm-cma driver.

The first is around the retval of get_kernel_id(), which we check for
negative error codes after assigning it to a u32 value. Fix it by using
a temporary signed integer for the check. While at it, also ensure
during error handling that we call free_kernel_id() only if we got a
valid one earlier.

The second is a minor warning around passing 0 instead of NULL for a
pointer argument.

Fixes: 0d6409fd70af ("platform/raspberrypi: Add VideoCore shared memory support")
Reported-by: kernel test robot <lkp@xxxxxxxxx>
Closes: https://lore.kernel.org/oe-kbuild-all/202611141042.Rxt6cuNo-lkp@xxxxxxxxx/
Closes: https://lore.kernel.org/oe-kbuild-all/202611141002.jCrJ06DU-lkp@xxxxxxxxx/
Signed-off-by: Jai Luthra <jai.luthra@xxxxxxxxxxxxxxxx>
---
drivers/platform/raspberrypi/vc-sm-cma/vc_sm.c | 11 +++++++----
drivers/platform/raspberrypi/vc-sm-cma/vc_sm_cma_vchi.c | 2 +-
2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/raspberrypi/vc-sm-cma/vc_sm.c b/drivers/platform/raspberrypi/vc-sm-cma/vc_sm.c
index 4dda06fee533..2d9bb5f957a3 100644
--- a/drivers/platform/raspberrypi/vc-sm-cma/vc_sm.c
+++ b/drivers/platform/raspberrypi/vc-sm-cma/vc_sm.c
@@ -415,6 +415,7 @@ vc_sm_cma_import_dmabuf_internal(struct dma_buf *dma_buf,
struct vc_sm_import import = { };
struct sg_table *sgt = NULL;
dma_addr_t dma_addr;
+ int kernel_id = -1;
u32 cache_alias;
int ret = 0;
int status;
@@ -469,11 +470,12 @@ vc_sm_cma_import_dmabuf_internal(struct dma_buf *dma_buf,
}
import.size = sg_dma_len(sgt->sgl);
import.allocator = current->tgid;
- import.kernel_id = get_kernel_id(buffer);
- if (import.kernel_id < 0) {
- ret = import.kernel_id;
+ kernel_id = get_kernel_id(buffer);
+ if (kernel_id < 0) {
+ ret = kernel_id;
goto error;
}
+ import.kernel_id = kernel_id;

memcpy(import.name, VC_SM_RESOURCE_NAME_DEFAULT,
sizeof(VC_SM_RESOURCE_NAME_DEFAULT));
@@ -544,7 +546,8 @@ vc_sm_cma_import_dmabuf_internal(struct dma_buf *dma_buf,
vc_sm_cma_vchi_free(sm_state->sm_handle, &free,
&sm_state->int_trans_id);
}
- free_kernel_id(import.kernel_id);
+ if (kernel_id >= 0)
+ free_kernel_id(import.kernel_id);
kfree(buffer);
if (sgt)
dma_buf_unmap_attachment_unlocked(attach, sgt,
diff --git a/drivers/platform/raspberrypi/vc-sm-cma/vc_sm_cma_vchi.c b/drivers/platform/raspberrypi/vc-sm-cma/vc_sm_cma_vchi.c
index 098342601895..54d318735575 100644
--- a/drivers/platform/raspberrypi/vc-sm-cma/vc_sm_cma_vchi.c
+++ b/drivers/platform/raspberrypi/vc-sm-cma/vc_sm_cma_vchi.c
@@ -481,7 +481,7 @@ int vc_sm_cma_vchi_free(struct sm_instance *handle, struct vc_sm_free_t *msg,
u32 *cur_trans_id)
{
return vc_sm_cma_vchi_send_msg(handle, VC_SM_MSG_TYPE_FREE,
- msg, sizeof(*msg), 0, 0, cur_trans_id, 0);
+ msg, sizeof(*msg), NULL, 0, cur_trans_id, 0);
}

int vc_sm_cma_vchi_import(struct sm_instance *handle, struct vc_sm_import *msg,

--
2.56.0