diff mbox

PM / clock_ops: initialize ret to avoid garbage being returned

Message ID 1420731061-5029-1-git-send-email-colin.king@canonical.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Colin King Jan. 8, 2015, 3:31 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

cppcheck detected an unitialised ret:
  [drivers/base/power/clock_ops.c:53]: (error) Uninitialized variable: ret

ret is only assigned if ce->status < PCE_STATUS_ERROR, if this is false
then __pm_clk_enable returns whatever garbage ret picks up from the stack.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/base/power/clock_ops.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Pavel Machek Jan. 18, 2015, 9 p.m. UTC | #1
On Thu 2015-01-08 15:31:01, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> cppcheck detected an unitialised ret:
>   [drivers/base/power/clock_ops.c:53]: (error) Uninitialized variable: ret
> 
> ret is only assigned if ce->status < PCE_STATUS_ERROR, if this is false
> then __pm_clk_enable returns whatever garbage ret picks up from the stack.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

> ---
>  drivers/base/power/clock_ops.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/base/power/clock_ops.c b/drivers/base/power/clock_ops.c
> index d626576..5bd283d 100644
> --- a/drivers/base/power/clock_ops.c
> +++ b/drivers/base/power/clock_ops.c
> @@ -39,7 +39,7 @@ struct pm_clock_entry {
>   */
>  static inline int __pm_clk_enable(struct device *dev, struct pm_clock_entry *ce)
>  {
> -	int ret;
> +	int ret = 0;
>  
>  	if (ce->status < PCE_STATUS_ERROR) {
>  		ret = clk_enable(ce->clk);

Actually, is this right solution? If clock entry has an error, we
won't enable it, and should probably return some kind of error...?

									Pavel
diff mbox

Patch

diff --git a/drivers/base/power/clock_ops.c b/drivers/base/power/clock_ops.c
index d626576..5bd283d 100644
--- a/drivers/base/power/clock_ops.c
+++ b/drivers/base/power/clock_ops.c
@@ -39,7 +39,7 @@  struct pm_clock_entry {
  */
 static inline int __pm_clk_enable(struct device *dev, struct pm_clock_entry *ce)
 {
-	int ret;
+	int ret = 0;
 
 	if (ce->status < PCE_STATUS_ERROR) {
 		ret = clk_enable(ce->clk);