Skip to contentSkip to conversation

drm/amdgpu/virt: don't dereference undefined 'module' struct

PATCH Applied Arnd Bergmann 4 participants 4 messages Nov 2, 2017 – Nov 3, 2017

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

PATCH 1/1 drm/amdgpu/virt: don't dereference undefined 'module' struct

Accessing the THIS_MODULE directly is only possible when modules are enabled, otherwise we get a build failure:

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c: In function 'amdgpu_virt_init_data_exchange':
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c:331:20: error: dereferencing pointer to incomplete type 'struct module'

Further, THIS_MODULE is NULL when the driver is built-in, so the code would likely cause a NULL pointer dereference.

This adds an #ifdef check to avoid the compile-time error, plus a NULL pointer check before dereferencing THIS_MODULE. It might be better to find a way to avoid using the module version altogether.

Fixes 2dc8f81e4f82 ("drm/amdgpu: SR-IOV data exchange between PF&VF")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +2 -0
index e97f80f86005..4e4a476593e8 100644
@@ -328,9 +328,11 @@ void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev)
 					sizeof(amdgim_vf2pf_info));
 				AMDGPU_FW_VRAM_VF2PF_READ(adev, driver_version,
 					&str);
+#ifdef MODULE
 				if (THIS_MODULE->version != NULL)
 					strcpy(str, THIS_MODULE->version);
 				else
+#endif
 					strcpy(str, "N/A");
 				AMDGPU_FW_VRAM_VF2PF_WRITE(adev, driver_cert,
 					0);
Signature · 6 lines
2.9.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Arnd Bergmann

Accessing the THIS_MODULE directly is only possible when modules are enabled, otherwise we get a build failure:

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c: In function 'amdgpu_virt_init_data_exchange':
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c:331:20: error: dereferencing pointer to incomplete type 'struct module'

Further, THIS_MODULE is NULL when the driver is built-in, so the code would likely cause a NULL pointer dereference.

Quoted 7 lines

This adds an #ifdef check to avoid the compile-time error, plus a NULL pointer check before dereferencing THIS_MODULE. It might be better to find a way to avoid using the module version altogether.

Fixes 2dc8f81e4f82 ("drm/amdgpu: SR-IOV data exchange between PF&VF")

Looks like 'str' isn't even used here.

Either way, this change by itself is correct and

Harry

Quoted 11 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -0
index e97f80f86005..4e4a476593e8 100644
@@ -328,9 +328,11 @@ void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev)
 					sizeof(amdgim_vf2pf_info));

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev) · line 338

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +2 -0
 				AMDGPU_FW_VRAM_VF2PF_READ(adev, driver_version,
 					&str);
+#ifdef MODULE
 				if (THIS_MODULE->version != NULL)
 					strcpy(str, THIS_MODULE->version);
 				else
+#endif
 					strcpy(str, "N/A");
 				AMDGPU_FW_VRAM_VF2PF_WRITE(adev, driver_cert,
 					0);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Applied
#2 lore raw
Quoted 15 lines · Harry Wentland
Quoted 14 lines · Arnd Bergmann

Accessing the THIS_MODULE directly is only possible when modules are enabled, otherwise we get a build failure:

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c: In function 'amdgpu_virt_init_data_exchange':
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c:331:20: error: dereferencing pointer to incomplete type 'struct module'

Further, THIS_MODULE is NULL when the driver is built-in, so the code would likely cause a NULL pointer dereference.

This adds an #ifdef check to avoid the compile-time error, plus a NULL pointer check before dereferencing THIS_MODULE. It might be better to find a way to avoid using the module version altogether.

Quoted 8 lines
Quoted 2 lines
Fixes 2dc8f81e4f82 ("drm/amdgpu: SR-IOV data exchange between PF&VF")

Looks like 'str' isn't even used here.

Either way, this change by itself is correct and

Applied. Thanks!

Alex

Quoted 19 lines

Harry

Quoted 17 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +2 -0
index e97f80f86005..4e4a476593e8 100644
@@ -328,9 +328,11 @@ void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev)
                                      sizeof(amdgim_vf2pf_info));
                              AMDGPU_FW_VRAM_VF2PF_READ(adev, driver_version,
                                      &str);
+#ifdef MODULE
                              if (THIS_MODULE->version != NULL)
                                      strcpy(str, THIS_MODULE->version);
                              else
+#endif
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev) · line 338

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +0 -0
                                      strcpy(str, "N/A");
                              AMDGPU_FW_VRAM_VF2PF_WRITE(adev, driver_cert,
                                      0);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reviewed-by on v1 1/1
#3 lore raw
In reply to Arnd Bergmann

Thanks!

Quoted 55 lines

-----Original Message-----
From: Arnd Bergmann [mailto:[email protected]]
Sent: Thursday, November 02, 2017 7:26 PM
To: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Cc: Arnd Bergmann <[email protected]>; David Airlie <[email protected]>; Liu, Monk <[email protected]>; Yu, Xiangliang <[email protected]>; Chen, Horace <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH] drm/amdgpu/virt: don't dereference undefined 'module' struct

Accessing the THIS_MODULE directly is only possible when modules are enabled, otherwise we get a build failure:

drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c: In function 'amdgpu_virt_init_data_exchange':
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c:331:20: error: dereferencing pointer to incomplete type 'struct module'

Further, THIS_MODULE is NULL when the driver is built-in, so the code would likely cause a NULL pointer dereference.

This adds an #ifdef check to avoid the compile-time error, plus a NULL pointer check before dereferencing THIS_MODULE. It might be better to find a way to avoid using the module version altogether.

Fixes 2dc8f81e4f82 ("drm/amdgpu: SR-IOV data exchange between PF&VF")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +2 -0
index e97f80f86005..4e4a476593e8 100644
@@ -328,9 +328,11 @@ void amdgpu_virt_init_data_exchange(struct
 amdgpu_device *adev)
 					sizeof(amdgim_vf2pf_info));
 				AMDGPU_FW_VRAM_VF2PF_READ(adev,
 driver_version,
 					&str);
+#ifdef MODULE
 				if (THIS_MODULE->version != NULL)
 					strcpy(str, THIS_MODULE->version);
 				else
+#endif
 					strcpy(str, "N/A");

AMDGPU_FW_VRAM_VF2PF_WRITE(adev,
driver_cert,
0);
--
2.9.0