Skip to contentSkip to conversation

omap3: Check return values for clk_get

PATCH Superseded Sanjeev Premi 3 participants 6 messages Jan 8, 2010 – Jan 28, 2010

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 omap3: Check return values for clk_get

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

---
 arch/arm/mach-omap2/clock34xx.c |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/clock34xx.c +23 -2
index d4217b9..2c2165b 100644
@@ -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");
 
Signature · 1 line
1.6.2.2
#1 lore raw
Quoted 14 lines · Sanjeev Premi

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

---
 arch/arm/mach-omap2/clock34xx.c |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/clock34xx.c +0 -0
index d4217b9..2c2165b 100644
@@ -316,17 +316,38 @@ static int __init omap2_clk_arch_init(void)
 {

arch/arm/mach-omap2/clock34xx.c static int __init omap2_clk_arch_init(void) · line 325

Quoted 10 lines
arch/arm/mach-omap2/clock34xx.c +2 -1
 	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"))
Quoted 14 lines
arch/arm/mach-omap2/clock34xx.c +12 -0
+		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");

arch/arm/mach-omap2/clock34xx.c static int __init omap2_clk_arch_init(void) · line 349

Quoted 10 lines
arch/arm/mach-omap2/clock34xx.c +9 -0
+	}
+
 	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

Quoted 11 lines
arch/arm/mach-omap2/clock34xx.c +0 -1
-	/* REVISIT: not yet ready for 343x */
 	if (clk_set_rate(dpll1_ck, mpurate))
 		printk(KERN_ERR "*** Unable to set MPU rate\n");
 
Signature · 6 lines
1.6.2.2

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 38 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Saturday, January 09, 2010 4:08 AM
To: Premi, Sanjeev
Cc: [email protected]
Subject: Re: [PATCH] omap3: Check return values for clk_get

Review

Quoted 9 lines · Sanjeev Premi

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

---
 arch/arm/mach-omap2/clock34xx.c |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/arch/arm/mach-omap2/clock34xx.c

Quoted 5 lines

index d4217b9..2c2165b 100644

arch/arm/mach-omap2/clock34xx.c +0 -0
@@ -316,17 +316,38 @@ static int __init omap2_clk_arch_init(void)
 {

arch/arm/mach-omap2/clock34xx.c static int __init omap2_clk_arch_init(void) · line 325

Quoted 10 lines
arch/arm/mach-omap2/clock34xx.c +2 -1
 	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

Quoted 3 lines
        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().
Quoted 6 lines

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.

Quoted 27 lines
Quoted 14 lines
arch/arm/mach-omap2/clock34xx.c +12 -0
+		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");

arch/arm/mach-omap2/clock34xx.c static int __init omap2_clk_arch_init(void) · line 349

Quoted 10 lines
arch/arm/mach-omap2/clock34xx.c +9 -0
+	}
+
 	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...

Quoted 4 lines

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

Quoted 17 lines

Kevin

Quoted 9 lines
arch/arm/mach-omap2/clock34xx.c +0 -1
-	/* REVISIT: not yet ready for 343x */
 	if (clk_set_rate(dpll1_ck, mpurate))
 		printk(KERN_ERR "*** Unable to set MPU rate\n");
 
Signature · 4 lines
1.6.2.2

--
To unsubscribe from this list: send the line "unsubscribe 

linux-omap" in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 52 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Premi, Sanjeev
Sent: Thursday, January 28, 2010 7:42 PM
To: Kevin Hilman
Cc: [email protected]
Subject: RE: [PATCH] omap3: Check return values for clk_get

Quoted 37 lines

-----Original Message-----
From: Kevin Hilman [mailto:[email protected]]
Sent: Saturday, January 09, 2010 4:08 AM
To: Premi, Sanjeev
Cc: [email protected]
Subject: Re: [PATCH] omap3: Check return values for clk_get

Review

Quoted 9 lines · Sanjeev Premi

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

---
 arch/arm/mach-omap2/clock34xx.c |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/arch/arm/mach-omap2/clock34xx.c

Quoted 5 lines

index d4217b9..2c2165b 100644

