linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>, Adam Radford <linux@3ware.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] 2.2: drivers/scsi/3c-xxxx.c resource release on failure
Date: Sat, 9 Dec 2000 18:03:21 -0200	[thread overview]
Message-ID: <20001209180321.H859@conectiva.com.br> (raw)
In-Reply-To: <20001209151425.E859@conectiva.com.br> <20001209174018.F859@conectiva.com.br> <20001209174918.G859@conectiva.com.br>
In-Reply-To: <20001209174918.G859@conectiva.com.br>; from acme@conectiva.com.br on Sat, Dec 09, 2000 at 05:49:18PM -0200

Alan/Adam,

	Please consider applying, a similar patch is already in 2.4.

- Arnaldo

--- linux-2.2.18-pre25/drivers/scsi/3w-xxxx.c	Tue Sep  5 19:13:35 2000
+++ linux-2.2.18-pre25.acme/drivers/scsi/3w-xxxx.c	Sat Dec  9 17:59:22 2000
@@ -3,6 +3,8 @@
 
    Written By: Adam Radford <linux@3ware.com>
    Modifications By: Joel Jacobson <linux@3ware.com>
+		     Arnaldo Carvalho de Melo <acme@conectiva.com.br>
+
 
    Copyright (C) 1999-2000 3ware Inc.
 
@@ -64,6 +66,8 @@
                  Bug fix so hot spare drives don't show up.
    1.02.00.002 - Fix bug with tw_setfeature() call that caused oops on some
                  systems.
+   12/09/2000  - release previously allocated resources on failure at
+		 tw_allocate_memory (acme)
 */
 
 #include <linux/module.h>
@@ -416,37 +420,29 @@
 /* This function will allocate memory and check if it is 16 d-word aligned */
 int tw_allocate_memory(TW_Device_Extension *tw_dev, int request_id, int size, int which)
 {
-	u32 *virt_addr;
+	u32 *virt_addr = kmalloc(size, GFP_ATOMIC);
 
 	dprintk(KERN_NOTICE "3w-xxxx: tw_allocate_memory()\n");
 
+	if (!virt_addr) {
+		printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): kmalloc() failed.\n");
+		return 1;
+	}
+
+	if ((u32)virt_addr % TW_ALIGNMENT) {
+		kfree(virt_addr);
+		printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): Found unaligned address.\n");
+		return 1;
+	}
+
 	if (which == 0) {
-		/* Allocate command packet memory */
-		virt_addr = kmalloc(size, GFP_ATOMIC);
-		if (virt_addr == NULL) {
-			printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): kmalloc() failed.\n");
-			return 1;
-		}
-		if ((u32)virt_addr % TW_ALIGNMENT) {
-			printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): Found unaligned address.\n");
-			return 1;
-		}
 		tw_dev->command_packet_virtual_address[request_id] = virt_addr;
 		tw_dev->command_packet_physical_address[request_id] = 
-		virt_to_bus(virt_addr);
+			virt_to_bus(virt_addr);
 	} else {
-		/* Allocate generic buffer */
-		virt_addr = kmalloc(size, GFP_ATOMIC);
-		if (virt_addr == NULL) {
-			printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): kmalloc() failed.\n");
-			return 1;
-		}
-		if ((u32)virt_addr % TW_ALIGNMENT) {
-			printk(KERN_WARNING "3w-xxxx: tw_allocate_memory(): Found unaligned address.\n");
-			return 1;
-		}
 		tw_dev->alignment_virtual_address[request_id] = virt_addr;
-		tw_dev->alignment_physical_address[request_id] = virt_to_bus(virt_addr);
+		tw_dev->alignment_physical_address[request_id] =
+			virt_to_bus(virt_addr);
 	}
 	return 0;
 } /* End tw_allocate_memory() */
-
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:[~2000-12-09 20:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20001209151425.E859@conectiva.com.br>
2000-12-09 19:40 ` [PATCH] scsi/sr.c resource alloc checking Arnaldo Carvalho de Melo
2000-12-09 19:49   ` [PATCH] drivers/net/sbni.c irq release on failure Arnaldo Carvalho de Melo
2000-12-09 20:03     ` Arnaldo Carvalho de Melo [this message]
2000-12-10  8:59     ` Yaroslav S. Polyakov

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=20001209180321.H859@conectiva.com.br \
    --to=acme@conectiva.com.br \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@3ware.com \
    /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).