diff options
author | Jiasheng Jiang <jiasheng@iscas.ac.cn> | 2021-12-31 09:40:36 +0800 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2022-01-07 14:30:01 +1100 |
commit | 5f21d7d283dd82865bdb0123795b3accf0d42b67 (patch) | |
tree | 36097762ae9524cbc46c2094cc197038c4cde865 /crypto | |
parent | dd827abe296fe4249b2f8c9b95f72f814ea8348c (diff) | |
download | linux-5f21d7d283dd82865bdb0123795b3accf0d42b67.tar.gz linux-5f21d7d283dd82865bdb0123795b3accf0d42b67.tar.bz2 linux-5f21d7d283dd82865bdb0123795b3accf0d42b67.zip |
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>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/af_alg.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 3dd5a773c320..e1ea18536a5f 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -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) { |