Skip to content

Commit

Permalink
crypto: af_alg - rewrite NULL pointer check
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
JiangJias authored and herbertx committed Jan 7, 2022
1 parent dd827ab commit 5f21d7d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crypto/af_alg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5f21d7d

Please sign in to comment.