Skip to content

Commit a63a05a

Browse files
Aditya Pakkigregkh
authored andcommitted
thunderbolt: Fix to check for kmemdup failure
[ Upstream commit 2cc1275 ] Memory allocated via kmemdup might fail and return a NULL pointer. This patch adds a check on the return value of kmemdup and passes the error upstream. Signed-off-by: Aditya Pakki <[email protected]> Reviewed-by: Mukesh Ojha <[email protected]> Signed-off-by: Mika Westerberg <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent deb757e commit a63a05a

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

drivers/thunderbolt/switch.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,21 +1206,24 @@ int tb_switch_configure(struct tb_switch *sw)
12061206
return tb_plug_events_active(sw, true);
12071207
}
12081208

1209-
static void tb_switch_set_uuid(struct tb_switch *sw)
1209+
static int tb_switch_set_uuid(struct tb_switch *sw)
12101210
{
12111211
u32 uuid[4];
1212-
int cap;
1212+
int cap, ret;
12131213

1214+
ret = 0;
12141215
if (sw->uuid)
1215-
return;
1216+
return ret;
12161217

12171218
/*
12181219
* The newer controllers include fused UUID as part of link
12191220
* controller specific registers
12201221
*/
12211222
cap = tb_switch_find_vse_cap(sw, TB_VSE_CAP_LINK_CONTROLLER);
12221223
if (cap > 0) {
1223-
tb_sw_read(sw, uuid, TB_CFG_SWITCH, cap + 3, 4);
1224+
ret = tb_sw_read(sw, uuid, TB_CFG_SWITCH, cap + 3, 4);
1225+
if (ret)
1226+
return ret;
12241227
} else {
12251228
/*
12261229
* ICM generates UUID based on UID and fills the upper
@@ -1235,6 +1238,9 @@ static void tb_switch_set_uuid(struct tb_switch *sw)
12351238
}
12361239

12371240
sw->uuid = kmemdup(uuid, sizeof(uuid), GFP_KERNEL);
1241+
if (!sw->uuid)
1242+
ret = -ENOMEM;
1243+
return ret;
12381244
}
12391245

12401246
static int tb_switch_add_dma_port(struct tb_switch *sw)
@@ -1280,7 +1286,9 @@ static int tb_switch_add_dma_port(struct tb_switch *sw)
12801286

12811287
if (status) {
12821288
tb_sw_info(sw, "switch flash authentication failed\n");
1283-
tb_switch_set_uuid(sw);
1289+
ret = tb_switch_set_uuid(sw);
1290+
if (ret)
1291+
return ret;
12841292
nvm_set_auth_status(sw, status);
12851293
}
12861294

@@ -1330,7 +1338,9 @@ int tb_switch_add(struct tb_switch *sw)
13301338
}
13311339
tb_sw_info(sw, "uid: %#llx\n", sw->uid);
13321340

1333-
tb_switch_set_uuid(sw);
1341+
ret = tb_switch_set_uuid(sw);
1342+
if (ret)
1343+
return ret;
13341344

13351345
for (i = 0; i <= sw->config.max_port_number; i++) {
13361346
if (sw->ports[i].disabled) {

0 commit comments

Comments
 (0)