All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V3] clk: vc5: Add memory check to prevent oops
@ 2020-07-16 12:26 Adam Ford
  2020-07-21  9:19 ` Stephen Boyd
  2020-07-23  1:46 ` Stephen Boyd
  0 siblings, 2 replies; 4+ messages in thread
From: Adam Ford @ 2020-07-16 12:26 UTC (permalink / raw)
  To: linux-clk
  Cc: dan.carpenter, luca, aford, Adam Ford, Marek Vasut,
	Michael Turquette, Stephen Boyd, linux-kernel

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: 260249f929e8 ("clk: vc5: Enable addition output configurations of the Versaclock")

Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Adam Ford <aford173@gmail.com>
Reviewed-by: Luca Ceresoli <luca@lucaceresoli.net>
---
V3:   Fix spelling error, and use the style of checking (!variable) instead of
      (variable == NULL)

V2:   Fix an issue where a goto was going to use an unitialized variable.

diff --git a/drivers/clk/clk-versaclock5.c b/drivers/clk/clk-versaclock5.c
index 9a5fb3834b9a..9a37168c4afc 100644
--- a/drivers/clk/clk-versaclock5.c
+++ b/drivers/clk/clk-versaclock5.c
@@ -789,10 +789,13 @@ static int vc5_get_output_config(struct i2c_client *client,
 	int ret = 0;
 
 	child_name = kasprintf(GFP_KERNEL, "OUT%d", clk_out->num + 1);
+	if (!child_name)
+		return -ENOMEM;
+
 	np_output = of_get_child_by_name(client->dev.of_node, child_name);
 	kfree(child_name);
 	if (!np_output)
-		goto output_done;
+		return 0;
 
 	ret = vc5_update_mode(np_output, clk_out);
 	if (ret)
@@ -813,7 +816,6 @@ static int vc5_get_output_config(struct i2c_client *client,
 
 	of_node_put(np_output);
 
-output_done:
 	return ret;
 }
 
@@ -828,7 +830,7 @@ static int vc5_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	int ret;
 
 	vc5 = devm_kzalloc(&client->dev, sizeof(*vc5), GFP_KERNEL);
-	if (vc5 == NULL)
+	if (!vc5)
 		return -ENOMEM;
 
 	i2c_set_clientdata(client, vc5);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V3] clk: vc5: Add memory check to prevent oops
  2020-07-16 12:26 [PATCH V3] clk: vc5: Add memory check to prevent oops Adam Ford
@ 2020-07-21  9:19 ` Stephen Boyd
  2020-07-21 10:10   ` Luca Ceresoli
  2020-07-23  1:46 ` Stephen Boyd
  1 sibling, 1 reply; 4+ messages in thread
From: Stephen Boyd @ 2020-07-21  9:19 UTC (permalink / raw)
  To: Adam Ford, linux-clk
  Cc: dan.carpenter, luca, aford, Adam Ford, Marek Vasut,
	Michael Turquette, linux-kernel

Quoting Adam Ford (2020-07-16 05:26:20)
> 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: 260249f929e8 ("clk: vc5: Enable addition output configurations of the Versaclock")
> 
> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Adam Ford <aford173@gmail.com>
> Reviewed-by: Luca Ceresoli <luca@lucaceresoli.net>
> ---
> V3:   Fix spelling error, and use the style of checking (!variable) instead of
>       (variable == NULL)
> 
> V2:   Fix an issue where a goto was going to use an unitialized variable.

Is the patch from Colin also needed?
https://lore.kernel.org/r/20200625132736.88832-1-colin.king@canonical.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V3] clk: vc5: Add memory check to prevent oops
  2020-07-21  9:19 ` Stephen Boyd
@ 2020-07-21 10:10   ` Luca Ceresoli
  0 siblings, 0 replies; 4+ messages in thread
From: Luca Ceresoli @ 2020-07-21 10:10 UTC (permalink / raw)
  To: Stephen Boyd, Adam Ford, linux-clk
  Cc: dan.carpenter, aford, Marek Vasut, Michael Turquette, linux-kernel

Hi Stephen,

On 21/07/20 11:19, Stephen Boyd wrote:
> Quoting Adam Ford (2020-07-16 05:26:20)
>> 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: 260249f929e8 ("clk: vc5: Enable addition output configurations of the Versaclock")
>>
>> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
>> Signed-off-by: Adam Ford <aford173@gmail.com>
>> Reviewed-by: Luca Ceresoli <luca@lucaceresoli.net>
>> ---
>> V3:   Fix spelling error, and use the style of checking (!variable) instead of
>>       (variable == NULL)
>>
>> V2:   Fix an issue where a goto was going to use an unitialized variable.
> 
> Is the patch from Colin also needed?
> https://lore.kernel.org/r/20200625132736.88832-1-colin.king@canonical.com

The two patches look completely orthogonal.

-- 
Luca

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V3] clk: vc5: Add memory check to prevent oops
  2020-07-16 12:26 [PATCH V3] clk: vc5: Add memory check to prevent oops Adam Ford
  2020-07-21  9:19 ` Stephen Boyd
@ 2020-07-23  1:46 ` Stephen Boyd
  1 sibling, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2020-07-23  1:46 UTC (permalink / raw)
  To: Adam Ford, linux-clk
  Cc: dan.carpenter, luca, aford, Adam Ford, Marek Vasut,
	Michael Turquette, linux-kernel

Quoting Adam Ford (2020-07-16 05:26:20)
> 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: 260249f929e8 ("clk: vc5: Enable addition output configurations of the Versaclock")
> 
> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Adam Ford <aford173@gmail.com>
> Reviewed-by: Luca Ceresoli <luca@lucaceresoli.net>
> ---

Applied to clk-next

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-23  1:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-16 12:26 [PATCH V3] clk: vc5: Add memory check to prevent oops Adam Ford
2020-07-21  9:19 ` Stephen Boyd
2020-07-21 10:10   ` Luca Ceresoli
2020-07-23  1:46 ` Stephen Boyd

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.