* [Bluez-devel] [PATCH] refactor cleanup code in hidd main.c
@ 2007-08-05 20:22 Simon Ruggier
2007-08-11 18:26 ` Marcel Holtmann
0 siblings, 1 reply; 2+ messages in thread
From: Simon Ruggier @ 2007-08-05 20:22 UTC (permalink / raw)
To: BlueZ development
[-- 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-08-11 18:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-05 20:22 [Bluez-devel] [PATCH] refactor cleanup code in hidd main.c Simon Ruggier
2007-08-11 18:26 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox