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 08:03:47 -0800 [thread overview]
Message-ID: <1265040227.31341.40.camel@localhost.localdomain> (raw)
In-Reply-To: <1265039424-1961-2-git-send-email-sjur.brandeland@stericsson.com>
[-- Attachment #1: Type: text/plain, Size: 1249 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.
Regards
Marcel
next prev parent reply other threads:[~2010-02-01 16:03 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 [this message]
2010-02-01 20:40 ` Sjur =?unknown-8bit?q?Br=C3=A6ndeland?=
2010-02-01 21:40 ` Marcel Holtmann
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=1265040227.31341.40.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox