Discussion:
[PATCH 3/3] bnep: Return errno instead of -1 and print error
Andrei Emeltchenko
2014-10-22 11:10:51 UTC
Permalink
From: Andrei Emeltchenko <andrei.emeltchenko-***@public.gmane.org>

Make code consistent with the rest returning -errno and printing error
message.
---
profiles/network/bnep.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 4cf38d9..09d4b65 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -231,7 +231,7 @@ static int bnep_if_down(const char *devname)
if (ioctl(sk, SIOCSIFFLAGS, (void *) &ifr) < 0) {
err = -errno;
error("bnep: Could not bring down %s: %s(%d)",
- devname, strerror(-err), -err);
+ devname, strerror(-err), -err);
}

close(sk);
@@ -520,7 +520,7 @@ static int bnep_del_from_bridge(const char *devname, const char *bridge)
{
int ifindex;
struct ifreq ifr;
- int sk, err;
+ int sk, err = 0;

if (!devname || !bridge)
return -EINVAL;
@@ -535,16 +535,16 @@ static int bnep_del_from_bridge(const char *devname, const char *bridge)
strncpy(ifr.ifr_name, bridge, IFNAMSIZ - 1);
ifr.ifr_ifindex = ifindex;

- err = ioctl(sk, SIOCBRDELIF, &ifr);
+ if (ioctl(sk, SIOCBRDELIF, &ifr) < 0) {
+ err = -errno;
+ error("bnep: Can't delete %s from the bridge %s: %s(%d)",
+ devname, bridge, strerror(-err), -err);
+ } else
+ info("bridge %s: interface %s removed", bridge, devname);

close(sk);

- if (err < 0)
- return err;
-
- info("bridge %s: interface %s removed", bridge, devname);
-
- return 0;
+ return err;
}

int bnep_server_add(int sk, uint16_t dst, char *bridge, char *iface,
--
1.9.1
Andrei Emeltchenko
2014-10-22 11:10:50 UTC
Permalink
From: Andrei Emeltchenko <andrei.emeltchenko-***@public.gmane.org>

---
profiles/network/bnep.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 1024919..4cf38d9 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -133,7 +133,6 @@ const char *bnep_name(uint16_t id)
int bnep_init(void)
{
ctl = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_BNEP);
-
if (ctl < 0) {
int err = -errno;

@@ -141,7 +140,7 @@ int bnep_init(void)
warn("kernel lacks bnep-protocol support");
else
error("bnep: Failed to open control socket: %s (%d)",
- strerror(-err), -err);
+ strerror(-err), -err);

return err;
}
@@ -165,7 +164,7 @@ static int bnep_conndel(const bdaddr_t *dst)
if (ioctl(ctl, BNEPCONNDEL, &req) < 0) {
int err = -errno;
error("bnep: Failed to kill connection: %s (%d)",
- strerror(-err), -err);
+ strerror(-err), -err);
return err;
}
return 0;
@@ -184,7 +183,7 @@ static int bnep_connadd(int sk, uint16_t role, char *dev)
if (ioctl(ctl, BNEPCONNADD, &req) < 0) {
int err = -errno;
error("bnep: Failed to add device %s: %s(%d)",
- dev, strerror(-err), -err);
+ dev, strerror(-err), -err);
return err;
}

@@ -208,7 +207,7 @@ static int bnep_if_up(const char *devname)
if (ioctl(sk, SIOCSIFFLAGS, (void *) &ifr) < 0) {
err = -errno;
error("bnep: Could not bring up %s: %s(%d)",
- devname, strerror(-err), -err);
+ devname, strerror(-err), -err);
}

close(sk);
--
1.9.1
Grzegorz Kolodziejczyk
2014-10-22 12:55:54 UTC
Permalink
Hi Andrei,

