public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] powerpc: fix 8xx and 82xx type-punning warnings with GCC 4.7
Date: Fri, 8 Mar 2013 18:27:51 -0600	[thread overview]
Message-ID: <1362788871.29198.8@snotra> (raw)
In-Reply-To: <20130308211652.A014F20025F@gemini.denx.de> (from wd@denx.de on Fri Mar  8 15:16:52 2013)

On 03/08/2013 03:16:52 PM, Wolfgang Denk wrote:
> Dear Scott,
> 
> In message  
> <1357696756-31079-1-git-send-email-scottwood@freescale.com> you wrote:
> > C99's strict aliasing rules are insane to use in low-level code  
> such as a
> > bootloader, but as Wolfgang has rejected -fno-strict-aliasing in the
> > past, add a union so that 16-bit accesses can be performed.
> 
> Sorry, I saw this patch only after re-inventing the fix for 8xx.
> 
> >  #ifdef CONFIG_HARD_I2C
> > -	*((unsigned short*)(&immr->im_dprambase[PROFF_I2C_BASE])) = 0;
> > +	immr->im_dprambase16[PROFF_I2C_BASE / 2] = 0;
> 
> I have to admit that I dislike this approach pretty much.
> 
> I think we agree that, if we attempted to play strictly by the rules,
> this code should probably rewritten using C structs and proper I/O
> accessors.  But then, both 8xx and 82xx are essentially dead horses,
> and I guess you have no more enthusiasm in cleaning up that old code
> than me.  So let's ignore that for now.

Yeah.  Especially since I don't have easy access to hardware to test  
this stuff, I wanted to be as conservative as possible with the  
changes, to just address the build breakage.

> But this "...[OFFSET / 2]" is basicly unreadable.  Can we please at
> least make this  "...[OFFSET / sizeof(u16)]" so the reader gets a hint
> of where this is coming from?

OK.

> > --- a/arch/powerpc/cpu/mpc8xx/cpu.c
> > +++ b/arch/powerpc/cpu/mpc8xx/cpu.c
> > @@ -79,7 +79,7 @@ static int check_CPU (long clock, uint pvr, uint  
> immr)
> >  	if ((pvr >> 16) != 0x0050)
> >  		return -1;
> >
> > -	k = (immr << 16) | *((ushort *) &  
> immap->im_cpm.cp_dparam[0xB0]);
> > +	k = (immr << 16) | immap->im_cpm.cp_dparam16[0xB0 / 2];
> >  	m = 0;
> >  	suf = "";
> >
> > @@ -195,7 +195,7 @@ static int check_CPU (long clock, uint pvr,  
> uint immr)
> >  	if ((pvr >> 16) != 0x0050)
> >  		return -1;
> >
> > -	k = (immr << 16) | *((ushort *) &  
> immap->im_cpm.cp_dparam[0xB0]);
> > +	k = (immr << 16) | in_be16((ushort  
> *)&immap->im_cpm.cp_dparam[0xB0]);
> 
> Now this is very inconsistent - you convert the very same code line in
> very different ways here.  Please don't.

Sorry -- I started to use the accessor approach, and then changed my  
mind, and some of that accidentally leaked through.

> Is there any specific reason you did not use a similar approach of
> using in_be16() in the other locations?  Actually I feel this is still
> the most readable version - I prefer this, even though it clashes
> with the style of the rest of the code.

Besides the issue of so much else not using accessors -- I certainly  
didn't want to get asked to convert the entire thing :-) -- switching  
to an I/O accessor would change the generated code slightly, and I  
wanted to avoid that since I can't test it.

It also doesn't really address the problem -- it's still type-punning,  
just not noticed by the compiler due to how in_be16() is implemented.   
I'm not sure why this is acceptable but -fno-strict-aliasing isn't.

> Oh, and can we please get rid of this magic number 0xB0 here, and
> introduce PROFF_REVNUM like we do everywhere else?

I suppose, though again I'd rather not get into doing random cleanups  
on this code.

-Scott

      reply	other threads:[~2013-03-09  0:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-09  1:59 [U-Boot] [PATCH] powerpc: fix 8xx and 82xx type-punning warnings with GCC 4.7 Scott Wood
2013-03-08 21:16 ` Wolfgang Denk
2013-03-09  0:27   ` Scott Wood [this message]

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=1362788871.29198.8@snotra \
    --to=scottwood@freescale.com \
    --cc=u-boot@lists.denx.de \
    /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