From owner-svn-src-stable@freebsd.org Fri Mar 30 18:13:45 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2E44DF5316D; Fri, 30 Mar 2018 18:13:45 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id CFEF373E82; Fri, 30 Mar 2018 18:13:44 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CAE3347C9; Fri, 30 Mar 2018 18:13:44 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w2UIDiHF065845; Fri, 30 Mar 2018 18:13:44 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w2UIDiFn065842; Fri, 30 Mar 2018 18:13:44 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201803301813.w2UIDiFn065842@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Fri, 30 Mar 2018 18:13:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r331771 - stable/11/lib/libusb X-SVN-Group: stable-11 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: stable/11/lib/libusb X-SVN-Commit-Revision: 331771 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Mar 2018 18:13:45 -0000 Author: hselasky Date: Fri Mar 30 18:13:44 2018 New Revision: 331771 URL: https://svnweb.freebsd.org/changeset/base/331771 Log: MFC r331419: Allow the libusb20_dev_get_port_path() function to be called when the USB device is closed. This fixes a compatibility issue with upstream libusb. Found by: romain@ Modified: stable/11/lib/libusb/libusb20.c stable/11/lib/libusb/libusb20_int.h stable/11/lib/libusb/libusb20_ugen20.c Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libusb/libusb20.c ============================================================================== --- stable/11/lib/libusb/libusb20.c Fri Mar 30 18:10:15 2018 (r331770) +++ stable/11/lib/libusb/libusb20.c Fri Mar 30 18:13:44 2018 (r331771) @@ -75,7 +75,6 @@ dummy_callback(struct libusb20_transfer *xfer) #define dummy_check_connected (void *)dummy_int #define dummy_set_power_mode (void *)dummy_int #define dummy_get_power_mode (void *)dummy_int -#define dummy_get_port_path (void *)dummy_int #define dummy_get_power_usage (void *)dummy_int #define dummy_kernel_driver_active (void *)dummy_int #define dummy_detach_kernel_driver (void *)dummy_int @@ -743,7 +742,26 @@ libusb20_dev_get_power_mode(struct libusb20_device *pd int libusb20_dev_get_port_path(struct libusb20_device *pdev, uint8_t *buf, uint8_t bufsize) { - return (pdev->methods->get_port_path(pdev, buf, bufsize)); + + if (pdev->port_level == 0) { + /* + * Fallback for backends without port path: + */ + if (bufsize < 2) + return (LIBUSB20_ERROR_OVERFLOW); + buf[0] = pdev->parent_address; + buf[1] = pdev->parent_port; + return (2); + } + + /* check if client buffer is too small */ + if (pdev->port_level > bufsize) + return (LIBUSB20_ERROR_OVERFLOW); + + /* copy port number information */ + memcpy(buf, pdev->port_path, pdev->port_level); + + return (pdev->port_level); /* success */ } uint16_t Modified: stable/11/lib/libusb/libusb20_int.h ============================================================================== --- stable/11/lib/libusb/libusb20_int.h Fri Mar 30 18:10:15 2018 (r331770) +++ stable/11/lib/libusb/libusb20_int.h Fri Mar 30 18:13:44 2018 (r331771) @@ -105,7 +105,6 @@ typedef int (libusb20_process_t)(struct libusb20_devic typedef int (libusb20_reset_device_t)(struct libusb20_device *pdev); typedef int (libusb20_set_power_mode_t)(struct libusb20_device *pdev, uint8_t power_mode); typedef int (libusb20_get_power_mode_t)(struct libusb20_device *pdev, uint8_t *power_mode); -typedef int (libusb20_get_port_path_t)(struct libusb20_device *pdev, uint8_t *buf, uint8_t bufsize); typedef int (libusb20_get_power_usage_t)(struct libusb20_device *pdev, uint16_t *power_usage); typedef int (libusb20_set_alt_index_t)(struct libusb20_device *pdev, uint8_t iface_index, uint8_t alt_index); typedef int (libusb20_set_config_index_t)(struct libusb20_device *pdev, uint8_t index); @@ -129,7 +128,6 @@ typedef void (libusb20_tr_cancel_async_t)(struct libus m(n, check_connected) \ m(n, set_power_mode) \ m(n, get_power_mode) \ - m(n, get_port_path) \ m(n, get_power_usage) \ m(n, set_alt_index) \ m(n, set_config_index) \ @@ -235,8 +233,11 @@ struct libusb20_device { uint8_t is_opened; uint8_t parent_address; uint8_t parent_port; + uint8_t port_level; char usb_desc[96]; +#define LIBUSB20_DEVICE_PORT_PATH_MAX 32 + uint8_t port_path[LIBUSB20_DEVICE_PORT_PATH_MAX]; }; extern const struct libusb20_backend_methods libusb20_ugen20_backend; Modified: stable/11/lib/libusb/libusb20_ugen20.c ============================================================================== --- stable/11/lib/libusb/libusb20_ugen20.c Fri Mar 30 18:10:15 2018 (r331770) +++ stable/11/lib/libusb/libusb20_ugen20.c Fri Mar 30 18:13:44 2018 (r331771) @@ -77,7 +77,6 @@ static libusb20_reset_device_t ugen20_reset_device; static libusb20_check_connected_t ugen20_check_connected; static libusb20_set_power_mode_t ugen20_set_power_mode; static libusb20_get_power_mode_t ugen20_get_power_mode; -static libusb20_get_port_path_t ugen20_get_port_path; static libusb20_get_power_usage_t ugen20_get_power_usage; static libusb20_kernel_driver_active_t ugen20_kernel_driver_active; static libusb20_detach_kernel_driver_t ugen20_detach_kernel_driver; @@ -134,6 +133,7 @@ ugen20_enumerate(struct libusb20_device *pdev, const c const char *tmp = id; struct usb_device_descriptor ddesc; struct usb_device_info devinfo; + struct usb_device_port_path udpp; uint32_t plugtime; char buf[64]; int f; @@ -217,6 +217,13 @@ ugen20_enumerate(struct libusb20_device *pdev, const c pdev->device_address, devinfo.udi_vendor, devinfo.udi_product, pdev->bus_number); + /* get device port path, if any */ + if (ioctl(f, IOUSB(USB_GET_DEV_PORT_PATH), &udpp) == 0 && + udpp.udp_port_level < LIBUSB20_DEVICE_PORT_PATH_MAX) { + memcpy(pdev->port_path, udpp.udp_port_no, udpp.udp_port_level); + pdev->port_level = udpp.udp_port_level; + } + error = 0; done: close(f); @@ -646,22 +653,6 @@ ugen20_get_power_mode(struct libusb20_device *pdev, ui } *power_mode = temp; return (0); /* success */ -} - -static int -ugen20_get_port_path(struct libusb20_device *pdev, uint8_t *buf, uint8_t bufsize) -{ - struct usb_device_port_path udpp; - - if (ioctl(pdev->file_ctrl, IOUSB(USB_GET_DEV_PORT_PATH), &udpp)) - return (LIBUSB20_ERROR_OTHER); - - if (udpp.udp_port_level > bufsize) - return (LIBUSB20_ERROR_OVERFLOW); - - memcpy(buf, udpp.udp_port_no, udpp.udp_port_level); - - return (udpp.udp_port_level); /* success */ } static int