Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp153353imm; Tue, 22 May 2018 15:57:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr4XtLb9Ok+XiidVnq+ic5xtYlJH//XuNIQRYEXadnjxlHpKqExGJ4Plm4MWMkrouttpiBY X-Received: by 2002:a17:902:9a4c:: with SMTP id x12-v6mr365427plv.213.1527029831314; Tue, 22 May 2018 15:57:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527029831; cv=none; d=google.com; s=arc-20160816; b=plDLnK/CN1O/cgg03LbZNcz9QZK8H/feDgvvCg58bazU5YYx+/PjjvAXVnFXRI0gBt 3Fl2I9ZZFxhdqQ0uL74X0PrSj6RN2NYxexiDiG5U6SzZOlyNVf7QZ8/qpG+Fgvgt6BAz HgEQSiyicypyew+k2oGZWVWPmhnzKJ7JxkR1LtApdyXIQlMvNQGqQODCQFZ2dOlA+Ls2 /+24lAss6SK1zWtnBOzGaXgf/09hasEL/4dBYfPMVkWWj7MJjgRXgnOD39mgCsEGSvEa CGeNJv9MPvcuBz0nzQSaM9WeOZOjP7Z/pYi41hJ0A6XM1o2wu+iZuCiyPyzaMDtvp9d6 ZYVw== 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=lnjfVvW9zVOUBRzCoKn7zJrn89SomOcWdE7HMMlh/Po=; b=CcSHgwlF+6Evfc1L16IYLuDCNNpJEbow2S/FdcuoJImzW/7O6u85TK70IgDFfKkWN0 /XUTx8yhaB3AOGNjDboYBmBBm1Y+3MsFjoBlyPjNfC4Te62VacfyczoGwJGijOxylhLY ftZQL77oV/zm9NxnuW4eYe9SKOmQPysNqZlWA7QTWBo5XaoG8RKXu16uC+BDpc1NDG7a 6K3qFGyLGU3irU9ymL6aGc4nPPnk5Dz5AkrSUt1vdgIgRZ/ETRvnUYYUVdFD4CoPwhij NKF0cC6cG0DUMO6K0iMVxkoVwyP9ibEYwYXLly94LXRxP9VVP/l/SwXSkc71DriQzKDh hQcw== 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 j2-v6si16589764pff.184.2018.05.22.15.56.56; Tue, 22 May 2018 15:57:11 -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 S1753447AbeEVW41 (ORCPT + 99 others); Tue, 22 May 2018 18:56:27 -0400 Received: from mailout.easymail.ca ([64.68.200.34]:52478 "EHLO mailout.easymail.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753366AbeEVW40 (ORCPT ); Tue, 22 May 2018 18:56:26 -0400 Received: from localhost (localhost [127.0.0.1]) by mailout.easymail.ca (Postfix) with ESMTP id B14F1C0808; Tue, 22 May 2018 22:56:25 +0000 (UTC) Received: from mailout.easymail.ca ([127.0.0.1]) by localhost (emo01-pco.easydns.vpn [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qvSPXaZi4y6z; Tue, 22 May 2018 22:56:25 +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 2EC89C07F6; Tue, 22 May 2018 22:56:14 +0000 (UTC) Subject: Re: [PATCH v2] 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: <05a0fd16-cd54-1bb8-7566-0d88e1bd73cf@kernel.org> <20180522170407.10102-1-m.grzeschik@pengutronix.de> From: Shuah Khan Message-ID: Date: Tue, 22 May 2018 16:56:13 -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: <20180522170407.10102-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 On 05/22/2018 11:04 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 > --- > v1 -> v2: - reworked memory allocation into one calloc call > - added error path on allocation failure > > tools/usb/usbip/libsrc/vhci_driver.c | 14 +++++++++----- > tools/usb/usbip/libsrc/vhci_driver.h | 3 +-- > 2 files changed, 10 insertions(+), 7 deletions(-) > > diff --git a/tools/usb/usbip/libsrc/vhci_driver.c b/tools/usb/usbip/libsrc/vhci_driver.c > index c9c81614a66ad..6e2a9edfd1f0d 100644 > --- a/tools/usb/usbip/libsrc/vhci_driver.c > +++ b/tools/usb/usbip/libsrc/vhci_driver.c > @@ -242,13 +242,20 @@ static int read_record(int rhport, char *host, unsigned long host_len, > > int usbip_vhci_driver_open(void) > { > + int nports = get_nports(); > I missed this error leg in my previous comments. get_nports() could return errorwhich is -1. > udev_context = udev_new(); > if (!udev_context) { > err("udev_new failed"); > return -1; > } > > - vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver)); > + vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver) + > + nports * sizeof(struct usbip_imported_device)); nports could be -1 at this point. > + if (!vhci_driver) { > + err("vhci_driver allocation failed"); > + return -1; > + } > > /* will be freed in usbip_driver_close() */ > vhci_driver->hc_device = > @@ -260,15 +267,12 @@ int usbip_vhci_driver_open(void) > goto err; > } > > - vhci_driver->nports = get_nports(); > + vhci_driver->nports = nports; > dbg("available ports: %d", vhci_driver->nports); > > if (vhci_driver->nports <= 0) { > err("no available ports"); > goto err; This check should move up along with the get_nports() call. > - } else if (vhci_driver->nports > MAXNPORT) { > - err("port number exceeds %d", MAXNPORT); > - goto err; > } > > vhci_driver->ncontrollers = get_ncontrollers(); > diff --git a/tools/usb/usbip/libsrc/vhci_driver.h b/tools/usb/usbip/libsrc/vhci_driver.h > index 418b404d51210..6c9aca2167051 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[]; > }; > > > thanks, -- Shuah