Skip to contentSkip to conversation

ti_sci: Address some issues found by Smatch

PATCH Superseded Andrew Goodbody 2 participants 8 messages Oct 7, 2025 – Oct 8, 2025 Texas instruments' system control interface (TISCI) protocol driver

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover ti_sci: Address some issues found by Smatch

Prevent a memory leak from a non-freed malloc. Return an error code on an error path.
Assign a value to a pointer before it is dereferenced.

---
Changes in v2:
- Add cast when assigning to resp
- Replace malloc with devm_kmalloc
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Andrew Goodbody (3):
ti_sci: Prevent memory leak
ti_sci: Provide error code on error exit
ti_sci: Pointer is never assigned to

 drivers/firmware/ti_sci.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

---
base-commit: c280c4f7e52f08255f491783b3143a3be1fc08b0
change-id: 20250725-ti_sci-7bc55cb0cdba

Best regards,

Signature · 1 line
Andrew Goodbody <[email protected]>
#1 lore raw

PATCH v2 1/3 ti_sci: Prevent memory leak

temp is assigned the pointer returned by malloc which is used without a NULL check and then never freed. Add a NULL check and ensure temp is freed on all return paths.

This issue was found by Smatch.

---
 drivers/firmware/ti_sci.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/firmware/ti_sci.c +5 -1
index 8013afef304dfb70ab14150ddc49d43ebebb5902..2042d88583766213e9d74dd17289cfd3562f0acb 100644
@@ -3083,7 +3083,10 @@ devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle,
 		dev_err(dev, "%s resource type ids not available\n", of_prop);
 		return ERR_PTR(sets);
 	}
-	temp = malloc(sets);
+	temp = devm_kmalloc(dev, sets, GFP_KERNEL);
+	if (!temp)
+		return ERR_PTR(-ENOMEM);
+
 	sets /= sizeof(u32);
 	res->sets = sets;
 
@@ -3123,6 +3126,7 @@ devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle,
 			return ERR_PTR(-ENOMEM);
 	}
 
+	devm_kfree(dev, temp);
 	if (valid_set)
 		return res;
 
Signature · 1 line
2.47.3
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] ti_sci: Prevent memory leak

Quoted 28 lines · Andrew Goodbody

temp is assigned the pointer returned by malloc which is used without a NULL check and then never freed. Add a NULL check and ensure temp is freed on all return paths.

This issue was found by Smatch.

---
  drivers/firmware/ti_sci.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/firmware/ti_sci.c +4 -1
index 8013afef304dfb70ab14150ddc49d43ebebb5902..2042d88583766213e9d74dd17289cfd3562f0acb 100644
@@ -3083,7 +3083,10 @@ devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle,
  		dev_err(dev, "%s resource type ids not available\n", of_prop);
  		return ERR_PTR(sets);
  	}
-	temp = malloc(sets);
+	temp = devm_kmalloc(dev, sets, GFP_KERNEL);
+	if (!temp)
+		return ERR_PTR(-ENOMEM);
+
  	sets /= sizeof(u32);
  	res->sets = sets;
 

drivers/firmware/ti_sci.c devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle, · line 3129

Quoted 4 lines
drivers/firmware/ti_sci.c +1 -0
@@ -3123,6 +3126,7 @@ devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle,
  			return ERR_PTR(-ENOMEM);
  	}
 
+	devm_kfree(dev, temp);
Quoted 4 lines
drivers/firmware/ti_sci.c +0 -0
  	if (valid_set)
  		return res;
 
#3 lore raw

PATCH v2 2/3 ti_sci: Provide error code on error exit

In reply to Andrew Goodbody

In ti_sci_get_response the check for message sequence will return ret on a fail but ret will be 0 at that point. Instead return -EINVAL.

This issue was found by Smatch.

---
 drivers/firmware/ti_sci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/ti_sci.c +1 -1
