linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V3 1/2] char: pcmcia: cm4000_cs: Fix failure handling
@ 2021-05-27 19:33 nizamhaider786
  2021-05-27 19:33 ` [PATCH V3 2/2] char: pcmcia: cm4040_cs: " nizamhaider786
  0 siblings, 1 reply; 2+ messages in thread
From: nizamhaider786 @ 2021-05-27 19:33 UTC (permalink / raw)
  To: laforge; +Cc: arnd, gregkh, linux-kernel, Nijam Haider

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/cm4000_cs.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index 89681f07bc78..e4a79866fbf3 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -1783,6 +1783,7 @@ static int cm4000_probe(struct pcmcia_device *link)
 {
 	struct cm4000_dev *dev;
 	int i, ret;
+	struct device *dev_ret;
 
 	for (i = 0; i < CM4000_MAX_DEV; i++)
 		if (dev_table[i] == NULL)
@@ -1808,15 +1809,22 @@ static int cm4000_probe(struct pcmcia_device *link)
 	init_waitqueue_head(&dev->readq);
 
 	ret = cm4000_config(link, i);
-	if (ret) {
-		dev_table[i] = NULL;
-		kfree(dev);
-		return ret;
-	}
-
-	device_create(cmm_class, NULL, MKDEV(major, i), NULL, "cmm%d", i);
+	if (ret)
+		goto err_config;
 
+	dev_ret = device_create(cmm_class, NULL, MKDEV(major, i), NULL, "cmm%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:
+	cm4000_release(link);
+err_config:
+	dev_table[i] = NULL;
+	kfree(dev);
+	return -ENODEV;
 }
 
 static void cm4000_detach(struct pcmcia_device *link)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH V3 2/2] char: pcmcia: cm4040_cs: Fix failure handling
  2021-05-27 19:33 [PATCH V3 1/2] char: pcmcia: cm4000_cs: Fix failure handling nizamhaider786
@ 2021-05-27 19:33 ` nizamhaider786
  0 siblings, 0 replies; 2+ messages in thread
From: nizamhaider786 @ 2021-05-27 19:33 UTC (permalink / raw)
  To: laforge; +Cc: arnd, gregkh, linux-kernel, Nijam Haider

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-27 19:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-27 19:33 [PATCH V3 1/2] char: pcmcia: cm4000_cs: Fix failure handling nizamhaider786
2021-05-27 19:33 ` [PATCH V3 2/2] char: pcmcia: cm4040_cs: " nizamhaider786

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).