Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usb, shut headers and drivers: update from ERROR_* macros to LIBUSB_ERROR_*… #1471

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions drivers/blazer_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ static int phoenix_command(const char *cmd, char *buf, size_t buflen)
*/
switch (ret)
{
case ERROR_PIPE: /** Pipe error or Broken pipe */
case LIBUSB_ERROR_PIPE: /** Pipe error or Broken pipe */
usb_clear_halt(udev, 0x81);
break;

case ERROR_TIMEOUT: /** Operation or Connection timed out */
case LIBUSB_ERROR_TIMEOUT: /** Operation or Connection timed out */
break;
}

Expand Down Expand Up @@ -204,7 +204,7 @@ static int ippon_command(const char *cmd, char *buf, size_t buflen)
0x09, 0x2, 0, (usb_ctrl_charbuf)&tmp[i], 8, 1000);

if (ret <= 0) {
upsdebugx(3, "send: %s", (ret != ERROR_TIMEOUT) ? nut_usb_strerror(ret) : "Connection timed out");
upsdebugx(3, "send: %s", (ret != LIBUSB_ERROR_TIMEOUT) ? nut_usb_strerror(ret) : "Connection timed out");
return ret;
}
}
Expand All @@ -221,7 +221,7 @@ static int ippon_command(const char *cmd, char *buf, size_t buflen)
* will happen after successfully writing a command to the UPS)
*/
if (ret <= 0) {
upsdebugx(3, "read: %s", (ret != ERROR_TIMEOUT) ? nut_usb_strerror(ret) : "Connection timed out");
upsdebugx(3, "read: %s", (ret != LIBUSB_ERROR_TIMEOUT) ? nut_usb_strerror(ret) : "Connection timed out");
return ret;
}

Expand Down Expand Up @@ -456,7 +456,7 @@ ssize_t blazer_command(const char *cmd, char *buf, size_t buflen)

