All of lore.kernel.org
 help / color / mirror / Atom feed
From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-scsi@vger.kernel.org
Cc: Akinobu Mita <akinobu.mita@gmail.com>,
	Anil Ravindranath <anil_ravindranath@pmc-sierra.com>,
	"James E.J. Bottomley" <JBottomley@parallels.com>
Subject: [PATCH 5/5] pmcraid: check error from device_create()
Date: Sat, 16 Feb 2013 23:27:59 +0900	[thread overview]
Message-ID: <1361024879-12934-5-git-send-email-akinobu.mita@gmail.com> (raw)
In-Reply-To: <1361024879-12934-1-git-send-email-akinobu.mita@gmail.com>

Fix an unchecked error from device_create() and convert to use standard
goto based unwinding for error cleanup.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Anil Ravindranath <anil_ravindranath@pmc-sierra.com>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>
Cc: linux-scsi@vger.kernel.org
---
 drivers/scsi/pmcraid.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index e3b68d9..d3034a8 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -5399,6 +5399,7 @@ static int pmcraid_setup_chrdev(struct pmcraid_instance *pinstance)
 {
 	int minor;
 	int error;
+	struct device *device;
 
 	minor = pmcraid_get_minor();
 	if (minor >= PMCRAID_MAX_ADAPTERS)
@@ -5408,12 +5409,23 @@ static int pmcraid_setup_chrdev(struct pmcraid_instance *pinstance)
 	pinstance->cdev.owner = THIS_MODULE;
 
 	error = cdev_add(&pinstance->cdev, MKDEV(pmcraid_major, minor), 1);
-
 	if (error)
-		pmcraid_release_minor(minor);
-	else
-		device_create(pmcraid_class, NULL, MKDEV(pmcraid_major, minor),
+		goto out_release_minor;
+
+	device = device_create(pmcraid_class, NULL, MKDEV(pmcraid_major, minor),
 			      NULL, "%s%u", PMCRAID_DEVFILE, minor);
+	if (IS_ERR(device)) {
+		error = PTR_ERR(device);
+		goto out_cdev_del;
+	}
+
+	return 0;
+
+out_cdev_del:
+	cdev_del(&pinstance->cdev);
+out_release_minor:
+	pmcraid_release_minor(minor);
+
 	return error;
 }
 
-- 
1.8.1


      parent reply	other threads:[~2013-02-16 14:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-16 14:27 [PATCH 1/5] pmcraid: fix a typo in error message Akinobu Mita
2013-02-16 14:27 ` [PATCH 2/5] pmcraid: fix pmcraid_netlink_init() error path in module_init Akinobu Mita
2013-02-16 14:27 ` [PATCH 3/5] pmcraid: make pmcraid_minor static Akinobu Mita
2013-02-16 14:27 ` [PATCH 4/5] pmcraid: check for exceeding the max adapters limit Akinobu Mita
2013-02-16 14:27 ` Akinobu Mita [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=1361024879-12934-5-git-send-email-akinobu.mita@gmail.com \
    --to=akinobu.mita@gmail.com \
    --cc=JBottomley@parallels.com \
    --cc=anil_ravindranath@pmc-sierra.com \
    --cc=linux-scsi@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.