From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 74587C4707B for ; Thu, 11 Jan 2024 10:03:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Rk4qCpbKdjF0LUiYZ1Vr8t8OcEt5meSzBVrjveuS7V0=; b=EXJ0aai7IXdCZG yZt7CSnzsQ437Mx2tcgkZw6WtsECpM4mJrqP2qMGuLwg6lhRy/xMdPCNbjWoohVjATvImXJSYiGmo D1m7gq+Wf1sgqoVcyrVXO2qlTtelFpoHCESWk0uLhQ5nkAZGcAt/rh068lANyt5YphzLB0jFruaxo haaFBxaLKe2YK/g9l2AENz/dHjAyefdnATP4t6K33LPCGNbuc/SjncoBYfVJ5knhqThb1p+JVfbFp 0RXHHFQdugTdlDuw/U2wKrV3IbBH5d9TlPPop1ILxjSA07UsyZMICbsVrxs/hkwUQEEuHl++ILtU1 K07zuuyJYL9YBRG7GovQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rNruE-00Gthx-33; Thu, 11 Jan 2024 10:03:22 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rNruB-00Gtgp-23 for linux-arm-kernel@lists.infradead.org; Thu, 11 Jan 2024 10:03:21 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id E0CC4CE1DA0; 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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <346b631c-8b46-4b41-9188-8cbaaa1ff178@kylinos.cn> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240111_020319_843957_F7C2B11C X-CRM114-Status: GOOD ( 27.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel