Skip to content

Commit 144601f

Browse files
claudiubezneabebarino
authored andcommitted
clk: vc5: check memory returned by kasprintf()
kasprintf() returns a pointer to dynamically allocated memory. Pointer could be NULL in case allocation fails. Check pointer validity. Identified with coccinelle (kmerr.cocci script). Fixes: f491276 ("clk: vc5: Allow Versaclock driver to support multiple instances") Signed-off-by: Claudiu Beznea <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Luca Ceresoli <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent ac9a786 commit 144601f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

drivers/clk/clk-versaclock5.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,11 @@ static int vc5_probe(struct i2c_client *client)
10281028
}
10291029

10301030
init.name = kasprintf(GFP_KERNEL, "%pOFn.mux", client->dev.of_node);
1031+
if (!init.name) {
1032+
ret = -ENOMEM;
1033+
goto err_clk;
1034+
}
1035+
10311036
init.ops = &vc5_mux_ops;
10321037
init.flags = 0;
10331038
init.parent_names = parent_names;
@@ -1042,6 +1047,10 @@ static int vc5_probe(struct i2c_client *client)
10421047
memset(&init, 0, sizeof(init));
10431048
init.name = kasprintf(GFP_KERNEL, "%pOFn.dbl",
10441049
client->dev.of_node);
1050+
if (!init.name) {
1051+
ret = -ENOMEM;
1052+
goto err_clk;
1053+
}
10451054
init.ops = &vc5_dbl_ops;
10461055
init.flags = CLK_SET_RATE_PARENT;
10471056
init.parent_names = parent_names;
@@ -1057,6 +1066,10 @@ static int vc5_probe(struct i2c_client *client)
10571066
/* Register PFD */
10581067
memset(&init, 0, sizeof(init));
10591068
init.name = kasprintf(GFP_KERNEL, "%pOFn.pfd", client->dev.of_node);
1069+
if (!init.name) {
1070+
ret = -ENOMEM;
1071+
goto err_clk;
1072+
}
10601073
init.ops = &vc5_pfd_ops;
10611074
init.flags = CLK_SET_RATE_PARENT;
10621075
init.parent_names = parent_names;
@@ -1074,6 +1087,10 @@ static int vc5_probe(struct i2c_client *client)
10741087
/* Register PLL */
10751088
memset(&init, 0, sizeof(init));
10761089
init.name = kasprintf(GFP_KERNEL, "%pOFn.pll", client->dev.of_node);
1090+
if (!init.name) {
1091+
ret = -ENOMEM;
1092+
goto err_clk;
1093+
}
10771094
init.ops = &vc5_pll_ops;
10781095
init.flags = CLK_SET_RATE_PARENT;
10791096
init.parent_names = parent_names;
@@ -1093,6 +1110,10 @@ static int vc5_probe(struct i2c_client *client)
10931110
memset(&init, 0, sizeof(init));
10941111
init.name = kasprintf(GFP_KERNEL, "%pOFn.fod%d",
10951112
client->dev.of_node, idx);
1113+
if (!init.name) {
1114+
ret = -ENOMEM;
1115+
goto err_clk;
1116+
}
10961117
init.ops = &vc5_fod_ops;
10971118
init.flags = CLK_SET_RATE_PARENT;
10981119
init.parent_names = parent_names;
@@ -1111,6 +1132,10 @@ static int vc5_probe(struct i2c_client *client)
11111132
memset(&init, 0, sizeof(init));
11121133
init.name = kasprintf(GFP_KERNEL, "%pOFn.out0_sel_i2cb",
11131134
client->dev.of_node);
1135+
if (!init.name) {
1136+
ret = -ENOMEM;
1137+
goto err_clk;
1138+
}
11141139
init.ops = &vc5_clk_out_ops;
11151140
init.flags = CLK_SET_RATE_PARENT;
11161141
init.parent_names = parent_names;
@@ -1137,6 +1162,10 @@ static int vc5_probe(struct i2c_client *client)
11371162
memset(&init, 0, sizeof(init));
11381163
init.name = kasprintf(GFP_KERNEL, "%pOFn.out%d",
11391164
client->dev.of_node, idx + 1);
1165+
if (!init.name) {
1166+
ret = -ENOMEM;
1167+
goto err_clk;
1168+
}
11401169
init.ops = &vc5_clk_out_ops;
11411170
init.flags = CLK_SET_RATE_PARENT;
11421171
init.parent_names = parent_names;

0 commit comments

Comments
 (0)