kernel/iomem.c:18:32: sparse: sparse: cast truncates bits from constant value (38400000050e becomes 50e)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   e936e7d4a83b5ff6b7a685722f0ba348383af68c
commit: 0453c9a78015cb2219cda7239d881f4e3137bff8 sh: mm: convert to GENERIC_IOREMAP
date:   1 year, 1 month ago
config: sh-randconfig-r113-20240913 (https://download.01.org/0day-ci/archive/20240914/202409140544.bY7KrkTy-lkp@xxxxxxxxx/config)
compiler: sh4-linux-gcc (GCC) 14.1.0
reproduce: (https://download.01.org/0day-ci/archive/20240914/202409140544.bY7KrkTy-lkp@xxxxxxxxx/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Closes: https://lore.kernel.org/oe-kbuild-all/202409140544.bY7KrkTy-lkp@xxxxxxxxx/

sparse warnings: (new ones prefixed by >>)
   kernel/iomem.c:113:22: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected void *[assigned] addr @@     got void [noderef] __iomem * @@
   kernel/iomem.c:113:22: sparse:     expected void *[assigned] addr
   kernel/iomem.c:113:22: sparse:     got void [noderef] __iomem *
   kernel/iomem.c:116:22: sparse: sparse: incorrect type in assignment (different address spaces) @@     expected void *[assigned] addr @@     got void [noderef] __iomem * @@
   kernel/iomem.c:116:22: sparse:     expected void *[assigned] addr
   kernel/iomem.c:116:22: sparse:     got void [noderef] __iomem *
>> kernel/iomem.c:18:32: sparse: sparse: cast truncates bits from constant value (38400000050e becomes 50e)
   kernel/iomem.c: note: in included file (through include/linux/gfp.h, include/linux/xarray.h, include/linux/radix-tree.h, ...):
   include/linux/mmzone.h:1997:40: sparse: sparse: self-comparison always evaluates to false
--
   drivers/usb/musb/tusb6010.c: note: in included file (through arch/sh/include/asm/io.h, include/linux/io.h, include/linux/irq.h, ...):
>> include/asm-generic/io.h:1089:41: sparse: sparse: cast truncates bits from constant value (384000000506 becomes 506)

vim +18 kernel/iomem.c

5981690ddb8f72 Dan Williams 2018-03-29   14  
5981690ddb8f72 Dan Williams 2018-03-29   15  #ifndef arch_memremap_wb
5981690ddb8f72 Dan Williams 2018-03-29   16  static void *arch_memremap_wb(resource_size_t offset, unsigned long size)
5981690ddb8f72 Dan Williams 2018-03-29   17  {
5981690ddb8f72 Dan Williams 2018-03-29  @18  	return (__force void *)ioremap_cache(offset, size);
5981690ddb8f72 Dan Williams 2018-03-29   19  }
5981690ddb8f72 Dan Williams 2018-03-29   20  #endif
5981690ddb8f72 Dan Williams 2018-03-29   21  
5981690ddb8f72 Dan Williams 2018-03-29   22  #ifndef arch_memremap_can_ram_remap
5981690ddb8f72 Dan Williams 2018-03-29   23  static bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size,
5981690ddb8f72 Dan Williams 2018-03-29   24  					unsigned long flags)
5981690ddb8f72 Dan Williams 2018-03-29   25  {
5981690ddb8f72 Dan Williams 2018-03-29   26  	return true;
5981690ddb8f72 Dan Williams 2018-03-29   27  }
5981690ddb8f72 Dan Williams 2018-03-29   28  #endif
5981690ddb8f72 Dan Williams 2018-03-29   29  
5981690ddb8f72 Dan Williams 2018-03-29   30  static void *try_ram_remap(resource_size_t offset, size_t size,
5981690ddb8f72 Dan Williams 2018-03-29   31  			   unsigned long flags)
5981690ddb8f72 Dan Williams 2018-03-29   32  {
5981690ddb8f72 Dan Williams 2018-03-29   33  	unsigned long pfn = PHYS_PFN(offset);
5981690ddb8f72 Dan Williams 2018-03-29   34  
5981690ddb8f72 Dan Williams 2018-03-29   35  	/* In the simple case just return the existing linear address */
5981690ddb8f72 Dan Williams 2018-03-29   36  	if (pfn_valid(pfn) && !PageHighMem(pfn_to_page(pfn)) &&
5981690ddb8f72 Dan Williams 2018-03-29   37  	    arch_memremap_can_ram_remap(offset, size, flags))
5981690ddb8f72 Dan Williams 2018-03-29   38  		return __va(offset);
5981690ddb8f72 Dan Williams 2018-03-29   39  
5981690ddb8f72 Dan Williams 2018-03-29   40  	return NULL; /* fallback to arch_memremap_wb */
5981690ddb8f72 Dan Williams 2018-03-29   41  }
5981690ddb8f72 Dan Williams 2018-03-29   42  
5981690ddb8f72 Dan Williams 2018-03-29   43  /**
5981690ddb8f72 Dan Williams 2018-03-29   44   * memremap() - remap an iomem_resource as cacheable memory
5981690ddb8f72 Dan Williams 2018-03-29   45   * @offset: iomem resource start address
5981690ddb8f72 Dan Williams 2018-03-29   46   * @size: size of remap
5981690ddb8f72 Dan Williams 2018-03-29   47   * @flags: any of MEMREMAP_WB, MEMREMAP_WT, MEMREMAP_WC,
5981690ddb8f72 Dan Williams 2018-03-29   48   *		  MEMREMAP_ENC, MEMREMAP_DEC
5981690ddb8f72 Dan Williams 2018-03-29   49   *
5981690ddb8f72 Dan Williams 2018-03-29   50   * memremap() is "ioremap" for cases where it is known that the resource
5981690ddb8f72 Dan Williams 2018-03-29   51   * being mapped does not have i/o side effects and the __iomem
5981690ddb8f72 Dan Williams 2018-03-29   52   * annotation is not applicable. In the case of multiple flags, the different
5981690ddb8f72 Dan Williams 2018-03-29   53   * mapping types will be attempted in the order listed below until one of
5981690ddb8f72 Dan Williams 2018-03-29   54   * them succeeds.
5981690ddb8f72 Dan Williams 2018-03-29   55   *
5981690ddb8f72 Dan Williams 2018-03-29   56   * MEMREMAP_WB - matches the default mapping for System RAM on
5981690ddb8f72 Dan Williams 2018-03-29   57   * the architecture.  This is usually a read-allocate write-back cache.
f6c6010a077341 Wei Yang     2019-03-05   58   * Moreover, if MEMREMAP_WB is specified and the requested remap region is RAM
5981690ddb8f72 Dan Williams 2018-03-29   59   * memremap() will bypass establishing a new mapping and instead return
5981690ddb8f72 Dan Williams 2018-03-29   60   * a pointer into the direct map.
5981690ddb8f72 Dan Williams 2018-03-29   61   *
5981690ddb8f72 Dan Williams 2018-03-29   62   * MEMREMAP_WT - establish a mapping whereby writes either bypass the
5981690ddb8f72 Dan Williams 2018-03-29   63   * cache or are written through to memory and never exist in a
5981690ddb8f72 Dan Williams 2018-03-29   64   * cache-dirty state with respect to program visibility.  Attempts to
5981690ddb8f72 Dan Williams 2018-03-29   65   * map System RAM with this mapping type will fail.
5981690ddb8f72 Dan Williams 2018-03-29   66   *
5981690ddb8f72 Dan Williams 2018-03-29   67   * MEMREMAP_WC - establish a writecombine mapping, whereby writes may
5981690ddb8f72 Dan Williams 2018-03-29   68   * be coalesced together (e.g. in the CPU's write buffers), but is otherwise
5981690ddb8f72 Dan Williams 2018-03-29   69   * uncached. Attempts to map System RAM with this mapping type will fail.
5981690ddb8f72 Dan Williams 2018-03-29   70   */
5981690ddb8f72 Dan Williams 2018-03-29   71  void *memremap(resource_size_t offset, size_t size, unsigned long flags)
5981690ddb8f72 Dan Williams 2018-03-29   72  {
5981690ddb8f72 Dan Williams 2018-03-29   73  	int is_ram = region_intersects(offset, size,
5981690ddb8f72 Dan Williams 2018-03-29   74  				       IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE);
5981690ddb8f72 Dan Williams 2018-03-29   75  	void *addr = NULL;
5981690ddb8f72 Dan Williams 2018-03-29   76  
5981690ddb8f72 Dan Williams 2018-03-29   77  	if (!flags)
5981690ddb8f72 Dan Williams 2018-03-29   78  		return NULL;
5981690ddb8f72 Dan Williams 2018-03-29   79  
5981690ddb8f72 Dan Williams 2018-03-29   80  	if (is_ram == REGION_MIXED) {
5981690ddb8f72 Dan Williams 2018-03-29   81  		WARN_ONCE(1, "memremap attempted on mixed range %pa size: %#lx\n",
5981690ddb8f72 Dan Williams 2018-03-29   82  				&offset, (unsigned long) size);
5981690ddb8f72 Dan Williams 2018-03-29   83  		return NULL;
5981690ddb8f72 Dan Williams 2018-03-29   84  	}
5981690ddb8f72 Dan Williams 2018-03-29   85  
5981690ddb8f72 Dan Williams 2018-03-29   86  	/* Try all mapping types requested until one returns non-NULL */
5981690ddb8f72 Dan Williams 2018-03-29   87  	if (flags & MEMREMAP_WB) {
5981690ddb8f72 Dan Williams 2018-03-29   88  		/*
f6c6010a077341 Wei Yang     2019-03-05   89  		 * MEMREMAP_WB is special in that it can be satisfied
5981690ddb8f72 Dan Williams 2018-03-29   90  		 * from the direct map.  Some archs depend on the
5981690ddb8f72 Dan Williams 2018-03-29   91  		 * capability of memremap() to autodetect cases where
5981690ddb8f72 Dan Williams 2018-03-29   92  		 * the requested range is potentially in System RAM.
5981690ddb8f72 Dan Williams 2018-03-29   93  		 */
5981690ddb8f72 Dan Williams 2018-03-29   94  		if (is_ram == REGION_INTERSECTS)
5981690ddb8f72 Dan Williams 2018-03-29   95  			addr = try_ram_remap(offset, size, flags);
5981690ddb8f72 Dan Williams 2018-03-29   96  		if (!addr)
5981690ddb8f72 Dan Williams 2018-03-29   97  			addr = arch_memremap_wb(offset, size);
5981690ddb8f72 Dan Williams 2018-03-29   98  	}
5981690ddb8f72 Dan Williams 2018-03-29   99  
5981690ddb8f72 Dan Williams 2018-03-29  100  	/*
5981690ddb8f72 Dan Williams 2018-03-29  101  	 * If we don't have a mapping yet and other request flags are
5981690ddb8f72 Dan Williams 2018-03-29  102  	 * present then we will be attempting to establish a new virtual
5981690ddb8f72 Dan Williams 2018-03-29  103  	 * address mapping.  Enforce that this mapping is not aliasing
5981690ddb8f72 Dan Williams 2018-03-29  104  	 * System RAM.
5981690ddb8f72 Dan Williams 2018-03-29  105  	 */
5981690ddb8f72 Dan Williams 2018-03-29  106  	if (!addr && is_ram == REGION_INTERSECTS && flags != MEMREMAP_WB) {
5981690ddb8f72 Dan Williams 2018-03-29  107  		WARN_ONCE(1, "memremap attempted on ram %pa size: %#lx\n",
5981690ddb8f72 Dan Williams 2018-03-29  108  				&offset, (unsigned long) size);
5981690ddb8f72 Dan Williams 2018-03-29  109  		return NULL;
5981690ddb8f72 Dan Williams 2018-03-29  110  	}
5981690ddb8f72 Dan Williams 2018-03-29  111  
5981690ddb8f72 Dan Williams 2018-03-29  112  	if (!addr && (flags & MEMREMAP_WT))
5981690ddb8f72 Dan Williams 2018-03-29 @113  		addr = ioremap_wt(offset, size);
5981690ddb8f72 Dan Williams 2018-03-29  114  
5981690ddb8f72 Dan Williams 2018-03-29  115  	if (!addr && (flags & MEMREMAP_WC))
5981690ddb8f72 Dan Williams 2018-03-29  116  		addr = ioremap_wc(offset, size);
5981690ddb8f72 Dan Williams 2018-03-29  117  
5981690ddb8f72 Dan Williams 2018-03-29  118  	return addr;
5981690ddb8f72 Dan Williams 2018-03-29  119  }
5981690ddb8f72 Dan Williams 2018-03-29  120  EXPORT_SYMBOL(memremap);
5981690ddb8f72 Dan Williams 2018-03-29  121  

:::::: The code at line 18 was first introduced by commit
:::::: 5981690ddb8f72f9546a2d017a914cf56095fc1f memremap: split devm_memremap_pages() and memremap() infrastructure

:::::: TO: Dan Williams <dan.j.williams@xxxxxxxxx>
:::::: CC: Dan Williams <dan.j.williams@xxxxxxxxx>

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux