LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Kees Cook <keescook@chromium.org>,
	Segher Boessenkool <segher@kernel.crashing.org>,
	Kernel Hardening <kernel-hardening@lists.openwall.com>,
	Andrew Morton <akpm@linuxfoundation.org>,
	Boris Brezillon <boris.brezillon@free-electrons.com>,
	Richard Weinberger <richard@nod.at>,
	David Woodhouse <dwmw2@infradead.org>,
	Alasdair Kergon <agk@redhat.com>,
	Mike Snitzer <snitzer@redhat.com>,
	Anton Vorontsov <anton@enomsg.org>,
	Colin Cross <ccross@android.com>, Tony Luck <tony.luck@intel.com>
Subject: [patch V3 07/10] rslib: Simplify error path
Date: Sun, 22 Apr 2018 18:23:52 +0200	[thread overview]
Message-ID: <20180422162512.915544167@linutronix.de> (raw)
In-Reply-To: <20180422162345.004292133@linutronix.de>

[-- Attachment #1: rslib--Simplify-error-path.patch --]
[-- Type: text/plain, Size: 1841 bytes --]

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>
---
 lib/reed_solomon/reed_solomon.c |   17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

--- 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 sy
 	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 sy
 	/* 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 sy
 	}
 	/* 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 sy
 		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;
 }

  parent reply	other threads:[~2018-04-22 16:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-22 16:23 [patch V3 00/10] rslib: Cleanup and VLA removal Thomas Gleixner
2018-04-22 16:23 ` [patch V3 01/10] rslib: Add GFP aware init function Thomas Gleixner
2018-04-25  1:16   ` Stephen Rothwell
2018-04-25  2:45     ` Kees Cook
2018-04-25  8:59       ` Thomas Gleixner
2018-04-22 16:23 ` [patch V3 02/10] dm/verity_fec: Use GFP aware reed solomon init Thomas Gleixner
2018-04-22 16:23 ` [patch V3 03/10] rslib: Cleanup whitespace damage Thomas Gleixner
2018-04-22 16:23 ` [patch V3 04/10] rslib: Cleanup top level comments Thomas Gleixner
2018-04-22 16:23 ` [patch V3 05/10] rslib: Add SPDX identifiers Thomas Gleixner
2018-04-22 16:23 ` [patch V3 06/10] rslib: Remove GPL boilerplate Thomas Gleixner
2018-04-22 16:23 ` Thomas Gleixner [this message]
2018-04-22 16:23 ` [patch V3 08/10] rslib: Split rs control struct Thomas Gleixner
2018-04-22 16:23 ` [patch V3 09/10] mtd: rawnand: diskonchip: Allocate rs control per instance Thomas Gleixner
2018-04-22 16:23 ` [patch V3 10/10] rslib: Allocate decoder buffers to avoid VLAs Thomas Gleixner
2018-04-24 16:42 ` [patch V3 00/10] rslib: Cleanup and VLA removal Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180422162512.915544167@linutronix.de \
    --to=tglx@linutronix.de \
    --cc=agk@redhat.com \
    --cc=akpm@linuxfoundation.org \
    --cc=anton@enomsg.org \
    --cc=boris.brezillon@free-electrons.com \
    --cc=ccross@android.com \
    --cc=dwmw2@infradead.org \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=richard@nod.at \
    --cc=segher@kernel.crashing.org \
    --cc=snitzer@redhat.com \
    --cc=tony.luck@intel.com \
    --subject='Re: [patch V3 07/10] rslib: Simplify error path' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).