Blame SOURCES/0064-scsi-scsi-qla2xxx-Unregister-chrdev-if-module-initia.patch

3c6e85
From 7f6f2106d0ef1540327b703cf5f6c1a178aa3dbb Mon Sep 17 00:00:00 2001
3c6e85
From: Himanshu Madhani <hmadhani@redhat.com>
3c6e85
Date: Thu, 1 Aug 2019 15:55:24 -0400
3c6e85
Subject: [PATCH 064/124] [scsi] scsi: qla2xxx: Unregister chrdev if module
3c6e85
 initialization fails
3c6e85
3c6e85
Message-id: <20190801155618.12650-65-hmadhani@redhat.com>
3c6e85
Patchwork-id: 267838
3c6e85
O-Subject: [RHEL 7.8 e-stor PATCH 064/118] scsi: qla2xxx: Unregister chrdev if module initialization fails
3c6e85
Bugzilla: 1729270
3c6e85
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
3c6e85
RH-Acked-by: Tony Camuso <tcamuso@redhat.com>
3c6e85
3c6e85
From: Bart Van Assche <bvanassche@acm.org>
3c6e85
3c6e85
Bugzilla 1729270
3c6e85
3c6e85
If module initialization fails after the character device has been
3c6e85
registered, unregister the character device. Additionally, avoid
3c6e85
duplicating error path code.
3c6e85
3c6e85
Cc: Himanshu Madhani <hmadhani@marvell.com>
3c6e85
Cc: Giridhar Malavali <giridhar.malavali@qlogic.com>
3c6e85
Fixes: 6a03b4cd78f3 ("[SCSI] qla2xxx: Add char device to increase driver use count") # v2.6.35.
3c6e85
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
3c6e85
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
3c6e85
(cherry picked from commit c794d24ec9eb6658909955772e70f34bef5b5b91)
3c6e85
Signed-off-by: Himanshu Madhani <hmadhani@redhat.com>
3c6e85
Signed-off-by: Jan Stancek <jstancek@redhat.com>
3c6e85
---
3c6e85
 drivers/scsi/qla2xxx/qla_os.c | 34 +++++++++++++++++++++-------------
3c6e85
 1 file changed, 21 insertions(+), 13 deletions(-)
3c6e85
3c6e85
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
3c6e85
index 1c9aac36d6fe..03d7d0af1f98 100644
3c6e85
--- a/drivers/scsi/qla2xxx/qla_os.c
3c6e85
+++ b/drivers/scsi/qla2xxx/qla_os.c
3c6e85
@@ -7366,8 +7366,7 @@ qla2x00_module_init(void)
3c6e85
 	/* Initialize target kmem_cache and mem_pools */
3c6e85
 	ret = qlt_init();
3c6e85
 	if (ret < 0) {
3c6e85
-		kmem_cache_destroy(srb_cachep);
3c6e85
-		return ret;
3c6e85
+		goto destroy_cache;
3c6e85
 	} else if (ret > 0) {
3c6e85
 		/*
3c6e85
 		 * If initiator mode is explictly disabled by qlt_init(),
3c6e85
@@ -7391,11 +7390,10 @@ qla2x00_module_init(void)
3c6e85
 	qla2xxx_transport_template =
3c6e85
 	    fc_attach_transport(&qla2xxx_transport_functions);
3c6e85
 	if (!qla2xxx_transport_template) {
3c6e85
-		kmem_cache_destroy(srb_cachep);
3c6e85
 		ql_log(ql_log_fatal, NULL, 0x0002,
3c6e85
 		    "fc_attach_transport failed...Failing load!.\n");
3c6e85
-		qlt_exit();
3c6e85
-		return -ENODEV;
3c6e85
+		ret = -ENODEV;
3c6e85
+		goto qlt_exit;
3c6e85
 	}
3c6e85
 
3c6e85
 	apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
3c6e85
@@ -7407,27 +7405,37 @@ qla2x00_module_init(void)
3c6e85
 	qla2xxx_transport_vport_template =
3c6e85
 	    fc_attach_transport(&qla2xxx_transport_vport_functions);
3c6e85
 	if (!qla2xxx_transport_vport_template) {
3c6e85
-		kmem_cache_destroy(srb_cachep);
3c6e85
-		qlt_exit();
3c6e85
-		fc_release_transport(qla2xxx_transport_template);
3c6e85
 		ql_log(ql_log_fatal, NULL, 0x0004,
3c6e85
 		    "fc_attach_transport vport failed...Failing load!.\n");
3c6e85
-		return -ENODEV;
3c6e85
+		ret = -ENODEV;
3c6e85
+		goto unreg_chrdev;
3c6e85
 	}
3c6e85
 	ql_log(ql_log_info, NULL, 0x0005,
3c6e85
 	    "QLogic Fibre Channel HBA Driver: %s.\n",
3c6e85
 	    qla2x00_version_str);
3c6e85
 	ret = pci_register_driver(&qla2xxx_pci_driver);
3c6e85
 	if (ret) {
3c6e85
-		kmem_cache_destroy(srb_cachep);
3c6e85
-		qlt_exit();
3c6e85
-		fc_release_transport(qla2xxx_transport_template);
3c6e85
-		fc_release_transport(qla2xxx_transport_vport_template);
3c6e85
 		ql_log(ql_log_fatal, NULL, 0x0006,
3c6e85
 		    "pci_register_driver failed...ret=%d Failing load!.\n",
3c6e85
 		    ret);
3c6e85
+		goto release_vport_transport;
3c6e85
 	}
3c6e85
 	return ret;
3c6e85
+
3c6e85
+release_vport_transport:
3c6e85
+	fc_release_transport(qla2xxx_transport_vport_template);
3c6e85
+
3c6e85
+unreg_chrdev:
3c6e85
+	if (apidev_major >= 0)
3c6e85
+		unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
3c6e85
+	fc_release_transport(qla2xxx_transport_template);
3c6e85
+
3c6e85
+qlt_exit:
3c6e85
+	qlt_exit();
3c6e85
+
3c6e85
+destroy_cache:
3c6e85
+	kmem_cache_destroy(srb_cachep);
3c6e85
+	return ret;
3c6e85
 }
3c6e85
 
3c6e85
 /**
3c6e85
-- 
3c6e85
2.13.6
3c6e85