arch/arm/mach-omap2/clock34xx.c +0 -0
@@ -316,17 +316,38 @@ static int __init omap2_clk_arch_init(void)
 {

arch/arm/mach-omap2/clock34xx.c static int __init omap2_clk_arch_init(void) · line 325

Quoted 10 lines
arch/arm/mach-omap2/clock34xx.c +2 -1
 	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

Quoted 3 lines
        if (IS_ERR(<clk>))       

instead of NULL pointer checks.

Kevin,

Quoted 16 lines
    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

Quoted 68 lines
Quoted 6 lines

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.

Quoted 27 lines
Quoted 14 lines
arch/arm/mach-omap2/clock34xx.c +12 -0
+		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");

arch/arm/mach-omap2/clock34xx.c static int __init omap2_clk_arch_init(void) · line 349

Quoted 10 lines
arch/arm/mach-omap2/clock34xx.c +9 -0
+	}
+
 	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...

Quoted 3 lines

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,

Quoted 1 line

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

Quoted 11 lines

Kevin

Quoted 7 lines
arch/arm/mach-omap2/clock34xx.c +0 -1
-	/* REVISIT: not yet ready for 343x */
 	if (clk_set_rate(dpll1_ck, mpurate))
 		printk(KERN_ERR "*** Unable to set MPU rate\n");
 
Signature · 1 line
1.6.2.2
Quoted 6 lines
Quoted 2 lines

--
To unsubscribe from this list: send the line "unsubscribe

linux-omap" in

Quoted 2 lines

the body of a message to [email protected]
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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#4 lore raw
In reply to Sanjeev Premi

Hello Sanjeev,

some comments.

Quoted 13 lines · Sanjeev Premi

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

---
 arch/arm/mach-omap2/clock34xx.c |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/clock34xx.c +0 -0
index d4217b9..2c2165b 100644

arch/arm/mach-omap2/clock34xx.c static int __init omap2_clk_arch_init(void) · line 319

Quoted 4 lines
arch/arm/mach-omap2/clock34xx.c +1 -0
@@ -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.

Quoted 21 lines
arch/arm/mach-omap2/clock34xx.c +13 -1
 	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");

arch/arm/mach-omap2/clock34xx.c static int __init omap2_clk_arch_init(void) · line 349

Quoted 10 lines
arch/arm/mach-omap2/clock34xx.c +9 -0
+	}
+
 	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?

Quoted 13 lines
arch/arm/mach-omap2/clock34xx.c +0 -1
-	/* REVISIT: not yet ready for 343x */
 	if (clk_set_rate(dpll1_ck, mpurate))
 		printk(KERN_ERR "*** Unable to set MPU rate\n");
 
Signature · 6 lines
1.6.2.2

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

- Paul

#5 lore raw
Quoted 62 lines

-----Original Message-----
From: Paul Walmsley [mailto:[email protected]]
Sent: Wednesday, January 20, 2010 6:49 AM
To: Premi, Sanjeev
Cc: [email protected]
Subject: Re: [PATCH] omap3: Check return values for clk_get

Hello Sanjeev,

some comments.

Review

Quoted 9 lines · Sanjeev Premi

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

---
 arch/arm/mach-omap2/clock34xx.c |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/arch/arm/mach-omap2/clock34xx.c

arch/arm/mach-omap2/clock34xx.c static int __init omap2_clk_arch_init(void) · line 319

Quoted 8 lines

index d4217b9..2c2165b 100644

arch/arm/mach-omap2/clock34xx.c +1 -0
@@ -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.

Quoted 27 lines
arch/arm/mach-omap2/clock34xx.c +18 -1
 	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");
Quoted 9 lines

arch/arm/mach-omap2/clock34xx.c static int __init omap2_clk_arch_init(void) · line 349

Quoted 4 lines
arch/arm/mach-omap2/clock34xx.c +4 -0
+	}
+
+	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

Quoted 18 lines
Quoted 10 lines
arch/arm/mach-omap2/clock34xx.c +0 -1
-	/* REVISIT: not yet ready for 343x */
 	if (clk_set_rate(dpll1_ck, mpurate))
 		printk(KERN_ERR "*** Unable to set MPU rate\n");
 
Signature · 4 lines
1.6.2.2

--
To unsubscribe from this list: send the line "unsubscribe 

linux-omap" in

Quoted 3 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

- Paul