Skip to content

Commit 5f21d7d

Browse files
JiangJiasherbertx
authored andcommitted
crypto: af_alg - rewrite NULL pointer check
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>
1 parent dd827ab commit 5f21d7d

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

crypto/af_alg.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,16 +931,19 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
931931
sg_unmark_end(sg + sgl->cur - 1);
932932

933933
do {
934+
struct page *pg;
934935
unsigned int i = sgl->cur;
935936

936937
plen = min_t(size_t, len, PAGE_SIZE);
937938

938-
sg_assign_page(sg + i, alloc_page(GFP_KERNEL));
939-
if (!sg_page(sg + i)) {
939+
pg = alloc_page(GFP_KERNEL);
940+
if (!pg) {
940941
err = -ENOMEM;
941942
goto unlock;
942943
}
943944

945+
sg_assign_page(sg + i, pg);
946+
944947
err = memcpy_from_msg(page_address(sg_page(sg + i)),
945948
msg, plen);
946949
if (err) {

0 commit comments

Comments
 (0)