aboutsummaryrefslogtreecommitdiffstats
path: root/common/recipes-kernel/linux/files/0842-drm-amd-dal-fix-memory-leaks-in-I2C-code.patch
blob: bd3a533e9d26b2ea2ebf7885e936bb51d013a7dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
From eed795bce45f220f363abebbf87fac8a52877e16 Mon Sep 17 00:00:00 2001
From: Mykola Lysenko <Mykola.Lysenko@amd.com>
Date: Fri, 26 Feb 2016 04:04:07 -0500
Subject: [PATCH 0842/1110] drm/amd/dal: fix memory leaks in I2C code

Two memory leaks were fixed

Signed-off-by: Mykola Lysenko <Mykola.Lysenko@amd.com>
Acked-by: Harry Wentland <harry.wentland@amd.com>
---
 drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_helpers.c | 10 +++++++++-
 drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_types.c   | 13 ++++++++++---
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_helpers.c b/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_helpers.c
index e414861..17240e0 100644
--- a/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_helpers.c
+++ b/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_helpers.c
@@ -515,6 +515,7 @@ bool dm_helpers_submit_i2c(
 	struct i2c_msg *msgs;
 	int i = 0;
 	int num = cmd->number_of_payloads;
+	bool result;
 
 	if (!aconnector) {
 		DRM_ERROR("Failed to found connector for link!");
@@ -523,6 +524,9 @@ bool dm_helpers_submit_i2c(
 
 	msgs = kzalloc(num * sizeof(struct i2c_msg), GFP_KERNEL);
 
+	if (!msgs)
+		return false;
+
 	for (i = 0; i < num; i++) {
 		msgs[i].flags = cmd->payloads[i].write ? I2C_M_RD : 0;
 		msgs[i].addr = cmd->payloads[i].address;
@@ -530,6 +534,10 @@ bool dm_helpers_submit_i2c(
 		msgs[i].buf = cmd->payloads[i].data;
 	}
 
-	return i2c_transfer(&aconnector->i2c->base, msgs, num) == num;
+	result = i2c_transfer(&aconnector->i2c->base, msgs, num) == num;
+
+	kfree(msgs);
+
+	return result;
 }
 
diff --git a/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_types.c b/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_types.c
index ec02029..f0eaafd 100644
--- a/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_types.c
+++ b/drivers/gpu/drm/amd/dal/amdgpu_dm/amdgpu_dm_types.c
@@ -1814,8 +1814,13 @@ int amdgpu_dm_i2c_xfer(struct i2c_adapter *i2c_adap,
 	struct amdgpu_i2c_adapter *i2c = i2c_get_adapdata(i2c_adap);
 	struct i2c_command cmd;
 	int i;
+	int result = -EIO;
 
 	cmd.payloads = kzalloc(num * sizeof(struct i2c_payload), GFP_KERNEL);
+
+	if (!cmd.payloads)
+		return result;
+
 	cmd.number_of_payloads = num;
 	cmd.engine = I2C_COMMAND_ENGINE_DEFAULT;
 	cmd.speed = 100;
@@ -1828,9 +1833,11 @@ int amdgpu_dm_i2c_xfer(struct i2c_adapter *i2c_adap,
 	}
 
 	if (dc_submit_i2c(i2c->dm->dc, i2c->link_index, &cmd))
-		return num;
-	else
-		return -EIO;
+		result = num;
+
+	kfree(cmd.payloads);
+
+	return result;
 }
 
 u32 amdgpu_dm_i2c_func(struct i2c_adapter *adap)
-- 
2.7.4