On 22 October 2014 13:10, Andrei Emeltchenko
Post by Andrei Emeltchenko
Make code consistent with the rest returning -errno and printing error
message.
---
profiles/network/bnep.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 4cf38d9..09d4b65 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -231,7 +231,7 @@ static int bnep_if_down(const char *devname)
if (ioctl(sk, SIOCSIFFLAGS, (void *) &ifr) < 0) {
err = -errno;
error("bnep: Could not bring down %s: %s(%d)",
- devname, strerror(-err), -err);
+ devname, strerror(-err), -err);
Why don't you fix this indention in first patch ? (this line is added
in previous patch)
Post by Andrei Emeltchenko
}
close(sk);
@@ -520,7 +520,7 @@ static int bnep_del_from_bridge(const char *devname, const char *bridge)
{
int ifindex;
struct ifreq ifr;
- int sk, err;
+ int sk, err = 0;
if (!devname || !bridge)
return -EINVAL;
@@ -535,16 +535,16 @@ static int bnep_del_from_bridge(const char *devname, const char *bridge)
strncpy(ifr.ifr_name, bridge, IFNAMSIZ - 1);
ifr.ifr_ifindex = ifindex;
- err = ioctl(sk, SIOCBRDELIF, &ifr);
+ if (ioctl(sk, SIOCBRDELIF, &ifr) < 0) {
+ err = -errno;
+ error("bnep: Can't delete %s from the bridge %s: %s(%d)",
+ devname, bridge, strerror(-err), -err);
+ } else
+ info("bridge %s: interface %s removed", bridge, devname);
close(sk);
- if (err < 0)
- return err;
-
- info("bridge %s: interface %s removed", bridge, devname);
-
- return 0;
+ return err;
}
int bnep_server_add(int sk, uint16_t dst, char *bridge, char *iface,
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
More majordomo info at http://vger.kernel.org/majordomo-info.html
BR,
Grzegorz
Andrei Emeltchenko
2014-10-22 13:34:29 UTC
Permalink
From: Andrei Emeltchenko <andrei.emeltchenko-***@public.gmane.org>

---
profiles/network/bnep.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index f8fcd1f..d8883d6 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -133,7 +133,6 @@ const char *bnep_name(uint16_t id)
int bnep_init(void)
{
ctl = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_BNEP);
-
if (ctl < 0) {
int err = -errno;

@@ -141,7 +140,7 @@ int bnep_init(void)
warn("kernel lacks bnep-protocol support");
else
error("bnep: Failed to open control socket: %s (%d)",
- strerror(-err), -err);
+ strerror(-err), -err);

return err;
}
@@ -165,7 +164,7 @@ static int bnep_conndel(const bdaddr_t *dst)
if (ioctl(ctl, BNEPCONNDEL, &req) < 0) {
int err = -errno;
error("bnep: Failed to kill connection: %s (%d)",
- strerror(-err), -err);
+ strerror(-err), -err);
return err;
}
return 0;
@@ -184,7 +183,7 @@ static int bnep_connadd(int sk, uint16_t role, char *dev)
if (ioctl(ctl, BNEPCONNADD, &req) < 0) {
int err = -errno;
error("bnep: Failed to add device %s: %s(%d)",
- dev, strerror(-err), -err);
+ dev, strerror(-err), -err);
return err;
}

@@ -208,7 +207,7 @@ static int bnep_if_up(const char *devname)
if (ioctl(sk, SIOCSIFFLAGS, (void *) &ifr) < 0) {
err = -errno;
error("bnep: Could not bring up %s: %s(%d)",
- devname, strerror(-err), -err);
+ devname, strerror(-err), -err);
}

close(sk);
--
1.9.1
Andrei Emeltchenko
2014-10-22 13:34:30 UTC
Permalink
From: Andrei Emeltchenko <andrei.emeltchenko-***@public.gmane.org>

Make code consistent with the rest returning -errno and printing error
message.
---
profiles/network/bnep.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index d8883d6..09d4b65 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -520,7 +520,7 @@ static int bnep_del_from_bridge(const char *devname, const char *bridge)
{
int ifindex;
struct ifreq ifr;
- int sk, err;
+ int sk, err = 0;

if (!devname || !bridge)
return -EINVAL;
@@ -535,16 +535,16 @@ static int bnep_del_from_bridge(const char *devname, const char *bridge)
strncpy(ifr.ifr_name, bridge, IFNAMSIZ - 1);
ifr.ifr_ifindex = ifindex;

- err = ioctl(sk, SIOCBRDELIF, &ifr);
+ if (ioctl(sk, SIOCBRDELIF, &ifr) < 0) {
+ err = -errno;
+ error("bnep: Can't delete %s from the bridge %s: %s(%d)",
+ devname, bridge, strerror(-err), -err);
+ } else
+ info("bridge %s: interface %s removed", bridge, devname);

close(sk);

- if (err < 0)
- return err;
-
- info("bridge %s: interface %s removed", bridge, devname);
-
- return 0;
+ return err;
}

