浏览代码

[AGPGART] Prevent (unlikely) memory leak in amd_create_gatt_pages()

If we fail an alloc, unwind the previous allocs that succeeded.

Spotted-by: Alan Grimes <agrimes@speakeasy.net>
Signed-off-by: Dave Jones <davej@redhat.com>
Dave Jones 18 年之前
父节点
当前提交
c30efbaeaa
共有 1 个文件被更改,包括 5 次插入0 次删除
  1. 5 0
      drivers/char/agp/amd-k7-agp.c

+ 5 - 0
drivers/char/agp/amd-k7-agp.c

@@ -101,6 +101,11 @@ static int amd_create_gatt_pages(int nr_tables)
 	for (i = 0; i < nr_tables; i++) {
 		entry = kzalloc(sizeof(struct amd_page_map), GFP_KERNEL);
 		if (entry == NULL) {
+			while (i > 0) {
+				kfree(tables[i-1]);
+				i--;
+			}
+			kfree(tables);
 			retval = -ENOMEM;
 			break;
 		}