From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753215AbbJMQgS (ORCPT ); Tue, 13 Oct 2015 12:36:18 -0400 Received: from mga09.intel.com ([134.134.136.24]:49178 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753128AbbJMQgR (ORCPT ); Tue, 13 Oct 2015 12:36:17 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,678,1437462000"; d="scan'208";a="825760987" Subject: Re: [PATCH] misc: mic: fix memory leak From: Sudeep Dutt To: Sudip Mukherjee Cc: Sudeep Dutt , Greg Kroah-Hartman , linux-kernel@vger.kernel.org In-Reply-To: <1444727291-4681-1-git-send-email-sudipm.mukherjee@gmail.com> References: <1444727291-4681-1-git-send-email-sudipm.mukherjee@gmail.com> Content-Type: text/plain; charset="UTF-8" Date: Tue, 13 Oct 2015 09:34:21 -0700 Message-ID: <1444754061.93285.246.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 (2.28.3-30.el6) Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2015-10-13 at 14:38 +0530, Sudip Mukherjee wrote: > In scif_node_connect() we were returning if the initialization of p2p_ji > fails. But at that time p2p_ij has already been initialized and > resources allocated for it. And since p2p_ij is not added to the list > till now so we will have a leak. > Lets deinitialize and release the resources connected to p2p_ij. > > Signed-off-by: Sudip Mukherjee > --- > > One sudip sending patch to another sudeep... :) > > drivers/misc/mic/scif/scif_nodeqp.c | 16 +++++++++++++++- > 1 file changed, 15 insertions(+), 1 deletion(-) > > diff --git a/drivers/misc/mic/scif/scif_nodeqp.c b/drivers/misc/mic/scif/scif_nodeqp.c > index 7180d56..5e94fac 100644 > --- a/drivers/misc/mic/scif/scif_nodeqp.c > +++ b/drivers/misc/mic/scif/scif_nodeqp.c > @@ -435,6 +435,18 @@ free_p2p: > return NULL; > } > > +/* Uninitialize and release resources from a p2p mapping */ > +void scif_deinit_p2p_info(struct scif_dev *scifdev, struct scif_p2p_info *p2p) > +{ > + struct scif_hw_dev *sdev = scifdev->sdev; > + > + dma_unmap_sg(&sdev->dev, p2p->ppi_sg[SCIF_PPI_MMIO], > + p2p->sg_nentries[SCIF_PPI_MMIO], DMA_BIDIRECTIONAL); Hi Sudip, You missed unmapping the aperture here: dma_unmap_sg(&sdev->dev, p2p->ppi_sg[SCIF_PPI_APER], p2p->sg_nentries[SCIF_PPI_APER], DMA_BIDIRECTIONAL); Can you please resubmit this patch with the change above? Also you should mention [PATCH char-misc-next] in the next revision. Thanks for the fix! Sudeep Dutt > + scif_p2p_freesg(p2p->ppi_sg[SCIF_PPI_MMIO]); > + scif_p2p_freesg(p2p->ppi_sg[SCIF_PPI_APER]); > + kfree(p2p); > +} > + > /** > * scif_node_connect: Respond to SCIF_NODE_CONNECT interrupt message > * @dst: Destination node > @@ -477,8 +489,10 @@ static void scif_node_connect(struct scif_dev *scifdev, int dst) > if (!p2p_ij) > return; > p2p_ji = scif_init_p2p_info(dev_j, dev_i); > - if (!p2p_ji) > + if (!p2p_ji) { > + scif_deinit_p2p_info(dev_i, p2p_ij); > return; > + } > list_add_tail(&p2p_ij->ppi_list, &dev_i->p2p); > list_add_tail(&p2p_ji->ppi_list, &dev_j->p2p); >