Skip to content

Commit 50f05bd

Browse files
mudonglianggregkh
authored andcommitted
ipack: tpci200: fix memory leak in the tpci200_register
The error handling code in tpci200_register does not free interface_regs allocated by ioremap and the current version of error handling code is problematic. Fix this by refactoring the error handling code and free interface_regs when necessary. Fixes: 4398679 ("ipack: add error handling for ioremap_nocache") Cc: [email protected] Reported-by: Dongliang Mu <[email protected]> Signed-off-by: Dongliang Mu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 57a1681 commit 50f05bd

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

drivers/ipack/carriers/tpci200.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ static int tpci200_register(struct tpci200_board *tpci200)
254254
"(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 2 !",
255255
tpci200->info->pdev->bus->number,
256256
tpci200->info->pdev->devfn);
257-
goto out_disable_pci;
257+
goto err_disable_device;
258258
}
259259

260260
/* Request IO ID INT space (Bar 3) */
@@ -266,7 +266,7 @@ static int tpci200_register(struct tpci200_board *tpci200)
266266
"(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 3 !",
267267
tpci200->info->pdev->bus->number,
268268
tpci200->info->pdev->devfn);
269-
goto out_release_ip_space;
269+
goto err_ip_interface_bar;
270270
}
271271

272272
/* Request MEM8 space (Bar 5) */
@@ -277,7 +277,7 @@ static int tpci200_register(struct tpci200_board *tpci200)
277277
"(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 5!",
278278
tpci200->info->pdev->bus->number,
279279
tpci200->info->pdev->devfn);
280-
goto out_release_ioid_int_space;
280+
goto err_io_id_int_spaces_bar;
281281
}
282282

283283
/* Request MEM16 space (Bar 4) */
@@ -288,7 +288,7 @@ static int tpci200_register(struct tpci200_board *tpci200)
288288
"(bn 0x%X, sn 0x%X) failed to allocate PCI resource for BAR 4!",
289289
tpci200->info->pdev->bus->number,
290290
tpci200->info->pdev->devfn);
291-
goto out_release_mem8_space;
291+
goto err_mem8_space_bar;
292292
}
293293

294294
/* Map internal tpci200 driver user space */
@@ -302,7 +302,7 @@ static int tpci200_register(struct tpci200_board *tpci200)
302302
tpci200->info->pdev->bus->number,
303303
tpci200->info->pdev->devfn);
304304
res = -ENOMEM;
305-
goto out_release_mem8_space;
305+
goto err_mem16_space_bar;
306306
}
307307

308308
/* Initialize lock that protects interface_regs */
@@ -341,18 +341,22 @@ static int tpci200_register(struct tpci200_board *tpci200)
341341
"(bn 0x%X, sn 0x%X) unable to register IRQ !",
342342
tpci200->info->pdev->bus->number,
343343
tpci200->info->pdev->devfn);
344-
goto out_release_ioid_int_space;
344+
goto err_interface_regs;
345345
}
346346

347347
return 0;
348348

349-
out_release_mem8_space:
349+
err_interface_regs:
350+
pci_iounmap(tpci200->info->pdev, tpci200->info->interface_regs);
351+
err_mem16_space_bar:
352+
pci_release_region(tpci200->info->pdev, TPCI200_MEM16_SPACE_BAR);
353+
err_mem8_space_bar:
350354
pci_release_region(tpci200->info->pdev, TPCI200_MEM8_SPACE_BAR);
351-
out_release_ioid_int_space:
355+
err_io_id_int_spaces_bar:
352356
pci_release_region(tpci200->info->pdev, TPCI200_IO_ID_INT_SPACES_BAR);
353-
out_release_ip_space:
357+
err_ip_interface_bar:
354358
pci_release_region(tpci200->info->pdev, TPCI200_IP_INTERFACE_BAR);
355-
out_disable_pci:
359+
err_disable_device:
356360
pci_disable_device(tpci200->info->pdev);
357361
return res;
358362
}

0 commit comments

Comments
 (0)