switch (ret)
{
case ERROR_BUSY: /* Device or resource busy */
case LIBUSB_ERROR_BUSY: /* Device or resource busy */
fatal_with_errno(EXIT_FAILURE, "Got disconnected by another driver");
#ifndef HAVE___ATTRIBUTE__NORETURN
exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */
Expand All @@ -470,7 +470,7 @@ ssize_t blazer_command(const char *cmd, char *buf, size_t buflen)
# endif
#endif /* WITH_LIBUSB_0_1 */

case ERROR_PIPE: /* Broken pipe */
case LIBUSB_ERROR_PIPE: /* Broken pipe */
if (usb_clear_halt(udev, 0x81) == 0) {
upsdebugx(1, "Stall condition cleared");
break;
Expand All @@ -484,21 +484,21 @@ ssize_t blazer_command(const char *cmd, char *buf, size_t buflen)
upsdebugx(1, "Device reset handled");
}
goto fallthrough_case_reconnect;
case ERROR_NO_DEVICE: /* No such device */
case ERROR_ACCESS: /* Permission denied */
case ERROR_IO: /* I/O error */
case LIBUSB_ERROR_NO_DEVICE: /* No such device */
case LIBUSB_ERROR_ACCESS: /* Permission denied */
case LIBUSB_ERROR_IO: /* I/O error */
#if WITH_LIBUSB_0_1 /* limit to libusb 0.1 implementation */
case -ENXIO: /* No such device or address */
#endif
case ERROR_NOT_FOUND: /* No such file or directory */
case LIBUSB_ERROR_NOT_FOUND: /* No such file or directory */
fallthrough_case_reconnect:
/* Uh oh, got to reconnect! */
usb->close(udev);
udev = NULL;
break;

case ERROR_TIMEOUT: /* Connection timed out */
case ERROR_OVERFLOW: /* Value too large for defined data type */
case LIBUSB_ERROR_TIMEOUT: /* Connection timed out */
case LIBUSB_ERROR_OVERFLOW: /* Value too large for defined data type */
#if EPROTO && WITH_LIBUSB_0_1
case -EPROTO: /* Protocol error */
#endif
Expand Down
21 changes: 13 additions & 8 deletions drivers/libshut.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,19 @@ typedef int usb_ctrl_timeout_msec; /* in milliseconds */
#define USB_CTRL_TIMEOUTMSEC_MAX INT_MAX

/* Same error-code definitions as in usb-common.h for libusb-0.1 API */
#define ERROR_ACCESS -EACCES
#define ERROR_BUSY -EBUSY
#define ERROR_IO -EIO
#define ERROR_NO_DEVICE -ENODEV
#define ERROR_NOT_FOUND -ENOENT
#define ERROR_OVERFLOW -EOVERFLOW
#define ERROR_PIPE -EPIPE
#define ERROR_TIMEOUT -ETIMEDOUT
#define LIBUSB_ERROR_ACCESS -EACCES
#define LIBUSB_ERROR_BUSY -EBUSY
#define LIBUSB_ERROR_IO -EIO
#define LIBUSB_ERROR_NO_DEVICE -ENODEV
#define LIBUSB_ERROR_NOT_FOUND -ENOENT
#define LIBUSB_ERROR_OVERFLOW -EOVERFLOW
#define LIBUSB_ERROR_PIPE -EPIPE
#define LIBUSB_ERROR_TIMEOUT -ETIMEDOUT
#define LIBUSB_ERROR_NO_MEM -ENOMEM
#define LIBUSB_ERROR_INVALID_PARAM -EINVAL
#define LIBUSB_ERROR_INTERRUPTED -EINTR
#define LIBUSB_ERROR_NOT_SUPPORTED -ENOSYS
#define LIBUSB_ERROR_OTHER -ERANGE

/*!
* SHUTDevice_t: Describe a SHUT device. This structure contains exactly
Expand Down
26 changes: 13 additions & 13 deletions drivers/nutdrv_qx.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ static int sgs_command(const char *cmd, char *buf, size_t buflen)

/* No error!!! */
/* if (ret == -110) */
if (ret == ERROR_TIMEOUT)
if (ret == LIBUSB_ERROR_TIMEOUT)
break;

/* Any errors here mean that we are unable to read a reply
Expand Down Expand Up @@ -669,11 +669,11 @@ static int phoenix_command(const char *cmd, char *buf, size_t buflen)
* data (e.g. it times out). */
switch (ret)
{
case ERROR_PIPE: /* Broken pipe */
case LIBUSB_ERROR_PIPE: /* Broken pipe */
usb_clear_halt(udev, 0x81);
break;

case ERROR_TIMEOUT: /* Connection timed out */
case LIBUSB_ERROR_TIMEOUT: /* Connection timed out */
break;
}

Expand Down Expand Up @@ -769,7 +769,7 @@ static int ippon_command(const char *cmd, char *buf, size_t buflen)

if (ret <= 0) {
upsdebugx(3, "send: %s (%d)",
(ret != ERROR_TIMEOUT) ? nut_usb_strerror(ret) : "Connection timed out",
(ret != LIBUSB_ERROR_TIMEOUT) ? nut_usb_strerror(ret) : "Connection timed out",
ret);
return ret;
}
Expand All @@ -788,7 +788,7 @@ static int ippon_command(const char *cmd, char *buf, size_t buflen)
* to the UPS) */
if (ret <= 0) {
upsdebugx(3, "read: %s (%d)",
(ret != ERROR_TIMEOUT) ? nut_usb_strerror(ret) : "Connection timed out",
(ret != LIBUSB_ERROR_TIMEOUT) ? nut_usb_strerror(ret) : "Connection timed out",
ret);
return ret;
}
Expand Down Expand Up @@ -3177,7 +3177,7 @@ static ssize_t qx_command(const char *cmd, char *buf, size_t buflen)

