[PATCH] scsi: pmcraid: check device_create() return value

Linkai Gong <[email protected]>
Newsgroups gmane.linux.scsi,gmane.linux.kernel
Message-ID <[email protected]>
device_create() can fail after a successful cdev_add(), but the driver
ignored the return value and still reported success. That leaves a
registered char device without its /dev node.

Check the return value, report the error, and unwind the cdev and
minor on failure.

Fixes: 89a368104150 ("[SCSI] pmcraid: PMC-Sierra MaxRAID driver to support 6Gb/s SAS RAID controller")
Signed-off-by: Linkai Gong <[email protected]>
---
 drivers/scsi/pmcraid.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index 942a99393204..65a87d30e65f 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -4721,12 +4721,21 @@ 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);
+		return error;
+	}
 
-	if (error)
+	error = PTR_ERR_OR_ZERO(device_create(&pmcraid_class, NULL,
+					      MKDEV(pmcraid_major, minor), NULL,
+					      "%s%u", PMCRAID_DEVFILE, minor));
+	if (error) {
+		pmcraid_err("failed to create device file for minor %d, error %d\n",
+			    minor, error);
+		cdev_del(&pinstance->cdev);
 		pmcraid_release_minor(minor);
-	else
-		device_create(&pmcraid_class, NULL, MKDEV(pmcraid_major, minor),
-			      NULL, "%s%u", PMCRAID_DEVFILE, minor);
+	}
+
 	return error;
 }
 
-- 
2.25.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.