Commit 4879610
s390/pci: Fix leak of struct zpci_dev when zpci_add_device() fails
Prior to commit 0467cdd ("s390/pci: Sort PCI functions prior to
creating virtual busses") the IOMMU was initialized and the device was
registered as part of zpci_create_device() with the struct zpci_dev
freed if either resulted in an error. With that commit this was moved
into a separate function called zpci_add_device().
While this new function logs when adding failed, it expects the caller
not to use and to free the struct zpci_dev on error. This difference
between it and zpci_create_device() was missed while changing the
callers and the incompletely initialized struct zpci_dev may get used in
zpci_scan_configured_device in the error path. This then leads to
a crash due to the device not being registered with the zbus. It was
also not freed in this case. Fix this by handling the error return of
zpci_add_device(). Since in this case the zdev was not added to the
zpci_list it can simply be discarded and freed. Also make this more
explicit by moving the kref_init() into zpci_add_device() and document
that zpci_zdev_get()/zpci_zdev_put() must be used after adding.
Cc: [email protected]
Fixes: 0467cdd ("s390/pci: Sort PCI functions prior to creating virtual busses")
Reviewed-by: Gerd Bayer <[email protected]>
Reviewed-by: Matthew Rosato <[email protected]>
Signed-off-by: Niklas Schnelle <[email protected]>
Signed-off-by: Heiko Carstens <[email protected]>1 parent adb44a4 commit 4879610
2 files changed
+25
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
776 | 776 | | |
777 | 777 | | |
778 | 778 | | |
779 | | - | |
780 | | - | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
781 | 782 | | |
782 | 783 | | |
783 | 784 | | |
| |||
800 | 801 | | |
801 | 802 | | |
802 | 803 | | |
803 | | - | |
804 | 804 | | |
805 | 805 | | |
806 | 806 | | |
| |||
813 | 813 | | |
814 | 814 | | |
815 | 815 | | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
816 | 827 | | |
817 | 828 | | |
818 | 829 | | |
| |||
826 | 837 | | |
827 | 838 | | |
828 | 839 | | |
| 840 | + | |
829 | 841 | | |
830 | 842 | | |
831 | 843 | | |
| |||
1118 | 1130 | | |
1119 | 1131 | | |
1120 | 1132 | | |
1121 | | - | |
| 1133 | + | |
| 1134 | + | |
1122 | 1135 | | |
1123 | 1136 | | |
1124 | 1137 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
343 | | - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
344 | 347 | | |
345 | 348 | | |
346 | 349 | | |
| |||
354 | 357 | | |
355 | 358 | | |
356 | 359 | | |
357 | | - | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
358 | 364 | | |
359 | 365 | | |
360 | 366 | | |
| |||
0 commit comments