linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers: fix a memory leak
@ 2019-11-07 19:36 wu000273
  2019-11-08 14:47 ` Arnd Bergmann
  2019-11-09 13:08 ` kbuild test robot
  0 siblings, 2 replies; 3+ messages in thread
From: wu000273 @ 2019-11-07 19:36 UTC (permalink / raw)
  To: airlied; +Cc: arnd, gregkh, linux-kernel, wu000273

From: Qiushi Wu <wu000273@umn.edu>

In intel_gtt_setup_scratch_page(), "page" is not released if
pci_dma_mapping_error() return errors. This will lead to memory leak.
Fix this issue by freeing "page" before return.

Signed-off-by: Qiushi Wu <wu000273@umn.edu>
---
 drivers/char/agp/intel-gtt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c
index c6271ce250b3..bd38b179157c 100644
--- a/drivers/char/agp/intel-gtt.c
+++ b/drivers/char/agp/intel-gtt.c
@@ -304,8 +304,10 @@ static int intel_gtt_setup_scratch_page(void)
 	if (intel_private.needs_dmar) {
 		dma_addr = pci_map_page(intel_private.pcidev, page, 0,
 				    PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
-		if (pci_dma_mapping_error(intel_private.pcidev, dma_addr))
+		if (pci_dma_mapping_error(intel_private.pcidev, dma_addr)) {
+			__free_pages(page);
 			return -EINVAL;
+		}
 
 		intel_private.scratch_page_dma = dma_addr;
 	} else
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drivers: fix a memory leak
  2019-11-07 19:36 [PATCH] drivers: fix a memory leak wu000273
@ 2019-11-08 14:47 ` Arnd Bergmann
  2019-11-09 13:08 ` kbuild test robot
  1 sibling, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2019-11-08 14:47 UTC (permalink / raw)
  To: wu000273; +Cc: David Airlie, gregkh, linux-kernel

On Thu, Nov 7, 2019 at 8:37 PM <wu000273@umn.edu> wrote:
>
> From: Qiushi Wu <wu000273@umn.edu>
>
> In intel_gtt_setup_scratch_page(), "page" is not released if
> pci_dma_mapping_error() return errors. This will lead to memory leak.
> Fix this issue by freeing "page" before return.
>
> Signed-off-by: Qiushi Wu <wu000273@umn.edu>

Reviewed-by: Arnd Bergmann <arnd@arndb.de>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drivers: fix a memory leak
  2019-11-07 19:36 [PATCH] drivers: fix a memory leak wu000273
  2019-11-08 14:47 ` Arnd Bergmann
@ 2019-11-09 13:08 ` kbuild test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kbuild test robot @ 2019-11-09 13:08 UTC (permalink / raw)
  To: wu000273; +Cc: kbuild-all, airlied, arnd, gregkh, linux-kernel, wu000273

[-- Attachment #1: Type: text/plain, Size: 2538 bytes --]

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on v5.4-rc6 next-20191108]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/wu000273-umn-edu/drivers-fix-a-memory-leak/20191109-191819
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git bce92136c28f3ae9ddbbac0ee7c0df2eb0ae0bef
config: x86_64-rhel (attached as .config)
compiler: gcc-7 (Debian 7.4.0-14) 7.4.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/char/agp/intel-gtt.c: In function 'intel_gtt_setup_scratch_page':
>> drivers/char/agp/intel-gtt.c:308:4: error: too few arguments to function '__free_pages'
       __free_pages(page);
       ^~~~~~~~~~~~
   In file included from include/linux/umh.h:4:0,
                    from include/linux/kmod.h:9,
                    from include/linux/module.h:13,
                    from drivers/char/agp/intel-gtt.c:18:
   include/linux/gfp.h:543:13: note: declared here
    extern void __free_pages(struct page *page, unsigned int order);
                ^~~~~~~~~~~~

vim +/__free_pages +308 drivers/char/agp/intel-gtt.c

   293	
   294	static int intel_gtt_setup_scratch_page(void)
   295	{
   296		struct page *page;
   297		dma_addr_t dma_addr;
   298	
   299		page = alloc_page(GFP_KERNEL | GFP_DMA32 | __GFP_ZERO);
   300		if (page == NULL)
   301			return -ENOMEM;
   302		set_pages_uc(page, 1);
   303	
   304		if (intel_private.needs_dmar) {
   305			dma_addr = pci_map_page(intel_private.pcidev, page, 0,
   306					    PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
   307			if (pci_dma_mapping_error(intel_private.pcidev, dma_addr)) {
 > 308				__free_pages(page);
   309				return -EINVAL;
   310			}
   311	
   312			intel_private.scratch_page_dma = dma_addr;
   313		} else
   314			intel_private.scratch_page_dma = page_to_phys(page);
   315	
   316		intel_private.scratch_page = page;
   317	
   318		return 0;
   319	}
   320	

---
0-DAY kernel test infrastructure                 Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 43712 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-09 13:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-07 19:36 [PATCH] drivers: fix a memory leak wu000273
2019-11-08 14:47 ` Arnd Bergmann
2019-11-09 13:08 ` kbuild test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).