Skip to contentSkip to conversation

drm/amd/display: Fix a couple of test failures

PATCH New John Harrison 2 participants 4 messages Dec 5

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover drm/amd/display: Fix a couple of test failures

Running the KUNIT tests with KASAN enabled hits a couple of memory splats. So let's fix them.

John Harrison (2):
drm/amd/display: Fix use-after-free in
dm_test_vblank_control_worker_enable_increments
drm/amd/display: Fix null pointer deref during

    dm_test_i2c_xfer_no_ddc_pin
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c   | 2 +-
 .../gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_crtc_test.c | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 drm/amd/display: Fix use-after-free in dm_test_vblank_control_worker_enable_increments

The test runs a worker thread and verifies that it did something. However, the worker frees up the work item object that the 'did something' check inspects.

The check is actually looking at data inside a different object (AMD CRTC) but using the work item object to get there. So just save a pointer to the desired CRTC object and use that in the test instead.

---
 .../gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_crtc_test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_crtc_test.c +3 -1
index 88f4e9281c4e..fd6fde434ae0 100644
@@ -2019,14 +2019,16 @@ static void dm_test_vblank_control_worker_enable_increments(struct kunit *test)
 {
 	struct vblank_control_work *work;
 	struct amdgpu_display_manager *dm;
+	struct amdgpu_crtc *acrtc;
 
 	work = dm_test_vblank_control_worker_setup(test, true, 0);
 	dm = work->dm;
+	acrtc = work->acrtc;
 
 	amdgpu_dm_crtc_vblank_control_worker(&work->work);
 
 	KUNIT_EXPECT_EQ(test, dm->active_vblank_irq_count, 1);
-	KUNIT_EXPECT_TRUE(test, work->acrtc->dm_irq_params.vblank_irq_programmed);
+	KUNIT_EXPECT_TRUE(test, acrtc->dm_irq_params.vblank_irq_programmed);
 }
 
 /**
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 1/2] drm/amd/display: Fix use-after-free in dm_test_vblank_control_worker_enable_increments

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm/amd/display: missing Fixes trailer in commit message --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm/amd/display: missing Fixes trailer in commit message --

commit 743bf16e2134d4dfb68bd75ac4f4ba7434f28d77
Author: John Harrison <[email protected]>

Quoted 11 lines

drm/amd/display: Fix use-after-free in dm_test_vblank_control_worker_enable_increments

The test runs a worker thread and verifies that it did something. However, the worker frees up the work item object that the 'did something' check inspects.

The check is actually looking at data inside a different object (AMD CRTC) but using the work item object to get there. So just save a pointer to the desired CRTC object and use that in the test instead.

[Severity: Low]
This fixes the use-after-free on work->acrtc introduced in dm_test_vblank_control_worker_enable_increments(). Should the commit message include:

Fixes 6455792e51db ("drm/amd/display: Fix KUnit tests for vblank control rework")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH 2/2 drm/amd/display: Fix null pointer deref during dm_test_i2c_xfer_no_ddc_pin

In reply to John Harrison

The above selftest creates a mimimal I2C device which does not have all the optional extras of a real hardware device. However, since the patch below, the I2C code was assuming some of that state was present. So add a check that 'ddc_service->link' is not null before trying to dereference it.

Fixes 8525c0e879da ("drm/amd/display: Route connector DDC over AUX for native DP sinks")
Cc Wayne Lin <[email protected]>
Cc Mario Limonciello <[email protected]>
Cc Alex Deucher <[email protected]>
Cc Alex Hung <[email protected]>
Cc Bhawanpreet Lakha <[email protected]>
Cc Fangzhi Zuo <[email protected]>
Cc George Zhang <[email protected]>
Cc Adrian Betschart <[email protected]>
Cc Alex Huang <[email protected]>
Cc Ivan Lipski <[email protected]>
Cc Albert Esteve <[email protected]>
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c +1 -1
index 85f00040c988..5f8b4ee582e7 100644
@@ -3445,7 +3445,7 @@ STATIC_IFN_KUNIT int amdgpu_dm_i2c_xfer(struct i2c_adapter *i2c_adap,
 
 	if (!i2c->oem) {
 		struct dc_link *link = ddc_service->link;
-		struct amdgpu_dm_connector *aconnector = link->priv;
+		struct amdgpu_dm_connector *aconnector = link ? link->priv : NULL;
 
 		/*
 		 * DDC to a native DisplayPort sink is tunneled over the AUX
Signature · 1 line
2.43.0