From patchwork Tue Nov 27 16:06:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Genoud X-Patchwork-Id: 10700755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 854D113AD for ; Tue, 27 Nov 2018 16:07:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 719282BE40 for ; Tue, 27 Nov 2018 16:07:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6509C2BE51; Tue, 27 Nov 2018 16:07:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 17A222BD41 for ; Tue, 27 Nov 2018 16:07:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=ZeWQHsmo4z7nHXBE3VK7Vzq1lf/oHK8fWfJUUIR09eI=; b=f1z8dD7CAVPMbq IGIKgYin9IRnh43XYLS58i5OdsaR28ziajY8kc0aW67RkABmGRtnGZRjjrotJUEZf88x33hOzw3zw bLFRQXyfXE2YTpfs6b5CQ19JE/bM7Nk6xRcofNEOpns+z8hZI35fSgi9lPzwPlnEIltB+KHco60sA bEUe0Iq/ziqg/3BQCz1Q3Mz1h+fnWErU0s+gyyfT4FzewKjStHZhS0k7Ld57sP8Yljqbf9UpdW7WG JasUPHoZ5heok5Y2Oqb04YTe9A5Ls8nADHQngKGmbRMU63OoQ+1XcLyrvKNz5HMncvxf3pO6qQiR4 HzPqVmpgpPugVpPV5lyw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gRfta-0007p7-C8; Tue, 27 Nov 2018 16:07:30 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gRftX-0007o6-Aq for linux-arm-kernel@lists.infradead.org; Tue, 27 Nov 2018 16:07:28 +0000 Received: by mail-wm1-x342.google.com with SMTP id c126so22724868wmh.0 for ; Tue, 27 Nov 2018 08:07:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1aMIj/Q4ZGhEQ80o3lPWygUgt+NmhvvS1EeJN+XmZJ4=; b=aOs7mb9vtWTKj/MiyL7700eVFTAM5PI3YJh5NDWz5ZOPgpq2KZbdXKuoP17m4HduWb Jj5Cqk8L+PuP7pPwUr0oXA9yIODyApx6T3N+AljPH1/KEyiQLa526uV8KPySYbna6wsb SEQtXJYVFMzVPwaMeRbwK4IXddHXtzJFPZy2+vpe0DiHq2DDTVJSM/hmhydPIygL2JjX 37p9Hmse1t9lkVh/7ZwXHxLBIYyD4TCL7T3yHsBAF10WlcGqSbCOjhvphPMzu4fOoMyk ZJYMooGekf9fVw5ACTDZtsEu6nJhvDIU0XeZQa6g9fvqvobbbxs2IPN3mhJM8yslJ+dB sXHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1aMIj/Q4ZGhEQ80o3lPWygUgt+NmhvvS1EeJN+XmZJ4=; b=Eza0gxWPnxnWg4Qfc+YGxvG7lfb8XHXQdQKJU+R6Qmke8WpLdCsiP9/9oUVysgLh9q pY1Rnv1yzYe5dQkgSoCKOqdT1HT8quelyt8dOhghy9A3if3vWiAtSRUfGcD194JuNaGn N7caRbfL/ClBMlNTxtcGzmhXBvQjd+1sqfAA1IquNsEX1jiQ1W2jMF3dXqC8pUSU+q6P hOS28RaZJP5aRBYdSEZDlw5bTilDHQlEJfSk0vmbFYnEb8K+mf4j1yJdt9+LxqtOoysJ xl7zVph1PX7IOwBtmkWF1P2dUIHDIz+lnodmkl6i3gdK8biJY3yTDJUaJ8I4IAP24Q9h ovDw== X-Gm-Message-State: AA+aEWbDxIh5EjwfekzUHBykr/s2Y1uquAc4HsfDQm5ZBMUHkeg/NfFW qqk8VarRrWVFZBIbCDyHr/c= X-Google-Smtp-Source: AFSGD/XZ18KWxcQaGfVtJlAORnHTsWdXEq6Vhmnn9zJnEhHWCwh7qQgyimTxBr3B2V2lGqB7caYd5A== X-Received: by 2002:a7b:ca53:: with SMTP id m19mr26448805wml.102.1543334834780; Tue, 27 Nov 2018 08:07:14 -0800 (PST) Received: from localhost ([46.227.18.67]) by smtp.gmail.com with ESMTPSA id x136sm5724249wme.0.2018.11.27.08.07.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Nov 2018 08:07:13 -0800 (PST) From: Richard Genoud To: Ludovic Desroches , Dan Williams , Vinod Koul Subject: [PATCH] dmaengine: at_hdmac: fix memory leak in at_dma_xlate() Date: Tue, 27 Nov 2018 17:06:34 +0100 Message-Id: <20181127160635.11836-1-richard.genoud@gmail.com> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181127_080727_408021_3C9C1A9B X-CRM114-Status: GOOD ( 14.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Mario Forner , Maxime Ripard , stable@vger.kernel.org, linux-kernel@vger.kernel.org, Richard Genoud , linux-serial@vger.kernel.org, dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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;