Revision 1a20a032

b/usb-bsd.c
306 306
{
307 307
    struct usb_device_info bus_info, dev_info;
308 308
    USBDevice *d = NULL;
309
    USBHostDevice *dev;
309
    USBHostDevice *dev, *ret = NULL;
310 310
    char ctlpath[PATH_MAX + 1];
311 311
    char buspath[PATH_MAX + 1];
312 312
    int bfd, dfd, bus, address, i;
313 313
    int ugendebug = UGEN_DEBUG_LEVEL;
314 314

  
315
    if (usb_host_find_device(&bus, &address, devname) < 0)
316
        return NULL;
315
    if (usb_host_find_device(&bus, &address, devname) < 0) {
316
        goto fail;
317
    }
317 318

  
318 319
    snprintf(buspath, PATH_MAX, "/dev/usb%d", bus);
319 320

  
......
323 324
        printf("usb_host_device_open: failed to open usb bus - %s\n",
324 325
               strerror(errno));
325 326
#endif
326
        return NULL;
327
        goto fail;
327 328
    }
328 329

  
329 330
    bus_info.udi_addr = address;
......
332 333
        printf("usb_host_device_open: failed to grab bus information - %s\n",
333 334
               strerror(errno));
334 335
#endif
335
        return NULL;
336
        goto fail_bfd;
336 337
    }
337 338

  
338 339
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
......
350 351
                   ctlpath, strerror(errno));
351 352
#endif
352 353
        }
354
        goto fail_dfd;
353 355
    }
354 356

  
355
    if (dfd >= 0) {
356
        if (ioctl(dfd, USB_GET_DEVICEINFO, &dev_info) < 0) {
357
    if (ioctl(dfd, USB_GET_DEVICEINFO, &dev_info) < 0) {
357 358
#ifdef DEBUG
358
            printf("usb_host_device_open: failed to grab device info - %s\n",
359
                   strerror(errno));
359
        printf("usb_host_device_open: failed to grab device info - %s\n",
360
               strerror(errno));
360 361
#endif
361
            goto fail;
362
        }
362
        goto fail_dfd;
363
    }
363 364

  
364
        d = usb_create(NULL /* FIXME */, "usb-host");
365
        dev = DO_UPCAST(USBHostDevice, dev, d);
365
    d = usb_create(NULL /* FIXME */, "usb-host");
366
    dev = DO_UPCAST(USBHostDevice, dev, d);
366 367

  
367
        if (dev_info.udi_speed == 1)
368
            dev->dev.speed = USB_SPEED_LOW - 1;
369
        else
370
            dev->dev.speed = USB_SPEED_FULL - 1;
368
    if (dev_info.udi_speed == 1) {
369
        dev->dev.speed = USB_SPEED_LOW - 1;
370
    } else {
371
        dev->dev.speed = USB_SPEED_FULL - 1;
372
    }
371 373

  
372
        if (strncmp(dev_info.udi_product, "product", 7) != 0)
373
            pstrcpy(dev->dev.product_desc, sizeof(dev->dev.product_desc),
374
                    dev_info.udi_product);
375
        else
376
            snprintf(dev->dev.product_desc, sizeof(dev->dev.product_desc),
377
                     "host:%s", devname);
374
    if (strncmp(dev_info.udi_product, "product", 7) != 0) {
375
        pstrcpy(dev->dev.product_desc, sizeof(dev->dev.product_desc),
376
                dev_info.udi_product);
377
    } else {
378
        snprintf(dev->dev.product_desc, sizeof(dev->dev.product_desc),
379
                 "host:%s", devname);
380
    }
378 381

  
379
        pstrcpy(dev->devpath, sizeof(dev->devpath), "/dev/");
380
        pstrcat(dev->devpath, sizeof(dev->devpath), dev_info.udi_devnames[0]);
382
    pstrcpy(dev->devpath, sizeof(dev->devpath), "/dev/");
383
    pstrcat(dev->devpath, sizeof(dev->devpath), dev_info.udi_devnames[0]);
381 384

  
382
        /* Mark the endpoints as not yet open */
383
        for (i = 0; i < USB_MAX_ENDPOINTS; i++)
384
           dev->ep_fd[i] = -1;
385
    /* Mark the endpoints as not yet open */
386
    for (i = 0; i < USB_MAX_ENDPOINTS; i++) {
387
        dev->ep_fd[i] = -1;
388
    }
385 389

  
386
        ioctl(dfd, USB_SETDEBUG, &ugendebug);
390
    ioctl(dfd, USB_SETDEBUG, &ugendebug);
387 391

  
388
        return (USBDevice *)dev;
389
    }
392
    ret = (USBDevice *)dev;
390 393

  
394
fail_dfd:
395
    close(dfd);
396
fail_bfd:
397
    close(bfd);
391 398
fail:
392
    return NULL;
399
    return ret;
393 400
}
394 401

  
395 402
static struct USBDeviceInfo usb_host_dev_info = {

Also available in: Unified diff