[Cbe-oss-dev] [PATCH] fix cbe_cpufreq for legacy SLOF tree.

Christian Krafft krafft at de.ibm.com
Thu Jun 28 01:19:16 EST 2007


On Tue, 26 Jun 2007 14:58:49 +0200
Jean-Christophe Dubois <jdubois at mc.com> wrote:

> On some legacy SLOF tree the generic code is unable to ioremap some Cell BE 
> registers. Therefore the "generic"" functions are returning a NULL pointer, 
> triggering a crash on such platforms.
> 
> Let's handle this more gracefully.
> 
> Signed-off-by: Jean-Christophe DUBOIS <jcd at tribudubois.net>
> 
> Index: linux-2.6.22-rc4/arch/powerpc/platforms/cell/cbe_cpufreq_pervasive.c
> ===================================================================
> --- linux-2.6.22-rc4.orig/arch/powerpc/platforms/cell/cbe_cpufreq_pervasive.c
> +++ linux-2.6.22-rc4/arch/powerpc/platforms/cell/cbe_cpufreq_pervasive.c
> @@ -68,6 +68,13 @@ int cbe_cpufreq_set_pmode(int cpu, unsig
>  	mic_tm_regs = cbe_get_cpu_mic_tm_regs(cpu);
>  	pmd_regs = cbe_get_cpu_pmd_regs(cpu);
> 
> +
> +	if (!mic_tm_regs || !pmd_regs) {
> +		WARN_ON_ONCE(!mic_tm_regs || !pmd_regs);
> +		local_irq_restore(flags);
> +		return -1;
> +	}
> +
>  	pr_debug("pm register is mapped at %p\n", &pmd_regs->pmcr);
>  	pr_debug("mic register is mapped at %p\n", &mic_tm_regs->slow_fast_timer_0);
> 
> @@ -114,6 +121,12 @@ int cbe_cpufreq_get_pmode(int cpu)
>  	struct cbe_pmd_regs __iomem *pmd_regs;
> 
>  	pmd_regs = cbe_get_cpu_pmd_regs(cpu);
> +
> +	if (!pmd_regs) {
> +		WARN_ON_ONCE(!pmd_regs);
> +		return -1;
> +	}
> +
>  	ret = in_be64(&pmd_regs->pmsr) & 0x07;
> 
>  	return ret;
> Index: linux-2.6.22-rc4/arch/powerpc/platforms/cell/cbe_cpufreq.c
> ===================================================================
> --- linux-2.6.22-rc4.orig/arch/powerpc/platforms/cell/cbe_cpufreq.c
> +++ linux-2.6.22-rc4/arch/powerpc/platforms/cell/cbe_cpufreq.c
> @@ -96,6 +96,11 @@ static int cbe_cpufreq_cpu_init(struct c
>  	cur_pmode = cbe_cpufreq_get_pmode(policy->cpu);
>  	pr_debug("current pmode is at %d\n",cur_pmode);
> 
> +	if (cur_pmode == -1) {
> +		WARN_ON_ONCE(cur_pmode == -1);
> +		return -EINVAL;
> +	}
> +
>  	policy->cur = cbe_freqs[cur_pmode].frequency;
> 
>  #ifdef CONFIG_SMP
> @@ -155,7 +160,11 @@ static int cbe_cpufreq_target(struct cpu
> 
>  	rc = set_pmode(policy->cpu, cbe_pmode_new);
> 
> -	cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
> +	if (rc != -1)
> +		cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
> +	else
> +		WARN_ON_ONCE(rc == -1);
> +
>  	mutex_unlock(&cbe_switch_mutex);
> 
>  	return rc;
> _______________________________________________
> cbe-oss-dev mailing list
> cbe-oss-dev at ozlabs.org
> https://ozlabs.org/mailman/listinfo/cbe-oss-dev

Why not including a check for the pmd registers in cbe_cpufreq_init.
In case of a broken devicetree the module would just refuse to load.
That looks cleaner to me than checking for the registers every time.

-- 
Mit freundlichen Gruessen,
kind regards,

Christian Krafft
IBM Systems & Technology Group,
Linux Kernel Development
IT Specialist


Vorsitzender des Aufsichtsrats:	Martin Jetter
Geschaeftsfuehrung:		Herbert Kircher
Sitz der Gesellschaft:		Boeblingen
Registriergericht:		Amtsgericht Stuttgart, HRB 243294

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/cbe-oss-dev/attachments/20070627/951e80d2/attachment.pgp>


More information about the cbe-oss-dev mailing list