linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rasmus Andersen <rasmus@jaquet.dk>
To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org
Subject: [PATCH] make drivers/scsi/hosts.c check kmalloc return codes (241p9)
Date: Tue, 23 Jan 2001 00:41:25 +0100	[thread overview]
Message-ID: <20010123004125.N602@jaquet.dk> (raw)

Hi.

The following patch makes drivers/scsi/hosts.c check kmalloc's
return code, drops some gratitious zero initializations and
makes it a little less panicky.

It applies cleanly against ac10 and 241p9.

Please comment.


--- linux-ac10-clean/drivers/scsi/hosts.c	Mon Oct 30 23:44:29 2000
+++ linux-ac10/drivers/scsi/hosts.c	Sat Jan 20 23:07:08 2001
@@ -69,7 +69,7 @@
  *  idiocy.
  */
 
-Scsi_Host_Template * scsi_hosts = NULL;
+Scsi_Host_Template * scsi_hosts;
 
 
 /*
@@ -77,12 +77,12 @@
  *      MAX_SCSI_HOSTS here.
  */
 
-Scsi_Host_Name * scsi_host_no_list = NULL;
-struct Scsi_Host * scsi_hostlist = NULL;
-struct Scsi_Device_Template * scsi_devicelist = NULL;
+Scsi_Host_Name * scsi_host_no_list;
+struct Scsi_Host * scsi_hostlist;
+struct Scsi_Device_Template * scsi_devicelist;
 
-int max_scsi_hosts = 0;
-int next_scsi_host = 0;
+int max_scsi_hosts;
+int next_scsi_host;
 
 void
 scsi_unregister(struct Scsi_Host * sh){
@@ -140,10 +140,7 @@
 					 (tpnt->unchecked_isa_dma && j ? 
 					  GFP_DMA : 0) | GFP_ATOMIC);
     if(retval == NULL)
-    {
-        printk("scsi: out of memory in scsi_register.\n");
-    	return NULL;
-    }
+        goto err_out;
     	
     memset(retval, 0, sizeof(struct Scsi_Host) + j);
 
@@ -163,12 +160,19 @@
     atomic_set(&retval->host_active,0);
     retval->host_busy = 0;
     retval->host_failed = 0;
-    if(j > 0xffff) panic("Too many extra bytes requested\n");
+    if(j > 0xffff) {
+            printk("scsi: Too many extra bytes requested\n");
+            goto err_dealloc_retval;
+    }
     retval->extra_bytes = j;
     retval->loaded_as_module = 1;
     if (flag_new) {
 	shn = (Scsi_Host_Name *) kmalloc(sizeof(Scsi_Host_Name), GFP_ATOMIC);
+        if (!shn)
+                goto err_dealloc_retval;
 	shn->name = kmalloc(hname_len + 1, GFP_ATOMIC);
+        if (!shn->name) 
+                goto err_dealloc_shn;
 	if (hname_len > 0)
 	    strncpy(shn->name, hname, hname_len);
 	shn->name[hname_len] = 0;
@@ -258,6 +262,14 @@
     }
     
     return retval;
+
+ err_dealloc_shn:
+    kfree(shn);
+ err_dealloc_retval:
+    kfree(retval);
+ err_out:
+    printk("scsi: out of memory in scsi_register.\n");
+    return NULL;
 }
 
 int

-- 
        Rasmus(rasmus@jaquet.dk)

While the Melissa license is a bit unclear, Melissa aggressively
encourages free distribution of its source code.
  -- Kevin Dalley on Melissa being Open Source
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

                 reply	other threads:[~2001-01-22 23:42 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=20010123004125.N602@jaquet.dk \
    --to=rasmus@jaquet.dk \
    --cc=linux-kernel@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).