When platform_driver_register() fails, pci_unregister_driver() is not
called to release the resource allocated by pci_register_driver().
To fix this bug, error handling code for platform_driver_register() and
pci_register_driver() is separately implemented.
This bug is found by a runtime fuzzing tool named FIZZER written by us.
Signed-off-by: Jia-Ju Bai <[email protected]>
---
drivers/net/ethernet/via/via-rhine.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
index 33949248c829..eb74e5a03aac 100644
--- a/drivers/net/ethernet/via/via-rhine.c
+++ b/drivers/net/ethernet/via/via-rhine.c
@@ -2633,10 +2633,15 @@ static int __init rhine_init(void)
pr_info("avoid_D3 set\n");
ret_pci = pci_register_driver(&rhine_driver_pci);
- ret_platform = platform_driver_register(&rhine_driver_platform);
- if ((ret_pci < 0) && (ret_platform < 0))
+ if (ret_pci)
return ret_pci;
+ ret_platform = platform_driver_register(&rhine_driver_platform);
+ if (ret_platform) {
+ pci_unregister_driver(&rhine_driver_pci);
+ return ret_platform;
+ }
+
return 0;
}
--
2.17.0