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

powerpc/ps3: Fix memory leak in device init

Free dynamically allocated device data structures when device registration
fails. This fixes memory leakage when the registration fails.

Signed-off-by: Masakazu Mokuno <mokuno@sm.sony.co.jp>
Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>

authored by

Masakazu Mokuno and committed by
Paul Mackerras
d4ad3048 3cc69878

+24 -5
+24 -5
arch/powerpc/platforms/ps3/device-init.c
··· 314 314 315 315 result = ps3_system_bus_device_register(&p->dev); 316 316 317 - if (result) 317 + if (result) { 318 318 pr_debug("%s:%d ps3_system_bus_device_register failed\n", 319 319 __func__, __LINE__); 320 - 320 + goto fail_device_register; 321 + } 321 322 pr_debug(" <- %s:%d\n", __func__, __LINE__); 323 + return 0; 324 + 325 + fail_device_register: 326 + kfree(p); 327 + pr_debug(" <- %s:%d fail\n", __func__, __LINE__); 322 328 return result; 323 329 } 324 330 ··· 469 463 470 464 result = ps3_system_bus_device_register(&p->dev); 471 465 472 - if (result) 466 + if (result) { 473 467 pr_debug("%s:%d ps3_system_bus_device_register failed\n", 474 468 __func__, __LINE__); 475 - 469 + goto fail_device_register; 470 + } 476 471 pr_debug(" <- %s:%d\n", __func__, __LINE__); 472 + return 0; 473 + 474 + fail_device_register: 475 + kfree(p); 476 + pr_debug(" <- %s:%d failed\n", __func__, __LINE__); 477 477 return result; 478 478 } 479 479 ··· 503 491 504 492 result = ps3_system_bus_device_register(&p->dev); 505 493 506 - if (result) 494 + if (result) { 507 495 pr_debug("%s:%d ps3_system_bus_device_register failed\n", 508 496 __func__, __LINE__); 497 + goto fail_device_register; 498 + } 509 499 510 500 pr_debug(" <- %s:%d\n", __func__, __LINE__); 501 + return 0; 502 + 503 + fail_device_register: 504 + kfree(p); 505 + pr_debug(" <- %s:%d failed\n", __func__, __LINE__); 511 506 return result; 512 507 } 513 508