Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 1/3] bnep: Add error print and return errno instead of -1
@ 2014-10-22 11:10 Andrei Emeltchenko
  2014-10-22 11:10 ` [PATCH 2/3] bnep: trivial: code cleanup Andrei Emeltchenko
  2014-10-22 11:10 ` [PATCH 3/3] bnep: Return errno instead of -1 and print error Andrei Emeltchenko
  0 siblings, 2 replies; 9+ messages in thread
From: Andrei Emeltchenko @ 2014-10-22 11:10 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

---
 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..1024919 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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] bnep: trivial: code cleanup
  2014-10-22 11:10 [PATCH 1/3] bnep: Add error print and return errno instead of -1 Andrei Emeltchenko
@ 2014-10-22 11:10 ` Andrei Emeltchenko
  2014-10-22 11:10 ` [PATCH 3/3] bnep: Return errno instead of -1 and print error Andrei Emeltchenko
  1 sibling, 0 replies; 9+ messages in thread
From: Andrei Emeltchenko @ 2014-10-22 11:10 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

---
 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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] bnep: Return errno instead of -1 and print error
  2014-10-22 11:10 [PATCH 1/3] bnep: Add error print and return errno instead of -1 Andrei Emeltchenko
  2014-10-22 11:10 ` [PATCH 2/3] bnep: trivial: code cleanup Andrei Emeltchenko
@ 2014-10-22 11:10 ` Andrei Emeltchenko
  2014-10-22 12:55   ` Grzegorz Kolodziejczyk
  1 sibling, 1 reply; 9+ messages in thread
From: Andrei Emeltchenko @ 2014-10-22 11:10 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] bnep: Return errno instead of -1 and print error
  2014-10-22 11:10 ` [PATCH 3/3] bnep: Return errno instead of -1 and print error Andrei Emeltchenko
@ 2014-10-22 12:55   ` Grzegorz Kolodziejczyk
  2014-10-22 13:34     ` [PATCHv2 1/3] bnep: Add error print and return errno instead of -1 Andrei Emeltchenko
  2014-10-22 13:37     ` [PATCH 3/3] bnep: Return errno instead of -1 and print error Andrei Emeltchenko
  0 siblings, 2 replies; 9+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-22 12:55 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth

Hi Andrei,

On 22 October 2014 13:10, Andrei Emeltchenko
<Andrei.Emeltchenko.news@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> 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)

>         }
>
>         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
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

BR,
Grzegorz

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCHv2 1/3] bnep: Add error print and return errno instead of -1
  2014-10-22 12:55   ` Grzegorz Kolodziejczyk
@ 2014-10-22 13:34     ` Andrei Emeltchenko
  2014-10-22 13:34       ` [PATCHv2 2/3] bnep: trivial: code cleanup Andrei Emeltchenko
                         ` (2 more replies)
  2014-10-22 13:37     ` [PATCH 3/3] bnep: Return errno instead of -1 and print error Andrei Emeltchenko
  1 sibling, 3 replies; 9+ messages in thread
From: Andrei Emeltchenko @ 2014-10-22 13:34 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

---
 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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCHv2 2/3] bnep: trivial: code cleanup
  2014-10-22 13:34     ` [PATCHv2 1/3] bnep: Add error print and return errno instead of -1 Andrei Emeltchenko
@ 2014-10-22 13:34       ` Andrei Emeltchenko
  2014-10-22 13:34       ` [PATCHv2 3/3] bnep: Return errno instead of -1 and print error Andrei Emeltchenko
  2014-10-23 10:23       ` [PATCHv2 1/3] bnep: Add error print and return errno instead of -1 Luiz Augusto von Dentz
  2 siblings, 0 replies; 9+ messages in thread
From: Andrei Emeltchenko @ 2014-10-22 13:34 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

---
 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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCHv2 3/3] bnep: Return errno instead of -1 and print error
  2014-10-22 13:34     ` [PATCHv2 1/3] bnep: Add error print and return errno instead of -1 Andrei Emeltchenko
  2014-10-22 13:34       ` [PATCHv2 2/3] bnep: trivial: code cleanup Andrei Emeltchenko
@ 2014-10-22 13:34       ` Andrei Emeltchenko
  2014-10-23 10:23       ` [PATCHv2 1/3] bnep: Add error print and return errno instead of -1 Luiz Augusto von Dentz
  2 siblings, 0 replies; 9+ messages in thread
From: Andrei Emeltchenko @ 2014-10-22 13:34 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] bnep: Return errno instead of -1 and print error
  2014-10-22 12:55   ` Grzegorz Kolodziejczyk
  2014-10-22 13:34     ` [PATCHv2 1/3] bnep: Add error print and return errno instead of -1 Andrei Emeltchenko
@ 2014-10-22 13:37     ` Andrei Emeltchenko
  1 sibling, 0 replies; 9+ messages in thread
From: Andrei Emeltchenko @ 2014-10-22 13:37 UTC (permalink / raw)
  To: Grzegorz Kolodziejczyk; +Cc: linux-bluetooth

Hi Grzegorz,

On Wed, Oct 22, 2014 at 02:55:54PM +0200, Grzegorz Kolodziejczyk wrote:
> Hi Andrei,
> 
> On 22 October 2014 13:10, Andrei Emeltchenko
> <Andrei.Emeltchenko.news@gmail.com> wrote:
> > From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> >
> > 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 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCHv2 1/3] bnep: Add error print and return errno instead of -1
  2014-10-22 13:34     ` [PATCHv2 1/3] bnep: Add error print and return errno instead of -1 Andrei Emeltchenko
  2014-10-22 13:34       ` [PATCHv2 2/3] bnep: trivial: code cleanup Andrei Emeltchenko
  2014-10-22 13:34       ` [PATCHv2 3/3] bnep: Return errno instead of -1 and print error Andrei Emeltchenko
@ 2014-10-23 10:23       ` Luiz Augusto von Dentz
  2 siblings, 0 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2014-10-23 10:23 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth@vger.kernel.org

Hi Andrei,

On Wed, Oct 22, 2014 at 4:34 PM, Andrei Emeltchenko
<Andrei.Emeltchenko.news@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> ---
>  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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-10-23 10:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-22 11:10 [PATCH 1/3] bnep: Add error print and return errno instead of -1 Andrei Emeltchenko
2014-10-22 11:10 ` [PATCH 2/3] bnep: trivial: code cleanup Andrei Emeltchenko
2014-10-22 11:10 ` [PATCH 3/3] bnep: Return errno instead of -1 and print error Andrei Emeltchenko
2014-10-22 12:55   ` Grzegorz Kolodziejczyk
2014-10-22 13:34     ` [PATCHv2 1/3] bnep: Add error print and return errno instead of -1 Andrei Emeltchenko
2014-10-22 13:34       ` [PATCHv2 2/3] bnep: trivial: code cleanup Andrei Emeltchenko
2014-10-22 13:34       ` [PATCHv2 3/3] bnep: Return errno instead of -1 and print error Andrei Emeltchenko
2014-10-23 10:23       ` [PATCHv2 1/3] bnep: Add error print and return errno instead of -1 Luiz Augusto von Dentz
2014-10-22 13:37     ` [PATCH 3/3] bnep: Return errno instead of -1 and print error Andrei Emeltchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox