drm/amdgpu/virt: don't dereference undefined 'module' struct
authorArnd Bergmann <arnd@arndb.de>
Thu, 2 Nov 2017 11:25:39 +0000 (12:25 +0100)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 3 Nov 2017 13:42:28 +0000 (09:42 -0400)
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>
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c

index e97f80f860050edf7f874cfceec083427cb4fd4a..4e4a476593e8a0d7090d9b0a71c6805298be2f06 100644 (file)
@@ -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);