All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: pmcraid: check device_create() return value
@ 2026-08-14  5:45 Linkai Gong
  2026-08-14  5:58 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Linkai Gong @ 2026-08-14  5:45 UTC (permalink / raw)
  To: James E . J . Bottomley, Martin K . Petersen
  Cc: Anil Ravindranath, James Bottomley, linux-scsi, linux-kernel,
	Linkai Gong

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 <gonglinkai@kylinos.cn>
---
 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


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

end of thread, other threads:[~2026-08-14  5:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14  5:45 [PATCH] scsi: pmcraid: check device_create() return value Linkai Gong
2026-08-14  5:58 ` sashiko-bot

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.