Skip to contentSkip to conversation

Revert "ASoC: SOF: icp3-dtrace: Fix wrong kfree() usage"

PATCH Superseded Peter Ujfalusi 1 participant 2 messages Dec 14, 2023 – Jan 5, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Peter Ujfalusi

author maintainer
#0 lore raw

PATCH 1/1 Revert "ASoC: SOF: icp3-dtrace: Fix wrong kfree() usage"

This reverts commit 8c91ca76f44804868d12aed20ebdbc2f89aa7d60.

The offending patch introduces memory leak when there is no error, the memory allocated for the temporary storage is not freed up.

As I have commented, the original code was correct and cleaner to follow but it was not obvious from the patch that it will introduce regression.

---
 sound/soc/sof/ipc3-dtrace.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/sof/ipc3-dtrace.c +1 -2
index 93b189c2d2ee..0dca139322f3 100644
@@ -137,7 +137,6 @@ static int trace_filter_parse(struct snd_sof_dev *sdev, char *string,
 			dev_err(sdev->dev,
 				"Parsing filter entry '%s' failed with %d\n",
 				entry, entry_len);
-			kfree(*out);
 			return -EINVAL;
 		}
 	}
@@ -209,13 +208,13 @@ static ssize_t dfsentry_trace_filter_write(struct file *file, const char __user
 		ret = ipc3_trace_update_filter(sdev, num_elems, elems);
 		if (ret < 0) {
 			dev_err(sdev->dev, "Filter update failed: %d\n", ret);
-			kfree(elems);
 			goto error;
 		}
 	}
 	ret = count;
 error:
 	kfree(string);
+	kfree(elems);
 	return ret;
 }
 
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

Hi Mark,

Quoted 8 lines · Peter Ujfalusi

This reverts commit 8c91ca76f44804868d12aed20ebdbc2f89aa7d60.

The offending patch introduces memory leak when there is no error, the memory allocated for the temporary storage is not freed up.

As I have commented, the original code was correct and cleaner to follow but it was not obvious from the patch that it will introduce regression.

Sorry to dump this, but can you take a look and pick this up? We are leaking memory in linux-next because of this.

Thanks,
Péter

Quoted 33 lines
---
 sound/soc/sof/ipc3-dtrace.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/sof/ipc3-dtrace.c +1 -2
index 93b189c2d2ee..0dca139322f3 100644
@@ -137,7 +137,6 @@ static int trace_filter_parse(struct snd_sof_dev *sdev, char *string,
 			dev_err(sdev->dev,
 				"Parsing filter entry '%s' failed with %d\n",
 				entry, entry_len);
-			kfree(*out);
 			return -EINVAL;
 		}
 	}
@@ -209,13 +208,13 @@ static ssize_t dfsentry_trace_filter_write(struct file *file, const char __user
 		ret = ipc3_trace_update_filter(sdev, num_elems, elems);
 		if (ret < 0) {
 			dev_err(sdev->dev, "Filter update failed: %d\n", ret);
-			kfree(elems);
 			goto error;
 		}
 	}
 	ret = count;
 error:
 	kfree(string);
+	kfree(elems);
 	return ret;
 }