summaryrefslogtreecommitdiff
path: root/lib/reed_solomon
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2018-04-22 18:23:52 +0200
committerKees Cook <keescook@chromium.org>2018-04-24 19:50:08 -0700
commita85e126abf944884d5b3eba86ec7d541e8327256 (patch)
treeef5e3a7ca4d1d22c5b9de0ffe44c79589ae04550 /lib/reed_solomon
parent689c6efdfb58d7b21c375f515349e4091e08100b (diff)
downloadlwn-a85e126abf944884d5b3eba86ec7d541e8327256.tar.gz
lwn-a85e126abf944884d5b3eba86ec7d541e8327256.zip
rslib: Simplify error path
The four error path labels in rs_init() can be reduced to one by allocating the struct with kzalloc so the pointers in the struct are NULL and can be unconditionally handed in to kfree() because they either point to an allocation or are NULL. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Kees Cook <keescook@chromium.org>
Diffstat (limited to 'lib/reed_solomon')
-rw-r--r--lib/reed_solomon/reed_solomon.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/lib/reed_solomon/reed_solomon.c b/lib/reed_solomon/reed_solomon.c
index 3e694ab9e3b2..02c19ecffc28 100644
--- a/lib/reed_solomon/reed_solomon.c
+++ b/lib/reed_solomon/reed_solomon.c
@@ -60,8 +60,7 @@ static struct rs_control *rs_init(int symsize, int gfpoly, int (*gffunc)(int),
struct rs_control *rs;
int i, j, sr, root, iprim;
- /* Allocate the control structure */
- rs = kmalloc(sizeof(*rs), gfp);
+ rs = kzalloc(sizeof(*rs), gfp);
if (!rs)
return NULL;
@@ -78,15 +77,15 @@ static struct rs_control *rs_init(int symsize, int gfpoly, int (*gffunc)(int),
/* Allocate the arrays */
rs->alpha_to = kmalloc(sizeof(uint16_t) * (rs->nn + 1), gfp);
if (rs->alpha_to == NULL)
- goto errrs;
+ goto err;
rs->index_of = kmalloc(sizeof(uint16_t) * (rs->nn + 1), gfp);
if (rs->index_of == NULL)
- goto erralp;
+ goto err;
rs->genpoly = kmalloc(sizeof(uint16_t) * (rs->nroots + 1), gfp);
if(rs->genpoly == NULL)
- goto erridx;
+ goto err;
/* Generate Galois field lookup tables */
rs->index_of[0] = rs->nn; /* log(zero) = -inf */
@@ -111,7 +110,7 @@ static struct rs_control *rs_init(int symsize, int gfpoly, int (*gffunc)(int),
}
/* If it's not primitive, exit */
if(sr != rs->alpha_to[0])
- goto errpol;
+ goto err;
/* Find prim-th root of 1, used in decoding */
for(iprim = 1; (iprim % prim) != 0; iprim += rs->nn);
@@ -141,14 +140,10 @@ static struct rs_control *rs_init(int symsize, int gfpoly, int (*gffunc)(int),
rs->genpoly[i] = rs->index_of[rs->genpoly[i]];
return rs;
- /* Error exit */
-errpol:
+err:
kfree(rs->genpoly);
-erridx:
kfree(rs->index_of);
-erralp:
kfree(rs->alpha_to);
-errrs:
kfree(rs);
return NULL;
}