ksmbd: smbd: change the return value of get_sg_list
authorHyunchul Lee <hyc.lee@gmail.com>
Fri, 29 Apr 2022 23:30:28 +0000 (08:30 +0900)
committerSteve French <stfrench@microsoft.com>
Sat, 21 May 2022 20:01:38 +0000 (15:01 -0500)
Make get_sg_list return EINVAL if there aren't
mapped scatterlists.

Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/ksmbd/transport_rdma.c

index 4372d631735e3e81148d13b9a073fe3d85259507..696ffd2ae661381b63d9aae8b40c4f61fa550063 100644 (file)
@@ -1079,7 +1079,7 @@ static int get_sg_list(void *buf, int size, struct scatterlist *sg_list, int nen
        int offset, len;
        int i = 0;
 
-       if (nentries < get_buf_page_count(buf, size))
+       if (size <= 0 || nentries < get_buf_page_count(buf, size))
                return -EINVAL;
 
        offset = offset_in_page(buf);
@@ -1111,7 +1111,7 @@ static int get_mapped_sg_list(struct ib_device *device, void *buf, int size,
        int npages;
 
        npages = get_sg_list(buf, size, sg_list, nentries);
-       if (npages <= 0)
+       if (npages < 0)
                return -EINVAL;
        return ib_dma_map_sg(device, sg_list, npages, dir);
 }