Commit 144601f6 authored by Claudiu Beznea's avatar Claudiu Beznea Committed by Stephen Boyd

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: f491276a ("clk: vc5: Allow Versaclock driver to support multiple instances")
Signed-off-by: default avatarClaudiu Beznea <claudiu.beznea@microchip.com>
Link: https://lore.kernel.org/r/20230530093913.1656095-2-claudiu.beznea@microchip.comReviewed-by: default avatarLuca Ceresoli <luca.ceresoli@bootlin.com>
Signed-off-by: default avatarStephen Boyd <sboyd@kernel.org>
parent ac9a7868
...@@ -1028,6 +1028,11 @@ static int vc5_probe(struct i2c_client *client) ...@@ -1028,6 +1028,11 @@ static int vc5_probe(struct i2c_client *client)
} }
init.name = kasprintf(GFP_KERNEL, "%pOFn.mux", client->dev.of_node); init.name = kasprintf(GFP_KERNEL, "%pOFn.mux", client->dev.of_node);
if (!init.name) {
ret = -ENOMEM;
goto err_clk;
}
init.ops = &vc5_mux_ops; init.ops = &vc5_mux_ops;
init.flags = 0; init.flags = 0;
init.parent_names = parent_names; init.parent_names = parent_names;
...@@ -1042,6 +1047,10 @@ static int vc5_probe(struct i2c_client *client) ...@@ -1042,6 +1047,10 @@ static int vc5_probe(struct i2c_client *client)
memset(&init, 0, sizeof(init)); memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.dbl", init.name = kasprintf(GFP_KERNEL, "%pOFn.dbl",
client->dev.of_node); client->dev.of_node);
if (!init.name) {
ret = -ENOMEM;
goto err_clk;
}
init.ops = &vc5_dbl_ops; init.ops = &vc5_dbl_ops;
init.flags = CLK_SET_RATE_PARENT; init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names; init.parent_names = parent_names;
...@@ -1057,6 +1066,10 @@ static int vc5_probe(struct i2c_client *client) ...@@ -1057,6 +1066,10 @@ static int vc5_probe(struct i2c_client *client)
/* Register PFD */ /* Register PFD */
memset(&init, 0, sizeof(init)); memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.pfd", client->dev.of_node); init.name = kasprintf(GFP_KERNEL, "%pOFn.pfd", client->dev.of_node);
if (!init.name) {
ret = -ENOMEM;
goto err_clk;
}
init.ops = &vc5_pfd_ops; init.ops = &vc5_pfd_ops;
init.flags = CLK_SET_RATE_PARENT; init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names; init.parent_names = parent_names;
...@@ -1074,6 +1087,10 @@ static int vc5_probe(struct i2c_client *client) ...@@ -1074,6 +1087,10 @@ static int vc5_probe(struct i2c_client *client)
/* Register PLL */ /* Register PLL */
memset(&init, 0, sizeof(init)); memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.pll", client->dev.of_node); init.name = kasprintf(GFP_KERNEL, "%pOFn.pll", client->dev.of_node);
if (!init.name) {
ret = -ENOMEM;
goto err_clk;
}
init.ops = &vc5_pll_ops; init.ops = &vc5_pll_ops;
init.flags = CLK_SET_RATE_PARENT; init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names; init.parent_names = parent_names;
...@@ -1093,6 +1110,10 @@ static int vc5_probe(struct i2c_client *client) ...@@ -1093,6 +1110,10 @@ static int vc5_probe(struct i2c_client *client)
memset(&init, 0, sizeof(init)); memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.fod%d", init.name = kasprintf(GFP_KERNEL, "%pOFn.fod%d",
client->dev.of_node, idx); client->dev.of_node, idx);
if (!init.name) {
ret = -ENOMEM;
goto err_clk;
}
init.ops = &vc5_fod_ops; init.ops = &vc5_fod_ops;
init.flags = CLK_SET_RATE_PARENT; init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names; init.parent_names = parent_names;
...@@ -1111,6 +1132,10 @@ static int vc5_probe(struct i2c_client *client) ...@@ -1111,6 +1132,10 @@ static int vc5_probe(struct i2c_client *client)
memset(&init, 0, sizeof(init)); memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.out0_sel_i2cb", init.name = kasprintf(GFP_KERNEL, "%pOFn.out0_sel_i2cb",
client->dev.of_node); client->dev.of_node);
if (!init.name) {
ret = -ENOMEM;
goto err_clk;
}
init.ops = &vc5_clk_out_ops; init.ops = &vc5_clk_out_ops;
init.flags = CLK_SET_RATE_PARENT; init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names; init.parent_names = parent_names;
...@@ -1137,6 +1162,10 @@ static int vc5_probe(struct i2c_client *client) ...@@ -1137,6 +1162,10 @@ static int vc5_probe(struct i2c_client *client)
memset(&init, 0, sizeof(init)); memset(&init, 0, sizeof(init));
init.name = kasprintf(GFP_KERNEL, "%pOFn.out%d", init.name = kasprintf(GFP_KERNEL, "%pOFn.out%d",
client->dev.of_node, idx + 1); client->dev.of_node, idx + 1);
if (!init.name) {
ret = -ENOMEM;
goto err_clk;
}
init.ops = &vc5_clk_out_ops; init.ops = &vc5_clk_out_ops;
init.flags = CLK_SET_RATE_PARENT; init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent_names; init.parent_names = parent_names;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment