All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcel Holtmann <marcel@holtmann.org>
To: ofono@ofono.org
Subject: RE: [PATCH 2/2] Fix: Check if interface exists before creating it.
Date: Mon, 01 Feb 2010 13:40:04 -0800	[thread overview]
Message-ID: <1265060404.31341.58.camel@localhost.localdomain> (raw)
In-Reply-To: <61D8D34BB13CFE408D154529C120E079032A1F20@eseldmw101.eemea.ericsson.se>

[-- Attachment #1: Type: text/plain, Size: 1692 bytes --]

Hi Sjur,

> >> diff --git a/drivers/stemodem/gprs-context.c
> >> b/drivers/stemodem/gprs-context.c index c178fb6..79e697b 100644
> >> --- a/drivers/stemodem/gprs-context.c
> >> +++ b/drivers/stemodem/gprs-context.c
> >> @@ -187,9 +187,11 @@ static gboolean caif_if_create(const char
> >>  	*interface, unsigned int connid)  		return FALSE; }
> >> 
> >> -	if (ioctl(s, SIOCCAIFNETNEW, &ifr) < 0) {
> >> -		ofono_debug("Failed to create IP interface for CAIF");
> >> -		return FALSE;
> >> +	if (ioctl(s, SIOCGIFINDEX, &ifr) != 0) {
> >> +		if (ioctl(s, SIOCCAIFNETNEW, &ifr) < 0) {
> >> +			ofono_debug("Failed to create IP interface for CAIF");
> >> +			return FALSE; +		}
> >>  	}
> >> 
> >>  	return TRUE;
> > 
> > just doing it like this would be better:
> > 
> > 	/* Check if interface exists */
> > 	if (ioctl(s, SIOCGIFINDEX, &ifr) == 0)
> > 		return TRUE;
> > 
> > 	if (ioctl(s, SIOCCAIFNETNEW, &ifr) < 0) {
> > 		...
> > 		return FALSE;
> > 	}
> > 
> > 	return TRUE;
> > 
> > We are not a big fan complicated if clauses if they can be avoid with
> > a simple goto or just a return. 
> > 
> > Also I think we need to check errno value here. Since potentially the
> > ioctl can fail for other reasons. And maybe extending CAIF with a
> > proper way of checking for an existing interface might be better.  
> 
> Do you have anything particular in mind here? 
> Maybe CAIF could simply return EEXIST from SIOCCAIFNETNEW if the interface
> already exists? In this case we could return TRUE anyway.

if it isn't that doing already, then it should be doing it. And yes,
just returning TRUE in that case seems fine to me.

Regards

Marcel



  reply	other threads:[~2010-02-01 21:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-01 15:50 [PATCH 1/2] Fix: Username and Password must be set after context is created sjur.brandeland
2010-02-01 15:50 ` [PATCH 2/2] Fix: Check if interface exists before creating it sjur.brandeland
2010-02-01 16:03   ` Marcel Holtmann
2010-02-01 20:40     ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2010-02-01 21:40       ` Marcel Holtmann [this message]
2010-02-01 16:09 ` [PATCH 1/2] Fix: Username and Password must be set after context is created Marcel Holtmann
2010-02-01 17:23   ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2010-02-01 19:10     ` Marcel Holtmann
2010-02-01 19:20       ` Denis Kenzior
2010-02-01 21:41         ` Marcel Holtmann

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=1265060404.31341.58.camel@localhost.localdomain \
    --to=marcel@holtmann.org \
    --cc=ofono@ofono.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.