mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@suse.de>
To: Andrew Morton <akpm@osdl.org>
Cc: Pavel Machek <pavel@ucw.cz>,
	linux-kernel@vger.kernel.org, trivial@rustcorp.com.au
Subject: Re: Untangle code in bio.c
Date: Wed, 15 Sep 2004 13:55:44 +0200	[thread overview]
Message-ID: <20040915115544.GB4111@suse.de> (raw)
In-Reply-To: <20040915043644.4fb58787.akpm@osdl.org>

On Wed, Sep 15 2004, Andrew Morton wrote:
> Pavel Machek <pavel@ucw.cz> wrote:
> >
> > Hi!
> > 
> > bio.c uses quite ugly code with goto's, completely
> > unneccessarily. Please apply,
> 
> I wouldn't describe this as an improvement, really.  Multiple return
> statements give me hysterics.

Me neither...

> > --- clean-mm/fs/bio.c	2004-09-15 12:58:10.000000000 +0200
> > +++ linux-mm/fs/bio.c	2004-09-15 13:00:51.000000000 +0200
> > @@ -143,7 +143,7 @@
> >  
> >  	bio = mempool_alloc(bio_pool, gfp_mask);
> >  	if (unlikely(!bio))
> > -		goto out;
> > +		return NULL;
> >  
> >  	bio_init(bio);
> >  
> > @@ -157,13 +157,11 @@
> >  noiovec:
> >  		bio->bi_io_vec = bvl;
> >  		bio->bi_destructor = bio_destructor;
> > -out:
> >  		return bio;
> >  	}
> >  
> >  	mempool_free(bio, bio_pool);
> > -	bio = NULL;
> > -	goto out;
> > +	return NULL;
> >  }
> 
> How's this look?
> 
> struct bio *bio_alloc(int gfp_mask, int nr_iovecs)
> {
> 	struct bio *bio = mempool_alloc(bio_pool, gfp_mask);
> 
> 	if (likely(bio)) {
> 		struct bio_vec *bvl = NULL;
> 
> 		bio_init(bio);
> 		if (likely(nr_iovecs)) {
> 			unsigned long idx;
> 
> 			bvl = bvec_alloc(gfp_mask, nr_iovecs, &idx);
> 			if (unlikely(!bvl)) {
> 				mempool_free(bio, bio_pool);
> 				bio = NULL;
> 				goto out;
> 			}
> 			bio->bi_flags |= idx << BIO_POOL_OFFSET;
> 		}
> 		bio->bi_io_vec = bvl;
> 		bio->bi_destructor = bio_destructor;
> 	}
> out:
> 	return bio;
> }

Same semantics and it looks good to me.

-- 
Jens Axboe


      reply	other threads:[~2004-09-15 11:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-15 11:18 Pavel Machek
2004-09-15 11:36 ` Andrew Morton
2004-09-15 11:55   ` Jens Axboe [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=20040915115544.GB4111@suse.de \
    --to=axboe@suse.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=trivial@rustcorp.com.au \
    /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®