index 2042d88583766213e9d74dd17289cfd3562f0acb..afe1ae13834d236015a3d5e4d8d4f9955ba8c822 100644
@@ -193,7 +193,7 @@ static int ti_sci_get_response(struct ti_sci_info *info,
 	if (hdr->seq != info->seq) {
 		dev_dbg(info->dev, "%s: Message for %d is not expected\n",
 			__func__, hdr->seq);
-		return ret;
+		return -EINVAL;
 	}
 
 	if (msg->len > info->desc->max_msg_size) {
Signature · 1 line
2.47.3
#4 lore raw

Re: [PATCH v2 2/3] ti_sci: Provide error code on error exit

Hello Andrew,

Quoted 15 lines · Andrew Goodbody

In ti_sci_get_response the check for message sequence will return ret on a fail but ret will be 0 at that point. Instead return -EINVAL.

This issue was found by Smatch.

---
  drivers/firmware/ti_sci.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/ti_sci.c +0 -0
index 2042d88583766213e9d74dd17289cfd3562f0acb..afe1ae13834d236015a3d5e4d8d4f9955ba8c822 100644

drivers/firmware/ti_sci.c static int ti_sci_get_response(struct ti_sci_info *info, · line 196

Quoted 5 lines
drivers/firmware/ti_sci.c +1 -1
@@ -193,7 +193,7 @@ static int ti_sci_get_response(struct ti_sci_info *info,
  	if (hdr->seq != info->seq) {
  		dev_dbg(info->dev, "%s: Message for %d is not expected\n",
  			__func__, hdr->seq);
-		return ret;
+		return -EINVAL;

I am looking on this patch, need to understand bit more , if this is really failure or intentionally returning 0.

if you look at other conditions, those are marked as dev_err, this particular condition marked as dev_dbg.

Please allow me some time.

Quoted 4 lines
drivers/firmware/ti_sci.c +0 -0
  	}
 
  	if (msg->len > info->desc->max_msg_size) {
Reviewed-by on v2 2/3
#5 lore raw

Re: [PATCH v2 2/3] ti_sci: Provide error code on error exit

In reply to Andrew Goodbody
Quoted 15 lines · Andrew Goodbody

In ti_sci_get_response the check for message sequence will return ret on a fail but ret will be 0 at that point. Instead return -EINVAL.

This issue was found by Smatch.

---
  drivers/firmware/ti_sci.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/ti_sci.c +0 -0
index 2042d88583766213e9d74dd17289cfd3562f0acb..afe1ae13834d236015a3d5e4d8d4f9955ba8c822 100644

drivers/firmware/ti_sci.c static int ti_sci_get_response(struct ti_sci_info *info, · line 196

Quoted 5 lines
drivers/firmware/ti_sci.c +1 -1
@@ -193,7 +193,7 @@ static int ti_sci_get_response(struct ti_sci_info *info,
  	if (hdr->seq != info->seq) {
  		dev_dbg(info->dev, "%s: Message for %d is not expected\n",
  			__func__, hdr->seq);
-		return ret;
+		return -EINVAL;

While you are at this,  Please change dev_dbg to dev_err,

with this change, Please use

Quoted 4 lines
drivers/firmware/ti_sci.c +0 -0
  	}
 
  	if (msg->len > info->desc->max_msg_size) {
#6 lore raw

PATCH v2 3/3 ti_sci: Pointer is never assigned to

In reply to Andrew Goodbody

The pointer resp is declared but never assigned a value but is then dereferenced. Fix this by assigning the pointer to the message buffer.

This issue was found by Smatch.

---
 drivers/firmware/ti_sci.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/firmware/ti_sci.c +2 -0
index afe1ae13834d236015a3d5e4d8d4f9955ba8c822..91edbc7898132bc10fcf4bd6a71c1e7aebd5147d 100644
@@ -1365,6 +1365,8 @@ static int ti_sci_cmd_clk_get_parent(const struct ti_sci_handle *handle,
 	if (ret)
 		return ret;
 
+	resp = (struct ti_sci_msg_resp_get_clock_parent *)xfer->tx_message.buf;
+
 	*parent_id = resp->parent_id;
 
 	return ret;
Signature · 1 line
2.47.3
Reviewed-by on v2 3/3
#7 lore raw

Re: [PATCH v2 3/3] ti_sci: Pointer is never assigned to

Hello Andrew,

Quoted 2 lines · Andrew Goodbody

The pointer resp is declared but never assigned a value but is then dereferenced. Fix this by assigning the pointer to the message buffer.

Tom, may comment, if need Fixes tag for this

Quoted 12 lines

This issue was found by Smatch.

---
  drivers/firmware/ti_sci.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/firmware/ti_sci.c +0 -0
index afe1ae13834d236015a3d5e4d8d4f9955ba8c822..91edbc7898132bc10fcf4bd6a71c1e7aebd5147d 100644

drivers/firmware/ti_sci.c static int ti_sci_cmd_clk_get_parent(const struct ti_sci_handle *handle, · line 1369

Quoted 5 lines
drivers/firmware/ti_sci.c +2 -0
@@ -1365,6 +1365,8 @@ static int ti_sci_cmd_clk_get_parent(const struct ti_sci_handle *handle,
  	if (ret)
  		return ret;
 
+	resp = (struct ti_sci_msg_resp_get_clock_parent *)xfer->tx_message.buf;
+

Sorry but subject (ti_sci: Pointer is never assigned to) does not complete story,

Please update subject to (ti_sci: Pointer is never assigned to valid value)

with subject change , Please use

Quoted 4 lines
drivers/firmware/ti_sci.c +0 -0
  	*parent_id = resp->parent_id;
 
  	return ret;