Skip to contentSkip to conversation

firmware: qcom_scm: Fix coccinelle warning

PATCH In review Mukesh Ojha 2 participants 4 messages Feb 2 – Feb 5

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firmware: qcom_scm: Fix coccinelle warning

Fix coccinelle warning of allocation and memory copying to allocated memory by replacing with kmemdup.

cocci warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

drivers/firmware/qcom/qcom_scm.c:916:11-18: WARNING opportunity for kmemdup

---
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(-)
drivers/firmware/qcom/qcom_scm.c +1 -2
index 8fbc96693a55..d439a9f5b62b 100644
@@ -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);
 
Signature · 1 line
2.50.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Mukesh Ojha

Fix coccinelle warning of allocation and memory copying to allocated memory by replacing with kmemdup.

cocci warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

drivers/firmware/qcom/qcom_scm.c:916:11-18: WARNING opportunity for kmemdup

---

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

Konrad

#2 lore raw
Quoted 7 lines · Konrad Dybcio
Quoted 6 lines · Mukesh Ojha

Fix coccinelle warning of allocation and memory copying to allocated memory by replacing with kmemdup.

cocci warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

drivers/firmware/qcom/qcom_scm.c:916:11-18: WARNING opportunity for kmemdup

Quoted 7 lines
Quoted 4 lines

---

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 ?

Quoted 4 lines

Konrad

Signature · 1 line
-Mukesh Ojha
#3 lore raw
Quoted 13 lines · Mukesh Ojha
Quoted 12 lines · Konrad Dybcio
Quoted 10 lines · Mukesh Ojha

Fix coccinelle warning of allocation and memory copying to allocated memory by replacing with kmemdup.

cocci warnings: (new ones prefixed by >>)

Quoted 1 line
Quoted 1 line

drivers/firmware/qcom/qcom_scm.c:916:11-18: WARNING opportunity for kmemdup

---

Quoted 5 lines
Quoted 2 lines

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