Commit 2c78ffec authored by Ingo Molnar's avatar Ingo Molnar
Browse files

x86/oprofile: Fix uninitialized variable use in debug printk



Stephen Rothwell reported this build warning:

  arch/x86/oprofile/op_model_amd.c: In function 'ibs_eilvt_valid':
  arch/x86/oprofile/op_model_amd.c:289: warning: 'offset' may be used uninitialized in this function

And correctly observed that indeed the variable is used uninitialized in
this function. The result of this bug can be a debug printk with a bogus
value.

Also fix a few more small details that made this function hard to read
and which probably contributed to the bug being introduced to begin with:

 - Use more symmetric error conditions

 - Remove the !0 obfuscation

 - Add newlines to the printk output

 - Remove bogus linebreaks in printk strings and elsewhere

Reported-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
LKML-Reference: <20101025115736.41d51abe.sfr@canb.auug.org.au>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent aa7b250c
Loading
Loading
Loading
Loading
+11 −15
Original line number Original line Diff line number Diff line
@@ -281,31 +281,27 @@ static inline int eilvt_is_available(int offset)


static inline int ibs_eilvt_valid(void)
static inline int ibs_eilvt_valid(void)
{
{
	u64 val;
	int offset;
	int offset;
	u64 val;


	rdmsrl(MSR_AMD64_IBSCTL, val);
	rdmsrl(MSR_AMD64_IBSCTL, val);
	offset = val & IBSCTL_LVT_OFFSET_MASK;

	if (!(val & IBSCTL_LVT_OFFSET_VALID)) {
	if (!(val & IBSCTL_LVT_OFFSET_VALID)) {
		pr_err(FW_BUG "cpu %d, invalid IBS "
		pr_err(FW_BUG "cpu %d, invalid IBS interrupt offset %d (MSR%08X=0x%016llx)\n",
		       "interrupt offset %d (MSR%08X=0x%016llx)",
		       smp_processor_id(), offset, MSR_AMD64_IBSCTL, val);
		       smp_processor_id(), offset,
		       MSR_AMD64_IBSCTL, val);
		return 0;
		return 0;
	}
	}


	offset = val & IBSCTL_LVT_OFFSET_MASK;
	if (!eilvt_is_available(offset)) {

		pr_err(FW_BUG "cpu %d, IBS interrupt offset %d not available (MSR%08X=0x%016llx)\n",
	if (eilvt_is_available(offset))
		       smp_processor_id(), offset, MSR_AMD64_IBSCTL, val);
		return !0;

	pr_err(FW_BUG "cpu %d, IBS interrupt offset %d "
	       "not available (MSR%08X=0x%016llx)",
	       smp_processor_id(), offset,
	       MSR_AMD64_IBSCTL, val);

		return 0;
		return 0;
	}
	}


	return 1;
}

static inline int get_ibs_offset(void)
static inline int get_ibs_offset(void)
{
{
	u64 val;
	u64 val;