From: "Simon Ruggier" <simon80@gmail.com>
To: "BlueZ development" <bluez-devel@lists.sourceforge.net>
Subject: [Bluez-devel] [PATCH] refactor cleanup code in hidd main.c
Date: Sun, 5 Aug 2007 16:22:53 -0400 [thread overview]
Message-ID: <c1fa8edf0708051322s1a14f64u4f6b98402a82c021@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 176 bytes --]
This is an almost entirely cosmetic patch to hidd's main.c that moves
some duplicated close()/exit() calls to the end of their respective
functions, replacing them with gotos.
[-- Attachment #2: hidd-cleanup.patch --]
[-- Type: text/x-diff, Size: 3604 bytes --]
Index: main.c
===================================================================
RCS file: /cvsroot/bluez/utils/hidd/main.c,v
retrieving revision 1.37
diff -u -p -r1.37 main.c
--- main.c 8 May 2007 16:38:47 -0000 1.37
+++ main.c 5 Aug 2007 20:13:47 -0000
@@ -460,8 +460,7 @@ static void do_connect(int ctl, bdaddr_t
if (err < 0) {
perror("Can't get device information");
- close(ctl);
- exit(1);
+ goto exit_ctl;
}
switch (uuid) {
@@ -471,22 +470,19 @@ static void do_connect(int ctl, bdaddr_t
case SERIAL_PORT_SVCLASS_ID:
if (subclass == 0x40 || !strcmp(name, "Cable Replacement")) {
if (epox_presenter(src, dst, channel) < 0) {
- close(ctl);
- exit(1);
+ goto exit_ctl;
}
break;
}
if (subclass == 0x1f || !strcmp(name, "SPP slave")) {
if (jthree_keyboard(src, dst, channel) < 0) {
- close(ctl);
- exit(1);
+ goto exit_ctl;
}
break;
}
if (subclass == 0x02 || !strcmp(name, "Serial Port")) {
if (celluon_keyboard(src, dst, channel) < 0) {
- close(ctl);
- exit(1);
+ goto exit_ctl;
}
break;
}
@@ -495,8 +491,7 @@ static void do_connect(int ctl, bdaddr_t
case HEADSET_SVCLASS_ID:
case HANDSFREE_SVCLASS_ID:
if (headset_presenter(src, dst, channel) < 0) {
- close(ctl);
- exit(1);
+ goto exit_ctl;
}
break;
}
@@ -507,28 +502,32 @@ connect:
csk = l2cap_connect(src, dst, L2CAP_PSM_HIDP_CTRL);
if (csk < 0) {
perror("Can't create HID control channel");
- close(ctl);
- exit(1);
+ goto exit_ctl;
}
isk = l2cap_connect(src, dst, L2CAP_PSM_HIDP_INTR);
if (isk < 0) {
perror("Can't create HID interrupt channel");
- close(csk);
- close(ctl);
- exit(1);
+ goto exit_csk;
}
err = create_device(ctl, csk, isk, subclass, 1, 1, bootonly, encrypt, timeout);
if (err < 0) {
fprintf(stderr, "HID create error %d (%s)\n",
errno, strerror(errno));
- close(isk);
- sleep(1);
- close(csk);
- close(ctl);
- exit(1);
+ goto exit_isk;
}
+ return;
+
+exit_isk:
+ close(isk);
+ sleep(1);
+exit_csk:
+ close(csk);
+exit_ctl:
+ close(ctl);
+
+ exit(1);
}
static void do_search(int ctl, bdaddr_t *bdaddr, uint8_t subclass, int fakehid, int bootonly, int encrypt, int timeout)
@@ -605,8 +604,7 @@ static void do_kill(int ctl, bdaddr_t *b
if (ioctl(ctl, HIDPGETCONNLIST, &cl) < 0) {
perror("Can't get connection list");
- close(ctl);
- exit(1);
+ goto fail_ctl;
}
for (i = 0; i < cl.cnum; i++) {
@@ -615,8 +613,7 @@ static void do_kill(int ctl, bdaddr_t *b
if (ioctl(ctl, HIDPCONNDEL, &req) < 0) {
perror("Can't release connection");
- close(ctl);
- exit(1);
+ goto fail_ctl;
}
}
@@ -626,10 +623,13 @@ static void do_kill(int ctl, bdaddr_t *b
if (ioctl(ctl, HIDPCONNDEL, &req) < 0) {
perror("Can't release connection");
- close(ctl);
- exit(1);
+ goto fail_ctl;
}
}
+
+fail_ctl:
+ close(ctl);
+ exit(1);
}
static void usage(void)
@@ -801,23 +801,19 @@ int main(int argc, char *argv[])
case SEARCH:
do_search(ctl, &bdaddr, subclass, fakehid, bootonly, encrypt, timeout);
- close(ctl);
- exit(0);
+ goto exit_ctl;
case CONNECT:
do_connect(ctl, &bdaddr, &dev, subclass, fakehid, bootonly, encrypt, timeout);
- close(ctl);
- exit(0);
+ goto exit_ctl;
case KILL:
do_kill(ctl, &dev, flags);
- close(ctl);
- exit(0);
+ goto exit_ctl;
default:
do_show(ctl);
- close(ctl);
- exit(0);
+ goto exit_ctl;
}
if (detach) {
@@ -854,6 +850,7 @@ int main(int argc, char *argv[])
close(csk);
close(isk);
+exit_ctl:
close(ctl);
return 0;
[-- Attachment #3: Type: text/plain, Size: 315 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
[-- Attachment #4: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
next reply other threads:[~2007-08-05 20:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-05 20:22 Simon Ruggier [this message]
2007-08-11 18:26 ` [Bluez-devel] [PATCH] refactor cleanup code in hidd main.c 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=c1fa8edf0708051322s1a14f64u4f6b98402a82c021@mail.gmail.com \
--to=simon80@gmail.com \
--cc=bluez-devel@lists.sourceforge.net \
/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