Skip to content

Commit

Permalink
crypto: drbg - fix error return code
Browse files Browse the repository at this point in the history
Fix to return a negative error code from the error handling
case instead of 0.

Signed-off-by: Wei Yongjun <[email protected]>
Acked-by: Stephan Mueller <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
weiyj authored and herbertx committed Aug 24, 2016
1 parent b46b9d1 commit 1a45d7e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions crypto/drbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,12 +1178,16 @@ static inline int drbg_alloc_state(struct drbg_state *drbg)
goto err;

drbg->Vbuf = kmalloc(drbg_statelen(drbg) + ret, GFP_KERNEL);
if (!drbg->Vbuf)
if (!drbg->Vbuf) {
ret = -ENOMEM;
goto fini;
}
drbg->V = PTR_ALIGN(drbg->Vbuf, ret + 1);
drbg->Cbuf = kmalloc(drbg_statelen(drbg) + ret, GFP_KERNEL);
if (!drbg->Cbuf)
if (!drbg->Cbuf) {
ret = -ENOMEM;
goto fini;
}
drbg->C = PTR_ALIGN(drbg->Cbuf, ret + 1);
/* scratchpad is only generated for CTR and Hash */
if (drbg->core->flags & DRBG_HMAC)
Expand All @@ -1199,8 +1203,10 @@ static inline int drbg_alloc_state(struct drbg_state *drbg)

if (0 < sb_size) {
drbg->scratchpadbuf = kzalloc(sb_size + ret, GFP_KERNEL);
if (!drbg->scratchpadbuf)
if (!drbg->scratchpadbuf) {
ret = -ENOMEM;
goto fini;
}
drbg->scratchpad = PTR_ALIGN(drbg->scratchpadbuf, ret + 1);
}

Expand Down Expand Up @@ -1999,7 +2005,7 @@ static int __init drbg_init(void)
{
unsigned int i = 0; /* pointer to drbg_algs */
unsigned int j = 0; /* pointer to drbg_cores */
int ret = -EFAULT;
int ret;

ret = drbg_healthcheck_sanity();
if (ret)
Expand All @@ -2009,7 +2015,7 @@ static int __init drbg_init(void)
pr_info("DRBG: Cannot register all DRBG types"
"(slots needed: %zu, slots available: %zu)\n",
ARRAY_SIZE(drbg_cores) * 2, ARRAY_SIZE(drbg_algs));
return ret;
return -EFAULT;
}

/*
Expand Down

0 comments on commit 1a45d7e

Please sign in to comment.