public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@steeleye.com>
To: SCSI Mailing List <linux-scsi@vger.kernel.org>,
	Russell King <rmk@arm.linux.org.uk>
Subject: Re: [PATCH] fix for memory leak in scsi_prep_fn
Date: 28 Jan 2003 12:52:28 -0600	[thread overview]
Message-ID: <1043779950.2991.101.camel@mulgrave> (raw)
In-Reply-To: <1043778768.2991.74.camel@mulgrave>

[-- Attachment #1: Type: text/plain, Size: 562 bytes --]

On Tue, 2003-01-28 at 12:32, James Bottomley wrote:
> This should fix the memory leak Russell King spotted if command
> initialisation fails in the request prep function.
> 
> The patch is against the scsi-combined-2.5 bkbits.net repository.

Well, OK, I had a closer look at what scsi_init_io is doing.  I
obviously don't want to release the command for a defer.  However,
there's also a bug in scsi_init_io which can cause
end_that_request_first to be called twice for the request.

This hopefully corrects that problem as well as the command leakage.

James


[-- Attachment #2: tmp.diff --]
[-- Type: text/plain, Size: 908 bytes --]

===== drivers/scsi/scsi_lib.c 1.63 vs edited =====
--- 1.63/drivers/scsi/scsi_lib.c	Tue Jan 28 10:19:35 2003
+++ edited/drivers/scsi/scsi_lib.c	Tue Jan 28 12:43:38 2003
@@ -781,11 +781,8 @@
 	printk(KERN_ERR "req nr_sec %lu, cur_nr_sec %u\n", req->nr_sectors,
 			req->current_nr_sectors);
 
-	/*
-	 * kill it. there should be no leftover blocks in this request
-	 */
-	SCpnt = scsi_end_request(SCpnt, 0, req->nr_sectors, 1);
-	BUG_ON(SCpnt);
+	/* release the command and kill it */
+	scsi_put_command(SCpnt);
 	ret = BLKPREP_KILL;
 out:
 	return ret;
@@ -884,6 +881,7 @@
 		 * required).
 		 */
 		if ((ret = scsi_init_io(SCpnt)))
+			/* BLKPREP_KILL return also releases the command */
 			return ret;
 		
 		/*
@@ -891,6 +889,7 @@
 		 */
 		if (!STpnt->init_command(SCpnt)) {
 			scsi_release_buffers(SCpnt);
+			scsi_put_command(SCpnt);
 			return BLKPREP_KILL;
 		}
 	}

      reply	other threads:[~2003-01-28 18:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-28 18:32 [PATCH] fix for memory leak in scsi_prep_fn James Bottomley
2003-01-28 18:52 ` James Bottomley [this message]

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=1043779950.2991.101.camel@mulgrave \
    --to=james.bottomley@steeleye.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=rmk@arm.linux.org.uk \
    /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