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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACF61C61DA3 for ; Fri, 24 Feb 2023 11:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230082AbjBXLIO (ORCPT ); Fri, 24 Feb 2023 06:08:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbjBXLHq (ORCPT ); Fri, 24 Feb 2023 06:07:46 -0500 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2AA8448A; Fri, 24 Feb 2023 03:06:15 -0800 (PST) Received: by mail-pg1-x535.google.com with SMTP id bn17so1691808pgb.10; Fri, 24 Feb 2023 03:06:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=F5kh1fzvUgUk/w1qLsxSxKG9Kl1fSNnNnBOIZOF4L7I=; b=WHBcrjNROiRHnYaDmxtq5sA1nFH8Bz5pluH7c+KV+iml30dLeMmLhRgwndHtgvhn4q j/aLvAo0qGL6lkhr6FzY2SwLNtnIoPhe6gAN3Y1yzBmb4LWdyZV3zpARtgj7vs3kRBpQ rRNFYQUaa2AiFqJzR2pFMAs1JHayazuJeops4W9XiMoEH8owevSoYVjQhYuRJF1xd9RR jT7IcPUspt1BhOEvK77XMN4vyFT+FuuhGweOZIEiCKDJP4W+pfryBCWXAetj9ILnlZDk 56RpxxyjVdB8/OtTYLnx3aWE/+votCpEVvRK9vX/ZVmXa8u7ba8/wl87w3kvjUTs3E5F qTmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=F5kh1fzvUgUk/w1qLsxSxKG9Kl1fSNnNnBOIZOF4L7I=; b=NYXaI4e1+bP2AYqivH4n7cG0agJNBYQxAxvq1Lf1Fc5FHR5appFJ2QgJxJ9qCjqHPu tauJNtQqiqPCbDVTNVg/eSi8LrLAtshJmsxm92xgihfBHAcaObA8lLHyg5tFSiQng+/W exuz5gs2VWwfv/vf3/kzaA97O+Yhgjxh1e7cF3D+ksnZd+ZN9VVh5GWi2UXVLrC+cTgc ve54D24cfW8lBMCadSeYVbvhPM46PgyS9PG5rAuRF4h4Du6M9fXRTbcquRqCvjeie0gc i/AibWAy7RtP6TokLx2Q9brI1dW2XYqgga/ko9iv8E4A9HBTNzrvCv6uEcSH7NcwYCKm OAVg== X-Gm-Message-State: AO0yUKVOL5cHuDzzh0ccu2HGzCDGZVm+Yr1WL19cz7z7WUguqAnyxDBx LBA+dopsmfnlQPxP0lqspgl+qaZoXPvZav3+qfnhXZzZ+pWadw2lsVk= X-Google-Smtp-Source: AK7set+e+TsRwRrzJh5Bc2e6/7zacw4W3BBD+1YIP0OY61aC9aEfrQT4F0JhVm0U1yHDLsuoReiVriaBzQ+ADmFReUY= X-Received: by 2002:a63:3687:0:b0:4fb:a28e:fa50 with SMTP id d129-20020a633687000000b004fba28efa50mr2743073pga.8.1677236775261; Fri, 24 Feb 2023 03:06:15 -0800 (PST) MIME-Version: 1.0 References: <20230224092044.3332374-1-void0red@gmail.com> In-Reply-To: <20230224092044.3332374-1-void0red@gmail.com> From: Dongliang Mu Date: Fri, 24 Feb 2023 19:03:27 +0800 Message-ID: Subject: Re: [PATCH] usb: gadget: udc: add return value check of kzalloc in mv_udc_probe To: void0red Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 24, 2023 at 5:28 PM void0red wrote: > > From: Kang Chen > > Even an 8-byte kzalloc will fail when we don't have enough memory, > so we need a nullptr check and do the cleanup when it fails. > > Reported-by: eriri <1527030098@qq.com> > Link: https://bugzilla.kernel.org/show_bug.cgi?id=217081 > > Signed-off-by: Kang Chen > --- > drivers/usb/gadget/udc/mv_udc_core.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/usb/gadget/udc/mv_udc_core.c b/drivers/usb/gadget/udc/mv_udc_core.c > index b397f3a84..6dd6d52de 100644 > --- a/drivers/usb/gadget/udc/mv_udc_core.c > +++ b/drivers/usb/gadget/udc/mv_udc_core.c > @@ -2230,6 +2230,10 @@ static int mv_udc_probe(struct platform_device *pdev) > > /* allocate a small amount of memory to get valid address */ > udc->status_req->req.buf = kzalloc(8, GFP_KERNEL); Hi Kang and gregkh, I think there is a memory leak in this kzalloc. It seems there is no deallocation for this allocated object. As the surrounding allocation statements suggest, we should turn kzalloc to devm_kzalloc. > + if (!udc->status_req->req.buf) { > + retval = -ENOMEM; > + goto err_destroy_dma; > + } > udc->status_req->req.dma = DMA_ADDR_INVALID; > > udc->resume_state = USB_STATE_NOTATTACHED; > -- > 2.34.1 >