[PATCH] firmware: qcom_scm: Fix coccinelle warning

Mukesh Ojha posted 1 patch 4 days, 22 hours ago
drivers/firmware/qcom/qcom_scm.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH] firmware: qcom_scm: Fix coccinelle warning
Posted by Mukesh Ojha 4 days, 22 hours ago
Fix coccinelle warning of allocation and memory copying to allocated
memory by replacing with kmemdup.

cocci warnings: (new ones prefixed by >>)
>> drivers/firmware/qcom/qcom_scm.c:916:11-18: WARNING opportunity for kmemdup

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202601142144.HvSlBSI9-lkp@intel.com/
Signed-off-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
---
Exact patch where this warning introduced is in Linux-next but not yet
hit stable.

 drivers/firmware/qcom/qcom_scm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c
index 8fbc96693a55..d439a9f5b62b 100644
--- a/drivers/firmware/qcom/qcom_scm.c
+++ b/drivers/firmware/qcom/qcom_scm.c
@@ -923,14 +923,13 @@ struct resource_table *qcom_scm_pas_get_rsc_table(struct qcom_scm_pas_context *c
 		goto free_input_rt;
 	}
 
-	tbl_ptr = kzalloc(size, GFP_KERNEL);
+	tbl_ptr = kmemdup(output_rt_tzm, size, GFP_KERNEL);
 	if (!tbl_ptr) {
 		qcom_tzmem_free(output_rt_tzm);
 		ret = -ENOMEM;
 		goto free_input_rt;
 	}
 
-	memcpy(tbl_ptr, output_rt_tzm, size);
 	*output_rt_size = size;
 	qcom_tzmem_free(output_rt_tzm);
 
-- 
2.50.1
Re: [PATCH] firmware: qcom_scm: Fix coccinelle warning
Posted by Konrad Dybcio 4 days, 21 hours ago
On 2/2/26 12:32 PM, Mukesh Ojha wrote:
> Fix coccinelle warning of allocation and memory copying to allocated
> memory by replacing with kmemdup.
> 
> cocci warnings: (new ones prefixed by >>)
>>> drivers/firmware/qcom/qcom_scm.c:916:11-18: WARNING opportunity for kmemdup
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202601142144.HvSlBSI9-lkp@intel.com/
> Signed-off-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
> ---

Preferably the subject would say something like 'don't opencode kmemdup',
but that's minor

Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

Konrad
Re: [PATCH] firmware: qcom_scm: Fix coccinelle warning
Posted by Mukesh Ojha 2 days, 1 hour ago
On Mon, Feb 02, 2026 at 12:51:31PM +0100, Konrad Dybcio wrote:
> On 2/2/26 12:32 PM, Mukesh Ojha wrote:
> > Fix coccinelle warning of allocation and memory copying to allocated
> > memory by replacing with kmemdup.
> > 
> > cocci warnings: (new ones prefixed by >>)
> >>> drivers/firmware/qcom/qcom_scm.c:916:11-18: WARNING opportunity for kmemdup
> > 
> > Reported-by: kernel test robot <lkp@intel.com>
> > Closes: https://lore.kernel.org/oe-kbuild-all/202601142144.HvSlBSI9-lkp@intel.com/
> > Signed-off-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
> > ---
> 
> Preferably the subject would say something like 'don't opencode kmemdup',
> but that's minor

Thanks, Just checking if the tool name like coccinelle, smatch, sparse
who may find some issue is not preferrable to get mentioned in commit at all ?

> 
> Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
> 
> Konrad

-- 
-Mukesh Ojha
Re: [PATCH] firmware: qcom_scm: Fix coccinelle warning
Posted by Konrad Dybcio 1 day, 22 hours ago
On 2/5/26 9:23 AM, Mukesh Ojha wrote:
> On Mon, Feb 02, 2026 at 12:51:31PM +0100, Konrad Dybcio wrote:
>> On 2/2/26 12:32 PM, Mukesh Ojha wrote:
>>> Fix coccinelle warning of allocation and memory copying to allocated
>>> memory by replacing with kmemdup.
>>>
>>> cocci warnings: (new ones prefixed by >>)
>>>>> drivers/firmware/qcom/qcom_scm.c:916:11-18: WARNING opportunity for kmemdup
>>>
>>> Reported-by: kernel test robot <lkp@intel.com>
>>> Closes: https://lore.kernel.org/oe-kbuild-all/202601142144.HvSlBSI9-lkp@intel.com/
>>> Signed-off-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
>>> ---
>>
>> Preferably the subject would say something like 'don't opencode kmemdup',
>> but that's minor
> 
> Thanks, Just checking if the tool name like coccinelle, smatch, sparse
> who may find some issue is not preferrable to get mentioned in commit at all ?

I think it's even required to mention it somewhere in the message..
I can't find the actual reference, but Greg said this last week:

https://lore.kernel.org/linux-arm-msm/2026012748-unblock-vacation-70b8@gregkh/

Konrad