mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kevin Corry <corry@ecn.purdue.edu>
To: jgarzik@pobox.com (Jeff Garzik)
Cc: joe@fib011235813.fsnet.co.uk (Joe Thornber),
	dm-devel@sistina.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dm.c : Check memory allocations
Date: Fri, 27 Dec 2002 17:16:17 -0500 (EST)	[thread overview]
Message-ID: <200212272216.gBRMGHB2016255@shay.ecn.purdue.edu> (raw)
In-Reply-To: <20021227220008.GA11577@gtf.org> from "Jeff Garzik" at Dec 27, 2002 05:00:08 PM

> On Fri, Dec 27, 2002 at 04:55:31PM -0500, Kevin Corry wrote:
> > Check memory allocations when cloning bio's.
> > 
> > --- linux-2.5.53a/drivers/md/dm.c	Mon Dec 23 23:21:04 2002
> > +++ linux-2.5.53b/drivers/md/dm.c	Fri Dec 27 14:50:29 2002
> > @@ -394,6 +393,10 @@
> >  		 */
> >  		clone = clone_bio(bio, ci->sector, ci->idx,
> >  				  bio->bi_vcnt - ci->idx, ci->sector_count);
> > +		if (!clone) {
> > +			dec_pending(ci->io, -ENOMEM);
> > +			return;
> > +		}
> >  		__map_bio(ti, clone, ci->io);
> >  		ci->sector_count = 0;
> >  
> > @@ -417,6 +420,10 @@
> >  		}
> >  
> >  		clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len);
> > +		if (!clone) {
> > +			dec_pending(ci->io, -ENOMEM);
> > +			return;
> > +		}
> >  		__map_bio(ti, clone, ci->io);
> >  
> >  		ci->sector += len;
> 
> 
> This seems a bit insufficient.  Why is this error not propagated up
> through to __split_bio ?
> 
> 	Jeff

At second glance, it does seem insufficient. I had simply copied the
same check that was already used later in __clone_and_map().

What we should do is set ci->sector_count to zero. This will prevent
__split_bio() from performing any further processing on the bio.

Alternatively, we could change __clone_and_map() to return an int, and
return the error to __split_bio() and let it do the cleanup.

Here is a replacement patch based on the first suggestion.

-Kevin

--- linux-2.5.53a/drivers/md/dm.c	Mon Dec 23 23:21:04 2002
+++ linux-2.5.53b/drivers/md/dm.c	Fri Dec 27 15:18:19 2002
@@ -394,6 +393,11 @@
 		 */
 		clone = clone_bio(bio, ci->sector, ci->idx,
 				  bio->bi_vcnt - ci->idx, ci->sector_count);
+		if (!clone) {
+			ci->sector_count = 0;
+			dec_pending(ci->io, -ENOMEM);
+			return;
+		}
 		__map_bio(ti, clone, ci->io);
 		ci->sector_count = 0;
 
@@ -417,6 +421,11 @@
 		}
 
 		clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len);
+		if (!clone) {
+			ci->sector_count = 0;
+			dec_pending(ci->io, -ENOMEM);
+			return;
+		}
 		__map_bio(ti, clone, ci->io);
 
 		ci->sector += len;
@@ -433,6 +442,7 @@
 		clone = split_bvec(bio, ci->sector, ci->idx,
 				   bv->bv_offset, max);
 		if (!clone) {
+			ci->sector_count = 0;
 			dec_pending(ci->io, -ENOMEM);
 			return;
 		}
@@ -447,6 +457,7 @@
 		clone = split_bvec(bio, ci->sector, ci->idx,
 				   bv->bv_offset + to_bytes(max), len);
 		if (!clone) {
+			ci->sector_count = 0;
 			dec_pending(ci->io, -ENOMEM);
 			return;
 		}

  reply	other threads:[~2002-12-27 22:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-27 21:55 Kevin Corry
2002-12-27 22:00 ` Jeff Garzik
2002-12-27 22:16   ` Kevin Corry [this message]
2002-12-30 10:51 ` Joe Thornber
2002-12-31 16:22   ` Kevin Corry
2003-01-02  9:55     ` Joe Thornber

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=200212272216.gBRMGHB2016255@shay.ecn.purdue.edu \
    --to=corry@ecn.purdue.edu \
    --cc=dm-devel@sistina.com \
    --cc=jgarzik@pobox.com \
    --cc=joe@fib011235813.fsnet.co.uk \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®