linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* linux-next: build warning after merge of the nvmem tree
@ 2020-03-06  4:28 Stephen Rothwell
  2020-03-06 10:03 ` H. Nikolaus Schaller
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Rothwell @ 2020-03-06  4:28 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: Linux Next Mailing List, Linux Kernel Mailing List,
	PrasannaKumar Muralidharan, Mathieu Malaterre,
	H. Nikolaus Schaller, Paul Cercueil

[-- Attachment #1: Type: text/plain, Size: 1253 bytes --]

Hi all,

After merging the nvmem tree, today's linux-next build (x86_64
allmodconfig) produced this warning:

In file included from include/linux/clk.h:13,
                 from drivers/nvmem/jz4780-efuse.c:25:
drivers/nvmem/jz4780-efuse.c: In function 'jz4780_efuse_read':
include/linux/kernel.h:842:29: warning: comparison of distinct pointer types lacks a cast
  842 |   (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
      |                             ^~
include/linux/kernel.h:856:4: note: in expansion of macro '__typecheck'
  856 |   (__typecheck(x, y) && __no_side_effects(x, y))
      |    ^~~~~~~~~~~
include/linux/kernel.h:866:24: note: in expansion of macro '__safe_cmp'
  866 |  __builtin_choose_expr(__safe_cmp(x, y), \
      |                        ^~~~~~~~~~
include/linux/kernel.h:875:19: note: in expansion of macro '__careful_cmp'
  875 | #define min(x, y) __careful_cmp(x, y, <)
      |                   ^~~~~~~~~~~~~
drivers/nvmem/jz4780-efuse.c:76:24: note: in expansion of macro 'min'
   76 |   unsigned int chunk = min(bytes, (start + JZ_EFU_READ_SIZE)
      |                        ^~~

Introduced by commit

  50a09dfd394a ("nvmem: add driver for JZ4780 efuse")

-- 
Cheers,
Stephen Rothwell

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: linux-next: build warning after merge of the nvmem tree
  2020-03-06  4:28 linux-next: build warning after merge of the nvmem tree Stephen Rothwell
@ 2020-03-06 10:03 ` H. Nikolaus Schaller
  0 siblings, 0 replies; 2+ messages in thread
From: H. Nikolaus Schaller @ 2020-03-06 10:03 UTC (permalink / raw)
  To: Stephen Rothwell
  Cc: Srinivas Kandagatla, Linux Next Mailing List,
	Linux Kernel Mailing List, PrasannaKumar Muralidharan,
	Mathieu Malaterre, Paul Cercueil

Hi,

> Am 06.03.2020 um 05:28 schrieb Stephen Rothwell <sfr@canb.auug.org.au>:
> 
> Hi all,
> 
> After merging the nvmem tree, today's linux-next build (x86_64
> allmodconfig) produced this warning:
> 
> In file included from include/linux/clk.h:13,
>                 from drivers/nvmem/jz4780-efuse.c:25:
> drivers/nvmem/jz4780-efuse.c: In function 'jz4780_efuse_read':
> include/linux/kernel.h:842:29: warning: comparison of distinct pointer types lacks a cast
>  842 |   (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
>      |                             ^~
> include/linux/kernel.h:856:4: note: in expansion of macro '__typecheck'
>  856 |   (__typecheck(x, y) && __no_side_effects(x, y))
>      |    ^~~~~~~~~~~
> include/linux/kernel.h:866:24: note: in expansion of macro '__safe_cmp'
>  866 |  __builtin_choose_expr(__safe_cmp(x, y), \
>      |                        ^~~~~~~~~~
> include/linux/kernel.h:875:19: note: in expansion of macro '__careful_cmp'
>  875 | #define min(x, y) __careful_cmp(x, y, <)
>      |                   ^~~~~~~~~~~~~
> drivers/nvmem/jz4780-efuse.c:76:24: note: in expansion of macro 'min'
>   76 |   unsigned int chunk = min(bytes, (start + JZ_EFU_READ_SIZE)
>      |                        ^~~
> 
> Introduced by commit
> 
>  50a09dfd394a ("nvmem: add driver for JZ4780 efuse")

The new kbuild robot message is more precise.

drivers/nvmem/jz4780-efuse.c:76:38: sparse: sparse: incompatible types in comparison expression (different type sizes):
drivers/nvmem/jz4780-efuse.c:76:38: sparse:    unsigned long *
drivers/nvmem/jz4780-efuse.c:76:38: sparse:    unsigned int *

A look into the code:

/* main entry point */
static int jz4780_efuse_read(void *context, unsigned int offset,
			     void *val, size_t bytes)
{
	struct jz4780_efuse *efuse = context;

	while (bytes > 0) {
		unsigned int start = offset & ~(JZ_EFU_READ_SIZE - 1);
		unsigned int chunk = min(bytes, (start + JZ_EFU_READ_SIZE)
					 - offset);

The problem seems to be that size_t is not always compatible to
unsigned int on all machines and compilers. My cross-gcc for MIPS
did not complain. kbuild robot tried for ARCH=x86_64 and in the
first warning for GCC_VERSION=7.5.0 make.cross ARCH=riscv 

So I think we have to use

		size_t start = offset & ~(JZ_EFU_READ_SIZE - 1);
		size_t chunk = min(bytes, (start + JZ_EFU_READ_SIZE)
					 - offset);

I'l send a patch (after trying on MIPS).

BR and thanks,
Nikolaus


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

end of thread, other threads:[~2020-03-06 10:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-06  4:28 linux-next: build warning after merge of the nvmem tree Stephen Rothwell
2020-03-06 10:03 ` H. Nikolaus Schaller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).