OSDN Git Service

crypto: af_alg - rewrite NULL pointer check
authorJiasheng Jiang <jiasheng@iscas.ac.cn>
Fri, 31 Dec 2021 01:40:36 +0000 (09:40 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 7 Jan 2022 03:30:01 +0000 (14:30 +1100)
Because of the possible alloc failure of the alloc_page(), it could
return NULL pointer.
And there is a check below the sg_assign_page().
But it will be more logical to move the NULL check before the
sg_assign_page().

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/af_alg.c

index 3dd5a77..e1ea185 100644 (file)
@@ -931,16 +931,19 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
                        sg_unmark_end(sg + sgl->cur - 1);
 
                do {
+                       struct page *pg;
                        unsigned int i = sgl->cur;
 
                        plen = min_t(size_t, len, PAGE_SIZE);
 
-                       sg_assign_page(sg + i, alloc_page(GFP_KERNEL));
-                       if (!sg_page(sg + i)) {
+                       pg = alloc_page(GFP_KERNEL);
+                       if (!pg) {
                                err = -ENOMEM;
                                goto unlock;
                        }
 
+                       sg_assign_page(sg + i, pg);
+
                        err = memcpy_from_msg(page_address(sg_page(sg + i)),
                                              msg, plen);
                        if (err) {