Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1140761imm; Wed, 1 Aug 2018 10:51:55 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdyx3XZwRgm/Vpaex97o4UDOdDto3p8k6dOBRVEC8P7O53S2vJN1BtSwks9Gm4oLNKShS9f X-Received: by 2002:a62:8913:: with SMTP id v19-v6mr6502867pfd.127.1533145915135; Wed, 01 Aug 2018 10:51:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533145915; cv=none; d=google.com; s=arc-20160816; b=OY6NpGra7B41fYR0VZimi2RIP4dMd/l0y6S23WYBTowzgGZb2NvhMNuqc4ycEcMBmM PIyInzDo/d6QguL/IUK7lbsKpml+WL4+ce7/JQxeRBgdpFNfwuquioTq1rKB9gYigS5a KBB9ToLM2E8fWtQnHRpnLQdimAPTaDuolweQ6aOrW6D6MiwM1WCAeckYjRmsiRqrS8Mg qgFG3Oj3o2AZXgYv+bZcxVbqcFz1JwWQ0dJqGUKK82DYXC+iGFRTF2uuFQPWt3JhoPUa m2SmMj9Zl25KYxq0TuaQI9bLgIRsPxFzAsVwjUd91X3PVoCk2B7CaICYXLHV1j74kyOX ZjEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=vNoIBBuRqPI92gnxKYN63rrNI7hgtETf2HPleNAs/Ew=; b=nVgXzkWhkNMJeI7j5TBxzfURzU7A27A1xfXZYikS/cSRh2OnZFLLyB9bx85aDa/b+f owKIWX16uJiRGW61D86fmbgxCOeu6XK7QTLWu123pBivXUo6bWfUPWpFdZdh4R+Hqyy0 SeONh7+MkUc5Vo0cctAcRpXwTHvBD3YaFIf5Xzd2Y3gAlB8p4hwfCHpzApiVC3PciNKA 111VNXTQqzjc4I+Kie35UXv3J5fWszP6flq2kIoLemQhQZuVbQ0JwjNTnO2dUx+He3XM kaIMuI+d5GTHVGiWTUzKXfBnsQkQ44tfCy7/veRW8OIkS/xmwWKQneLz9d3lPunr6Syk +GlQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w3-v6si14828873pgp.220.2018.08.01.10.51.40; Wed, 01 Aug 2018 10:51:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406122AbeHATIm (ORCPT + 99 others); Wed, 1 Aug 2018 15:08:42 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49886 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406034AbeHATIl (ORCPT ); Wed, 1 Aug 2018 15:08:41 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 76E3313DD; Wed, 1 Aug 2018 17:16:22 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Grzeschik , "Shuah Khan (Samsung OSG)" , Sasha Levin Subject: [PATCH 4.14 064/246] usbip: dynamically allocate idev by nports found in sysfs Date: Wed, 1 Aug 2018 18:49:34 +0200 Message-Id: <20180801165014.767218088@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael Grzeschik [ Upstream commit de19ca6fd72c7dd45ad82403e7b3fe9c74ef6767 ] As the amount of available ports varies by the kernels build configuration. To remove the limitation of the fixed 128 ports we allocate the amount of idevs by using the number we get from the kernel. Signed-off-by: Michael Grzeschik Acked-by: Shuah Khan (Samsung OSG) Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- tools/usb/usbip/libsrc/vhci_driver.c | 32 +++++++++++++++++++------------- tools/usb/usbip/libsrc/vhci_driver.h | 3 +-- 2 files changed, 20 insertions(+), 15 deletions(-) --- a/tools/usb/usbip/libsrc/vhci_driver.c +++ b/tools/usb/usbip/libsrc/vhci_driver.c @@ -135,11 +135,11 @@ static int refresh_imported_device_list( return 0; } -static int get_nports(void) +static int get_nports(struct udev_device *hc_device) { const char *attr_nports; - attr_nports = udev_device_get_sysattr_value(vhci_driver->hc_device, "nports"); + attr_nports = udev_device_get_sysattr_value(hc_device, "nports"); if (!attr_nports) { err("udev_device_get_sysattr_value nports failed"); return -1; @@ -242,35 +242,41 @@ static int read_record(int rhport, char int usbip_vhci_driver_open(void) { + int nports; + struct udev_device *hc_device; + udev_context = udev_new(); if (!udev_context) { err("udev_new failed"); return -1; } - vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver)); - /* will be freed in usbip_driver_close() */ - vhci_driver->hc_device = + hc_device = udev_device_new_from_subsystem_sysname(udev_context, USBIP_VHCI_BUS_TYPE, USBIP_VHCI_DEVICE_NAME); - if (!vhci_driver->hc_device) { + if (!hc_device) { err("udev_device_new_from_subsystem_sysname failed"); goto err; } - vhci_driver->nports = get_nports(); - dbg("available ports: %d", vhci_driver->nports); - - if (vhci_driver->nports <= 0) { + nports = get_nports(hc_device); + if (nports <= 0) { err("no available ports"); goto err; - } else if (vhci_driver->nports > MAXNPORT) { - err("port number exceeds %d", MAXNPORT); + } + dbg("available ports: %d", nports); + + vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver) + + nports * sizeof(struct usbip_imported_device)); + if (!vhci_driver) { + err("vhci_driver allocation failed"); goto err; } + vhci_driver->nports = nports; + vhci_driver->hc_device = hc_device; vhci_driver->ncontrollers = get_ncontrollers(); dbg("available controllers: %d", vhci_driver->ncontrollers); @@ -285,7 +291,7 @@ int usbip_vhci_driver_open(void) return 0; err: - udev_device_unref(vhci_driver->hc_device); + udev_device_unref(hc_device); if (vhci_driver) free(vhci_driver); --- a/tools/usb/usbip/libsrc/vhci_driver.h +++ b/tools/usb/usbip/libsrc/vhci_driver.h @@ -13,7 +13,6 @@ #define USBIP_VHCI_BUS_TYPE "platform" #define USBIP_VHCI_DEVICE_NAME "vhci_hcd.0" -#define MAXNPORT 128 enum hub_speed { HUB_SPEED_HIGH = 0, @@ -41,7 +40,7 @@ struct usbip_vhci_driver { int ncontrollers; int nports; - struct usbip_imported_device idev[MAXNPORT]; + struct usbip_imported_device idev[]; };