Skip to content

Commit

Permalink
USB driver: adjust to WITH_USB_BUSPORT normally being always defined,…
Browse files Browse the repository at this point in the history
… just not always active [networkupstools#2043]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Sep 16, 2023
1 parent 5db58c9 commit cee9d32
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions drivers/blazer_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ void upsdrv_initups(void)
regex_array[4] = getval("serial");
regex_array[5] = getval("bus");
regex_array[6] = getval("device");
# ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
regex_array[7] = getval("busport");
# else
if (getval("busport")) {
Expand Down Expand Up @@ -732,7 +732,7 @@ void upsdrv_cleanup(void)
free(usbdevice.Serial);
free(usbdevice.Bus);
free(usbdevice.Device);
# ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
free(usbdevice.BusPort);
# endif
#endif /* TESTING */
Expand Down
6 changes: 3 additions & 3 deletions drivers/libshut.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ static int libshut_open(
free(curDevice->Serial);
free(curDevice->Bus);
free(curDevice->Device);
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
free(curDevice->BusPort);
#endif
memset(curDevice, '\0', sizeof(*curDevice));
Expand All @@ -477,7 +477,7 @@ static int libshut_open(
curDevice->ProductID = dev_descriptor->idProduct;
curDevice->Bus = strdup("serial");
curDevice->Device = strdup(arg_device_path);
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
curDevice->BusPort = (char *)malloc(4);
if (curDevice->BusPort == NULL) {
fatal_with_errno(EXIT_FAILURE, "Out of memory");
Expand Down Expand Up @@ -529,7 +529,7 @@ static int libshut_open(
upsdebugx(2, "- Product: %s", curDevice->Product);
upsdebugx(2, "- Serial Number: %s", curDevice->Serial);
upsdebugx(2, "- Bus: %s", curDevice->Bus);
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
upsdebugx(2, "- Bus Port: %s", curDevice->BusPort ? curDevice->BusPort : "unknown");
#endif
upsdebugx(2, "- Device: %s", curDevice->Device ? curDevice->Device : "unknown");
Expand Down
6 changes: 3 additions & 3 deletions drivers/libusb0.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ static int libusb_open(usb_dev_handle **udevp,
free(curDevice->Serial);
free(curDevice->Bus);
free(curDevice->Device);
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
free(curDevice->BusPort);
#endif
memset(curDevice, '\0', sizeof(*curDevice));
Expand All @@ -306,7 +306,7 @@ static int libusb_open(usb_dev_handle **udevp,
curDevice->Device = xstrdup(dev->filename);
curDevice->bcdDevice = dev->descriptor.bcdDevice;

#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
curDevice->BusPort = (char *)malloc(4);
if (curDevice->BusPort == NULL) {
fatal_with_errno(EXIT_FAILURE, "Out of memory");
Expand Down Expand Up @@ -364,7 +364,7 @@ static int libusb_open(usb_dev_handle **udevp,
upsdebugx(2, "- Serial Number: %s", curDevice->Serial ? curDevice->Serial : "unknown");
upsdebugx(2, "- Bus: %s", curDevice->Bus ? curDevice->Bus : "unknown");
upsdebugx(2, "- Device: %s", curDevice->Device ? curDevice->Device : "unknown");
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
upsdebugx(2, "- Bus Port: %s", curDevice->BusPort ? curDevice->BusPort : "unknown");
#endif
upsdebugx(2, "- Device release number: %04x", curDevice->bcdDevice);
Expand Down
10 changes: 5 additions & 5 deletions drivers/libusb1.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void nut_usb_addvars(void)
addvar(VAR_VALUE, "bus", "Regular expression to match USB bus name");
addvar(VAR_VALUE, "device", "Regular expression to match USB device name");
addvar(VAR_VALUE, "busport", "Regular expression to match USB bus port name"
#ifndef WITH_USB_BUSPORT
#if (!defined WITH_USB_BUSPORT) || (!WITH_USB_BUSPORT)
/* Not supported by this version of libusb1,
* but let's not crash config parsing on
* unknown keywords due to such nuances! :)
Expand Down Expand Up @@ -172,7 +172,7 @@ static int nut_libusb_open(libusb_device_handle **udevp,
const struct libusb_interface_descriptor *if_desc;
libusb_device_handle *udev;
uint8_t bus_num, device_addr;
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
uint8_t bus_port;
#endif
int ret, res;
Expand Down Expand Up @@ -249,7 +249,7 @@ static int nut_libusb_open(libusb_device_handle **udevp,
free(curDevice->Serial);
free(curDevice->Bus);
free(curDevice->Device);
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
free(curDevice->BusPort);
#endif
memset(curDevice, '\0', sizeof(*curDevice));
Expand Down Expand Up @@ -293,7 +293,7 @@ static int nut_libusb_open(libusb_device_handle **udevp,
}
}

#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
bus_port = libusb_get_port_number(device);
curDevice->BusPort = (char *)malloc(4);
if (curDevice->BusPort == NULL) {
Expand Down Expand Up @@ -372,7 +372,7 @@ static int nut_libusb_open(libusb_device_handle **udevp,
upsdebugx(2, "- Product: %s", curDevice->Product ? curDevice->Product : "unknown");
upsdebugx(2, "- Serial Number: %s", curDevice->Serial ? curDevice->Serial : "unknown");
upsdebugx(2, "- Bus: %s", curDevice->Bus ? curDevice->Bus : "unknown");
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
upsdebugx(2, "- Bus Port: %s", curDevice->BusPort ? curDevice->BusPort : "unknown");
#endif
upsdebugx(2, "- Device: %s", curDevice->Device ? curDevice->Device : "unknown");
Expand Down
6 changes: 3 additions & 3 deletions drivers/nutdrv_qx.c
Original file line number Diff line number Diff line change
Expand Up @@ -3016,7 +3016,7 @@ void upsdrv_initups(void)
getval("serial") ||
getval("bus") ||
getval("langid_fix")
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
|| getval("busport")
#endif
) {
Expand Down Expand Up @@ -3124,7 +3124,7 @@ void upsdrv_initups(void)
regex_array[4] = getval("serial");
regex_array[5] = getval("bus");
regex_array[6] = getval("device");
# ifdef WITH_USB_BUSPORT
# if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
regex_array[7] = getval("busport");
# else
if (getval("busport")) {
Expand Down Expand Up @@ -3294,7 +3294,7 @@ void upsdrv_cleanup(void)
free(usbdevice.Serial);
free(usbdevice.Bus);
free(usbdevice.Device);
# ifdef WITH_USB_BUSPORT
# if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
free(usbdevice.BusPort);
# endif

Expand Down
4 changes: 2 additions & 2 deletions drivers/riello_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ void upsdrv_initups(void)
regex_array[4] = getval("serial");
regex_array[5] = getval("bus");
regex_array[6] = getval("device");
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
regex_array[7] = getval("busport");
#else
if (getval("busport")) {
Expand Down Expand Up @@ -1240,7 +1240,7 @@ void upsdrv_cleanup(void)
free(usbdevice.Serial);
free(usbdevice.Bus);
free(usbdevice.Device);
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
free(usbdevice.BusPort);
#endif
}
4 changes: 2 additions & 2 deletions drivers/tripplite_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ void upsdrv_initups(void)
regex_array[4] = getval("serial"); /* probably won't see this */
regex_array[5] = getval("bus");
regex_array[6] = getval("device");
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
regex_array[7] = getval("busport");
#endif

Expand Down Expand Up @@ -1659,7 +1659,7 @@ void upsdrv_cleanup(void)
free(curDevice.Serial);
free(curDevice.Bus);
free(curDevice.Device);
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
free(curDevice.BusPort);
#endif
}
4 changes: 2 additions & 2 deletions drivers/usb-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static int match_function_exact(USBDevice_t *hd, void *privdata)
return 0;
}
#endif
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
#ifdef DEBUG_EXACT_MATCH_BUSPORT
if (strcmp_null(hd->BusPort, data->BusPort) != 0) {
upsdebugx(2, "%s: failed match of %s: %s != %s",
Expand Down Expand Up @@ -400,7 +400,7 @@ static int match_function_regex(USBDevice_t *hd, void *privdata)
return r;
}

#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
r = match_regex(data->regex[7], hd->BusPort);
if (r != 1) {
/*
Expand Down
4 changes: 2 additions & 2 deletions drivers/usb-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@

/* USB standard timeout [ms] */
#define USB_TIMEOUT 5000
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
# define USBMATCHER_REGEXP_ARRAY_LIMIT 8
#else
# define USBMATCHER_REGEXP_ARRAY_LIMIT 7
Expand All @@ -487,7 +487,7 @@ typedef struct USBDevice_s {
char *Bus; /*!< Bus name, e.g. "003" */
uint16_t bcdDevice; /*!< Device release number */
char *Device; /*!< Device name on the bus, e.g. "001" */
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
char *BusPort; /*!< Port name, e.g. "001" */
#endif
} USBDevice_t;
Expand Down
4 changes: 2 additions & 2 deletions drivers/usbhid-ups.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ void upsdrv_initups(void)
regex_array[4] = getval("serial");
regex_array[5] = getval("bus");
regex_array[6] = getval("device");
#ifdef WITH_USB_BUSPORT
#if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
regex_array[7] = getval("busport");
#else
if (getval("busport")) {
Expand Down Expand Up @@ -1184,7 +1184,7 @@ void upsdrv_cleanup(void)
free(curDevice.Serial);
free(curDevice.Bus);
free(curDevice.Device);
# ifdef WITH_USB_BUSPORT
# if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT)
free(curDevice.BusPort);
# endif
#endif /* !SHUT_MODE => USB */
Expand Down

0 comments on commit cee9d32

Please sign in to comment.