public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] omap3: Check return values for clk_get
@ 2010-01-08 18:19 Sanjeev Premi
  2010-01-08 22:37 ` Kevin Hilman
  2010-01-20  1:19 ` Paul Walmsley
  0 siblings, 2 replies; 6+ messages in thread
From: Sanjeev Premi @ 2010-01-08 18:19 UTC (permalink / raw)
  To: linux-omap; +Cc: Sanjeev Premi

This patch checks if clk_get() returned success for
the clocks used in function omap2_clk_arch_init().

Signed-off-by: Sanjeev Premi <premi@ti.com>
---
 arch/arm/mach-omap2/clock34xx.c |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-omap2/clock34xx.c b/arch/arm/mach-omap2/clock34xx.c
index d4217b9..2c2165b 100644
--- a/arch/arm/mach-omap2/clock34xx.c
+++ b/arch/arm/mach-omap2/clock34xx.c
@@ -316,17 +316,38 @@ static int __init omap2_clk_arch_init(void)
 {
 	struct clk *osc_sys_ck, *dpll1_ck, *arm_fck, *core_ck;
 	unsigned long osc_sys_rate;
+	short err = 0 ;
 
 	if (!mpurate)
 		return -EINVAL;
 
-	/* XXX test these for success */
 	dpll1_ck = clk_get(NULL, "dpll1_ck");
+	if (dpll1_ck == NULL) {
+		err = 1;
+		pr_err("*** Failed to get dpll1_ck.\n");
+	}
+
 	arm_fck = clk_get(NULL, "arm_fck");
+	if (arm_fck == NULL) {
+		err = 1;
+		pr_err("*** Failed to get arm_fck.\n");
+	}
+
 	core_ck = clk_get(NULL, "core_ck");
+	if (core_ck == NULL) {
+		err = 1;
+		pr_err("*** Failed to get core_ck.\n");
+	}
+
 	osc_sys_ck = clk_get(NULL, "osc_sys_ck");
+	if (osc_sys_ck == NULL) {
+		err = 1;
+		pr_err("*** Failed to get osc_sys_ck.\n");
+	}
+
+	if (err)
+		return 1;
 
-	/* REVISIT: not yet ready for 343x */
 	if (clk_set_rate(dpll1_ck, mpurate))
 		printk(KERN_ERR "*** Unable to set MPU rate\n");
 
-- 
1.6.2.2


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

* Re: [PATCH] omap3: Check return values for clk_get
  2010-01-08 18:19 [PATCH] omap3: Check return values for clk_get Sanjeev Premi
@ 2010-01-08 22:37 ` Kevin Hilman
  2010-01-28 14:11   ` Premi, Sanjeev
  2010-01-20  1:19 ` Paul Walmsley
  1 sibling, 1 reply; 6+ messages in thread
From: Kevin Hilman @ 2010-01-08 22:37 UTC (permalink / raw)
  To: Sanjeev Premi; +Cc: linux-omap

Sanjeev Premi <premi@ti.com> writes:

> This patch checks if clk_get() returned success for
> the clocks used in function omap2_clk_arch_init().
>
> Signed-off-by: Sanjeev Premi <premi@ti.com>
> ---
>  arch/arm/mach-omap2/clock34xx.c |   25 +++++++++++++++++++++++--
>  1 files changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/mach-omap2/clock34xx.c b/arch/arm/mach-omap2/clock34xx.c
> index d4217b9..2c2165b 100644
> --- a/arch/arm/mach-omap2/clock34xx.c
> +++ b/arch/arm/mach-omap2/clock34xx.c
> @@ -316,17 +316,38 @@ static int __init omap2_clk_arch_init(void)
>  {
>  	struct clk *osc_sys_ck, *dpll1_ck, *arm_fck, *core_ck;
>  	unsigned long osc_sys_rate;
> +	short err = 0 ;
>  
>  	if (!mpurate)
>  		return -EINVAL;
>  
> -	/* XXX test these for success */
>  	dpll1_ck = clk_get(NULL, "dpll1_ck");
> +	if (dpll1_ck == NULL) {

All of these checks should be of the form

        if (IS_ERR(<clk>))       

instead of NULL pointer checks.

You could also do something more compact like this, which takes
care of the error check and warning print:

        if (WARN(IS_ERR(<clk ptr>), "Failed to get <name>\n"))

> +		err = 1;
> +		pr_err("*** Failed to get dpll1_ck.\n");
> +	}
> +
>  	arm_fck = clk_get(NULL, "arm_fck");
> +	if (arm_fck == NULL) {
> +		err = 1;
> +		pr_err("*** Failed to get arm_fck.\n");
> +	}
> +
>  	core_ck = clk_get(NULL, "core_ck");
> +	if (core_ck == NULL) {
> +		err = 1;
> +		pr_err("*** Failed to get core_ck.\n");
> +	}
> +
>  	osc_sys_ck = clk_get(NULL, "osc_sys_ck");
> +	if (osc_sys_ck == NULL) {
> +		err = 1;
> +		pr_err("*** Failed to get osc_sys_ck.\n");
> +	}
> +
> +	if (err)
> +		return 1;

Minor issue...

Do you want to skip the rest of the init in case of any failure?

It seems like the DPLL1 is the only one that would be a real failure,
the others just affect the clock display.


Kevin

> -	/* REVISIT: not yet ready for 343x */
>  	if (clk_set_rate(dpll1_ck, mpurate))
>  		printk(KERN_ERR "*** Unable to set MPU rate\n");
>  
> -- 
> 1.6.2.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] omap3: Check return values for clk_get
  2010-01-08 18:19 [PATCH] omap3: Check return values for clk_get Sanjeev Premi
  2010-01-08 22:37 ` Kevin Hilman
@ 2010-01-20  1:19 ` Paul Walmsley
  2010-01-21 14:35   ` Premi, Sanjeev
  1 sibling, 1 reply; 6+ messages in thread
From: Paul Walmsley @ 2010-01-20  1:19 UTC (permalink / raw)
  To: Sanjeev Premi; +Cc: linux-omap

Hello Sanjeev,

some comments.


On Fri, 8 Jan 2010, Sanjeev Premi wrote:

> This patch checks if clk_get() returned success for
> the clocks used in function omap2_clk_arch_init().
> 
> Signed-off-by: Sanjeev Premi <premi@ti.com>
> ---
>  arch/arm/mach-omap2/clock34xx.c |   25 +++++++++++++++++++++++--
>  1 files changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/mach-omap2/clock34xx.c b/arch/arm/mach-omap2/clock34xx.c
> index d4217b9..2c2165b 100644
> --- a/arch/arm/mach-omap2/clock34xx.c
> +++ b/arch/arm/mach-omap2/clock34xx.c
> @@ -316,17 +316,38 @@ static int __init omap2_clk_arch_init(void)
>  {
>  	struct clk *osc_sys_ck, *dpll1_ck, *arm_fck, *core_ck;
>  	unsigned long osc_sys_rate;
> +	short err = 0 ;

Why a 'short' here?  Seems like it makes more sense as a bool.

>  
>  	if (!mpurate)
>  		return -EINVAL;
>  
> -	/* XXX test these for success */
>  	dpll1_ck = clk_get(NULL, "dpll1_ck");
> +	if (dpll1_ck == NULL) {
> +		err = 1;
> +		pr_err("*** Failed to get dpll1_ck.\n");
> +	}
> +
>  	arm_fck = clk_get(NULL, "arm_fck");
> +	if (arm_fck == NULL) {
> +		err = 1;
> +		pr_err("*** Failed to get arm_fck.\n");
> +	}
> +
>  	core_ck = clk_get(NULL, "core_ck");
> +	if (core_ck == NULL) {
> +		err = 1;
> +		pr_err("*** Failed to get core_ck.\n");
> +	}
> +
>  	osc_sys_ck = clk_get(NULL, "osc_sys_ck");
> +	if (osc_sys_ck == NULL) {
> +		err = 1;
> +		pr_err("*** Failed to get osc_sys_ck.\n");
> +	}
> +
> +	if (err)
> +		return 1;

This is not a good error value.  This function should return either 0 for 
success or a negative error number on failure.  Maybe ENOENT?

>  
> -	/* REVISIT: not yet ready for 343x */
>  	if (clk_set_rate(dpll1_ck, mpurate))
>  		printk(KERN_ERR "*** Unable to set MPU rate\n");
>  
> -- 
> 1.6.2.2
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


- Paul

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

* RE: [PATCH] omap3: Check return values for clk_get
  2010-01-20  1:19 ` Paul Walmsley
@ 2010-01-21 14:35   ` Premi, Sanjeev
  0 siblings, 0 replies; 6+ messages in thread
From: Premi, Sanjeev @ 2010-01-21 14:35 UTC (permalink / raw)
  To: Paul Walmsley; +Cc: linux-omap@vger.kernel.org

> -----Original Message-----
> From: Paul Walmsley [mailto:paul@pwsan.com] 
> Sent: Wednesday, January 20, 2010 6:49 AM
> To: Premi, Sanjeev
> Cc: linux-omap@vger.kernel.org
> Subject: Re: [PATCH] omap3: Check return values for clk_get
> 
> Hello Sanjeev,
> 
> some comments.
> 
> 
> On Fri, 8 Jan 2010, Sanjeev Premi wrote:
> 
> > This patch checks if clk_get() returned success for
> > the clocks used in function omap2_clk_arch_init().
> > 
> > Signed-off-by: Sanjeev Premi <premi@ti.com>
> > ---
> >  arch/arm/mach-omap2/clock34xx.c |   25 +++++++++++++++++++++++--
> >  1 files changed, 23 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/arm/mach-omap2/clock34xx.c 
> b/arch/arm/mach-omap2/clock34xx.c
> > index d4217b9..2c2165b 100644
> > --- a/arch/arm/mach-omap2/clock34xx.c
> > +++ b/arch/arm/mach-omap2/clock34xx.c
> > @@ -316,17 +316,38 @@ static int __init omap2_clk_arch_init(void)
> >  {
> >  	struct clk *osc_sys_ck, *dpll1_ck, *arm_fck, *core_ck;
> >  	unsigned long osc_sys_rate;
> > +	short err = 0 ;
> 
> Why a 'short' here?  Seems like it makes more sense as a bool.
> 
> >  
> >  	if (!mpurate)
> >  		return -EINVAL;
> >  
> > -	/* XXX test these for success */
> >  	dpll1_ck = clk_get(NULL, "dpll1_ck");
> > +	if (dpll1_ck == NULL) {
> > +		err = 1;
> > +		pr_err("*** Failed to get dpll1_ck.\n");
> > +	}
> > +
> >  	arm_fck = clk_get(NULL, "arm_fck");
> > +	if (arm_fck == NULL) {
> > +		err = 1;
> > +		pr_err("*** Failed to get arm_fck.\n");
> > +	}
> > +
> >  	core_ck = clk_get(NULL, "core_ck");
> > +	if (core_ck == NULL) {
> > +		err = 1;
> > +		pr_err("*** Failed to get core_ck.\n");
> > +	}
> > +
> >  	osc_sys_ck = clk_get(NULL, "osc_sys_ck");
> > +	if (osc_sys_ck == NULL) {
> > +		err = 1;
> > +		pr_err("*** Failed to get osc_sys_ck.\n");
> > +	}
> > +
> > +	if (err)
> > +		return 1;
> 
> This is not a good error value.  This function should return 
> either 0 for 
> success or a negative error number on failure.  Maybe ENOENT?
> 

Thanks for comments Paul.

After Kevin's comments, I had reworked this patch and I believe all
your comments are getting addressed there

I am stuck in some 3630/3730 boot issues; will be sending the
updated patch soon.

Best regards,
Sanjeev

> >  
> > -	/* REVISIT: not yet ready for 343x */
> >  	if (clk_set_rate(dpll1_ck, mpurate))
> >  		printk(KERN_ERR "*** Unable to set MPU rate\n");
> >  
> > -- 
> > 1.6.2.2
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe 
> linux-omap" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 
> 
> 
> - Paul
> 

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

* RE: [PATCH] omap3: Check return values for clk_get
  2010-01-08 22:37 ` Kevin Hilman
@ 2010-01-28 14:11   ` Premi, Sanjeev
  2010-01-28 15:01     ` Premi, Sanjeev
  0 siblings, 1 reply; 6+ messages in thread
From: Premi, Sanjeev @ 2010-01-28 14:11 UTC (permalink / raw)
  To: Kevin Hilman; +Cc: linux-omap@vger.kernel.org

 
> -----Original Message-----
> From: Kevin Hilman [mailto:khilman@deeprootsystems.com] 
> Sent: Saturday, January 09, 2010 4:08 AM
> To: Premi, Sanjeev
> Cc: linux-omap@vger.kernel.org
> Subject: Re: [PATCH] omap3: Check return values for clk_get
> 
> Sanjeev Premi <premi@ti.com> writes:
> 
> > This patch checks if clk_get() returned success for
> > the clocks used in function omap2_clk_arch_init().
> >
> > Signed-off-by: Sanjeev Premi <premi@ti.com>
> > ---
> >  arch/arm/mach-omap2/clock34xx.c |   25 +++++++++++++++++++++++--
> >  1 files changed, 23 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/arm/mach-omap2/clock34xx.c 
> b/arch/arm/mach-omap2/clock34xx.c
> > index d4217b9..2c2165b 100644
> > --- a/arch/arm/mach-omap2/clock34xx.c
> > +++ b/arch/arm/mach-omap2/clock34xx.c
> > @@ -316,17 +316,38 @@ static int __init omap2_clk_arch_init(void)
> >  {
> >  	struct clk *osc_sys_ck, *dpll1_ck, *arm_fck, *core_ck;
> >  	unsigned long osc_sys_rate;
> > +	short err = 0 ;
> >  
> >  	if (!mpurate)
> >  		return -EINVAL;
> >  
> > -	/* XXX test these for success */
> >  	dpll1_ck = clk_get(NULL, "dpll1_ck");
> > +	if (dpll1_ck == NULL) {
> 
> All of these checks should be of the form
> 
>         if (IS_ERR(<clk>))       
> 
> instead of NULL pointer checks.

Kevin,

    In include/linux/err.h

    #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)

    static inline long PTR_ERR(const void *ptr)
    {
        return (long) ptr;
    }

    static inline long IS_ERR(const void *ptr)
    {
        return IS_ERR_VALUE((unsigned long)ptr);
    }

    I believe you wanted me to use PTR_ERR(); not IS_ERR().

> 
> You could also do something more compact like this, which takes
> care of the error check and warning print:
> 
>         if (WARN(IS_ERR(<clk ptr>), "Failed to get <name>\n"))
> 
[sp] Sure will compact it.

> > +		err = 1;
> > +		pr_err("*** Failed to get dpll1_ck.\n");
> > +	}
> > +
> >  	arm_fck = clk_get(NULL, "arm_fck");
> > +	if (arm_fck == NULL) {
> > +		err = 1;
> > +		pr_err("*** Failed to get arm_fck.\n");
> > +	}
> > +
> >  	core_ck = clk_get(NULL, "core_ck");
> > +	if (core_ck == NULL) {
> > +		err = 1;
> > +		pr_err("*** Failed to get core_ck.\n");
> > +	}
> > +
> >  	osc_sys_ck = clk_get(NULL, "osc_sys_ck");
> > +	if (osc_sys_ck == NULL) {
> > +		err = 1;
> > +		pr_err("*** Failed to get osc_sys_ck.\n");
> > +	}
> > +
> > +	if (err)
> > +		return 1;
> 
> Minor issue...
> 
> Do you want to skip the rest of the init in case of any failure?
> 
> It seems like the DPLL1 is the only one that would be a real failure,
> the others just affect the clock display.

[sp] But, even when if we use bad pointers for displaying clocks, it
     could be bad.

Best regards,
Sanjeev
> 
> 
> Kevin
> 
> > -	/* REVISIT: not yet ready for 343x */
> >  	if (clk_set_rate(dpll1_ck, mpurate))
> >  		printk(KERN_ERR "*** Unable to set MPU rate\n");
> >  
> > -- 
> > 1.6.2.2
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe 
> linux-omap" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

* RE: [PATCH] omap3: Check return values for clk_get
  2010-01-28 14:11   ` Premi, Sanjeev
@ 2010-01-28 15:01     ` Premi, Sanjeev
  0 siblings, 0 replies; 6+ messages in thread
From: Premi, Sanjeev @ 2010-01-28 15:01 UTC (permalink / raw)
  To: Premi, Sanjeev, Kevin Hilman; +Cc: linux-omap@vger.kernel.org

> -----Original Message-----
> From: linux-omap-owner@vger.kernel.org 
> [mailto:linux-omap-owner@vger.kernel.org] On Behalf Of Premi, Sanjeev
> Sent: Thursday, January 28, 2010 7:42 PM
> To: Kevin Hilman
> Cc: linux-omap@vger.kernel.org
> Subject: RE: [PATCH] omap3: Check return values for clk_get
> 
>  
> > -----Original Message-----
> > From: Kevin Hilman [mailto:khilman@deeprootsystems.com] 
> > Sent: Saturday, January 09, 2010 4:08 AM
> > To: Premi, Sanjeev
> > Cc: linux-omap@vger.kernel.org
> > Subject: Re: [PATCH] omap3: Check return values for clk_get
> > 
> > Sanjeev Premi <premi@ti.com> writes:
> > 
> > > This patch checks if clk_get() returned success for
> > > the clocks used in function omap2_clk_arch_init().
> > >
> > > Signed-off-by: Sanjeev Premi <premi@ti.com>
> > > ---
> > >  arch/arm/mach-omap2/clock34xx.c |   25 +++++++++++++++++++++++--
> > >  1 files changed, 23 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/arch/arm/mach-omap2/clock34xx.c 
> > b/arch/arm/mach-omap2/clock34xx.c
> > > index d4217b9..2c2165b 100644
> > > --- a/arch/arm/mach-omap2/clock34xx.c
> > > +++ b/arch/arm/mach-omap2/clock34xx.c
> > > @@ -316,17 +316,38 @@ static int __init omap2_clk_arch_init(void)
> > >  {
> > >  	struct clk *osc_sys_ck, *dpll1_ck, *arm_fck, *core_ck;
> > >  	unsigned long osc_sys_rate;
> > > +	short err = 0 ;
> > >  
> > >  	if (!mpurate)
> > >  		return -EINVAL;
> > >  
> > > -	/* XXX test these for success */
> > >  	dpll1_ck = clk_get(NULL, "dpll1_ck");
> > > +	if (dpll1_ck == NULL) {
> > 
> > All of these checks should be of the form
> > 
> >         if (IS_ERR(<clk>))       
> > 
> > instead of NULL pointer checks.
> 
> Kevin,
> 
>     In include/linux/err.h
> 
>     #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
> 
>     static inline long PTR_ERR(const void *ptr)
>     {
>         return (long) ptr;
>     }
> 
>     static inline long IS_ERR(const void *ptr)
>     {
>         return IS_ERR_VALUE((unsigned long)ptr);
>     }
> 
>     I believe you wanted me to use PTR_ERR(); not IS_ERR().
> 

Kevin,

  Ignore this comment.

Best regards,
Sanjeev

> > 
> > You could also do something more compact like this, which takes
> > care of the error check and warning print:
> > 
> >         if (WARN(IS_ERR(<clk ptr>), "Failed to get <name>\n"))
> > 
> [sp] Sure will compact it.
> 
> > > +		err = 1;
> > > +		pr_err("*** Failed to get dpll1_ck.\n");
> > > +	}
> > > +
> > >  	arm_fck = clk_get(NULL, "arm_fck");
> > > +	if (arm_fck == NULL) {
> > > +		err = 1;
> > > +		pr_err("*** Failed to get arm_fck.\n");
> > > +	}
> > > +
> > >  	core_ck = clk_get(NULL, "core_ck");
> > > +	if (core_ck == NULL) {
> > > +		err = 1;
> > > +		pr_err("*** Failed to get core_ck.\n");
> > > +	}
> > > +
> > >  	osc_sys_ck = clk_get(NULL, "osc_sys_ck");
> > > +	if (osc_sys_ck == NULL) {
> > > +		err = 1;
> > > +		pr_err("*** Failed to get osc_sys_ck.\n");
> > > +	}
> > > +
> > > +	if (err)
> > > +		return 1;
> > 
> > Minor issue...
> > 
> > Do you want to skip the rest of the init in case of any failure?
> > 
> > It seems like the DPLL1 is the only one that would be a 
> real failure,
> > the others just affect the clock display.
> 
> [sp] But, even when if we use bad pointers for displaying clocks, it
>      could be bad.
> 
> Best regards,
> Sanjeev
> > 
> > 
> > Kevin
> > 
> > > -	/* REVISIT: not yet ready for 343x */
> > >  	if (clk_set_rate(dpll1_ck, mpurate))
> > >  		printk(KERN_ERR "*** Unable to set MPU rate\n");
> > >  
> > > -- 
> > > 1.6.2.2
> > >
> > > --
> > > To unsubscribe from this list: send the line "unsubscribe 
> > linux-omap" in
> > > the body of a message to majordomo@vger.kernel.org
> > > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > --
> To unsubscribe from this list: send the line "unsubscribe 
> linux-omap" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

end of thread, other threads:[~2010-01-28 15:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-08 18:19 [PATCH] omap3: Check return values for clk_get Sanjeev Premi
2010-01-08 22:37 ` Kevin Hilman
2010-01-28 14:11   ` Premi, Sanjeev
2010-01-28 15:01     ` Premi, Sanjeev
2010-01-20  1:19 ` Paul Walmsley
2010-01-21 14:35   ` Premi, Sanjeev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox