Message ID | 1487245547-24384-14-git-send-email-tom.leiming@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 02/16/2017 12:45 PM, Ming Lei wrote: > @@ -998,7 +998,8 @@ static void alloc_behind_pages(struct bio *bio, struct r1bio *r1_bio) > { > int i; > struct bio_vec *bvec; > - struct bio_vec *bvecs = kzalloc(bio->bi_vcnt * sizeof(struct bio_vec), > + unsigned vcnt = bio_segments_all(bio); > + struct bio_vec *bvecs = kzalloc(vcnt * sizeof(struct bio_vec), > GFP_NOIO); Maybe use kcalloc() instead of kzalloc() with a multiplication. Byte, Johannes
On Thu, Feb 16, 2017 at 8:35 PM, Johannes Thumshirn <jthumshirn@suse.de> wrote: > On 02/16/2017 12:45 PM, Ming Lei wrote: >> @@ -998,7 +998,8 @@ static void alloc_behind_pages(struct bio *bio, struct r1bio *r1_bio) >> { >> int i; >> struct bio_vec *bvec; >> - struct bio_vec *bvecs = kzalloc(bio->bi_vcnt * sizeof(struct bio_vec), >> + unsigned vcnt = bio_segments_all(bio); >> + struct bio_vec *bvecs = kzalloc(vcnt * sizeof(struct bio_vec), >> GFP_NOIO); > > Maybe use kcalloc() instead of kzalloc() with a multiplication. That doesn't belong to this patch, which just wants to remove direct access to .bi_vcnt. Thanks, Ming Lei
On 02/16/2017 02:32 PM, Ming Lei wrote: > On Thu, Feb 16, 2017 at 8:35 PM, Johannes Thumshirn <jthumshirn@suse.de> wrote: >> On 02/16/2017 12:45 PM, Ming Lei wrote: >>> @@ -998,7 +998,8 @@ static void alloc_behind_pages(struct bio *bio, struct r1bio *r1_bio) >>> { >>> int i; >>> struct bio_vec *bvec; >>> - struct bio_vec *bvecs = kzalloc(bio->bi_vcnt * sizeof(struct bio_vec), >>> + unsigned vcnt = bio_segments_all(bio); >>> + struct bio_vec *bvecs = kzalloc(vcnt * sizeof(struct bio_vec), >>> GFP_NOIO); >> >> Maybe use kcalloc() instead of kzalloc() with a multiplication. > > That doesn't belong to this patch, which just wants to remove direct > access to .bi_vcnt. But you're touching it anyways, aren't you?
On Thu, Feb 16, 2017 at 9:34 PM, Johannes Thumshirn <jthumshirn@suse.de> wrote: > On 02/16/2017 02:32 PM, Ming Lei wrote: >> On Thu, Feb 16, 2017 at 8:35 PM, Johannes Thumshirn <jthumshirn@suse.de> wrote: >>> On 02/16/2017 12:45 PM, Ming Lei wrote: >>>> @@ -998,7 +998,8 @@ static void alloc_behind_pages(struct bio *bio, struct r1bio *r1_bio) >>>> { >>>> int i; >>>> struct bio_vec *bvec; >>>> - struct bio_vec *bvecs = kzalloc(bio->bi_vcnt * sizeof(struct bio_vec), >>>> + unsigned vcnt = bio_segments_all(bio); >>>> + struct bio_vec *bvecs = kzalloc(vcnt * sizeof(struct bio_vec), >>>> GFP_NOIO); >>> >>> Maybe use kcalloc() instead of kzalloc() with a multiplication. >> >> That doesn't belong to this patch, which just wants to remove direct >> access to .bi_vcnt. > > But you're touching it anyways, aren't you? Don't you know the policy of 'do one thing, do it better' in one patch? If you want to switch to kcalloc(), just post a patch, that is fine, but please don't push me to do that in this patch. Thanks, Ming Lei
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 54ec32be3277..02cfece74981 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -998,7 +998,8 @@ static void alloc_behind_pages(struct bio *bio, struct r1bio *r1_bio) { int i; struct bio_vec *bvec; - struct bio_vec *bvecs = kzalloc(bio->bi_vcnt * sizeof(struct bio_vec), + unsigned vcnt = bio_segments_all(bio); + struct bio_vec *bvecs = kzalloc(vcnt * sizeof(struct bio_vec), GFP_NOIO); if (unlikely(!bvecs)) return; @@ -1014,12 +1015,12 @@ static void alloc_behind_pages(struct bio *bio, struct r1bio *r1_bio) kunmap(bvec->bv_page); } r1_bio->behind_bvecs = bvecs; - r1_bio->behind_page_count = bio->bi_vcnt; + r1_bio->behind_page_count = vcnt; set_bit(R1BIO_BehindIO, &r1_bio->state); return; do_sync_io: - for (i = 0; i < bio->bi_vcnt; i++) + for (i = 0; i < vcnt; i++) if (bvecs[i].bv_page) put_page(bvecs[i].bv_page); kfree(bvecs);
Use this helper, instead of direct access to .bi_vcnt. Signed-off-by: Ming Lei <tom.leiming@gmail.com> --- drivers/md/raid1.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)