All of lore.kernel.org
 help / color / mirror / Atom feed
* arch/powerpc/xmon/dis-asm.h: 2 * wrong specifiers ?
@ 2016-06-27  8:04 David Binderman
  2016-06-28  4:08 ` Michael Ellerman
  0 siblings, 1 reply; 7+ messages in thread
From: David Binderman @ 2016-06-27  8:04 UTC (permalink / raw)
  To: benh, paulus, mpe, linuxppc-dev, Linux Kernel Mailing List, dcb314

Hello there,

linux-4.7-rc5/arch/powerpc/xmon/dis-asm.h:20]: (warning) %x in format
string (no. 1) requires 'unsigned int' but the argument type is
'unsigned long'.
[linux-4.7-rc5/arch/powerpc/xmon/dis-asm.h:26]: (warning) %x in format
string (no. 1) requires 'unsigned int' but the argument type is
'unsigned long'.

Source code is

static inline int print_insn_powerpc(unsigned long insn, unsigned long memaddr)
{
    printf("%.8x", insn);
    return 0;
}

static inline int print_insn_spu(unsigned long insn, unsigned long memaddr)
{
    printf("%.8x", insn);
    return 0;
}

Regards

David Binderman

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

* Re: arch/powerpc/xmon/dis-asm.h: 2 * wrong specifiers ?
  2016-06-27  8:04 arch/powerpc/xmon/dis-asm.h: 2 * wrong specifiers ? David Binderman
@ 2016-06-28  4:08 ` Michael Ellerman
  2016-06-28  7:06   ` David Binderman
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Ellerman @ 2016-06-28  4:08 UTC (permalink / raw)
  To: David Binderman, benh, paulus, linuxppc-dev,
	Linux Kernel Mailing List, dcb314

On Mon, 2016-06-27 at 09:04 +0100, David Binderman wrote:

> Hello there,
> 
> linux-4.7-rc5/arch/powerpc/xmon/dis-asm.h:20]: (warning) %x in format
> string (no. 1) requires 'unsigned int' but the argument type is
> 'unsigned long'.
> [linux-4.7-rc5/arch/powerpc/xmon/dis-asm.h:26]: (warning) %x in format
> string (no. 1) requires 'unsigned int' but the argument type is
> 'unsigned long'.

What config / toolchain are you using? I've never seen these.

Oh, I see, with CONFIG_XMON_DISASSEMBLY=n.

> static inline int print_insn_powerpc(unsigned long insn, unsigned long memaddr)
> {
>     printf("%.8x", insn);
>     return 0;
> }

Send me a patch to cast insn to unsigned int?

cheers

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

* Re: arch/powerpc/xmon/dis-asm.h: 2 * wrong specifiers ?
  2016-06-28  4:08 ` Michael Ellerman
@ 2016-06-28  7:06   ` David Binderman
  2016-06-28  7:17       ` Michael Ellerman
                       ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: David Binderman @ 2016-06-28  7:06 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: benh, paulus, linuxppc-dev, Linux Kernel Mailing List, dcb314

Hello there,

On Tue, Jun 28, 2016 at 5:08 AM, Michael Ellerman <mpe@ellerman.id.au> wrote:
> What config / toolchain are you using? I've never seen these.

A static analyser for C & C++ called cppcheck. Available from sourceforge.

I think you can also get a similar warning if you tweek the gcc compiler warning
flags. -Wformat=2 maybe.

>> static inline int print_insn_powerpc(unsigned long insn, unsigned long memaddr)
>> {
>>     printf("%.8x", insn);
>>     return 0;
>> }
>
> Send me a patch to cast insn to unsigned int?

I don't know the code, but given that insn is unsigned long and so can go
past 32 bits, using a cast to unsigned int might throw away the
possibly important
upper bits.


Regards

David Binderman

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

* Re: arch/powerpc/xmon/dis-asm.h: 2 * wrong specifiers ?
  2016-06-28  7:06   ` David Binderman
@ 2016-06-28  7:17       ` Michael Ellerman
  2016-06-28  7:30     ` Segher Boessenkool
  2016-06-28  9:35     ` Benjamin Herrenschmidt
  2 siblings, 0 replies; 7+ messages in thread
From: Michael Ellerman @ 2016-06-28  7:17 UTC (permalink / raw)
  To: David Binderman
  Cc: benh, paulus, linuxppc-dev, Linux Kernel Mailing List, dcb314

On Tue, 2016-06-28 at 08:06 +0100, David Binderman wrote:
> On Tue, Jun 28, 2016 at 5:08 AM, Michael Ellerman <mpe@ellerman.id.au> wrote:
> > What config / toolchain are you using? I've never seen these.
> 
> A static analyser for C & C++ called cppcheck. Available from sourceforge.
> 
> I think you can also get a similar warning if you tweek the gcc compiler warning
> flags. -Wformat=2 maybe.
 
