public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <matthew@wil.cx>
To: Borislav Petkov <bp@alien8.de>, Borislav Petkov <bp@amd64.org>,
	Ingo Molnar <mingo@elte.hu>, Dan Carpenter <error27@gmail.com>,
	"Herrmann3, Andreas" <Andreas.Herrmann3@amd.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	"maintainer:X86 ARCHITECTURE..." <x86@kernel.org>,
	"open list:AMD MICROCODE UPD..." <amd64-microcode@amd64.org>,
	open list <linux-kernel@vger.kernel.org>,
	"kernel-janitors@vger.kernel.org"
	<kernel-janitors@vger.kernel.org>
Subject: Re: [patch -next] x86, microcode, AMD: signedness bug in generic_load_microcode()
Date: Sun, 20 Feb 2011 11:42:17 -0700	[thread overview]
Message-ID: <20110220184217.GB13726@parisc-linux.org> (raw)
In-Reply-To: <20110220180845.GA6713@liondog.tnic>

On Sun, Feb 20, 2011 at 07:08:45PM +0100, Borislav Petkov wrote:
> On Sun, Feb 20, 2011 at 10:50:11AM -0700, Matthew Wilcox wrote:
> > No, that's not what's going on.  GCC _is_ truncating to a byte, 0xa5,
> > whether it's signed or not.  Then at the time of the call to printf,
> > the 0xa5 is cast to int.  If the char is signed, 0xa5 is sign-extended;
> > if unsigned, it's zero-extended.
> 
> Yes, you're right, I missed the fact that printf does convert its
> arguments based on the format string. I should've done
> 
> 	printf("ret = 0x%hhx\n", ret);

GCC's special treatment of the printf format string is only in the
gneration of warnings.  It doesn't promote differently based on the
format string.

You need to look at 6.5.2.2, parts 6 and 7.  Part 7 says:

	The ellipsis notation in a function prototype declarator causes
	argument type conversion to stop after the last declared
	parameter. The default argument promotions are performed on
	trailing arguments.

And part 6 describes the default argument promotions:

	If the expression that denotes the called function has a type that
	does not include a prototype, the integer promotions are performed
	on each argument, and arguments that have type float are promoted
	to double. These are called the default argument promotions.

So passing a char to printf will cause it to be promoted to int, no
matter what the format string says.  All the format string will do is
change how it's printed.  Probably by casting it back to a char :-)

-- 
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."

  reply	other threads:[~2011-02-20 18:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-18  9:17 [patch -next] x86, microcode, AMD: signedness bug in generic_load_microcode() Dan Carpenter
2011-02-18  9:39 ` Borislav Petkov
2011-02-20 13:02 ` Ingo Molnar
2011-02-20 13:09   ` Dan Carpenter
2011-02-20 14:14   ` Borislav Petkov
2011-02-20 17:50     ` Matthew Wilcox
2011-02-20 18:08       ` Borislav Petkov
2011-02-20 18:42         ` Matthew Wilcox [this message]
2011-02-20 19:33           ` Borislav Petkov
2011-02-20 13:07 ` [tip:x86/microcode] x86, microcode, AMD: Fix " tip-bot for Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110220184217.GB13726@parisc-linux.org \
    --to=matthew@wil.cx \
    --cc=Andreas.Herrmann3@amd.com \
    --cc=amd64-microcode@amd64.org \
    --cc=bp@alien8.de \
    --cc=bp@amd64.org \
    --cc=error27@gmail.com \
    --cc=hpa@zytor.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox