Re: [PATCH] dm.c : Check memory allocations

From: Joe Thornber (joe@fib011235813.fsnet.co.uk)
Date: Thu Jan 02 2003 - 04:55:01 EST


On Tue, Dec 31, 2002 at 11:22:28AM -0500, Kevin Corry wrote:
> >
> > On Fri, Dec 27, 2002 at 04:55:31PM -0500, Kevin Corry wrote:
> > > Check memory allocations when cloning bio's.
> >
> > Rejected, clone_bio() cannot fail since it's allocating from a mempool
> > with __GFP_WAIT set.
> >
> > - Joe
>
> Hmm. Yep. I must have mistaken GFP_NOIO for GFP_ATOMIC.
>
> But based on that reasoning, shouldn't the bio_alloc() call
> in split_bvec() always return a valid bio, and hence make the
> checks in split_bvec() and __clone_and_map() unnecessary?

y, I was mistakenly under the impression that bio_alloc could fail
during the allocation of the bvec. I'll add the following patch.

- Joe

--- diff/drivers/md/dm.c 2002-12-30 11:40:30.000000000 +0000
+++ source/drivers/md/dm.c 2003-01-02 09:51:07.000000000 +0000
@@ -347,18 +347,15 @@
         struct bio_vec *bv = bio->bi_io_vec + idx;
 
         clone = bio_alloc(GFP_NOIO, 1);
+ memcpy(clone->bi_io_vec, bv, sizeof(*bv));
 
- if (clone) {
- memcpy(clone->bi_io_vec, bv, sizeof(*bv));
-
- clone->bi_sector = sector;
- clone->bi_bdev = bio->bi_bdev;
- clone->bi_rw = bio->bi_rw;
- clone->bi_vcnt = 1;
- clone->bi_size = to_bytes(len);
- clone->bi_io_vec->bv_offset = offset;
- clone->bi_io_vec->bv_len = clone->bi_size;
- }
+ clone->bi_sector = sector;
+ clone->bi_bdev = bio->bi_bdev;
+ clone->bi_rw = bio->bi_rw;
+ clone->bi_vcnt = 1;
+ clone->bi_size = to_bytes(len);
+ clone->bi_io_vec->bv_offset = offset;
+ clone->bi_io_vec->bv_len = clone->bi_size;
 
         return clone;
 }
@@ -432,11 +429,6 @@
 
                 clone = split_bvec(bio, ci->sector, ci->idx,
                                    bv->bv_offset, max);
- if (!clone) {
- dec_pending(ci->io, -ENOMEM);
- return;
- }
-
                 __map_bio(ti, clone, ci->io);
 
                 ci->sector += max;
@@ -446,11 +438,6 @@
                 len = to_sector(bv->bv_len) - max;
                 clone = split_bvec(bio, ci->sector, ci->idx,
                                    bv->bv_offset + to_bytes(max), len);
- if (!clone) {
- dec_pending(ci->io, -ENOMEM);
- return;
- }
-
                 __map_bio(ti, clone, ci->io);
 
                 ci->sector += len;

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Jan 07 2003 - 22:00:17 EST