[Nut-upsdev] blazer_usb: compatibility with Ippon BackPro UPSes (Phoenix Power Co., Ltd usb-to-serial controller)

Alexey Loukianov mooroon2 at mail.ru
Wed Jan 13 13:58:29 UTC 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

13.01.2010 16:16, Arjen de Korte wrote:
> Citeren Alexey Loukianov <mooroon2 at mail.ru>:
> This is a bit tricky. I'm not sure if we can still (or need to) call
> usb_close() on the device handle after that. This might be very much
> depending on the OS in use. On Linux you should not call usb_close()
> in some cases, since that might cause a double free corruption and
> should in other cases. So if we can avoid it, that would probably be a
> safer option (although I added something to the trunk that tries
> anyway).

This is surely system-dependent, but it seems that while device handle becomes
invalid just after the call to usb_reset() (so bus should be re-enumarated and a
new call to usb_open() is required) you still need to call usb_close() to free
heap mem allocated by libusb and to close the file descriptor.

Just tested it on Fedora 8 gives no double free corruption.

Another way to reset a device (I used to use it instead of usb_reset() as it is
more generic) is as follows:

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>

#include <linux/usbdevice_fs.h>


int main(int argc, char **argv)
{
    const char *filename;
    int fd;
    int rc;

    if (argc != 2) {
        fprintf(stderr, "Usage: usbreset device-filename\n");
        return 1;
    }
    filename = argv[1];

    fd = open(filename, O_WRONLY);
    if (fd < 0) {
        perror("Error opening output file");
        return 1;
    }

    printf("Resetting USB device %s\n", filename);
    rc = ioctl(fd, USBDEVFS_RESET, 0);
    if (rc < 0) {
        perror("Error in ioctl");
        return 1;
    }
    printf("Reset successful\n");

    close(fd);
    return 0;
}

It is totally linux-dependent, so if you will take such approach some IFDEFs
will be required (but they are some already there to avoid double free
corruption anyway).

- -- 
Best regards,
Alexey Loukianov                          mailto:mooroon2 at mail.ru
System Engineer,                            Mob.:+7(926)218-1320
*nix Specialist

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJLTdGFAAoJEPB9BOdTkBUL7EQH/0jJY0npAejgLhv2W0DdYAhK
3/GtrDGqVLorBXaU0bb0FsCos0vLh+ByVn5e1GHKP4lkOR1paMxuJcV3QXVQqpNU
oFP4VsU7krztESSxi4q3k8hYrFIUSit3om5Qweprfswyw+ijUeOcQMUpuxiHZOHx
Ry+FvbYWnCDBh/zT1I5Np6pDBJndE96m/lEpl2nJsvUWx+Va0ydEOVajwcWk5vg6
yNCIuMQTXtXRrfIKR1eEUFd5twrVsGmYK3bnmm1Ofn/yFEzM1zxYnrenInLS4zlw
ysN7nvVt9JClDqVt4jcyLC/hpQKzElCItuW7UwmqqyBvz1iAqiQyX+Q7hPEOz+E=
=UeZq
-----END PGP SIGNATURE-----



More information about the Nut-upsdev mailing list