]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/common/memory: Return `-EINVAL` on insertion of empty memregions
authorSergiu Moga <sergiu@unikraft.io>
Sat, 23 Sep 2023 08:23:55 +0000 (11:23 +0300)
committerRazvan Deaconescu <razvand@unikraft.io>
Fri, 20 Oct 2023 16:35:55 +0000 (19:35 +0300)
Since insertion of empty memory regions should not happen, return
`-EINVAL` in case the program does somehow end up doing this.

This way we will know early on if a memregion computation is wrong
or if we are met with an unhandled edge case.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #1060

plat/common/include/uk/plat/common/memory.h

index 01ffe77077dcec3fad58960b9ef1425054cd21de..0a585e9155820cb45bd4e1b073edc0bd36160fc8 100644 (file)
@@ -90,6 +90,9 @@ ukplat_memregion_list_insert(struct ukplat_memregion_list *list,
        struct ukplat_memregion_desc *p;
        __u32 i;
 
+       if (unlikely(!mrd->len))
+               return -EINVAL;
+
        if (unlikely(list->count == list->capacity))
                return -ENOMEM;
 
@@ -206,6 +209,9 @@ ukplat_memregion_list_insert_at_idx(struct ukplat_memregion_list *list,
 {
        struct ukplat_memregion_desc *p;
 
+       if (unlikely(!mrd->len))
+               return -EINVAL;
+
        if (unlikely(list->count == list->capacity))
                return -ENOMEM;
 
@@ -247,6 +253,9 @@ ukplat_memregion_list_insert_split_phys(struct ukplat_memregion_list *list,
        int i;
        int rc;
 
+       if (unlikely(!mrd->len))
+               return -EINVAL;
+
        voffset = mrd->vbase - mrd->pbase;
        pstart = mrd->pbase;
        pend = mrd->pbase + mrd->len;