Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4596610imm; Fri, 18 May 2018 07:41:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqTE8VLs60KxNyjAe+Zc1RdgW+0ZpHxwu8+xsZghOwKU/eSsCP7ptaevdcKyPc8J+Ixxlqf X-Received: by 2002:a62:211c:: with SMTP id h28-v6mr9444865pfh.249.1526654467299; Fri, 18 May 2018 07:41:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526654467; cv=none; d=google.com; s=arc-20160816; b=qjX7zj840R9aBWJaUaf1aQzOKuv8waZj2n8uMR3O4Vz4KgV5106RwbIUmVtGRsNuv2 ENq0d24O7bGqHcXrBn+4YgPEWjyG5fSU+zEgaFud8hSEzBZlnwgEMNRt9MUpqh8oNvrC qM6lG/oMONcR4uRh/4x2YgMewPOu/gNAfmYGEM67WEdWhrzZpLAdleUZo9WO5kk95ote K08CIvRwAi6atxur5+FXK2IVFDKlTJMeDuc4nZVFBi/6uIcFT808Emi42W1EXbyRY/G3 xtZ6hqg6wGBADdHbkKHt/FV9/Zzys0hDJ6h26cQoPN/eAXMRHIjcBheul6VjuY/Uof6H u9nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Pit/D1ZIDXTjc91LpT6RVf8u0ORbC0zilAcgskgwEbI=; b=EscLMGvnxrE2035Uv3QDHZEFpkwzfPduE/rj8dWjpety1C53t5vpZu8HHHBGKZTyop GEMe8EqyKNUAqhfuAb0WXkbEvZXduh5TyIZhGWmK0Hz9mgJajs6b1wG4Q2A88ThRsVrR gBwcZ2VFPVtLILxTTNdpra7beoRMJBQ0VEENcu53RPOVGnq2vltoLI2Cx/K6SHfMmImX +wIiXgwsE8Al6aaMynYsjd89OLqt08lec6fA2T2rIUcZLOohxWEIvgcbyjZO18KUPnBk 49JkZr5I2yWftcbPbXnRoxmxlx1oCrkNpQgkmEQC/pcl6Hq7HPB4NEJRYs9jfWgJRwbP 7yBQ== 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 u71-v6si6101096pgd.147.2018.05.18.07.40.44; Fri, 18 May 2018 07:41:07 -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 S1752189AbeEROkF (ORCPT + 99 others); Fri, 18 May 2018 10:40:05 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:51067 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752056AbeEROkC (ORCPT ); Fri, 18 May 2018 10:40:02 -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-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; }; -- 2.17.0