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 577D8C4332F for ; Sun, 20 Nov 2022 11:50:41 +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-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-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=oZv6JxadSBsJmOjOnW4SDDSjuhgHSVZDwGr664b5aTc=; b=acf0h4brSB6T5U6ZPFgTgjMLlg YEPA79egfvCoRw1B16CN4zUeqBbSRSzv/r2WqbC68usckDKZzWO2Kie6ZfJdfHkZxaT/cu9K3E3Jg JNmlocdk0vFL8ly19L68uzeZlMcB3L7jvBMY0kN+dublOxDFl2U2OJEE7dn7iI4v7lbWFq7kWUs12 SvjsjQ7R9N6Z8HKjDjM08q9A1oIRS2SRy00E8F6KsLjpI+qg0G4GvSh7frCHtAjlkGswyalGJpmJJ DYQHUyDmbBLw0P9+dEynDO4roWWtCe+N0oS77aQsEBT0HLm8xVazjDO9Fuyax1btLudigtcY7I8vu Kp2/zf3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1owip0-00456k-Lh; Sun, 20 Nov 2022 11:49:14 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1owiox-00452K-Qm for linux-arm-kernel@lists.infradead.org; Sun, 20 Nov 2022 11:49:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668944949; 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=P4PHhxhfygJuIAicsT4vorWcFjQ4lei9JIrcunAPzDg0fsGOSiSQ1y5bPs0jJ+35anlT5D /y1QUGkXl0ulVuWrwiJovNnPCUxjsalz7UGG33kjnLycuhcscm99z23+qNuCCKoviOjTaK vS5I7pcWnn58+iBHsNBsHtjbLDf4mrA= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-575-k_ERFzCmNQKTX8lp4zI5TA-1; Sun, 20 Nov 2022 06:49:05 -0500 X-MC-Unique: k_ERFzCmNQKTX8lp4zI5TA-1 Received: by mail-wr1-f72.google.com with SMTP id m17-20020adfa3d1000000b00241cbfd296eso395031wrb.15 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=WpMvZHLqW9lWldP4a7V9njTOVFivByilnALPgp1fZijBnDM4fGQQrzB+v7fUgOy7CZ dYqvpyBMMrJdhVc/XDEH8BKciTTxRinDKxyXu6ZCpLjylV0Ysbf798e9bpVPwXSsoecm 85I5Y2bWg1GnjX0yhwjWCyk1ouys8wzF2vnVCNYquc4eG8qcOI8qAgt7Gu7IUgbU5G4q PfcAw3R4RhRDAgi1qH53BwB2/CMv0LGW3/TTBzThtXUJvnxO2etWeIWGgk8f+PqKt4kJ RaAoxMf4PP7jK84j3SCJ2mJdOWoLxfrtaqiBUDtCZAcoTcjvd0xovNVtVQsKs7sVbqfC ffNA== X-Gm-Message-State: ANoB5pnQHz0VxDJ6co76KgxxPksjGu34xeKQQFwshZi69cIZO1ispPZr maMkiOPI2QEPQtRXHqvv7Vxbs4CIo9vnilEdLzTDGi7XuZCBWSqEQD74+92/jpUzv9SfC0yY9zD pADFqOCSXMxVVkEIv1CYsk7CqnGc7l3K5aGw= X-Received: by 2002:adf:f74d:0:b0:236:4e3c:7720 with SMTP id z13-20020adff74d000000b002364e3c7720mr8545081wrp.674.1668944944672; Sun, 20 Nov 2022 03:49:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf7udSW6/pfqawh/yYUkdpdhzbG5vE8EEGEBnisT1ahzb5hGEDLmfhdqECpSPgvVpZoIghYixw== 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 In-Reply-To: <20221120035405.1464341-1-william.xuanziyang@huawei.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221120_034911_969276_F8C589F2 X-CRM114-Status: GOOD ( 19.35 ) 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: multipart/mixed; boundary="===============2199399993842357446==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============2199399993842357446== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Mg3mLB7M7b1XKZaD" Content-Disposition: inline --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-- --===============2199399993842357446== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============2199399993842357446==--