switch (ret)
{
case ERROR_BUSY: /* Device or resource busy */
case LIBUSB_ERROR_BUSY: /* Device or resource busy */
fatal_with_errno(EXIT_FAILURE, "Got disconnected by another driver");
#ifndef HAVE___ATTRIBUTE__NORETURN
# if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE)
Expand Down Expand Up @@ -3205,7 +3205,7 @@ static ssize_t qx_command(const char *cmd, char *buf, size_t buflen)
#endif
#endif /* WITH_LIBUSB_0_1 */

case ERROR_PIPE: /* Broken pipe */
case LIBUSB_ERROR_PIPE: /* Broken pipe */
if (usb_clear_halt(udev, 0x81) == 0) {
upsdebugx(1, "Stall condition cleared");
break;
Expand All @@ -3219,21 +3219,21 @@ static ssize_t qx_command(const char *cmd, char *buf, size_t buflen)
upsdebugx(1, "Device reset handled");
}
goto fallthrough_case_reconnect;
case ERROR_NO_DEVICE: /* No such device */
case ERROR_ACCESS: /* Permission denied */
case ERROR_IO: /* I/O error */
case LIBUSB_ERROR_NO_DEVICE: /* No such device */
case LIBUSB_ERROR_ACCESS: /* Permission denied */
case LIBUSB_ERROR_IO: /* I/O error */
#if WITH_LIBUSB_0_1 /* limit to libusb 0.1 implementation */
case -ENXIO: /* No such device or address */
#endif /* WITH_LIBUSB_0_1 */
case ERROR_NOT_FOUND: /* No such file or directory */
case LIBUSB_ERROR_NOT_FOUND: /* No such file or directory */
fallthrough_case_reconnect:
/* Uh oh, got to reconnect! */
usb->close(udev);
udev = NULL;
break;

case ERROR_TIMEOUT: /* Connection timed out */
case ERROR_OVERFLOW: /* Value too large for defined data type */
case LIBUSB_ERROR_TIMEOUT: /* Connection timed out */
case LIBUSB_ERROR_OVERFLOW: /* Value too large for defined data type */
#if EPROTO && WITH_LIBUSB_0_1 /* limit to libusb 0.1 implementation */
case -EPROTO: /* Protocol error */
#endif
Expand Down
16 changes: 8 additions & 8 deletions drivers/riello_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ static int riello_command(uint8_t *cmd, uint8_t *buf, uint16_t length, uint16_t

switch (ret)
{
case ERROR_BUSY: /* Device or resource busy */
case LIBUSB_ERROR_BUSY: /* Device or resource busy */
fatal_with_errno(EXIT_FAILURE, "Got disconnected by another driver");
#ifndef HAVE___ATTRIBUTE__NORETURN
exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */
Expand All @@ -383,7 +383,7 @@ static int riello_command(uint8_t *cmd, uint8_t *buf, uint16_t length, uint16_t
# endif
#endif

case ERROR_PIPE: /* Broken pipe */
case LIBUSB_ERROR_PIPE: /* Broken pipe */
if (usb_clear_halt(udev, 0x81) == 0) {
upsdebugx(1, "Stall condition cleared");
break;
Expand All @@ -397,24 +397,24 @@ static int riello_command(uint8_t *cmd, uint8_t *buf, uint16_t length, uint16_t
upsdebugx(1, "Device reset handled");
}
goto fallthrough_case_reconnect;
case ERROR_NO_DEVICE: /* No such device */
case ERROR_ACCESS: /* Permission denied */
case ERROR_IO: /* I/O error */
case LIBUSB_ERROR_NO_DEVICE: /* No such device */
case LIBUSB_ERROR_ACCESS: /* Permission denied */
case LIBUSB_ERROR_IO: /* I/O error */
#if WITH_LIBUSB_0_1 /* limit to libusb 0.1 implementation */
case -ENXIO: /* No such device or address */
#endif
case ERROR_NOT_FOUND: /* No such file or directory */
case LIBUSB_ERROR_NOT_FOUND: /* No such file or directory */
fallthrough_case_reconnect:
/* Uh oh, got to reconnect! */
usb->close(udev);
udev = NULL;
break;

case ERROR_TIMEOUT: /* Connection timed out */
case LIBUSB_ERROR_TIMEOUT: /* Connection timed out */
upsdebugx (3, "riello_command err: Resource temporarily unavailable");
break;

case ERROR_OVERFLOW: /* Value too large for defined data type */
case LIBUSB_ERROR_OVERFLOW: /* Value too large for defined data type */
#if EPROTO && WITH_LIBUSB_0_1
case -EPROTO: /* Protocol error */
#endif
Expand Down
4 changes: 2 additions & 2 deletions drivers/tripplite_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ static void usb_comm_fail(int res, const char *msg)
static int try = 0;

switch(res) {
case ERROR_BUSY:
case LIBUSB_ERROR_BUSY:
upslogx(LOG_WARNING,
"%s: Device claimed by another process", msg);
fatalx(EXIT_FAILURE, "Terminating: EBUSY");
Expand Down Expand Up @@ -1017,7 +1017,7 @@ void upsdrv_initinfo(void)
if(tl_model != TRIPP_LITE_SMARTPRO ) {
ret = send_cmd(w_msg, sizeof(w_msg), w_value, sizeof(w_value)-1);
if(ret <= 0) {
if(ret == ERROR_PIPE) {
if(ret == LIBUSB_ERROR_PIPE) {
fatalx(EXIT_FAILURE, "Could not reset watchdog. Please check and"
"see if usbhid-ups(8) works with this UPS.");
} else {
Expand Down
23 changes: 15 additions & 8 deletions drivers/usb-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
#define USB_TYPE_CLASS LIBUSB_REQUEST_TYPE_CLASS
#define USB_TYPE_VENDOR LIBUSB_REQUEST_TYPE_VENDOR

/* Codebase updated to use LIBUSB_* tokens:
#define ERROR_ACCESS LIBUSB_ERROR_ACCESS
#define ERROR_BUSY LIBUSB_ERROR_BUSY
#define ERROR_IO LIBUSB_ERROR_IO
Expand All @@ -175,6 +176,7 @@
#define ERROR_INTERRUPTED LIBUSB_ERROR_INTERRUPTED
#define ERROR_NOT_SUPPORTED LIBUSB_ERROR_NOT_SUPPORTED
#define ERROR_OTHER LIBUSB_ERROR_OTHER
*/

/* Functions, including range-checks to convert data types of the two APIs.
* Follows an example from libusb-1.0 headers that liberally cast int args
Expand Down Expand Up @@ -430,14 +432,19 @@
#define USB_CTRL_TIMEOUTMSEC_MAX INT_MAX

/* defines */
#define ERROR_ACCESS -EACCES
#define ERROR_BUSY -EBUSY
#define ERROR_IO -EIO
#define ERROR_NO_DEVICE -ENODEV
#define ERROR_NOT_FOUND -ENOENT
#define ERROR_OVERFLOW -EOVERFLOW
#define ERROR_PIPE -EPIPE
#define ERROR_TIMEOUT -ETIMEDOUT
#define LIBUSB_ERROR_ACCESS -EACCES
#define LIBUSB_ERROR_BUSY -EBUSY
#define LIBUSB_ERROR_IO -EIO
#define LIBUSB_ERROR_NO_DEVICE -ENODEV
#define LIBUSB_ERROR_NOT_FOUND -ENOENT
#define LIBUSB_ERROR_OVERFLOW -EOVERFLOW
#define LIBUSB_ERROR_PIPE -EPIPE
#define LIBUSB_ERROR_TIMEOUT -ETIMEDOUT
#define LIBUSB_ERROR_NO_MEM -ENOMEM
#define LIBUSB_ERROR_INVALID_PARAM -EINVAL
#define LIBUSB_ERROR_INTERRUPTED -EINTR
#define LIBUSB_ERROR_NOT_SUPPORTED -ENOSYS
#define LIBUSB_ERROR_OTHER -ERANGE

/* Functions for which simple mappings seem to suffice (no build warnings emitted): */
#define nut_usb_strerror(a) usb_strerror()
Expand Down
Loading