linux-ppp.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guillaume Nault <g.nault@alphalink.fr>
To: walter harms <wharms@bfs.de>
Cc: netdev@vger.kernel.org, linux-ppp@vger.kernel.org,
	David Miller <davem@davemloft.net>,
	Paul Mackerras <paulus@samba.org>
Subject: Re: [PATCH 2/2] ppp: implement rtnetlink device handling
Date: Mon, 25 Jan 2016 15:28:30 +0000	[thread overview]
Message-ID: <20160125152830.GW18510@alphalink.fr> (raw)
In-Reply-To: <56A6026E.4020709@bfs.de>

On Mon, Jan 25, 2016 at 12:09:34PM +0100, walter harms wrote:
> 
> 
> Am 23.12.2015 21:04, schrieb Guillaume Nault:
> > @@ -1012,7 +1017,24 @@ static int ppp_dev_configure(struct net *src_net, struct net_device *dev,
> >  	int indx;
> >  	int err;
> >  
> > -	file = conf->file;
> > +	if (conf->fd >= 0) {
> > +		file = fget(conf->fd);
> > +		if (file) {
> > +			if (file->f_op != &ppp_device_fops) {
> > +				fput(file);
> > +				return -EBADF;
> > +			}
> > +
> > +			/* Don't hold reference on file: ppp_release() is
> > +			 * responsible for safely freeing the associated
> > +			 * resources upon release. So file won't go away
> > +			 * from under us.
> > +			 */
> > +			fput(file);
> > +		}
> > +	} else {
> > +		file = conf->file;
> > +	}
> >  	if (!file)
> >  		return -EBADF;
> 
> 
> I would write that a bid different to reduce indent
> und improve readability
> 
> (note: totaly untested just reviewing)
> 
> if (conf->fd < 0) {
> 	file = conf->file;
> 	if (!file)
>   		return -EBADF;
> }
> else
> {
> file = fget(conf->fd);
> if (!file)
>   	return -EBADF;
> 
Early return on fget() failure looks indeed simpler.

> fput(file);
> if (file->f_op != &ppp_device_fops) {		
> 		return -EBADF;
> 	}
> 
But this is wrong: we can't act on file after fput(). So we have to
place fput() after the test.

Thanks for your review.

  reply	other threads:[~2016-01-25 15:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-23 20:04 [PATCH 0/2] ppp: add netlink support Guillaume Nault
2015-12-23 20:04 ` [PATCH 1/2] ppp: define reusable device creation functions Guillaume Nault
2015-12-23 20:04 ` [PATCH 2/2] ppp: implement rtnetlink device handling Guillaume Nault
2016-01-25 11:09   ` walter harms
2016-01-25 15:28     ` Guillaume Nault [this message]
2015-12-23 20:09 ` [PATCH 0/2] ppp: add netlink support Guillaume Nault
2016-01-05 18:10 ` Guillaume Nault
2016-01-05 19:15   ` David Miller
2016-01-05 19:20     ` Guillaume Nault

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=20160125152830.GW18510@alphalink.fr \
    --to=g.nault@alphalink.fr \
    --cc=davem@davemloft.net \
    --cc=linux-ppp@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=paulus@samba.org \
    --cc=wharms@bfs.de \
    /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;
as well as URLs for NNTP newsgroup(s).