public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Remove indirect variable usage at arch/x86/kernel/tsc.c
@ 2009-05-19 18:03 Subrata Modak
  2009-05-19 18:53 ` Frans Pop
  2009-05-24 19:42 ` Pavel Machek
  0 siblings, 2 replies; 4+ messages in thread
From: Subrata Modak @ 2009-05-19 18:03 UTC (permalink / raw)
  To: x86
  Cc: Sachin P Sant, H. Peter Anvin, Andi Kleen, Thomas Gleixner,
	Linux Kernel, Ingo Molnar, Subrata Modak, Balbir Singh

Hi,

The following warning is generated on compilation:

CC      arch/x86/kernel/tsc.o
arch/x86/kernel/tsc.c: In function 'time_cpufreq_notifier':
arch/x86/kernel/tsc.c:634: warning: 'dummy' may be used uninitialized in this function

However, there seems to be no practical usage of variable 'dummy'
in the following piece of code:

630 static int time_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
631                                 void *data)
632 {
633         struct cpufreq_freqs *freq = data;
634         unsigned long *lpj, dummy;
635 
636         if (cpu_has(&cpu_data(freq->cpu), X86_FEATURE_CONSTANT_TSC))
637                 return 0;
638 
639         lpj = &dummy;
640         if (!(freq->flags & CPUFREQ_CONST_LOOPS))
641 #ifdef CONFIG_SMP
642                 lpj = &cpu_data(freq->cpu).loops_per_jiffy;
643 #else
644         lpj = &boot_cpu_data.loops_per_jiffy;
645 #endif
646 

'lpj' probably will get to point to some address after this if() statement.

647         if (!ref_freq) {
648                 ref_freq = freq->old;
649                 loops_per_jiffy_ref = *lpj;

And, if it does, then "loops_per_jiffy_ref" will have a proper value,
else, even with "lpj = &dummy" will not gurantee "loops_per_jiffy_ref = *lpj"
to have the expected value.

650                 tsc_khz_ref = tsc_khz;
651         }
652         if ((val == CPUFREQ_PRECHANGE  && freq->old < freq->new) ||
653                         (val == CPUFREQ_POSTCHANGE && freq->old > freq->new) ||
654                         (val == CPUFREQ_RESUMECHANGE)) {
655                 *lpj =  cpufreq_scale(loops_per_jiffy_ref, ref_freq, freq->new);
656 
657                 tsc_khz = cpufreq_scale(tsc_khz_ref, ref_freq, freq->new);
658                 if (!(freq->flags & CPUFREQ_CONST_LOOPS))
659                         mark_tsc_unstable("cpufreq changes");
660         }
661 
662         set_cyc2ns_scale(tsc_khz, freq->cpu);
663 
664         return 0;
665 }

Is there any specific reason for 'dummy' to exist in this function ?
If not, i would like to propose the following fix.

Signed-off-by: Subrata Modak <subrata@linux.vnet.ibm.com>
To: <x86@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>
Cc: Sachin P Sant <sachinp@linux.vnet.ibm.com>
Cc: Linux Kernel <linux-kernel@vger.kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Subject: [PATCH] Remove indirect variable usage at arch/x86/kernel/tsc.c
---

