Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2899832rwb; Sun, 20 Nov 2022 03:58:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf6GruthSkTjACryVYwQgqbZJ0lUgETnW+D8NODvI7UQq6PgW8Z4xzGdv0KE3EFcUjKMuczo X-Received: by 2002:a05:6402:448c:b0:461:7378:3501 with SMTP id er12-20020a056402448c00b0046173783501mr12062890edb.35.1668945485832; Sun, 20 Nov 2022 03:58:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668945485; cv=none; d=google.com; s=arc-20160816; b=Ho85VRIk9VhWYhjogDHp/WBNsxC944VZVkQSW497uDMdAyCrqyZ0Ky5aKAlmsimFC9 hQK1srAlVSK8CoGU2gC2l81ZOly+yanpRybku3BlWNsFAnHlSJcOTwW2Cp7+Cb84ZU+l RdsyVAc0VH6og3jd0v7PEkXSLLpow8j85kk4Lu//mkXqmxonpLCMVwJzaXCMEcHNtJXE B4db/DCUcCN21Xlq2UknMB42QB9T1qty+hJzAGkrpw8ZT+N68Jmfc6/I9fkQ7gGg4ZgH KOG6RYAuAFhB76vuLS11+zlUeJkm79mLESN01qqlCyVysWHGrtbzJjBcqtXeh4pW9P24 Ka8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=eFFRtDG3SnY31rS3/TY9saZ3cpDv+kx8E+R9eiFK10I=; b=d+9toMguwYKaWTClYGRTkRevMF0D/7GOI4NH65qlltzXYSv22RINr20WWa7ZtxAHk3 hAbdslOoD/z0p5RFb4CA6JjOBHmnKzlAE3XCzUQHofQMgRWCZa1JzyYVnFULzDqy+mxV RAAiLMoW0+lOGBcz6dz2AI4WNwWUCGc9IJW2gSDNkyCJahiOhUAzwwJDYA7WPsfPNi/S wpm7dxhPyD/QHCf7IeY4uvKUrikRVPWtXMurJbWWyRqciWdob3fbq9gGewkxhijKSIcT YAREs7eOBxvDOZXGm9SltGjl3nfnVvoSPPZPh4mqk+F+8omx5jtkx47G5qCd/cK3szrP piIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QcMrffzZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xh13-20020a170906da8d00b007ae4c686a4dsi6786877ejb.649.2022.11.20.03.57.42; Sun, 20 Nov 2022 03:58:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QcMrffzZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229680AbiKTLuE (ORCPT + 92 others); Sun, 20 Nov 2022 06:50:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbiKTLuC (ORCPT ); Sun, 20 Nov 2022 06:50:02 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D06CE2870D for ; Sun, 20 Nov 2022 03:49:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668944947; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=eFFRtDG3SnY31rS3/TY9saZ3cpDv+kx8E+R9eiFK10I=; b=QcMrffzZSfwBoEAtK1sberGc+k2aeBzqCBqQuldXlK7gxFKqCUvrmRdXsPX4vHXgUlNRKz jWNWCZtnrZ3TYrFgxbWeXsX5fw59bE/1YaJf5PKfmxtic+aIOKNTdgjC50fYwsI+E9fD0z oYIZkbAni2UrCw/x5kfcfVqaOFL8uLY= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-527-rleWJY-9ORS8eFSQ5deidw-1; Sun, 20 Nov 2022 06:49:05 -0500 X-MC-Unique: rleWJY-9ORS8eFSQ5deidw-1 Received: by mail-wr1-f69.google.com with SMTP id h2-20020adfa4c2000000b00241cf936619so289554wrb.9 for ; Sun, 20 Nov 2022 03:49:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=eFFRtDG3SnY31rS3/TY9saZ3cpDv+kx8E+R9eiFK10I=; b=tSzI7XRl6juDuRixlxHea1Hu+WDtMnDf+NqlPvz9tZHWdY7mkqwd0lUX93I2EiLitJ lyGDvKaaZg1mMSrgwRX9zR8xzWkdnz8PNNX2iygKHbfpVjlMx9pGCBgGIXfinHzY8pC0 sju0RnCe+DdBjMISZs9Y7QNrnb+kiu/bFfSLeU4qdbG65T3ht/qsvDxrDzOzMg7gZMvQ 67FCvCx901+TxB4X/iIOmJu/dR0Tq/BUDUZ6E2Yrgh5fDcxmK6bwVmI0u+TCijfV4MJh 6z3ueHalYd1EKh/1YHS/BdeFoNzM8PGIsE8t62G4XvrimWhjdZflcW4RMXEkLcH9OmvY kDCw== X-Gm-Message-State: ANoB5pnXdOK8jUecjrk5SAtNHV8pXc1MQZlSM3LMzsWWAFkyKIP15tVl nadclDVHIpeOp2L7TDsUYsvDbWL+Fg9CzMq6ujbJ66PVcSwzvEyVzsTod9/Pb+LUsQkzOg8pRuq JX2FHPGxEFc7gzE7Y5AAfydUR X-Received: by 2002:adf:f74d:0:b0:236:4e3c:7720 with SMTP id z13-20020adff74d000000b002364e3c7720mr8545090wrp.674.1668944944703; Sun, 20 Nov 2022 03:49:04 -0800 (PST) X-Received: by 2002:adf:f74d:0:b0:236:4e3c:7720 with SMTP id z13-20020adff74d000000b002364e3c7720mr8545068wrp.674.1668944944420; Sun, 20 Nov 2022 03:49:04 -0800 (PST) Received: from localhost (net-188-216-77-84.cust.vodafonedsl.it. [188.216.77.84]) by smtp.gmail.com with ESMTPSA id t11-20020adff60b000000b0022e035a4e93sm8629318wrp.87.2022.11.20.03.49.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Nov 2022 03:49:03 -0800 (PST) Date: Sun, 20 Nov 2022 12:49:01 +0100 From: Lorenzo Bianconi To: Ziyang Xuan Cc: nbd@nbd.name, john@phrozen.org, sean.wang@mediatek.com, Mark-MC.Lee@mediatek.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, matthias.bgg@gmail.com, linux@armlinux.org.uk, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, lorenzo@kernel.org Subject: Re: [PATCH net] net: ethernet: mtk_eth_soc: fix potential memory leak in mtk_rx_alloc() Message-ID: References: <20221120035405.1464341-1-william.xuanziyang@huawei.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Mg3mLB7M7b1XKZaD" Content-Disposition: inline In-Reply-To: <20221120035405.1464341-1-william.xuanziyang@huawei.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --Mg3mLB7M7b1XKZaD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable > When fail to dma_map_single() in mtk_rx_alloc(), it returns directly. > But the memory allocated for local variable data is not freed, and > local variabel data has not been attached to ring->data[i] yet, so the > memory allocated for local variable data will not be freed outside > mtk_rx_alloc() too. Thus memory leak would occur in this scenario. >=20 > Add skb_free_frag(data) when dma_map_single() failed. >=20 > Fixes: 23233e577ef9 ("net: ethernet: mtk_eth_soc: rely on page_pool for s= ingle page buffers") > Signed-off-by: Ziyang Xuan > --- > drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) Acked-by: Lorenzo Bianconi >=20 > diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/et= hernet/mediatek/mtk_eth_soc.c > index 7cd381530aa4..bc47ef1e4dd5 100644 > --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c > +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c > @@ -2378,8 +2378,10 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int r= ing_no, int rx_flag) > data + NET_SKB_PAD + eth->ip_align, > ring->buf_size, DMA_FROM_DEVICE); > if (unlikely(dma_mapping_error(eth->dma_dev, > - dma_addr))) > + dma_addr))) { > + skb_free_frag(data); > return -ENOMEM; > + } > } > rxd->rxd1 =3D (unsigned int)dma_addr; > ring->data[i] =3D data; > --=20 > 2.25.1 >=20 --Mg3mLB7M7b1XKZaD Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQTquNwa3Txd3rGGn7Y6cBh0uS2trAUCY3oULQAKCRA6cBh0uS2t rB+XAQC1NS342yCNR/mijZECnJw0DZzDUciWxdRU9qpQUcIisAD8C9l7RVkWprf7 ZY5de9YVDFIspT/WErMrTjJIkJRU4g8= =vshG -----END PGP SIGNATURE----- --Mg3mLB7M7b1XKZaD--