Skip to content

Commit faf2933

Browse files
aford173bebarino
authored andcommitted
clk: vc5: Add memory check to prevent oops
When getting the names of the child nodes, kasprintf is used to allocate memory which is used to create the string for the node name. Unfortunately, there is no memory check to determine if this allocation fails, it may cause an error when trying to get child node name. This patch will check if the memory allocation fails, and returns and -ENOMEM error instead of blindly moving on. Fixes: 260249f ("clk: vc5: Enable addition output configurations of the Versaclock") Suggested-by: Dan Carpenter <[email protected]> Signed-off-by: Adam Ford <[email protected]> Reviewed-by: Luca Ceresoli <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 8200597 commit faf2933

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/clk/clk-versaclock5.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,13 @@ static int vc5_get_output_config(struct i2c_client *client,
789789
int ret = 0;
790790

791791
child_name = kasprintf(GFP_KERNEL, "OUT%d", clk_out->num + 1);
792+
if (!child_name)
793+
return -ENOMEM;
794+
792795
np_output = of_get_child_by_name(client->dev.of_node, child_name);
793796
kfree(child_name);
794797
if (!np_output)
795-
goto output_done;
798+
return 0;
796799

797800
ret = vc5_update_mode(np_output, clk_out);
798801
if (ret)
@@ -813,7 +816,6 @@ static int vc5_get_output_config(struct i2c_client *client,
813816

814817
of_node_put(np_output);
815818

816-
output_done:
817819
return ret;
818820
}
819821

@@ -828,7 +830,7 @@ static int vc5_probe(struct i2c_client *client, const struct i2c_device_id *id)
828830
int ret;
829831

830832
vc5 = devm_kzalloc(&client->dev, sizeof(*vc5), GFP_KERNEL);
831-
if (vc5 == NULL)
833+
if (!vc5)
832834
return -ENOMEM;
833835

834836
i2c_set_clientdata(client, vc5);

0 commit comments

Comments
 (0)