linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/msm/adreno: Add a null pointer check to the zap_shader_load_mdt
@ 2024-01-16  3:27 Kunwu Chan
  2024-01-17 18:50 ` [PATCH] drm/msm/adreno: Add a null pointer check in zap_shader_load_mdt() Markus Elfring
  0 siblings, 1 reply; 4+ messages in thread
From: Kunwu Chan @ 2024-01-16  3:27 UTC (permalink / raw)
  To: robdclark, quic_abhinavk, dmitry.baryshkov, sean, marijn.suijten,
	airlied, daniel
  Cc: linux-arm-msm, dri-devel, freedreno, linux-kernel, Kunwu Chan

kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.

Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
 drivers/gpu/drm/msm/adreno/adreno_gpu.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.c b/drivers/gpu/drm/msm/adreno/adreno_gpu.c
index 074fb498706f..7e79ead4fe00 100644
--- a/drivers/gpu/drm/msm/adreno/adreno_gpu.c
+++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c
@@ -144,6 +144,10 @@ static int zap_shader_load_mdt(struct msm_gpu *gpu, const char *fwname,
 		char *newname;
 
 		newname = kasprintf(GFP_KERNEL, "qcom/%s", fwname);
+		if (!newname) {
+			ret = -ENOMEM;
+			goto out;
+		}
 
 		ret = qcom_mdt_load(dev, fw, newname, pasid,
 				mem_region, mem_phys, mem_size, NULL);
-- 
2.39.2


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

* Re: [PATCH] drm/msm/adreno: Add a null pointer check in zap_shader_load_mdt()
  2024-01-16  3:27 [PATCH] drm/msm/adreno: Add a null pointer check to the zap_shader_load_mdt Kunwu Chan
@ 2024-01-17 18:50 ` Markus Elfring
  2024-01-18  2:16   ` Kunwu Chan
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2024-01-17 18:50 UTC (permalink / raw)
  To: Kunwu Chan, freedreno, dri-devel, linux-arm-msm, kernel-janitors,
	Abhinav Kumar, Dmitry Baryshkov, Daniel Vetter, David Airlie,
	Marijn Suijten, Rob Clark, Sean Paul
  Cc: LKML

> kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure. Ensure the allocation was successful
> by checking the pointer validity.
> +++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c
> @@ -144,6 +144,10 @@ static int zap_shader_load_mdt(struct msm_gpu *gpu, const char *fwname,
>  		char *newname;
>
>  		newname = kasprintf(GFP_KERNEL, "qcom/%s", fwname);
> +		if (!newname) {
> +			ret = -ENOMEM;
> +			goto out;
> +		}
…

How do you think about to avoid the repetition of the pointer check
for the variable “mem_region”?
Can the usage of other labels become more appropriate?

Regards,
Markus

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

* Re: [PATCH] drm/msm/adreno: Add a null pointer check in zap_shader_load_mdt()
  2024-01-17 18:50 ` [PATCH] drm/msm/adreno: Add a null pointer check in zap_shader_load_mdt() Markus Elfring
@ 2024-01-18  2:16   ` Kunwu Chan
  2024-01-18  8:06     ` Markus Elfring
  0 siblings, 1 reply; 4+ messages in thread
From: Kunwu Chan @ 2024-01-18  2:16 UTC (permalink / raw)
  To: Markus Elfring, freedreno, dri-devel, linux-arm-msm,
	kernel-janitors, Abhinav Kumar, Dmitry Baryshkov, Daniel Vetter,
	David Airlie, Marijn Suijten, Rob Clark, Sean Paul
  Cc: LKML

On 2024/1/18 02:50, Markus Elfring wrote:
>> kasprintf() returns a pointer to dynamically allocated memory
>> which can be NULL upon failure. Ensure the allocation was successful
>> by checking the pointer validity.
> …
>> +++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c
>> @@ -144,6 +144,10 @@ static int zap_shader_load_mdt(struct msm_gpu *gpu, const char *fwname,
>>   		char *newname;
>>
>>   		newname = kasprintf(GFP_KERNEL, "qcom/%s", fwname);
>> +		if (!newname) {
>> +			ret = -ENOMEM;
>> +			goto out;
>> +		}
> …
> 
> How do you think about to avoid the repetition of the pointer check
> for the variable “mem_region”?
"mem_region"? Is this a clerical error, do you mean 'newname'?

No check found in __qcom_mdt_load for 'newname'.
'newname' is used for printing in '__qcom_mdt_load' in some cases, which 
is a bit dangerous.
So it's necessary check it before using it.

> Can the usage of other labels become more appropriate?
> 
> Regards,
> Markus
-- 
Thanks,
   Kunwu


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

* Re: [PATCH] drm/msm/adreno: Add a null pointer check in zap_shader_load_mdt()
  2024-01-18  2:16   ` Kunwu Chan
@ 2024-01-18  8:06     ` Markus Elfring
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2024-01-18  8:06 UTC (permalink / raw)
  To: Kunwu Chan, freedreno, dri-devel, linux-arm-msm, kernel-janitors,
	Abhinav Kumar, Dmitry Baryshkov, Daniel Vetter, David Airlie,
	Marijn Suijten, Rob Clark, Sean Paul
  Cc: LKML

>>> kasprintf() returns a pointer to dynamically allocated memory
>>> which can be NULL upon failure. Ensure the allocation was successful
>>> by checking the pointer validity.
>> …
>>> +++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c
>>> @@ -144,6 +144,10 @@ static int zap_shader_load_mdt(struct msm_gpu *gpu, const char *fwname,
>>>           char *newname;
>>>
>>>           newname = kasprintf(GFP_KERNEL, "qcom/%s", fwname);
>>> +        if (!newname) {
>>> +            ret = -ENOMEM;
>>> +            goto out;
>>> +        }
>> …
>>
>> How do you think about to avoid the repetition of the pointer check
>> for the variable “mem_region”?
> "mem_region"? Is this a clerical error, do you mean 'newname'?

Please take another look at implementation details:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/msm/adreno/adreno_gpu.c?h=v6.7#n124>> Can the usage of other labels become more appropriate?

I propose to reconsider also the influence of the label “out” here.
https://elixir.bootlin.com/linux/v6.7/source/drivers/gpu/drm/msm/adreno/adreno_gpu.c#L167

Regards,
Markus

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

end of thread, other threads:[~2024-01-18  8:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16  3:27 [PATCH] drm/msm/adreno: Add a null pointer check to the zap_shader_load_mdt Kunwu Chan
2024-01-17 18:50 ` [PATCH] drm/msm/adreno: Add a null pointer check in zap_shader_load_mdt() Markus Elfring
2024-01-18  2:16   ` Kunwu Chan
2024-01-18  8:06     ` Markus Elfring

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