summaryrefslogtreecommitdiffstats
path: root/drivers/staging/dgnc
diff options
context:
space:
mode:
authorGiedrius Statkevičius <giedrius.statkevicius@gmail.com>2015-04-10 02:42:29 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-05-08 09:24:00 +0200
commitfa52d96c3ea110acb77e51c856ec0b54606cc17e (patch)
treedfd4783d9c659f9a66e29da825f21218f333555d /drivers/staging/dgnc
parent258f6a5005b2b113888e3435453ace3de552d1d1 (diff)
downloadlinux-fa52d96c3ea110acb77e51c856ec0b54606cc17e.tar.bz2
staging: dgnc: clean up allocation of ->channels[i]
Check if kzalloc fails in dgnc_tty_init() and if it does then free all previously allocated ->channels[i] and set them to NULL. This makes the code less error/bug prone because instead of needing programmers attention to add checks everywhere we do that in one place. Also, remove a bogus comment and check in the same loop because ->channels[i] isn't allocated anywhere else. Finally, remove a unnecessary check if ->channels[i] is NULL in the next loop because it can't be. Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/dgnc')
-rw-r--r--drivers/staging/dgnc/dgnc_tty.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index f954228a5064..a8c88f829e42 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -304,19 +304,15 @@ int dgnc_tty_init(struct dgnc_board *brd)
brd->nasync = brd->maxports;
- /*
- * Allocate channel memory that might not have been allocated
- * when the driver was first loaded.
- */
for (i = 0; i < brd->nasync; i++) {
- if (!brd->channels[i]) {
-
- /*
- * Okay to malloc with GFP_KERNEL, we are not at
- * interrupt context, and there are no locks held.
- */
- brd->channels[i] = kzalloc(sizeof(*brd->channels[i]), GFP_KERNEL);
- }
+ /*
+ * Okay to malloc with GFP_KERNEL, we are not at
+ * interrupt context, and there are no locks held.
+ */
+ brd->channels[i] = kzalloc(sizeof(*brd->channels[i]),
+ GFP_KERNEL);
+ if (!brd->channels[i])
+ goto err_free_channels;
}
ch = brd->channels[0];
@@ -324,10 +320,6 @@ int dgnc_tty_init(struct dgnc_board *brd)
/* Set up channel variables */
for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
-
- if (!brd->channels[i])
- continue;
-
spin_lock_init(&ch->ch_lock);
/* Store all our magic numbers */
@@ -375,6 +367,13 @@ int dgnc_tty_init(struct dgnc_board *brd)
}
return 0;
+
+err_free_channels:
+ for (i = i - 1; i >= 0; --i) {
+ kfree(brd->channels[i]);
+ brd->channels[i] = NULL;
+ }
+ return -ENOMEM;
}