From patchwork Fri May 18 14:39:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Grzeschik X-Patchwork-Id: 10410935 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4AB2760353 for ; Fri, 18 May 2018 14:40:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AAD6284F1 for ; Fri, 18 May 2018 14:40:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C8DC289EA; Fri, 18 May 2018 14:40:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DB3C289E4 for ; Fri, 18 May 2018 14:40:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752163AbeEROkD (ORCPT ); Fri, 18 May 2018 10:40:03 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:45243 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751497AbeEROkA (ORCPT ); Fri, 18 May 2018 10:40:00 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fJgY2-0003n0-6b; Fri, 18 May 2018 16:39:58 +0200 Received: from mgr by dude.hi.pengutronix.de with local (Exim 4.91) (envelope-from ) id 1fJgY1-0008LH-LI; Fri, 18 May 2018 16:39:57 +0200 From: Michael Grzeschik To: linux-usb@vger.kernel.org Cc: valentina.manea.m@gmail.com, shuah@kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH] usbip: dynamically allocate idev by nports found in sysfs Date: Fri, 18 May 2018 16:39:47 +0200 Message-Id: <20180518143947.27963-1-m.grzeschik@pengutronix.de> X-Mailer: git-send-email 2.17.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: mgr@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-usb@vger.kernel.org Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- tools/usb/usbip/libsrc/vhci_driver.c | 11 ++++++++--- tools/usb/usbip/libsrc/vhci_driver.h | 3 +-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/usb/usbip/libsrc/vhci_driver.c b/tools/usb/usbip/libsrc/vhci_driver.c index c9c81614a66ad..9a8acfc7697fa 100644 --- a/tools/usb/usbip/libsrc/vhci_driver.c +++ b/tools/usb/usbip/libsrc/vhci_driver.c @@ -266,11 +266,11 @@ int usbip_vhci_driver_open(void) if (vhci_driver->nports <= 0) { err("no available ports"); goto err; - } else if (vhci_driver->nports > MAXNPORT) { - err("port number exceeds %d", MAXNPORT); - goto err; } + vhci_driver->idev = calloc(vhci_driver->nports, + sizeof(struct usbip_imported_device)); + vhci_driver->ncontrollers = get_ncontrollers(); dbg("available controllers: %d", vhci_driver->ncontrollers); @@ -287,6 +287,9 @@ int usbip_vhci_driver_open(void) err: udev_device_unref(vhci_driver->hc_device); + if (vhci_driver->idev) + free(vhci_driver->idev); + if (vhci_driver) free(vhci_driver); @@ -305,6 +308,8 @@ void usbip_vhci_driver_close(void) udev_device_unref(vhci_driver->hc_device); + free(vhci_driver->idev); + free(vhci_driver); vhci_driver = NULL; diff --git a/tools/usb/usbip/libsrc/vhci_driver.h b/tools/usb/usbip/libsrc/vhci_driver.h index 418b404d51210..67dbd1551e159 100644 --- 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; };