RDMA/uverbs: Check for null return of kmalloc_array
authorJiasheng Jiang <jiasheng@iscas.ac.cn>
Fri, 31 Dec 2021 09:33:15 +0000 (17:33 +0800)
committerJason Gunthorpe <jgg@nvidia.com>
Wed, 5 Jan 2022 18:16:53 +0000 (14:16 -0400)
Because of the possible failure of the allocation, data might be NULL
pointer and will cause the dereference of the NULL pointer later.
Therefore, it might be better to check it and return -ENOMEM.

Fixes: 6884c6c4bd09 ("RDMA/verbs: Store the write/write_ex uapi entry points in the uverbs_api")
Link: https://lore.kernel.org/r/20211231093315.1917667-1-jiasheng@iscas.ac.cn
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/core/uverbs_uapi.c

index 2f2c7646fce1763e0b9bbccd5b5cf300ded16f02..a02916a3a79cee319212c5908a75285d659c7f40 100644 (file)
@@ -447,6 +447,9 @@ static int uapi_finalize(struct uverbs_api *uapi)
        uapi->num_write_ex = max_write_ex + 1;
        data = kmalloc_array(uapi->num_write + uapi->num_write_ex,
                             sizeof(*uapi->write_methods), GFP_KERNEL);
+       if (!data)
+               return -ENOMEM;
+
        for (i = 0; i != uapi->num_write + uapi->num_write_ex; i++)
                data[i] = &uapi->notsupp_method;
        uapi->write_methods = data;