[PATCH 3/6] main: Rearrange iterate_dfu_devices() slightly

Stefan Schmidt stefan at datenfreihafen.org
Tue Sep 6 19:38:56 CEST 2011


Hello.

On Wed, 2011-08-31 at 23:26, Tormod Volden wrote:
> From: Tormod Volden <debian.tormod at gmail.com>
> 
> Limit the scope of some variables, get rid of others.
> Continue as soon as possible on non-match.
> ---
>  src/main.c |   20 +++++++-------------
>  1 files changed, 7 insertions(+), 13 deletions(-)
> 
> diff --git a/src/main.c b/src/main.c
> index 9fbaed9..e547a05 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -293,32 +293,26 @@ static int count_dfu_interfaces(libusb_device *dev)
>  static int iterate_dfu_devices(libusb_context *ctx, struct dfu_if *dif,
>      int (*action)(struct libusb_device *dev, void *user), void *user)
>  {
> -	struct libusb_device_descriptor desc;
> -	struct libusb_device *dev;
>  	libusb_device **list;
>  	ssize_t num_devs, i;
>  
> -	dev = NULL;
>  	num_devs = libusb_get_device_list(ctx, &list);
> -
> -	/* Walk the tree and find our device. */
>  	for (i = 0; i < num_devs; ++i) {
> -		uint8_t bnum = libusb_get_bus_number(list[i]);
> -		uint8_t dnum = libusb_get_device_address(list[i]);
> -
>  		int retval;
> -		dev = list[i];
> -		libusb_get_device_descriptor(list[i], &desc);
> +		struct libusb_device_descriptor desc;
> +		struct libusb_device *dev = list[i];
>  
> +		if (dif && (dif->flags & DFU_IFF_DEVNUM) &&
> +		    (libusb_get_bus_number(dev) != dif->bus ||
> +		     libusb_get_device_address(dev) != dif->devnum))

General a nice cleanup, but I find this if clause pretty hard to
follow in all detail. :)

But I'm in good mood and happy to see all your contributions so I
applied it as-is. :)

regards
Stefan Schmidt



More information about the devel mailing list