All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: James.Bottomley@steeleye.com
Cc: linux-scsi@vger.kernel.org
Subject: [PATCH] handles possible failures in scsi initialization
Date: Thu, 20 Feb 2003 20:41:51 +0100	[thread overview]
Message-ID: <20030220204151.A19476@lst.de> (raw)

.. and unwind properly to avoid leaks


--- 1.91/drivers/scsi/scsi.c	Tue Feb 11 10:53:40 2003
+++ edited/drivers/scsi/scsi.c	Thu Feb 20 17:57:04 2003
@@ -1148,29 +1148,6 @@
 }
 
 /**
- * scsi_dev_list_init: set up the dynamic device list.
- * @dev_list:	string of device flags to add
- *
- * Description:
- * 	Add command line @dev_list entries, then add
- * 	scsi_static_device_list entries to the scsi device info list.
- **/
-static void scsi_dev_info_list_init (char *dev_list)
-{
-	int i;
-
-	if (scsi_dev_info_list_add_str(dev_list) == -ENOMEM)
-		return;
-	for (i = 0; scsi_static_device_list[i].vendor != NULL; i++)
-		if (scsi_dev_info_list_add(1 /* compatibile */,
-			   scsi_static_device_list[i].vendor,
-			   scsi_static_device_list[i].model,
-			   NULL,
-			   scsi_static_device_list[i].flags) == -ENOMEM)
-			return;
-}
-
-/**
  * scsi_dev_info_list_delete: called from scsi.c:exit_scsi to remove
  * 	the scsi_dev_info_list.
  **/
@@ -1187,6 +1164,37 @@
 }
 
 /**
+ * scsi_dev_list_init: set up the dynamic device list.
+ * @dev_list:	string of device flags to add
+ *
+ * Description:
+ * 	Add command line @dev_list entries, then add
+ * 	scsi_static_device_list entries to the scsi device info list.
+ **/
+static int scsi_dev_info_list_init (char *dev_list)
+{
+	int error, i;
+
+	error = scsi_dev_info_list_add_str(dev_list);
+	if (error)
+		return error;
+
+	for (i = 0; scsi_static_device_list[i].vendor != NULL; i++) {
+		error = scsi_dev_info_list_add(1 /* compatibile */,
+				scsi_static_device_list[i].vendor,
+				scsi_static_device_list[i].model,
+				NULL,
+				scsi_static_device_list[i].flags);
+		if (error)
+			break;
+	}
+
+	if (error)
+		scsi_dev_info_list_delete();
+	return error;
+}
+
+/**
  * get_device_flags - get device specific flags from the dynamic device
  * list. Called during scan time.
  * @vendor:	vendor name
@@ -1437,17 +1445,39 @@
 
 #endif
 
-/* FIXME(hch): add proper error handling */
 static int __init init_scsi(void)
 {
-	scsi_init_queue();
-	scsi_init_procfs();
-	devfs_mk_dir(NULL, "scsi", NULL);
+	int error;
+
+	error = scsi_init_queue();
+	if (error)
+		return error;
+	error = scsi_init_procfs();
+	if (error)
+		goto cleanup_queue;
+	error = -ENOMEM;
+	if (!devfs_mk_dir(NULL, "scsi", NULL))
+		goto cleanup_procfs;
+	error = scsi_dev_info_list_init(scsi_dev_flags);
+	if (error)
+		goto cleanup_devfs;
+	error = scsi_sysfs_register();
+	if (error)
+		goto cleanup_devlist;
+
 	scsi_host_init();
-	scsi_dev_info_list_init(scsi_dev_flags);
-	scsi_sysfs_register();
 	open_softirq(SCSI_SOFTIRQ, scsi_softirq, NULL);
 	return 0;
+
+cleanup_devlist:
+	scsi_dev_info_list_delete();
+cleanup_devfs:
+	devfs_remove("scsi");
+cleanup_procfs:
+	scsi_exit_procfs();
+cleanup_queue:
+	scsi_exit_queue();
+	return error;
 }
 
 static void __exit exit_scsi(void)

                 reply	other threads:[~2003-02-20 19:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20030220204151.A19476@lst.de \
    --to=hch@lst.de \
    --cc=James.Bottomley@steeleye.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.