Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: ecc - Streamline alloc_point and remove {alloc,free}_digits_space

Check 'ndigits' before allocating 'struct ecc_point' to return early if
needed. Inline the code from and remove ecc_alloc_digits_space() and
ecc_free_digits_space(), respectively.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Thorsten Blum and committed by
Herbert Xu
c66e0a27 c0008a29

+10 -19
+10 -19
crypto/ecc.c
··· 90 90 } 91 91 EXPORT_SYMBOL(ecc_digits_from_bytes); 92 92 93 - static u64 *ecc_alloc_digits_space(unsigned int ndigits) 94 - { 95 - size_t len = ndigits * sizeof(u64); 96 - 97 - if (!len) 98 - return NULL; 99 - 100 - return kmalloc(len, GFP_KERNEL); 101 - } 102 - 103 - static void ecc_free_digits_space(u64 *space) 104 - { 105 - kfree_sensitive(space); 106 - } 107 - 108 93 struct ecc_point *ecc_alloc_point(unsigned int ndigits) 109 94 { 110 - struct ecc_point *p = kmalloc(sizeof(*p), GFP_KERNEL); 95 + struct ecc_point *p; 96 + size_t ndigits_sz; 111 97 98 + if (!ndigits) 99 + return NULL; 100 + 101 + p = kmalloc(sizeof(*p), GFP_KERNEL); 112 102 if (!p) 113 103 return NULL; 114 104 115 - p->x = ecc_alloc_digits_space(ndigits); 105 + ndigits_sz = ndigits * sizeof(u64); 106 + p->x = kmalloc(ndigits_sz, GFP_KERNEL); 116 107 if (!p->x) 117 108 goto err_alloc_x; 118 109 119 - p->y = ecc_alloc_digits_space(ndigits); 110 + p->y = kmalloc(ndigits_sz, GFP_KERNEL); 120 111 if (!p->y) 121 112 goto err_alloc_y; 122 113 ··· 116 125 return p; 117 126 118 127 err_alloc_y: 119 - ecc_free_digits_space(p->x); 128 + kfree(p->x); 120 129 err_alloc_x: 121 130 kfree(p); 122 131 return NULL;