From 1c346883d55ccdd7be3098683599ee6ddb4b15bb Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Wed, 27 May 2015 10:30:22 +0200 Subject: [PATCH] hmcfgusb: unify error-handling in interrupt --- hmcfgusb.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/hmcfgusb.c b/hmcfgusb.c index e3cde0f..652eb42 100644 --- a/hmcfgusb.c +++ b/hmcfgusb.c @@ -262,15 +262,7 @@ static void LIBUSB_CALL hmcfgusb_interrupt(struct libusb_transfer *transfer) fprintf(stderr, "Interrupt transfer not completed: %s!\n", usb_strerror(transfer->status)); quit = EIO; - - libusb_free_transfer(transfer); - if (cb_data) { - if (cb_data->dev && cb_data->dev->transfer) { - cb_data->dev->transfer = NULL; - } - free(cb_data); - } - return; + goto out; } } else { if (cb_data && cb_data->cb) { @@ -279,14 +271,7 @@ static void LIBUSB_CALL hmcfgusb_interrupt(struct libusb_transfer *transfer) if (!cb_data->cb(transfer->buffer, transfer->actual_length, cb_data->data)) { quit = EIO; - - libusb_free_transfer(transfer); - if (cb_data && cb_data->dev && cb_data->dev->transfer) { - cb_data->dev->transfer = NULL; - free(cb_data); - } - - return; + goto out; } } else { hexdump(transfer->buffer, transfer->actual_length, "> "); @@ -296,12 +281,18 @@ static void LIBUSB_CALL hmcfgusb_interrupt(struct libusb_transfer *transfer) err = libusb_submit_transfer(transfer); if (err != 0) { fprintf(stderr, "Can't re-submit transfer: %s\n", usb_strerror(err)); - libusb_free_transfer(transfer); - if (cb_data) { - if (cb_data->dev) - cb_data->dev->transfer = NULL; - free(cb_data); + goto out; + } + + return; + +out: + libusb_free_transfer(transfer); + if (cb_data) { + if (cb_data->dev && cb_data->dev->transfer) { + cb_data->dev->transfer = NULL; } + free(cb_data); } } -- 2.39.5