Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2484834imu; Thu, 29 Nov 2018 05:52:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/UfAA7o3IWUCL3B6QZU+iThyVgFFH+nIXasGoOxdFXTFAF5lXor8GSRxZ/KhZtej6MRQhO1 X-Received: by 2002:a63:9306:: with SMTP id b6mr1271487pge.36.1543499547088; Thu, 29 Nov 2018 05:52:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543499547; cv=none; d=google.com; s=arc-20160816; b=doXjrUObkpupb+NQs3E+Bv6JI6/WY7XjaI8to411rP1jKb9dNGFIUomeO7N4UmH0PG nqCIHi3ADY2DIU0RJvtp5Y98f8lnIXLiqQnLClFlUOP0QJyFacZKbABhg59TCTv90QeR bfqgwg+osSWgd71Iwc5zHrq/Ahe8MRKJGigN12FfdRhtIitfyMJx6yaIpUPTHdsyKpcY 1JfAn+J20gUZsqN2DmcYxxgIes9k+1CrN/OyjiKC479SWEjnjQUZC9+SjE/v/nDOInmQ 3w47dMwGliIakWVFnuJDNiEN5kS+3s5cZPrbdjCpOogeMNzor2PB/vZ0eFtI0mkxmoNj ciQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date; bh=5XZU9Td3wKOO/O9G3RYvYBDQ2Dl6yvS6lKITnJH1i7s=; b=Ycx3W6dkPcoW/AtVpBvjixSRsRWrPSKWTsJ1EMOZh/5w9KWVxuH7w9e5xtamAKzYYL Urhxi7V5h/PwpzVhVKcqPIVPE9iibRtgqPotexH/Upv07G/87lmMYpKBlFmPZHzBgfTT ecg0CLrEyB9BTfpyI16Z/vqsf3xtChkZ0lXOdJhnFviCcavg/PdjKJjVd/xzWZGeywfN M3iS22y7Mqhua6PL4jODEtA/qzs/FNnu8/c4Q3GUtQvC5CkC3il+yCHmSvfSC1iMG2ri GRdvMUpopvmpBhsemX5gHeHiLFvQzlLIigEEj7Gke3g6jYQXLtnwfkhGyRRMf7mp2zG8 UdZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g2si2028284pgk.497.2018.11.29.05.52.12; Thu, 29 Nov 2018 05:52:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728272AbeK3A46 (ORCPT + 99 others); Thu, 29 Nov 2018 19:56:58 -0500 Received: from esa1.microchip.iphmx.com ([68.232.147.91]:50912 "EHLO esa1.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726949AbeK3A46 (ORCPT ); Thu, 29 Nov 2018 19:56:58 -0500 X-IronPort-AV: E=Sophos;i="5.56,294,1539673200"; d="scan'208";a="24655063" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 29 Nov 2018 06:51:32 -0700 Received: from localhost (10.10.76.4) by chn-sv-exch06.mchp-main.com (10.10.76.107) with Microsoft SMTP Server id 14.3.352.0; Thu, 29 Nov 2018 06:51:31 -0700 Date: Thu, 29 Nov 2018 14:51:24 +0100 From: Ludovic Desroches To: Richard Genoud CC: Dan Williams , Vinod Koul , Alexandre Belloni , Nicolas Ferre , Maxime Ripard , Mario Forner , , , , , Subject: Re: [PATCH] dmaengine: at_hdmac: fix memory leak in at_dma_xlate() Message-ID: <20181129135124.qyz6avwqidk7dfyu@M43218.corp.atmel.com> Mail-Followup-To: Richard Genoud , Dan Williams , Vinod Koul , Alexandre Belloni , Nicolas Ferre , Maxime Ripard , Mario Forner , linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, stable@vger.kernel.org References: <20181127160635.11836-1-richard.genoud@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20181127160635.11836-1-richard.genoud@gmail.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 27, 2018 at 05:06:34PM +0100, Richard Genoud wrote: > The leak was found when opening/closing a serial port a great number of > time, increasing kmalloc-32 in slabinfo. > > Each time the port was opened, dma_request_slave_channel() was called. > Then, in at_dma_xlate(), atslave was allocated with devm_kzalloc() and > never freed. (Well, it was free at module unload, but that's not what we > want). > So, here, kzalloc is more suited for the job since it has to be freed in > atc_free_chan_resources(). > > Cc: stable@vger.kernel.org > Fixes: bbe89c8e3d59 ("at_hdmac: move to generic DMA binding") > Reported-by: Mario Forner > Suggested-by: Alexandre Belloni > Acked-by: Alexandre Belloni > Signed-off-by: Richard Genoud Acked-by: Ludovic Desroches Thanks for handling this issue. Ludovic > --- > drivers/dma/at_hdmac.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c > index 7cbac6e8c113..1b7f0ca0d5cd 100644 > --- a/drivers/dma/at_hdmac.c > +++ b/drivers/dma/at_hdmac.c > @@ -1641,6 +1641,12 @@ static void atc_free_chan_resources(struct dma_chan *chan) > atchan->descs_allocated = 0; > atchan->status = 0; > > + /* > + * Free atslave allocated in at_dma_xlate() > + */ > + kfree(chan->private); > + chan->private = NULL; > + > dev_vdbg(chan2dev(chan), "free_chan_resources: done\n"); > } > > @@ -1675,7 +1681,7 @@ static struct dma_chan *at_dma_xlate(struct of_phandle_args *dma_spec, > dma_cap_zero(mask); > dma_cap_set(DMA_SLAVE, mask); > > - atslave = devm_kzalloc(&dmac_pdev->dev, sizeof(*atslave), GFP_KERNEL); > + atslave = kzalloc(sizeof(*atslave), GFP_KERNEL); > if (!atslave) > return NULL; >