drm/sysfb: ofdrm: fix PCI device reference leaks
Subsystems (3)
PATCH 1/1 drm/sysfb: ofdrm: fix PCI device reference leaks
display_get_pci_dev_of() gets a referenced PCI device via pci_get_device(). Drop that reference when pci_enable_device() fails and release it during the managed teardown path after pci_disable_device().
Without that, ofdrm leaks the pci_dev reference on both the error path and the normal cleanup path.
--- drivers/gpu/drm/sysfb/ofdrm.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/sysfb/ofdrm.c +2 -0
@@ -350,6 +350,7 @@ static void ofdrm_pci_release(void *data)struct pci_dev *pcidev = data;pci_disable_device (pcidev); +pci_dev_put (pcidev); }static int ofdrm_device_init_pci (struct ofdrm_device *odev)
@@ -375,6 +376,7 @@ static int ofdrm_device_init_pci(struct ofdrm_device *odev)if (ret) {drm_err (dev,"pci_enable_device(%s) failed: %d\n" ,dev_name (&pcidev->dev), ret); +pci_dev_put (pcidev);return ret; } ret =devm_add_action_or_reset (&pdev->dev, ofdrm_pci_release, pcidev);
Signature · 1 line
2.50.1 (Apple Git-155)
Thomas Zimmermann
maintainerHi,
thanks for the patch.
Am 20.04.26 um 02:25 schrieb Yuho Choi:
Quoted 6 lines
display_get_pci_dev_of()gets a referenced PCI device viapci_get_device(). Drop that reference whenpci_enable_device()fails and release it during the managed teardown path afterpci_disable_device().Without that, ofdrm leaks the
pci_devreference on both the error path and the normal cleanup path.
Did you use an AI to find or fix this bug?
https://docs.kernel.org/process/coding-assistants.html
Best regards
Thomas
Quoted 33 lines
Fixes c8a17756c425 ("drm/ofdrm: Add ofdrm for Open Firmware framebuffers")Co-developed-by Myeonghun Pak <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>Co-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Co-developed-by Taegyu Kim <[email protected]>Signed-off-by Taegyu Kim <[email protected]>Signed-off-by Yuho Choi <[email protected]>--- drivers/gpu/drm/sysfb/ofdrm.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/sysfb/ofdrm.c +2
-0@@ -350,6 +350,7 @@ static void ofdrm_pci_release(void *data)struct pci_dev *pcidev = data;pci_disable_device (pcidev); +pci_dev_put (pcidev); }static int ofdrm_device_init_pci (struct ofdrm_device *odev)@@ -375,6 +376,7 @@ static int ofdrm_device_init_pci(struct ofdrm_device *odev)if (ret) {drm_err (dev,"pci_enable_device(%s) failed: %d\n" ,dev_name (&pcidev->dev), ret); +pci_dev_put (pcidev);return ret; } ret =devm_add_action_or_reset (&pdev->dev, ofdrm_pci_release, pcidev);
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Dear Thomas,
This issue was identified during our ongoing static-analysis research while reviewing
kernel code. Specifically, an experimental static analysis tool found that we are currently
developing. The tool is not public yet, so I prefer not to disclose further project details
at this stage. AI was used only for cross-review, not as the primary means of finding or
fixing the bug. I manually reviewed the code and verified the issue before sending
the patch.
Best regards,
Yuho Choi
Quoted 63 lines · Thomas Zimmermann
Hi,
thanks for the patch.
Am 20.04.26 um 02:25 schrieb Yuho Choi:
Quoted 6 lines
display_get_pci_dev_of()gets a referenced PCI device viapci_get_device(). Drop that reference whenpci_enable_device()fails and release it during the managed teardown path afterpci_disable_device().Without that, ofdrm leaks the
pci_devreference on both the error path and the normal cleanup path.Did you use an AI to find or fix this bug?
https://docs.kernel.org/process/coding-assistants.html
Best regards
ThomasQuoted 26 lines
Fixes c8a17756c425 ("drm/ofdrm: Add ofdrm for Open Firmware framebuffers")Co-developed-by Myeonghun Pak <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>Co-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Co-developed-by Taegyu Kim <[email protected]>Signed-off-by Taegyu Kim <[email protected]>Signed-off-by Yuho Choi <[email protected]>--- drivers/gpu/drm/sysfb/ofdrm.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/sysfb/ofdrm.c +1
-0@@ -350,6 +350,7 @@ static void ofdrm_pci_release(void *data)struct pci_dev *pcidev = data;pci_disable_device (pcidev); +pci_dev_put (pcidev); }static int ofdrm_device_init_pci (struct ofdrm_device *odev)drivers/gpu/drm/sysfb/ofdrm.c static int ofdrm_device_init_pci(struct ofdrm_device *odev) · line 382
Quoted 7 lines
drivers/gpu/drm/sysfb/ofdrm.c +1
-0@@ -375,6 +376,7 @@ static int ofdrm_device_init_pci(struct ofdrm_device *odev)if (ret) {drm_err (dev,"pci_enable_device(%s) failed: %d\n" ,dev_name (&pcidev->dev), ret); +pci_dev_put (pcidev);return ret; } ret =devm_add_action_or_reset (&pdev->dev, ofdrm_pci_release, pcidev);--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Thomas Zimmermann
maintainerHi
Am 20.04.26 um 22:55 schrieb 최유호:
Quoted 13 lines
Dear Thomas,
This issue was identified during our ongoing static-analysis research while reviewing
kernel code. Specifically, an experimental static analysis tool found that we are currently
developing. The tool is not public yet, so I prefer not to disclose further project details
at this stage. AI was used only for cross-review, not as the primary means of finding or
fixing the bug. I manually reviewed the code and verified the issue before sending
the patch.
Thanks.
Best regards
Thomas
Quoted 65 lines
Best regards,
Yuho ChoiQuoted 59 lines · Thomas Zimmermann
Hi,
thanks for the patch.
Am 20.04.26 um 02:25 schrieb Yuho Choi:
Quoted 6 lines
display_get_pci_dev_of()gets a referenced PCI device viapci_get_device(). Drop that reference whenpci_enable_device()fails and release it during the managed teardown path afterpci_disable_device().Without that, ofdrm leaks the
pci_devreference on both the error path and the normal cleanup path.Did you use an AI to find or fix this bug?
https://docs.kernel.org/process/coding-assistants.html
Best regards
ThomasQuoted 25 lines
Fixes c8a17756c425 ("drm/ofdrm: Add ofdrm for Open Firmware framebuffers")Co-developed-by Myeonghun Pak <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>Co-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Co-developed-by Taegyu Kim <[email protected]>Signed-off-by Taegyu Kim <[email protected]>Signed-off-by Yuho Choi <[email protected]>--- drivers/gpu/drm/sysfb/ofdrm.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/sysfb/ofdrm.c +1
-0@@ -350,6 +350,7 @@ static void ofdrm_pci_release(void *data)struct pci_dev *pcidev = data;pci_disable_device (pcidev); +pci_dev_put (pcidev); }static int ofdrm_device_init_pci (struct ofdrm_device *odev)drivers/gpu/drm/sysfb/ofdrm.c static int ofdrm_device_init_pci(struct ofdrm_device *odev) · line 382
Quoted 7 lines
drivers/gpu/drm/sysfb/ofdrm.c +1
-0@@ -375,6 +376,7 @@ static int ofdrm_device_init_pci(struct ofdrm_device *odev)if (ret) {drm_err (dev,"pci_enable_device(%s) failed: %d\n" ,dev_name (&pcidev->dev), ret); +pci_dev_put (pcidev);return ret; } ret =devm_add_action_or_reset (&pdev->dev, ofdrm_pci_release, pcidev);--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Am 20.04.26 um 02:25 schrieb Yuho Choi:
Quoted 7 lines
display_get_pci_dev_of()gets a referenced PCI device viapci_get_device(). Drop that reference whenpci_enable_device()fails and release it during the managed teardown path afterpci_disable_device().Without that, ofdrm leaks the
pci_devreference on both the error path and the normal cleanup path.
Quoted 8 lines
Fixes c8a17756c425 ("drm/ofdrm: Add ofdrm for Open Firmware framebuffers")Co-developed-by Myeonghun Pak <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>Co-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Co-developed-by Taegyu Kim <[email protected]>Signed-off-by Taegyu Kim <[email protected]>Signed-off-by Yuho Choi <[email protected]>
Quoted 24 lines
--- drivers/gpu/drm/sysfb/ofdrm.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/sysfb/ofdrm.c +2
-0@@ -350,6 +350,7 @@ static void ofdrm_pci_release(void *data)struct pci_dev *pcidev = data;pci_disable_device (pcidev); +pci_dev_put (pcidev); }static int ofdrm_device_init_pci (struct ofdrm_device *odev)@@ -375,6 +376,7 @@ static int ofdrm_device_init_pci(struct ofdrm_device *odev)if (ret) {drm_err (dev,"pci_enable_device(%s) failed: %d\n" ,dev_name (&pcidev->dev), ret); +pci_dev_put (pcidev);return ret; } ret =devm_add_action_or_reset (&pdev->dev, ofdrm_pci_release, pcidev);
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Quoted 4 lines
This issue was identified during our ongoing static-analysis research
while reviewing kernel code. Specifically, an experimental static analysis tool found that we are currently developing. The tool is not public yet, so I prefer not to disclose further project details at this stage. …
Will any additional background information become available?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/researcher-guidelines.rst?h=v7.0#n5
Regards,
Markus