int bnep_server_add(int sk, uint16_t dst, char *bridge, char *iface,
--
1.9.1
Andrei Emeltchenko
2014-10-22 13:34:28 UTC
Permalink
From: Andrei Emeltchenko <andrei.emeltchenko-***@public.gmane.org>

---
profiles/network/bnep.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 927367c..f8fcd1f 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -219,7 +219,7 @@ static int bnep_if_up(const char *devname)
static int bnep_if_down(const char *devname)
{
struct ifreq ifr;
- int sk, err;
+ int sk, err = 0;

sk = socket(AF_INET, SOCK_DGRAM, 0);

@@ -229,16 +229,15 @@ static int bnep_if_down(const char *devname)
ifr.ifr_flags &= ~IFF_UP;

/* Bring down the interface */
- err = ioctl(sk, SIOCSIFFLAGS, (void *) &ifr);
+ if (ioctl(sk, SIOCSIFFLAGS, (void *) &ifr) < 0) {
+ err = -errno;
+ error("bnep: Could not bring down %s: %s(%d)",
+ devname, strerror(-err), -err);
+ }

close(sk);

- if (err < 0) {
- error("bnep: Could not bring down %s", devname);
- return err;
- }
-
- return 0;
+ return err;
}

static gboolean bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond,
--
1.9.1
Luiz Augusto von Dentz
2014-10-23 10:23:48 UTC
Permalink
Hi Andrei,

On Wed, Oct 22, 2014 at 4:34 PM, Andrei Emeltchenko
Post by Andrei Emeltchenko
---
profiles/network/bnep.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 927367c..f8fcd1f 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -219,7 +219,7 @@ static int bnep_if_up(const char *devname)
static int bnep_if_down(const char *devname)
{
struct ifreq ifr;
- int sk, err;
+ int sk, err = 0;
sk = socket(AF_INET, SOCK_DGRAM, 0);
@@ -229,16 +229,15 @@ static int bnep_if_down(const char *devname)
ifr.ifr_flags &= ~IFF_UP;
/* Bring down the interface */
- err = ioctl(sk, SIOCSIFFLAGS, (void *) &ifr);
+ if (ioctl(sk, SIOCSIFFLAGS, (void *) &ifr) < 0) {
+ err = -errno;
+ error("bnep: Could not bring down %s: %s(%d)",
+ devname, strerror(-err), -err);
+ }
close(sk);
- if (err < 0) {
- error("bnep: Could not bring down %s", devname);
- return err;
- }
-
- return 0;
+ return err;
}
static gboolean bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond,
--
1.9.1
Applied, thanks.
--
Luiz Augusto von Dentz
Andrei Emeltchenko
2014-10-22 13:37:44 UTC
Permalink
Hi Grzegorz,
Post by Grzegorz Kolodziejczyk
Hi Andrei,
On 22 October 2014 13:10, Andrei Emeltchenko
Post by Andrei Emeltchenko
Make code consistent with the rest returning -errno and printing error
message.
---
profiles/network/bnep.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 4cf38d9..09d4b65 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -231,7 +231,7 @@ static int bnep_if_down(const char *devname)
if (ioctl(sk, SIOCSIFFLAGS, (void *) &ifr) < 0) {
err = -errno;
error("bnep: Could not bring down %s: %s(%d)",
- devname, strerror(-err), -err);
+ devname, strerror(-err), -err);
Why don't you fix this indention in first patch ? (this line is added
in previous patch)
Sorry, resend the series.

Best regards
Andrei Emeltchenko
Loading...