Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1536748rdd; Thu, 11 Jan 2024 02:03:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlmdsjx6WD6d6emDljmJSOFo1McArRhPlilJpTOryfPUsBuyGcIYnnGLjJuOHz2TrFZrJq X-Received: by 2002:a17:902:6b0c:b0:1cf:61c8:73e9 with SMTP id o12-20020a1709026b0c00b001cf61c873e9mr947304plk.50.1704967427877; Thu, 11 Jan 2024 02:03:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704967427; cv=none; d=google.com; s=arc-20160816; b=cuBx13RW/BHC2NMPZhCJJ0kYv9+gFqhan80X5565Mf1YNC/mtidPnURVK6pdcFk4i9 g9YZWcXhYfsUiWQMGwg25MHCSKZ/GH91E/IMLiL9OBsOi9fOpnMxtz5Zwdf7FkJ32rcl MDzhzRLCO+bChdTqjjy2d5NqGuXZdqdH/GLxJVYcV/B7/c1NQQYxO/49Sf7g8m/yGvBN hgpsXsJMPZXB4+pY48TvL5mVEqbAfNB5URumgHvyGNowGDzu9pRpnBo/MfFlBTSazi7L aWd1LGGNt0nqS6Ps+gxqjM3M2OjsTk/XlYayZD1n1SoG8prZqRl3QADeFKkD6942xnEA OwoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=6IqX+sf8SwDzeyFvI1yVFUW74pFszXEfJw+nP8ibST8=; fh=My6HwmPs7lXYIkdAi54Lfr4X1CIfFhebLp5mU9uzZGY=; b=kaQ2bhLCL6hTV3IaT24QNlulDZbFG6BElVhtyf9gm06a6EjUGBDJW7k4rU/aTjhy1l gQd5HniEb0zsW/nux0ZtCjuoNid6qnnpfr8MNuqzoJhuB7tNC3z0OjvHc9/7RtN+rLkd WDPPohzKNhZXQkxi0uQkpaFKrtqyvgXutj+0VeZE8IU/CSN5TYhUcA5xSsC2QmPhXG/3 kq1jytF+CvXxXi918g4HTN3jmd31jCmbCJoez2ZVhI1uxEFlV0MS1LCPXLyMgFq+jpvP v9TQ60vfd+ef/hRNr4JVaZ+ja/lWc5wmohuDe8raMmLqQoWHgB5OPr8OM4ANwwDXCUPz EVgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vE1AA7fU; spf=pass (google.com: domain of linux-kernel+bounces-23355-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23355-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q11-20020a170902b10b00b001d3f1b7685esi705558plr.547.2024.01.11.02.03.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 02:03:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23355-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vE1AA7fU; spf=pass (google.com: domain of linux-kernel+bounces-23355-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23355-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 77A4DB2187A for ; Thu, 11 Jan 2024 10:03:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BD1112E56; Thu, 11 Jan 2024 10:03:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="vE1AA7fU" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD22B12E47; Thu, 11 Jan 2024 10:03:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE793C433C7; Thu, 11 Jan 2024 10:03:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1704967397; bh=XKju82+bUIQUC2/IEKI3rWnSmsS5G+w7eqtJG86hh90=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vE1AA7fUthH45yZcRUBa4OzJIYWGm2k2UED9/2miba5n74LCLpqMXf3CcA56sdNwd RIjFQwZwSuqpk/s6FCLAQSGE9bEsCRc9uq0drr43QB+1NTB5heMTEzweqs+s0U1WMV INM5Zrvf1NpL4bcpYm9UnSqoHRliv8nfYP8xIl50= Date: Thu, 11 Jan 2024 11:03:14 +0100 From: Greg KH To: Kunwu Chan Cc: joel@jms.id.au, andrew@codeconstruct.com.au, andriy.shevchenko@linux.intel.com, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kunwu.chan@hotmail.com, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: gadget: aspeed: Check return value of kasprintf in ast_vhub_alloc_epn Message-ID: <2024011132-gigolo-cornmeal-844f@gregkh> References: <20231122014212.304254-1-chentao@kylinos.cn> <2023112236-bullseye-pranker-491e@gregkh> <346b631c-8b46-4b41-9188-8cbaaa1ff178@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <346b631c-8b46-4b41-9188-8cbaaa1ff178@kylinos.cn> On Thu, Jan 11, 2024 at 05:31:35PM +0800, Kunwu Chan wrote: > Sorry, I didn't find out about this email until now because it was > intercepted by my company's email server. > > On 2023/11/22 20:10, Greg KH wrote: > > On Wed, Nov 22, 2023 at 09:42:12AM +0800, Kunwu Chan wrote: > > > kasprintf() returns a pointer to dynamically allocated memory > > > which can be NULL upon failure. Ensure the allocation was successful > > > by checking the pointer validity. > > > > > > Signed-off-by: Kunwu Chan > > > --- > > > drivers/usb/gadget/udc/aspeed-vhub/epn.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/drivers/usb/gadget/udc/aspeed-vhub/epn.c b/drivers/usb/gadget/udc/aspeed-vhub/epn.c > > > index 148d7ec3ebf4..e0854e878411 100644 > > > --- a/drivers/usb/gadget/udc/aspeed-vhub/epn.c > > > +++ b/drivers/usb/gadget/udc/aspeed-vhub/epn.c > > > @@ -826,6 +826,8 @@ struct ast_vhub_ep *ast_vhub_alloc_epn(struct ast_vhub_dev *d, u8 addr) > > > ep->vhub = vhub; > > > ep->ep.ops = &ast_vhub_epn_ops; > > > ep->ep.name = kasprintf(GFP_KERNEL, "ep%d", addr); > > > + if (!ep->ep.name) > > > + return NULL; > > > > This will break things if this ever triggers. How was this tested? The > It's my fault, I think it's too simplistic. Compiled test only. > Cause I don't know how to test effectively. I didn't find a way to test this > in 'Documentation/usb/gadget-testing.rst'. > > "slot" for this device will still be seen as used and so the resources > > never freed and then you can run out of space for real devices, right? > > > > Looks like the other error handling in this function below this call is > > also broken, can you fix that up too?Yes, after reading the relevant code, I found that this is indeed a problem. > So I write the v2 patch below, but the same question bothering me, about how > to test effectively and what hardware equipment is needed? I'm new to this > area, do you have any suggestions? That is up to you, but you need to test stuff like this if you wish to change it as your previous patch obviously would have broken things. good luck! greg k-h