Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1775168imm; Tue, 22 May 2018 09:07:34 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo8f4WV2fdZaPmYDwMBcJO/h3xOfTa7jcUUYgXiFkXPKmM7qgAq/V+izazkR5gfkol/K5lk X-Received: by 2002:a17:902:8bc5:: with SMTP id r5-v6mr6532890plo.182.1527005253996; Tue, 22 May 2018 09:07:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527005253; cv=none; d=google.com; s=arc-20160816; b=VNrXAejyzMHZ+g+nsecpldi/IHFOps7imHb6vlaScUbA4+pewrTbmlzsVuMz+TK2Cz JA2OaMkysqZ8lD9sUw4BE5LKWFAfbv22vAUFzIeCxpiqz9Jtp1CASdYR+z5Hc4wXcVgb t0w94FYO4SVzGa+5ykamwZTi8Z0C90iq+pCIrKxYLMyFghhc4VDGZC7JCJuEKYVkUBGH GGNVDkRxszXq8lRhU9aVjBCd0eFSZPpX/5mOfqVIKaf7y6DiXukNXfvqdsKawMcJMGrJ KX62bFQrYRRQ+EI3jeC9aRR+oFc78WTgnOMW6CbmgxA5L4uz+omEzu2cwufdZOXNvsdG DpZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=5ynLLeO9Bt9NY8QH/T0Q8MQQJ0oSP3XL7Zq7UzwLZLo=; b=mw+579DroquL6aWq6jW0ZC0ZfsRpfe6+IDjxEvvh6GiWdaOwn87kg6bmnV2JiPtAR7 1+AkgPIF6I4pQ0eMOWotIH0FH0QyCZ8sQaPj4pCBYLBZiw4RCarzUHd0as1XCyb3aa82 9kbGLi/AfHhIspRvO5Pv6BdX0bzX6SvNUEgvurcDiEKULxlDciYxMZRQ/uJeCLn0S5yj 6MVfPeAVPhvb0CnZHsQpTGg+w+PXNWpR7Ot9Fb0KqnxtbA176yTV0QCtX33Ix2VBoOKq oMEHid3+bVkFXXJOnXRx19SwStJHvpluCr+aUKSkkapZIgoiGbPLeb24h7KQ88L4rN2u FS8Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y34-v6si16785914plb.17.2018.05.22.09.07.19; Tue, 22 May 2018 09:07:33 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751880AbeEVQGj (ORCPT + 99 others); Tue, 22 May 2018 12:06:39 -0400 Received: from mailout.easymail.ca ([64.68.200.34]:36161 "EHLO mailout.easymail.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751257AbeEVQGi (ORCPT ); Tue, 22 May 2018 12:06:38 -0400 Received: from localhost (localhost [127.0.0.1]) by mailout.easymail.ca (Postfix) with ESMTP id 4C9E640B49; Tue, 22 May 2018 16:06:37 +0000 (UTC) Received: from mailout.easymail.ca ([127.0.0.1]) by localhost (emo03-pco.easydns.vpn [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RfMG3Dd68PdM; Tue, 22 May 2018 16:06:37 +0000 (UTC) Received: from [192.168.1.87] (c-24-9-64-241.hsd1.co.comcast.net [24.9.64.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailout.easymail.ca (Postfix) with ESMTPSA id E261840D02; Tue, 22 May 2018 16:06:28 +0000 (UTC) Subject: Re: [PATCH] usbip: dynamically allocate idev by nports found in sysfs To: Michael Grzeschik , linux-usb@vger.kernel.org Cc: valentina.manea.m@gmail.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Shuah Khan References: <20180518143947.27963-1-m.grzeschik@pengutronix.de> From: Shuah Khan Message-ID: <05a0fd16-cd54-1bb8-7566-0d88e1bd73cf@kernel.org> Date: Tue, 22 May 2018 10:06:27 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180518143947.27963-1-m.grzeschik@pengutronix.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Michael, Thanks for the patch. Couple of comments below: On 05/18/2018 08:39 AM, Michael Grzeschik wrote: > 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)); > + Missing check for memory allocation failure. Please add it. > 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; > }; > > > Rest looks good. thanks, -- Shuah