Skip to contentSkip to conversation

cpufreq: kryo: Fix possible error code dereference

PATCH Superseded [email protected] 3 participants 5 messages Jun 14, 2018 – Jun 21, 2018

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

PATCH 1/1 cpufreq: kryo: Fix possible error code dereference

From: Ilia Lin <[email protected]>

In event of error returned by the nvmem_cell_read() non-pointer value may be dereferenced. Fix this with error handling.

---
 drivers/cpufreq/qcom-cpufreq-kryo.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/cpufreq/qcom-cpufreq-kryo.c +2 -0
index d049fe4b80c4..5e9511223ce9 100644
@@ -115,6 +115,8 @@ static int qcom_cpufreq_kryo_probe(struct platform_device *pdev)
 
 	speedbin = nvmem_cell_read(speedbin_nvmem, &len);
 	nvmem_cell_put(speedbin_nvmem);
+	if (IS_ERR(speedbin))
+		return PTR_ERR(speedbin);
 
 	switch (msm8996_version) {
 	case MSM8996_V3:
Signature · 1 line
2.11.0
maintainer
#1 lore raw
Quoted 6 lines · On 14-06-18, 22:29, [email protected] wrote:

From: Ilia Lin <[email protected]>

In event of error returned by the nvmem_cell_read() non-pointer value may be dereferenced. Fix this with error handling.

Fixes tag ?

Quoted 19 lines
---
 drivers/cpufreq/qcom-cpufreq-kryo.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/cpufreq/qcom-cpufreq-kryo.c +2 -0
index d049fe4b80c4..5e9511223ce9 100644
@@ -115,6 +115,8 @@ static int qcom_cpufreq_kryo_probe(struct platform_device *pdev)
 
 	speedbin = nvmem_cell_read(speedbin_nvmem, &len);
 	nvmem_cell_put(speedbin_nvmem);
+	if (IS_ERR(speedbin))
+		return PTR_ERR(speedbin);
 
 	switch (msm8996_version) {
 	case MSM8996_V3:
Signature · 1 line
2.11.0
Signature · 1 line
viresh
#2 lore raw

PATCH v2 1/1 cpufreq: kryo: Fix possible error code dereference

In reply to [email protected]

From: Ilia Lin <[email protected]>

In event of error returned by the nvmem_cell_read() non-pointer value may be dereferenced. Fix this with error handling. Additionally free the allocated speedbin buffer, as per the API.

Fixes 9ce36edd1a52 (cpufreq: Add Kryo CPU scaling driver)
---
 drivers/cpufreq/qcom-cpufreq-kryo.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/cpufreq/qcom-cpufreq-kryo.c +3 -0
index d049fe4b80c4..74b9b93d511b 100644
@@ -115,6 +115,8 @@ static int qcom_cpufreq_kryo_probe(struct platform_device *pdev)
 
 	speedbin = nvmem_cell_read(speedbin_nvmem, &len);
 	nvmem_cell_put(speedbin_nvmem);
+	if (IS_ERR(speedbin))
+		return PTR_ERR(speedbin);
 
 	switch (msm8996_version) {
 	case MSM8996_V3:
@@ -127,6 +129,7 @@ static int qcom_cpufreq_kryo_probe(struct platform_device *pdev)
 		BUG();
 		break;
 	}
+	kfree(speedbin);
 
 	for_each_possible_cpu(cpu) {
 		cpu_dev = get_cpu_device(cpu);
Signature · 1 line
2.11.0
maintainer Acked-by on v2 1/1
#3 lore raw
Quoted 26 lines · On 17-06-18, 21:58, [email protected] wrote:

From: Ilia Lin <[email protected]>

In event of error returned by the nvmem_cell_read() non-pointer value may be dereferenced. Fix this with error handling. Additionally free the allocated speedbin buffer, as per the API.

Fixes 9ce36edd1a52 (cpufreq: Add Kryo CPU scaling driver)
---
 drivers/cpufreq/qcom-cpufreq-kryo.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/cpufreq/qcom-cpufreq-kryo.c +2 -0
index d049fe4b80c4..74b9b93d511b 100644
@@ -115,6 +115,8 @@ static int qcom_cpufreq_kryo_probe(struct platform_device *pdev)
 
 	speedbin = nvmem_cell_read(speedbin_nvmem, &len);
 	nvmem_cell_put(speedbin_nvmem);
+	if (IS_ERR(speedbin))
+		return PTR_ERR(speedbin);
 
 	switch (msm8996_version) {
 	case MSM8996_V3:

drivers/cpufreq/qcom-cpufreq-kryo.c static int qcom_cpufreq_kryo_probe(struct platform_device *pdev) · line 135

Quoted 7 lines
drivers/cpufreq/qcom-cpufreq-kryo.c +1 -0
@@ -127,6 +129,7 @@ static int qcom_cpufreq_kryo_probe(struct platform_device *pdev)
 		BUG();
 		break;
 	}
+	kfree(speedbin);
 
 	for_each_possible_cpu(cpu) {
 		cpu_dev = get_cpu_device(cpu);

Ideally this should have been two patches as you were fixing two different problems. But anyway, you can go through this time.

Signature · 1 line
viresh
#4 lore raw
Quoted 32 lines · CEST Viresh Kumar
Quoted 31 lines · On 17-06-18, 21:58, [email protected] wrote:

From: Ilia Lin <[email protected]>

In event of error returned by the nvmem_cell_read() non-pointer value may be dereferenced. Fix this with error handling. Additionally free the allocated speedbin buffer, as per the API.

Fixes 9ce36edd1a52 (cpufreq: Add Kryo CPU scaling driver)
---
 drivers/cpufreq/qcom-cpufreq-kryo.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/cpufreq/qcom-cpufreq-kryo.c +3 -0
index d049fe4b80c4..74b9b93d511b 100644
@@ -115,6 +115,8 @@ static int qcom_cpufreq_kryo_probe(struct platform_device *pdev)
 
 	speedbin = nvmem_cell_read(speedbin_nvmem, &len);
 	nvmem_cell_put(speedbin_nvmem);
+	if (IS_ERR(speedbin))
+		return PTR_ERR(speedbin);
 
 	switch (msm8996_version) {
 	case MSM8996_V3:
@@ -127,6 +129,7 @@ static int qcom_cpufreq_kryo_probe(struct platform_device *pdev)
 		BUG();
 		break;
 	}
+	kfree(speedbin);
 
Quoted 7 lines

drivers/cpufreq/qcom-cpufreq-kryo.c static int qcom_cpufreq_kryo_probe(struct platform_device *pdev) · line 135

Quoted 2 lines
drivers/cpufreq/qcom-cpufreq-kryo.c +0 -0
 	for_each_possible_cpu(cpu) {
 		cpu_dev = get_cpu_device(cpu);

Ideally this should have been two patches as you were fixing two different problems. But anyway, you can go through this time.

Patch applied, thanks!