linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu/virt: don't dereference undefined 'module' struct
@ 2017-11-02 11:25 Arnd Bergmann
  2017-11-02 19:22 ` Harry Wentland
  2017-11-03  6:57 ` Yu, Xiangliang
  0 siblings, 2 replies; 4+ messages in thread
From: Arnd Bergmann @ 2017-11-02 11:25 UTC (permalink / raw)
  To: Alex Deucher, Christian König
  Cc: Arnd Bergmann, David Airlie, Monk Liu, Xiangliang Yu,
	Horace Chen, amd-gfx, dri-devel, linux-kernel

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>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 2 ++
 1 file changed, 2 insertions(+)

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)
 					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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/amdgpu/virt: don't dereference undefined 'module' struct
  2017-11-02 11:25 [PATCH] drm/amdgpu/virt: don't dereference undefined 'module' struct Arnd Bergmann
@ 2017-11-02 19:22 ` Harry Wentland
  2017-11-02 20:57   ` Alex Deucher
  2017-11-03  6:57 ` Yu, Xiangliang
  1 sibling, 1 reply; 4+ messages in thread
From: Harry Wentland @ 2017-11-02 19:22 UTC (permalink / raw)
  To: Arnd Bergmann, Alex Deucher, Christian König
  Cc: David Airlie, Horace Chen, linux-kernel, amd-gfx, Xiangliang Yu,
	dri-devel, Monk Liu

On 2017-11-02 07:25 AM, Arnd Bergmann wrote:
> 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>

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

Either way, this change by itself is correct and
Reviewed-by: Harry Wentland <harry.wentland@amd.com>

Harry

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> 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)
>  					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);
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/amdgpu/virt: don't dereference undefined 'module' struct
  2017-11-02 19:22 ` Harry Wentland
@ 2017-11-02 20:57   ` Alex Deucher
  0 siblings, 0 replies; 4+ messages in thread
From: Alex Deucher @ 2017-11-02 20:57 UTC (permalink / raw)
  To: Harry Wentland
  Cc: Arnd Bergmann, Alex Deucher, Christian König, David Airlie,
	Horace Chen, LKML, Maling list - DRI developers, Xiangliang Yu,
	amd-gfx list, Monk Liu

On Thu, Nov 2, 2017 at 3:22 PM, Harry Wentland <harry.wentland@amd.com> wrote:
> On 2017-11-02 07:25 AM, Arnd Bergmann wrote:
>> 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>
>
> Looks like 'str' isn't even used here.
>
> Either way, this change by itself is correct and
> Reviewed-by: Harry Wentland <harry.wentland@amd.com>
>

Applied.  Thanks!

Alex

> Harry
>
>> ---
>>  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> 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)
>>                                       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);
>>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] drm/amdgpu/virt: don't dereference undefined 'module' struct
  2017-11-02 11:25 [PATCH] drm/amdgpu/virt: don't dereference undefined 'module' struct Arnd Bergmann
  2017-11-02 19:22 ` Harry Wentland
@ 2017-11-03  6:57 ` Yu, Xiangliang
  1 sibling, 0 replies; 4+ messages in thread
From: Yu, Xiangliang @ 2017-11-03  6:57 UTC (permalink / raw)
  To: Arnd Bergmann, Deucher, Alexander, Koenig, Christian
  Cc: David Airlie, Liu, Monk, Chen, Horace, amd-gfx, dri-devel, linux-kernel

Reviewed-By: Xiangliang Yu <Xiangliang.Yu@amd.com>

Thanks!

> -----Original Message-----
> From: Arnd Bergmann [mailto:arnd@arndb.de]
> Sent: Thursday, November 02, 2017 7:26 PM
> To: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian
> <Christian.Koenig@amd.com>
> Cc: Arnd Bergmann <arnd@arndb.de>; David Airlie <airlied@linux.ie>; Liu,
> Monk <Monk.Liu@amd.com>; Yu, Xiangliang <Xiangliang.Yu@amd.com>;
> Chen, Horace <Horace.Chen@amd.com>; amd-gfx@lists.freedesktop.org;
> dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org
> 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")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> 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)
>  					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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-03  6:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-02 11:25 [PATCH] drm/amdgpu/virt: don't dereference undefined 'module' struct Arnd Bergmann
2017-11-02 19:22 ` Harry Wentland
2017-11-02 20:57   ` Alex Deucher
2017-11-03  6:57 ` Yu, Xiangliang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).