diff options
author | Arnd Bergmann <arnd@arndb.de> | 2017-11-02 07:25:39 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2017-11-03 09:42:28 -0400 |
commit | e477e940dad1836c6f6d23353e424665b9316b6e (patch) | |
tree | ff281ae5c9913f1481f786ea677aeb06cdcec940 /drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | |
parent | bf6eb600e5b835a96d676b2b9df603362a1e714c (diff) |
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")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Harry Wentland <harry.wentland@amd.com>
Reviewed-By: Xiangliang Yu <Xiangliang.Yu@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c index e97f80f86005..4e4a476593e8 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | |||
@@ -328,9 +328,11 @@ void amdgpu_virt_init_data_exchange(struct amdgpu_device *adev) | |||
328 | sizeof(amdgim_vf2pf_info)); | 328 | sizeof(amdgim_vf2pf_info)); |
329 | AMDGPU_FW_VRAM_VF2PF_READ(adev, driver_version, | 329 | AMDGPU_FW_VRAM_VF2PF_READ(adev, driver_version, |
330 | &str); | 330 | &str); |
331 | #ifdef MODULE | ||
331 | if (THIS_MODULE->version != NULL) | 332 | if (THIS_MODULE->version != NULL) |
332 | strcpy(str, THIS_MODULE->version); | 333 | strcpy(str, THIS_MODULE->version); |
333 | else | 334 | else |
335 | #endif | ||
334 | strcpy(str, "N/A"); | 336 | strcpy(str, "N/A"); |
335 | AMDGPU_FW_VRAM_VF2PF_WRITE(adev, driver_cert, | 337 | AMDGPU_FW_VRAM_VF2PF_WRITE(adev, driver_cert, |
336 | 0); | 338 | 0); |