Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

misc: mic: fix memory leak

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 <sudip@vectorindia.org>
Reviewed-by: Sudeep Dutt <sudeep.dutt@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Sudip Mukherjee and committed by
Greg Kroah-Hartman
a2a47d00 82ff3ac7

+18 -1
+18 -1
drivers/misc/mic/scif/scif_nodeqp.c
··· 435 435 return NULL; 436 436 } 437 437 438 + /* Uninitialize and release resources from a p2p mapping */ 439 + static void scif_deinit_p2p_info(struct scif_dev *scifdev, 440 + struct scif_p2p_info *p2p) 441 + { 442 + struct scif_hw_dev *sdev = scifdev->sdev; 443 + 444 + dma_unmap_sg(&sdev->dev, p2p->ppi_sg[SCIF_PPI_MMIO], 445 + p2p->sg_nentries[SCIF_PPI_MMIO], DMA_BIDIRECTIONAL); 446 + dma_unmap_sg(&sdev->dev, p2p->ppi_sg[SCIF_PPI_APER], 447 + p2p->sg_nentries[SCIF_PPI_APER], DMA_BIDIRECTIONAL); 448 + scif_p2p_freesg(p2p->ppi_sg[SCIF_PPI_MMIO]); 449 + scif_p2p_freesg(p2p->ppi_sg[SCIF_PPI_APER]); 450 + kfree(p2p); 451 + } 452 + 438 453 /** 439 454 * scif_node_connect: Respond to SCIF_NODE_CONNECT interrupt message 440 455 * @dst: Destination node ··· 492 477 if (!p2p_ij) 493 478 return; 494 479 p2p_ji = scif_init_p2p_info(dev_j, dev_i); 495 - if (!p2p_ji) 480 + if (!p2p_ji) { 481 + scif_deinit_p2p_info(dev_i, p2p_ij); 496 482 return; 483 + } 497 484 list_add_tail(&p2p_ij->ppi_list, &dev_i->p2p); 498 485 list_add_tail(&p2p_ji->ppi_list, &dev_j->p2p); 499 486