Ah OK. I've heard of it.

> > > static inline int print_insn_powerpc(unsigned long insn, unsigned long memaddr)
> > > {
> > >     printf("%.8x", insn);
> > >     return 0;
> > > }
> > 
> > Send me a patch to cast insn to unsigned int?
> 
> I don't know the code, but given that insn is unsigned long and so can go
> past 32 bits, using a cast to unsigned int might throw away the
> possibly important upper bits.

powerpc instructions are always 32-bit.

We could change the signature for the function to take u32. Except it's the
fallback implementation for the real version which comes from binutils and we'd
prefer to keep that code the same as the binutils version.

cheers

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

* Re: arch/powerpc/xmon/dis-asm.h: 2 * wrong specifiers ?
@ 2016-06-28  7:17       ` Michael Ellerman
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Ellerman @ 2016-06-28  7:17 UTC (permalink / raw)
  To: David Binderman
  Cc: benh, paulus, linuxppc-dev, Linux Kernel Mailing List, dcb314

On Tue, 2016-06-28 at 08:06 +0100, David Binderman wrote:
> On Tue, Jun 28, 2016 at 5:08 AM, Michael Ellerman <mpe@ellerman.id.au> wrote:
> > What config / toolchain are you using? I've never seen these.
> 
> A static analyser for C & C++ called cppcheck. Available from sourceforge.
> 
> I think you can also get a similar warning if you tweek the gcc compiler warning
> flags. -Wformat=2 maybe.
 
Ah OK. I've heard of it.

> > > static inline int print_insn_powerpc(unsigned long insn, unsigned long memaddr)
> > > {
> > >     printf("%.8x", insn);
> > >     return 0;
> > > }
> > 
> > Send me a patch to cast insn to unsigned int?
> 
> I don't know the code, but given that insn is unsigned long and so can go
> past 32 bits, using a cast to unsigned int might throw away the
> possibly important upper bits.

powerpc instructions are always 32-bit.

We could change the signature for the function to take u32. Except it's the
fallback implementation for the real version which comes from binutils and we'd
prefer to keep that code the same as the binutils version.

cheers

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

* Re: arch/powerpc/xmon/dis-asm.h: 2 * wrong specifiers ?
  2016-06-28  7:06   ` David Binderman
  2016-06-28  7:17       ` Michael Ellerman
@ 2016-06-28  7:30     ` Segher Boessenkool
  2016-06-28  9:35     ` Benjamin Herrenschmidt
  2 siblings, 0 replies; 7+ messages in thread
From: Segher Boessenkool @ 2016-06-28  7:30 UTC (permalink / raw)
  To: David Binderman
  Cc: Michael Ellerman, paulus, linuxppc-dev, dcb314,
	Linux Kernel Mailing List

On Tue, Jun 28, 2016 at 08:06:56AM +0100, David Binderman wrote:
> I think you can also get a similar warning if you tweek the gcc compiler warning
> flags. -Wformat=2 maybe.

-Wformat=1 (which is enabled by -Wall) already warns for this.

warning: format '%x' expects argument of type 'unsigned int', but argument 2 has type 'long unsigned int' [-Wformat=]


Segher

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

* Re: arch/powerpc/xmon/dis-asm.h: 2 * wrong specifiers ?
  2016-06-28  7:06   ` David Binderman
  2016-06-28  7:17       ` Michael Ellerman
  2016-06-28  7:30     ` Segher Boessenkool
@ 2016-06-28  9:35     ` Benjamin Herrenschmidt
  2 siblings, 0 replies; 7+ messages in thread
From: Benjamin Herrenschmidt @ 2016-06-28  9:35 UTC (permalink / raw)
  To: David Binderman, Michael Ellerman
  Cc: paulus, linuxppc-dev, Linux Kernel Mailing List, dcb314

On Tue, 2016-06-28 at 08:06 +0100, David Binderman wrote:
> 
> I don't know the code, but given that insn is unsigned long and so
> can go
> past 32 bits, using a cast to unsigned int might throw away the
> possibly important
> upper bits.

our instructions are only ever 32-bits. That xmon code is ancient and
originated from 32-bits stuff. In fact some of Paulus earliest xmons
might even have run on platforms where int is 16 bits :-)

Cheers,
Ben.

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

end of thread, other threads:[~2016-06-28  9:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-27  8:04 arch/powerpc/xmon/dis-asm.h: 2 * wrong specifiers ? David Binderman
2016-06-28  4:08 ` Michael Ellerman
2016-06-28  7:06   ` David Binderman
2016-06-28  7:17     ` Michael Ellerman
2016-06-28  7:17       ` Michael Ellerman
2016-06-28  7:30     ` Segher Boessenkool
2016-06-28  9:35     ` Benjamin Herrenschmidt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.