Skip to content

Commit 2cc1275

Browse files
Aditya Pakkiwesteri
authored andcommitted
thunderbolt: Fix to check for kmemdup failure
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]>
1 parent e4dfdd5 commit 2cc1275

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
@@ -1294,21 +1294,24 @@ int tb_switch_configure(struct tb_switch *sw)
12941294
return tb_plug_events_active(sw, true);
12951295
}
12961296

1297-
static void tb_switch_set_uuid(struct tb_switch *sw)
1297+
static int tb_switch_set_uuid(struct tb_switch *sw)
12981298
{
12991299
u32 uuid[4];
1300-
int cap;
1300+
int cap, ret;
13011301

1302+
ret = 0;
13021303
if (sw->uuid)
1303-
return;
1304+
return ret;
13041305

13051306
/*
13061307
* The newer controllers include fused UUID as part of link
13071308
* controller specific registers
13081309
*/
13091310
cap = tb_switch_find_vse_cap(sw, TB_VSE_CAP_LINK_CONTROLLER);
13101311
if (cap > 0) {
1311-
tb_sw_read(sw, uuid, TB_CFG_SWITCH, cap + 3, 4);
1312+
ret = tb_sw_read(sw, uuid, TB_CFG_SWITCH, cap + 3, 4);
1313+
if (ret)
1314+
return ret;
13121315
} else {
13131316
/*
13141317
* ICM generates UUID based on UID and fills the upper
@@ -1323,6 +1326,9 @@ static void tb_switch_set_uuid(struct tb_switch *sw)
13231326
}
13241327

13251328
sw->uuid = kmemdup(uuid, sizeof(uuid), GFP_KERNEL);
1329+
if (!sw->uuid)
1330+
ret = -ENOMEM;
1331+
return ret;
13261332
}
13271333

13281334
static int tb_switch_add_dma_port(struct tb_switch *sw)
@@ -1372,7 +1378,9 @@ static int tb_switch_add_dma_port(struct tb_switch *sw)
13721378

13731379
if (status) {
13741380
tb_sw_info(sw, "switch flash authentication failed\n");
1375-
tb_switch_set_uuid(sw);
1381+
ret = tb_switch_set_uuid(sw);
1382+
if (ret)
1383+
return ret;
13761384
nvm_set_auth_status(sw, status);
13771385
}
13781386

@@ -1422,7 +1430,9 @@ int tb_switch_add(struct tb_switch *sw)
14221430
}
14231431
tb_sw_dbg(sw, "uid: %#llx\n", sw->uid);
14241432

1425-
tb_switch_set_uuid(sw);
1433+
ret = tb_switch_set_uuid(sw);
1434+
if (ret)
1435+
return ret;
14261436

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

0 commit comments

Comments
 (0)