uio: msm_sharedmem: Added checks to catch failed kcalloc calls

Added checks to catch failed kcalloc allocations. The function now
returns without proceeding in cases where NULL is returned
by kcalloc.

Change-Id: Ia9f4d6e059ea0623c3e9bed49ab60f3c30edf9ac
Signed-off-by: Marc Guillaume <quic_mguillau@quicinc.com>
This commit is contained in:
Marc Guillaume 2023-07-19 16:24:12 -07:00
parent 6e05c0cfa2
commit 9dc6d85c84

View File

@ -83,12 +83,21 @@ static void setup_shared_ram_perms(u32 client_id, phys_addr_t addr, u32 size,
if (vm_nav_path) {
nr = 3;
dest_vmids = kcalloc(nr, sizeof(struct qcom_scm_vmperm), GFP_KERNEL);
if (!dest_vmids) {
pr_err("failed to alloc memory when vm_nav_path=true\n");
return;
}
*dest_vmids = (struct qcom_scm_vmperm){VMID_HLOS, PERM_READ|PERM_WRITE};
*(dest_vmids + 1) = (struct qcom_scm_vmperm){VMID_MSS_MSA, PERM_READ|PERM_WRITE};
*(dest_vmids + 2) = (struct qcom_scm_vmperm){VMID_NAV, PERM_READ|PERM_WRITE};
} else {
nr = 2;
dest_vmids = kcalloc(nr, sizeof(struct qcom_scm_vmperm), GFP_KERNEL);
if (!dest_vmids) {
pr_err("failed to alloc memory when vm_nav_path=false\n");
return;
}
*dest_vmids = (struct qcom_scm_vmperm){VMID_HLOS, PERM_READ|PERM_WRITE};
*(dest_vmids + 1) = (struct qcom_scm_vmperm){VMID_MSS_MSA, PERM_READ|PERM_WRITE};
}