--- a/arch/x86/kernel/tsc.c	2009-05-19 00:57:26.000000000 +0530
+++ b/arch/x86/kernel/tsc.c	2009-05-19 21:45:46.000000000 +0530
@@ -631,12 +631,11 @@ static int time_cpufreq_notifier(struct 
 				void *data)
 {
 	struct cpufreq_freqs *freq = data;
-	unsigned long *lpj, dummy;
+	unsigned long *lpj = NULL;
 
 	if (cpu_has(&cpu_data(freq->cpu), X86_FEATURE_CONSTANT_TSC))
 		return 0;
 
-	lpj = &dummy;
 	if (!(freq->flags & CPUFREQ_CONST_LOOPS))
 #ifdef CONFIG_SMP
 		lpj = &cpu_data(freq->cpu).loops_per_jiffy;

---
Regards--
Subrata


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

* Re: [PATCH] Remove indirect variable usage at arch/x86/kernel/tsc.c
  2009-05-19 18:03 [PATCH] Remove indirect variable usage at arch/x86/kernel/tsc.c Subrata Modak
@ 2009-05-19 18:53 ` Frans Pop
  2009-05-20  6:10   ` Subrata Modak
  2009-05-24 19:42 ` Pavel Machek
  1 sibling, 1 reply; 4+ messages in thread
From: Frans Pop @ 2009-05-19 18:53 UTC (permalink / raw)
  To: Subrata Modak
  Cc: x86, sachinp, hpa, andi, tglx, linux-kernel, mingo, subrata,
	balbir

Subrata Modak wrote:
> 640         if (!(freq->flags & CPUFREQ_CONST_LOOPS))
> 641 #ifdef CONFIG_SMP
> 642                 lpj = &cpu_data(freq->cpu).loops_per_jiffy;
> 643 #else
> 644         lpj = &boot_cpu_data.loops_per_jiffy;
> 645 #endif

No comments on your patch, but it might be good to also fix the incorrect 
indentation here: line 644 needs an extra tab.

Cheers,
FJP

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

* Re: [PATCH] Remove indirect variable usage at arch/x86/kernel/tsc.c
  2009-05-19 18:53 ` Frans Pop
@ 2009-05-20  6:10   ` Subrata Modak
  0 siblings, 0 replies; 4+ messages in thread
From: Subrata Modak @ 2009-05-20  6:10 UTC (permalink / raw)
  To: Frans Pop; +Cc: x86, sachinp, hpa, andi, tglx, linux-kernel, mingo, balbir

On Tue, 2009-05-19 at 20:53 +0200, Frans Pop wrote:
> Subrata Modak wrote:
> > 640         if (!(freq->flags & CPUFREQ_CONST_LOOPS))
> > 641 #ifdef CONFIG_SMP
> > 642                 lpj = &cpu_data(freq->cpu).loops_per_jiffy;
> > 643 #else
> > 644         lpj = &boot_cpu_data.loops_per_jiffy;
> > 645 #endif
> 
> No comments on your patch, but it might be good to also fix the incorrect 
> indentation here: line 644 needs an extra tab.

Sure, i will do that in the updated patch.

Regards--
Subrata

> 
> Cheers,
> FJP


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

* Re: [PATCH] Remove indirect variable usage at arch/x86/kernel/tsc.c
  2009-05-19 18:03 [PATCH] Remove indirect variable usage at arch/x86/kernel/tsc.c Subrata Modak
  2009-05-19 18:53 ` Frans Pop
@ 2009-05-24 19:42 ` Pavel Machek
  1 sibling, 0 replies; 4+ messages in thread
From: Pavel Machek @ 2009-05-24 19:42 UTC (permalink / raw)
  To: Subrata Modak
  Cc: x86, Sachin P Sant, H. Peter Anvin, Andi Kleen, Thomas Gleixner,
	Linux Kernel, Ingo Molnar, Balbir Singh

Hi!

> CC      arch/x86/kernel/tsc.o
> arch/x86/kernel/tsc.c: In function 'time_cpufreq_notifier':
> arch/x86/kernel/tsc.c:634: warning: 'dummy' may be used uninitialized in this function
> 
> However, there seems to be no practical usage of variable 'dummy'
> in the following piece of code:
> 
> 630 static int time_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
> 631                                 void *data)
> 632 {
> 633         struct cpufreq_freqs *freq = data;
> 634         unsigned long *lpj, dummy;
> 635 
> 636         if (cpu_has(&cpu_data(freq->cpu), X86_FEATURE_CONSTANT_TSC))
> 637                 return 0;
> 638 
> 639         lpj = &dummy;
> 640         if (!(freq->flags & CPUFREQ_CONST_LOOPS))
> 641 #ifdef CONFIG_SMP
> 642                 lpj = &cpu_data(freq->cpu).loops_per_jiffy;
> 643 #else
> 644         lpj = &boot_cpu_data.loops_per_jiffy;
> 645 #endif
> 646 
> 
> 'lpj' probably will get to point to some address after this if() statement.
> 
> 647         if (!ref_freq) {
> 648                 ref_freq = freq->old;
> 649                 loops_per_jiffy_ref = *lpj;
> 
> And, if it does, then "loops_per_jiffy_ref" will have a proper value,
> else, even with "lpj = &dummy" will not gurantee "loops_per_jiffy_ref = *lpj"
> to have the expected value.

But that's a bug to be fixed, I'd say? ... actually I believe you are
introducing a bug here. Yes, old code would put random numbers in
loops_per_jiffy_ref for !CPUFREQ_CONST_LOOPS, but you are introducing
oops there.

Have you tested the code?

> @@ -631,12 +631,11 @@ static int time_cpufreq_notifier(struct 
>  				void *data)
>  {
>  	struct cpufreq_freqs *freq = data;
> -	unsigned long *lpj, dummy;
> +	unsigned long *lpj = NULL;
>  
>  	if (cpu_has(&cpu_data(freq->cpu), X86_FEATURE_CONSTANT_TSC))
>  		return 0;
>  
> -	lpj = &dummy;
>  	if (!(freq->flags & CPUFREQ_CONST_LOOPS))
>  #ifdef CONFIG_SMP
>  		lpj = &cpu_data(freq->cpu).loops_per_jiffy;
> 

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

end of thread, other threads:[~2009-05-24 19:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-19 18:03 [PATCH] Remove indirect variable usage at arch/x86/kernel/tsc.c Subrata Modak
2009-05-19 18:53 ` Frans Pop
2009-05-20  6:10   ` Subrata Modak
2009-05-24 19:42 ` Pavel Machek

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