mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: nizamhaider786@gmail.com
To: laforge@gnumonks.org
Cc: arnd@arndb.de, gregkh@linuxfoundation.org,
	linux-kernel@vger.kernel.org,
	Nijam Haider <nizamhaider786@gmail.com>
Subject: [PATCH V3 2/2] char: pcmcia: cm4040_cs: Fix failure handling
Date: Fri, 28 May 2021 01:03:51 +0530	[thread overview]
Message-ID: <20210527193351.638-2-nizamhaider786@gmail.com> (raw)
In-Reply-To: <20210527193351.638-1-nizamhaider786@gmail.com>

From: Nijam Haider <nizamhaider786@gmail.com>

Handled failure cases of device_create()

Signed-off-by: Nijam Haider <nizamhaider786@gmail.com>
---
V2 -> V3: Added label and moved the cleanup code
V1 -> V2: Added description and changelog
---
 drivers/char/pcmcia/cm4040_cs.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index d5e43606339c..81cc48403eb8 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -558,6 +558,7 @@ static void reader_release(struct pcmcia_device *link)
 static int reader_probe(struct pcmcia_device *link)
 {
 	struct reader_dev *dev;
+	struct device *dev_ret;
 	int i, ret;
 
 	for (i = 0; i < CM_MAX_DEV; i++) {
@@ -587,15 +588,22 @@ static int reader_probe(struct pcmcia_device *link)
 	timer_setup(&dev->poll_timer, cm4040_do_poll, 0);
 
 	ret = reader_config(link, i);
-	if (ret) {
-		dev_table[i] = NULL;
-		kfree(dev);
-		return ret;
-	}
-
-	device_create(cmx_class, NULL, MKDEV(major, i), NULL, "cmx%d", i);
+	if (ret)
+		goto err_reader_config;
 
+	dev_ret = device_create(cmx_class, NULL, MKDEV(major, i), NULL, "cmx%d", i);
+	if (IS_ERR(dev_ret)) {
+		dev_err(&link->dev, "device_create failed for %d\n", i);
+		goto err_device_create;
+	}
 	return 0;
+
+err_device_create:
+	reader_release(link);
+err_reader_config:
+	dev_table[i] = NULL;
+	kfree(dev);
+	return -ENODEV;
 }
 
 static void reader_detach(struct pcmcia_device *link)
-- 
2.17.1


      reply	other threads:[~2021-05-27 19:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-27 19:33 [PATCH V3 1/2] char: pcmcia: cm4000_cs: " nizamhaider786
2021-05-27 19:33 ` nizamhaider786 [this message]

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=20210527193351.638-2-nizamhaider786@gmail.com \
    --to=nizamhaider786@gmail.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=laforge@gnumonks.org \
    --cc=linux-kernel@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®