Skip to content

Commit 1a485f4

Browse files
Shanker DonthineniKAGA-KOKO
authored andcommitted
irqchip/gicv3-its: Fix memory leak in its_free_tables()
The current ITS driver has a memory leak in its_free_tables(). It happens on tear down path of the driver when its_probe() call fails. its_free_tables() should free the exact number of pages that have been allocated, not just a single page as current code does. This patch records the memory size for each ITS_BASERn at the time of page allocation and uses the same size information when freeing pages to fix the issue. Signed-off-by: Shanker Donthineni <shankerd@codeaurora.org> Acked-by: Marc Zyngier <marc.zyngier@arm.com> Cc: Jason Cooper <jason@lakedaemon.net> Cc: Vikram Sethi <vikrams@codeaurora.org> Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/1454379584-21772-1-git-send-email-shankerd@codeaurora.org Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 6235f0e commit 1a485f4

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

drivers/irqchip/irq-gic-v3-its.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ struct its_node {
6666
unsigned long phys_base;
6767
struct its_cmd_block *cmd_base;
6868
struct its_cmd_block *cmd_write;
69-
void *tables[GITS_BASER_NR_REGS];
69+
struct {
70+
void *base;
71+
u32 order;
72+
} tables[GITS_BASER_NR_REGS];
7073
struct its_collection *collections;
7174
struct list_head its_device_list;
7275
u64 flags;
@@ -807,9 +810,10 @@ static void its_free_tables(struct its_node *its)
807810
int i;
808811

809812
for (i = 0; i < GITS_BASER_NR_REGS; i++) {
810-
if (its->tables[i]) {
811-
free_page((unsigned long)its->tables[i]);
812-
its->tables[i] = NULL;
813+
if (its->tables[i].base) {
814+
free_pages((unsigned long)its->tables[i].base,
815+
its->tables[i].order);
816+
its->tables[i].base = NULL;
813817
}
814818
}
815819
}
@@ -890,7 +894,8 @@ static int its_alloc_tables(const char *node_name, struct its_node *its)
890894
goto out_free;
891895
}
892896

893-
its->tables[i] = base;
897+
its->tables[i].base = base;
898+
its->tables[i].order = order;
894899

895900
retry_baser:
896901
val = (virt_to_phys(base) |
@@ -940,7 +945,7 @@ static int its_alloc_tables(const char *node_name, struct its_node *its)
940945
* something is horribly wrong...
941946
*/
942947
free_pages((unsigned long)base, order);
943-
its->tables[i] = NULL;
948+
its->tables[i].base = NULL;
944949

945950
switch (psz) {
946951
case SZ_16K:

0 commit comments

Comments
 (0)