diff mbox series

is just a wrong function name of libusb_get_port_number? request for a review of the bug fix

Message ID 02a07a59c3964199b73b1145e4abe0e9@tencent.com (mailing list archive)
State New, archived
Headers show
Series is just a wrong function name of libusb_get_port_number? request for a review of the bug fix | expand

Commit Message

bauerchen(陈蒙蒙) April 2, 2020, 11:47 a.m. UTC
From 6bfb3087866606ed36a21e7bd05f0674e6a97158 Mon Sep 17 00:00:00 2001
From: Bauerchen <bauerchen@tencent.com>
Date: Thu, 2 Apr 2020 19:19:00 +0800
Subject: [PATCH] Fix:fix the wrong function name of libusb_get_port_number

[desc]:
libusb_get_port_numbers is called in function
usb_host_get_port, and qemu crashed with:
symbol lookup error: undefined symbol: libusb_get_port_numbers
I check /lib64/libusb-1.0.so.0 and output is libusb_get_port_number, I
change it to libusb_get_port_number, crash problem is gone;
so is it just a function name bug?

Signed-off-by: Bauerchen <bauerchen@tencent.com>
---
 hw/usb/host-libusb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
1.8.3.1


-------------
bauerchen

Comments

Gerd Hoffmann April 3, 2020, 6:50 a.m. UTC | #1
On Thu, Apr 02, 2020 at 11:47:17AM +0000, bauerchen(陈蒙蒙) wrote:
> From 6bfb3087866606ed36a21e7bd05f0674e6a97158 Mon Sep 17 00:00:00 2001
> From: Bauerchen <bauerchen@tencent.com>
> Date: Thu, 2 Apr 2020 19:19:00 +0800
> Subject: [PATCH] Fix:fix the wrong function name of libusb_get_port_number
> 
> [desc]:
> libusb_get_port_numbers is called in function
> usb_host_get_port, and qemu crashed with:
> symbol lookup error: undefined symbol: libusb_get_port_numbers
> I check /lib64/libusb-1.0.so.0 and output is libusb_get_port_number, I
> change it to libusb_get_port_number, crash problem is gone;
> so is it just a function name bug?
> 
> Signed-off-by: Bauerchen <bauerchen@tencent.com>
> ---
>  hw/usb/host-libusb.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
> index 2ac7a93..713db8d 100644
> --- a/hw/usb/host-libusb.c
> +++ b/hw/usb/host-libusb.c
> @@ -285,7 +285,7 @@ static int usb_host_get_port(libusb_device *dev, char *port, size_t len)
>      int rc, i;
>  
>  #if LIBUSB_API_VERSION >= 0x01000102
> -    rc = libusb_get_port_numbers(dev, path, 7);
> +    rc = libusb_get_port_number(dev, path, 7);

Surely not that simple.  libusb_get_port_number isn't a drop-in
replacement for libusb_get_port_numbers.  Also it was probably added
later to libusb, so some LIBUSB_API_VERSION #ifdef will be needed so the
one or the other will be used depending on the library version.

cheers,
  Gerd
bauerchen(陈蒙蒙) April 3, 2020, 7:05 a.m. UTC | #2
thanks, but my libusbx version is libusbx-1.0.15-4.el7.x86_64 ,
I can find libusb_get_port_numbers function in libusb-1.0.so.0 but find libusb_get_port_number

[root@t]# strings /lib64/libusb-1.0.so.0 |grep libusb_get_port_number
libusb_get_port_number
[root@t]#

is my libusbx package problem?
Gerd Hoffmann April 3, 2020, 8:19 a.m. UTC | #3
On Fri, Apr 03, 2020 at 07:05:13AM +0000, bauerchen(陈蒙蒙) wrote:
> thanks, but my libusbx version is libusbx-1.0.15-4.el7.x86_64 ,
> I can find libusb_get_port_numbers function in libusb-1.0.so.0 but find libusb_get_port_number
> 
> [root@t]# strings /lib64/libusb-1.0.so.0 |grep libusb_get_port_number
> libusb_get_port_number
> [root@t]#

kraxel@sirius ~# grep libusb_get_port_number /usr/include/libusb-1.0/libusb.h 
uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev);
int LIBUSB_CALL libusb_get_port_numbers(libusb_device *dev, uint8_t* port_numbers, int port_numbers_len);
LIBUSB_DEPRECATED_FOR(libusb_get_port_numbers)

So libusb_get_port_numbers replaces libusb_get_port_number, seems you have an
old version which hasn't yet libusb_get_port_numbers.

On old version qemu should fallback to libusb_get_port_path, but maybe the
version #ifdef is wrong so this doesn't work properly for some versions ...

According to my /usr/include/libusb-1.0/libusb.h libusb >= 1.0.16 declares
LIBUSB_API_VERSION >= 0x01000102, so that looks ok.  Hmm, not sure what is
going on here.  In any case the libusb_get_port_path fallback code path
should work.

cheers,
  Gerd
bauerchen(陈蒙蒙) April 3, 2020, 8:50 a.m. UTC | #4
OK,thanks, I will try .
diff mbox series

Patch

diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index 2ac7a93..713db8d 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -285,7 +285,7 @@  static int usb_host_get_port(libusb_device *dev, char *port, size_t len)
     int rc, i;
 
 #if LIBUSB_API_VERSION >= 0x01000102
-    rc = libusb_get_port_numbers(dev, path, 7);
+    rc = libusb_get_port_number(dev, path, 7);
 #else
     rc = libusb_get_port_path(ctx, dev, path, 7);
 #endif