linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression
@ 2020-11-02  4:42 kernel test robot
  2020-11-10 11:38 ` Serge Semin
  0 siblings, 1 reply; 12+ messages in thread
From: kernel test robot @ 2020-11-02  4:42 UTC (permalink / raw)
  To: Serge Semin; +Cc: kbuild-all, linux-kernel, Miquel Raynal

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

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   3cea11cd5e3b00d91caf0b4730194039b45c5891
commit: b3e79e7682e075326df8041b826b03453acacd0a mtd: physmap: Add Baikal-T1 physically mapped ROM support
date:   4 weeks ago
config: sparc64-randconfig-s032-20201031 (attached as .config)
compiler: sparc64-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.3-76-gf680124b-dirty
        # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=b3e79e7682e075326df8041b826b03453acacd0a
        git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
        git fetch --no-tags linus master
        git checkout b3e79e7682e075326df8041b826b03453acacd0a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=sparc64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


"sparse warnings: (new ones prefixed by >>)"
>> drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression

vim +/__iomem +78 drivers/mtd/maps/physmap-bt1-rom.c

    57	
    58	static void __xipram bt1_rom_map_copy_from(struct map_info *map,
    59						   void *to, unsigned long from,
    60						   ssize_t len)
    61	{
    62		void __iomem *src = map->virt + from;
    63		ssize_t shift, chunk;
    64		u32 data;
    65	
    66		if (len <= 0 || from >= map->size)
    67			return;
    68	
    69		/* Make sure we don't go over the map limit. */
    70		len = min_t(ssize_t, map->size - from, len);
    71	
    72		/*
    73		 * Since requested data size can be pretty big we have to implement
    74		 * the copy procedure as optimal as possible. That's why it's split
    75		 * up into the next three stages: unaligned head, aligned body,
    76		 * unaligned tail.
    77		 */
  > 78		shift = (ssize_t)src & 0x3;
    79		if (shift) {
    80			chunk = min_t(ssize_t, 4 - shift, len);
    81			data = readl_relaxed(src - shift);
    82			memcpy(to, &data + shift, chunk);
    83			src += chunk;
    84			to += chunk;
    85			len -= chunk;
    86		}
    87	
    88		while (len >= 4) {
    89			data = readl_relaxed(src);
    90			memcpy(to, &data, 4);
    91			src += 4;
    92			to += 4;
    93			len -= 4;
    94		}
    95	
    96		if (len) {
    97			data = readl_relaxed(src);
    98			memcpy(to, &data, len);
    99		}
   100	}
   101	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 36802 bytes --]

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

* Re: drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression
  2020-11-02  4:42 drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression kernel test robot
@ 2020-11-10 11:38 ` Serge Semin
  2020-11-10 15:35   ` Miquel Raynal
  0 siblings, 1 reply; 12+ messages in thread
From: Serge Semin @ 2020-11-10 11:38 UTC (permalink / raw)
  To: Miquel Raynal; +Cc: kernel test robot, kbuild-all, linux-kernel, linux-mtd

Hello Miquel,

A situation noted by the warning below won't cause any problem because
the casting is done to a non-dereferenced variable. It is utilized
as a pointer bias later in that function. Shall we just ignore the
warning or still fix it somehow?

-Sergey

On Mon, Nov 02, 2020 at 12:42:57PM +0800, kernel test robot wrote:
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head:   3cea11cd5e3b00d91caf0b4730194039b45c5891
> commit: b3e79e7682e075326df8041b826b03453acacd0a mtd: physmap: Add Baikal-T1 physically mapped ROM support
> date:   4 weeks ago
> config: sparc64-randconfig-s032-20201031 (attached as .config)
> compiler: sparc64-linux-gcc (GCC) 9.3.0
> reproduce:
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # apt-get install sparse
>         # sparse version: v0.6.3-76-gf680124b-dirty
>         # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=b3e79e7682e075326df8041b826b03453acacd0a
>         git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
>         git fetch --no-tags linus master
>         git checkout b3e79e7682e075326df8041b826b03453acacd0a
>         # save the attached .config to linux build tree
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=sparc64 
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> 
> "sparse warnings: (new ones prefixed by >>)"
> >> drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression
> 
> vim +/__iomem +78 drivers/mtd/maps/physmap-bt1-rom.c
> 
>     57	
>     58	static void __xipram bt1_rom_map_copy_from(struct map_info *map,
>     59						   void *to, unsigned long from,
>     60						   ssize_t len)
>     61	{
>     62		void __iomem *src = map->virt + from;
>     63		ssize_t shift, chunk;
>     64		u32 data;
>     65	
>     66		if (len <= 0 || from >= map->size)
>     67			return;
>     68	
>     69		/* Make sure we don't go over the map limit. */
>     70		len = min_t(ssize_t, map->size - from, len);
>     71	
>     72		/*
>     73		 * Since requested data size can be pretty big we have to implement
>     74		 * the copy procedure as optimal as possible. That's why it's split
>     75		 * up into the next three stages: unaligned head, aligned body,
>     76		 * unaligned tail.
>     77		 */
>   > 78		shift = (ssize_t)src & 0x3;
>     79		if (shift) {
>     80			chunk = min_t(ssize_t, 4 - shift, len);
>     81			data = readl_relaxed(src - shift);
>     82			memcpy(to, &data + shift, chunk);
>     83			src += chunk;
>     84			to += chunk;
>     85			len -= chunk;
>     86		}
>     87	
>     88		while (len >= 4) {
>     89			data = readl_relaxed(src);
>     90			memcpy(to, &data, 4);
>     91			src += 4;
>     92			to += 4;
>     93			len -= 4;
>     94		}
>     95	
>     96		if (len) {
>     97			data = readl_relaxed(src);
>     98			memcpy(to, &data, len);
>     99		}
>    100	}
>    101	
> 
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org



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

* Re: drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression
  2020-11-10 11:38 ` Serge Semin
@ 2020-11-10 15:35   ` Miquel Raynal
  2020-11-11 19:22     ` Serge Semin
  0 siblings, 1 reply; 12+ messages in thread
From: Miquel Raynal @ 2020-11-10 15:35 UTC (permalink / raw)
  To: Serge Semin; +Cc: kernel test robot, kbuild-all, linux-kernel, linux-mtd

Hi Serge,

Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Tue, 10 Nov
2020 14:38:27 +0300:

> Hello Miquel,
> 
> A situation noted by the warning below won't cause any problem because
> the casting is done to a non-dereferenced variable. It is utilized
> as a pointer bias later in that function. Shall we just ignore the
> warning or still fix it somehow?

Do you think the cast to a !__iomem value is mandatory here?

Perhaps if you find an elegant wait to avoid the warning it would be
nice, otherwise I guess we'll let it aside as a false positive.

Cheers,
Miquèl

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

* Re: drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression
  2020-11-10 15:35   ` Miquel Raynal
@ 2020-11-11 19:22     ` Serge Semin
  2020-11-12  8:27       ` Miquel Raynal
  0 siblings, 1 reply; 12+ messages in thread
From: Serge Semin @ 2020-11-11 19:22 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Serge Semin, kernel test robot, kbuild-all, linux-kernel, linux-mtd

On Tue, Nov 10, 2020 at 04:35:56PM +0100, Miquel Raynal wrote:
> Hi Serge,
> 
> Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Tue, 10 Nov
> 2020 14:38:27 +0300:
> 
> > Hello Miquel,
> > 
> > A situation noted by the warning below won't cause any problem because
> > the casting is done to a non-dereferenced variable. It is utilized
> > as a pointer bias later in that function. Shall we just ignore the
> > warning or still fix it somehow?
> 

> Do you think the cast to a !__iomem value is mandatory here?

It's not mandatory to have the casting with no __iomem, but wouldn't
doing like this:
+ 	shift = (ssize_t __iomem)src & 0x3;
be looking weird? Really, is there a good way to somehow extract the first
two bits of a __iomem pointer without getting the sparse warning?

-Sergey

> 
> Perhaps if you find an elegant wait to avoid the warning it would be
> nice, otherwise I guess we'll let it aside as a false positive.
> 
> Cheers,
> Miquèl

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

* Re: drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression
  2020-11-11 19:22     ` Serge Semin
@ 2020-11-12  8:27       ` Miquel Raynal
  2020-11-12 11:20         ` Serge Semin
  2020-11-12 15:00         ` Vignesh Raghavendra
  0 siblings, 2 replies; 12+ messages in thread
From: Miquel Raynal @ 2020-11-12  8:27 UTC (permalink / raw)
  To: Serge Semin
  Cc: Serge Semin, kernel test robot, kbuild-all, linux-kernel, linux-mtd

Hi Sergey,

Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Wed, 11 Nov
2020 22:22:59 +0300:

> On Tue, Nov 10, 2020 at 04:35:56PM +0100, Miquel Raynal wrote:
> > Hi Serge,
> > 
> > Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Tue, 10 Nov
> > 2020 14:38:27 +0300:
> >   
> > > Hello Miquel,
> > > 
> > > A situation noted by the warning below won't cause any problem because
> > > the casting is done to a non-dereferenced variable. It is utilized
> > > as a pointer bias later in that function. Shall we just ignore the
> > > warning or still fix it somehow?  
> >   
> 
> > Do you think the cast to a !__iomem value is mandatory here?  
> 
> It's not mandatory to have the casting with no __iomem, but wouldn't
> doing like this:
> + 	shift = (ssize_t __iomem)src & 0x3;
> be looking weird? Really, is there a good way to somehow extract the first
> two bits of a __iomem pointer without getting the sparse warning?

I asked around me, what about trying uintptr_t?

Thanks,
Miquèl

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

* Re: drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression
  2020-11-12  8:27       ` Miquel Raynal
@ 2020-11-12 11:20         ` Serge Semin
  2020-11-12 15:00         ` Vignesh Raghavendra
  1 sibling, 0 replies; 12+ messages in thread
From: Serge Semin @ 2020-11-12 11:20 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Serge Semin, kernel test robot, kbuild-all, linux-kernel, linux-mtd

On Thu, Nov 12, 2020 at 09:27:15AM +0100, Miquel Raynal wrote:
> Hi Sergey,
> 
> Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Wed, 11 Nov
> 2020 22:22:59 +0300:
> 
> > On Tue, Nov 10, 2020 at 04:35:56PM +0100, Miquel Raynal wrote:
> > > Hi Serge,
> > > 
> > > Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Tue, 10 Nov
> > > 2020 14:38:27 +0300:
> > >   
> > > > Hello Miquel,
> > > > 
> > > > A situation noted by the warning below won't cause any problem because
> > > > the casting is done to a non-dereferenced variable. It is utilized
> > > > as a pointer bias later in that function. Shall we just ignore the
> > > > warning or still fix it somehow?  
> > >   
> > 

> > > Do you think the cast to a !__iomem value is mandatory here?  
> > 
> > It's not mandatory to have the casting with no __iomem, but wouldn't
> > doing like this:
> > + 	shift = (ssize_t __iomem)src & 0x3;
> > be looking weird? Really, is there a good way to somehow extract the first
> > two bits of a __iomem pointer without getting the sparse warning?
> 
> I asked around me, what about trying uintptr_t?

Hm, that's weird. sparse gets happy if a casting to an unsigned type
is used here. That's why the similar statement defined in
bt1_rom_map_read() doesn't cause the sparse warning, while the
statement with ssize_t does.

Can people around explain whether that is just an internal sparse
feature or there is a particular reason of having the unsigned types
casting ignored by sparse in this case? I don't really understand why
removing the __iomem attribute with casting to a signed type cause the
warning, while casting to an unsigned type doesn't...

Anyway I'll send a patch with the fix of using the uintptr_t casting
here. Thanks for suggesting the solution.

-Sergey

> 
> Thanks,
> Miquèl

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

* Re: drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression
  2020-11-12  8:27       ` Miquel Raynal
  2020-11-12 11:20         ` Serge Semin
@ 2020-11-12 15:00         ` Vignesh Raghavendra
  2020-11-12 15:27           ` Serge Semin
  1 sibling, 1 reply; 12+ messages in thread
From: Vignesh Raghavendra @ 2020-11-12 15:00 UTC (permalink / raw)
  To: Miquel Raynal, Serge Semin
  Cc: linux-mtd, kbuild-all, kernel test robot, Serge Semin, linux-kernel



On 11/12/20 1:57 PM, Miquel Raynal wrote:
> Hi Sergey,
> 
> Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Wed, 11 Nov
> 2020 22:22:59 +0300:
> 
>> On Tue, Nov 10, 2020 at 04:35:56PM +0100, Miquel Raynal wrote:
>>> Hi Serge,
>>>
>>> Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Tue, 10 Nov
>>> 2020 14:38:27 +0300:
>>>   
>>>> Hello Miquel,
>>>>
>>>> A situation noted by the warning below won't cause any problem because
>>>> the casting is done to a non-dereferenced variable. It is utilized
>>>> as a pointer bias later in that function. Shall we just ignore the
>>>> warning or still fix it somehow?  
>>>   
>>
>>> Do you think the cast to a !__iomem value is mandatory here?  
>>
>> It's not mandatory to have the casting with no __iomem, but wouldn't
>> doing like this:
>> + 	shift = (ssize_t __iomem)src & 0x3;
>> be looking weird? Really, is there a good way to somehow extract the first
>> two bits of a __iomem pointer without getting the sparse warning?
> 
> I asked around me, what about trying uintptr_t?
> 

One more way is to use __force to tell sparse that this casting is
intentional:

       shift = (__force ssize_t)src & 0x3;


> Thanks,
> Miquèl
> 
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/
> 

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

* Re: drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression
  2020-11-12 15:00         ` Vignesh Raghavendra
@ 2020-11-12 15:27           ` Serge Semin
  2020-11-12 15:43             ` Miquel Raynal
  0 siblings, 1 reply; 12+ messages in thread
From: Serge Semin @ 2020-11-12 15:27 UTC (permalink / raw)
  To: Vignesh Raghavendra
  Cc: Serge Semin, Miquel Raynal, linux-mtd, kbuild-all,
	kernel test robot, linux-kernel

Hello Vignesh

On Thu, Nov 12, 2020 at 08:30:42PM +0530, Vignesh Raghavendra wrote:
> 
> 
> On 11/12/20 1:57 PM, Miquel Raynal wrote:
> > Hi Sergey,
> > 
> > Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Wed, 11 Nov
> > 2020 22:22:59 +0300:
> > 
> >> On Tue, Nov 10, 2020 at 04:35:56PM +0100, Miquel Raynal wrote:
> >>> Hi Serge,
> >>>
> >>> Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Tue, 10 Nov
> >>> 2020 14:38:27 +0300:
> >>>   
> >>>> Hello Miquel,
> >>>>
> >>>> A situation noted by the warning below won't cause any problem because
> >>>> the casting is done to a non-dereferenced variable. It is utilized
> >>>> as a pointer bias later in that function. Shall we just ignore the
> >>>> warning or still fix it somehow?  
> >>>   
> >>
> >>> Do you think the cast to a !__iomem value is mandatory here?  
> >>
> >> It's not mandatory to have the casting with no __iomem, but wouldn't
> >> doing like this:
> >> + 	shift = (ssize_t __iomem)src & 0x3;
> >> be looking weird? Really, is there a good way to somehow extract the first
> >> two bits of a __iomem pointer without getting the sparse warning?
> > 
> > I asked around me, what about trying uintptr_t?
> > 
> 

> One more way is to use __force to tell sparse that this casting is
> intentional:
> 
>        shift = (__force ssize_t)src & 0x3;

Oh, great! That solution is actually much better than using some
currently unexplained sparse peculiarity! I was thinking about applying
some other attribute, but __force just didn't come to my mind. Thank
you very much for the suggestion. I'll post the fix with the solution
suggested by you.

-Sergey

> 
> 
> > Thanks,
> > Miquèl
> > 
> > ______________________________________________________
> > Linux MTD discussion mailing list
> > http://lists.infradead.org/mailman/listinfo/linux-mtd/
> > 

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

* Re: drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression
  2020-11-12 15:27           ` Serge Semin
@ 2020-11-12 15:43             ` Miquel Raynal
  2020-11-12 16:10               ` Serge Semin
  0 siblings, 1 reply; 12+ messages in thread
From: Miquel Raynal @ 2020-11-12 15:43 UTC (permalink / raw)
  To: Serge Semin
  Cc: Vignesh Raghavendra, Serge Semin, linux-mtd, kbuild-all,
	kernel test robot, linux-kernel

Hi Serge,

Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Thu, 12 Nov
2020 18:27:39 +0300:

> Hello Vignesh
> 
> On Thu, Nov 12, 2020 at 08:30:42PM +0530, Vignesh Raghavendra wrote:
> > 
> > 
> > On 11/12/20 1:57 PM, Miquel Raynal wrote:  
> > > Hi Sergey,
> > > 
> > > Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Wed, 11 Nov
> > > 2020 22:22:59 +0300:
> > >   
> > >> On Tue, Nov 10, 2020 at 04:35:56PM +0100, Miquel Raynal wrote:  
> > >>> Hi Serge,
> > >>>
> > >>> Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Tue, 10 Nov
> > >>> 2020 14:38:27 +0300:
> > >>>     
> > >>>> Hello Miquel,
> > >>>>
> > >>>> A situation noted by the warning below won't cause any problem because
> > >>>> the casting is done to a non-dereferenced variable. It is utilized
> > >>>> as a pointer bias later in that function. Shall we just ignore the
> > >>>> warning or still fix it somehow?    
> > >>>     
> > >>  
> > >>> Do you think the cast to a !__iomem value is mandatory here?    
> > >>
> > >> It's not mandatory to have the casting with no __iomem, but wouldn't
> > >> doing like this:
> > >> + 	shift = (ssize_t __iomem)src & 0x3;
> > >> be looking weird? Really, is there a good way to somehow extract the first
> > >> two bits of a __iomem pointer without getting the sparse warning?  
> > > 
> > > I asked around me, what about trying uintptr_t?
> > >   
> >   
> 
> > One more way is to use __force to tell sparse that this casting is
> > intentional:
> > 
> >        shift = (__force ssize_t)src & 0x3;  
> 
> Oh, great! That solution is actually much better than using some
> currently unexplained sparse peculiarity! I was thinking about applying
> some other attribute, but __force just didn't come to my mind. Thank
> you very much for the suggestion. I'll post the fix with the solution
> suggested by you.

Is the ssize_t cast the right one btw? I would definitely prefer an
unsigned type here.

Thanks,
Miquèl

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

* Re: drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression
  2020-11-12 15:43             ` Miquel Raynal
@ 2020-11-12 16:10               ` Serge Semin
  2020-11-12 16:15                 ` Miquel Raynal
  0 siblings, 1 reply; 12+ messages in thread
From: Serge Semin @ 2020-11-12 16:10 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Serge Semin, Vignesh Raghavendra, linux-mtd, kbuild-all,
	kernel test robot, linux-kernel

On Thu, Nov 12, 2020 at 04:43:01PM +0100, Miquel Raynal wrote:
> Hi Serge,
> 
> Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Thu, 12 Nov
> 2020 18:27:39 +0300:
> 
> > Hello Vignesh
> > 
> > On Thu, Nov 12, 2020 at 08:30:42PM +0530, Vignesh Raghavendra wrote:
> > > 
> > > 
> > > On 11/12/20 1:57 PM, Miquel Raynal wrote:  
> > > > Hi Sergey,
> > > > 
> > > > Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Wed, 11 Nov
> > > > 2020 22:22:59 +0300:
> > > >   
> > > >> On Tue, Nov 10, 2020 at 04:35:56PM +0100, Miquel Raynal wrote:  
> > > >>> Hi Serge,
> > > >>>
> > > >>> Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Tue, 10 Nov
> > > >>> 2020 14:38:27 +0300:
> > > >>>     
> > > >>>> Hello Miquel,
> > > >>>>
> > > >>>> A situation noted by the warning below won't cause any problem because
> > > >>>> the casting is done to a non-dereferenced variable. It is utilized
> > > >>>> as a pointer bias later in that function. Shall we just ignore the
> > > >>>> warning or still fix it somehow?    
> > > >>>     
> > > >>  
> > > >>> Do you think the cast to a !__iomem value is mandatory here?    
> > > >>
> > > >> It's not mandatory to have the casting with no __iomem, but wouldn't
> > > >> doing like this:
> > > >> + 	shift = (ssize_t __iomem)src & 0x3;
> > > >> be looking weird? Really, is there a good way to somehow extract the first
> > > >> two bits of a __iomem pointer without getting the sparse warning?  
> > > > 
> > > > I asked around me, what about trying uintptr_t?
> > > >   
> > >   
> > 
> > > One more way is to use __force to tell sparse that this casting is
> > > intentional:
> > > 
> > >        shift = (__force ssize_t)src & 0x3;  
> > 
> > Oh, great! That solution is actually much better than using some
> > currently unexplained sparse peculiarity! I was thinking about applying
> > some other attribute, but __force just didn't come to my mind. Thank
> > you very much for the suggestion. I'll post the fix with the solution
> > suggested by you.
> 

> Is the ssize_t cast the right one btw? I would definitely prefer an
> unsigned type here.

The reason of me deciding to use the ssize_t type here was to prevent
the types casting across the "shift", "chunk" and "len" variables
within this method. It seemed a bit better than having a standard type
like "unsigned int" here seeing the ssize_t type width won't exceed
the long type size anyway. Moreover since the "len" variable has got
the ssize_t type and I couldn't change it (the method is the map_info
callback), I've decided to stick with what is available and defined
"shift" and "chunk" as ssize_t-es. Another callback method
bt1_rom_map_read() in his module has been designed in the same way.

Do you think it's better to change it in favor of using a different
type like "unsigned int" here anyway? If so for unification I'd need to
change bt1_rom_map_read() (though the "shift" variable has been
defined as "unsigned long" there in the first place because the offs
argument has got that type).

What to do with the __force attribute here? It does seem appropriate
even if for some mystical reasons we haven't got the sparse warning
for the unsigned types.

-Sergey

> 
> Thanks,
> Miquèl

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

* Re: drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression
  2020-11-12 16:10               ` Serge Semin
@ 2020-11-12 16:15                 ` Miquel Raynal
  2020-11-12 16:21                   ` Serge Semin
  0 siblings, 1 reply; 12+ messages in thread
From: Miquel Raynal @ 2020-11-12 16:15 UTC (permalink / raw)
  To: Serge Semin
  Cc: Serge Semin, Vignesh Raghavendra, linux-mtd, kbuild-all,
	kernel test robot, linux-kernel

Hi Serge,

Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Thu, 12 Nov
2020 19:10:43 +0300:

> On Thu, Nov 12, 2020 at 04:43:01PM +0100, Miquel Raynal wrote:
> > Hi Serge,
> > 
> > Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Thu, 12 Nov
> > 2020 18:27:39 +0300:
> >   
> > > Hello Vignesh
> > > 
> > > On Thu, Nov 12, 2020 at 08:30:42PM +0530, Vignesh Raghavendra wrote:  
> > > > 
> > > > 
> > > > On 11/12/20 1:57 PM, Miquel Raynal wrote:    
> > > > > Hi Sergey,
> > > > > 
> > > > > Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Wed, 11 Nov
> > > > > 2020 22:22:59 +0300:
> > > > >     
> > > > >> On Tue, Nov 10, 2020 at 04:35:56PM +0100, Miquel Raynal wrote:    
> > > > >>> Hi Serge,
> > > > >>>
> > > > >>> Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Tue, 10 Nov
> > > > >>> 2020 14:38:27 +0300:
> > > > >>>       
> > > > >>>> Hello Miquel,
> > > > >>>>
> > > > >>>> A situation noted by the warning below won't cause any problem because
> > > > >>>> the casting is done to a non-dereferenced variable. It is utilized
> > > > >>>> as a pointer bias later in that function. Shall we just ignore the
> > > > >>>> warning or still fix it somehow?      
> > > > >>>       
> > > > >>    
> > > > >>> Do you think the cast to a !__iomem value is mandatory here?      
> > > > >>
> > > > >> It's not mandatory to have the casting with no __iomem, but wouldn't
> > > > >> doing like this:
> > > > >> + 	shift = (ssize_t __iomem)src & 0x3;
> > > > >> be looking weird? Really, is there a good way to somehow extract the first
> > > > >> two bits of a __iomem pointer without getting the sparse warning?    
> > > > > 
> > > > > I asked around me, what about trying uintptr_t?
> > > > >     
> > > >     
> > >   
> > > > One more way is to use __force to tell sparse that this casting is
> > > > intentional:
> > > > 
> > > >        shift = (__force ssize_t)src & 0x3;    
> > > 
> > > Oh, great! That solution is actually much better than using some
> > > currently unexplained sparse peculiarity! I was thinking about applying
> > > some other attribute, but __force just didn't come to my mind. Thank
> > > you very much for the suggestion. I'll post the fix with the solution
> > > suggested by you.  
> >   
> 
> > Is the ssize_t cast the right one btw? I would definitely prefer an
> > unsigned type here.  
> 
> The reason of me deciding to use the ssize_t type here was to prevent
> the types casting across the "shift", "chunk" and "len" variables
> within this method. It seemed a bit better than having a standard type
> like "unsigned int" here seeing the ssize_t type width won't exceed
> the long type size anyway. Moreover since the "len" variable has got
> the ssize_t type and I couldn't change it (the method is the map_info
> callback), I've decided to stick with what is available and defined
> "shift" and "chunk" as ssize_t-es. Another callback method
> bt1_rom_map_read() in his module has been designed in the same way.
> 
> Do you think it's better to change it in favor of using a different
> type like "unsigned int" here anyway?

I would say yes.

> If so for unification I'd need to
> change bt1_rom_map_read() (though the "shift" variable has been
> defined as "unsigned long" there in the first place because the offs
> argument has got that type).

Fine.

> 
> What to do with the __force attribute here? It does seem appropriate
> even if for some mystical reasons we haven't got the sparse warning
> for the unsigned types.

Yeah this is strange. I would, however, suggest not to add this keyword
if we don't need it.

Thanks,
Miquèl

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

* Re: drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression
  2020-11-12 16:15                 ` Miquel Raynal
@ 2020-11-12 16:21                   ` Serge Semin
  0 siblings, 0 replies; 12+ messages in thread
From: Serge Semin @ 2020-11-12 16:21 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Vignesh Raghavendra, linux-mtd, kbuild-all, kernel test robot,
	linux-kernel

On Thu, Nov 12, 2020 at 05:15:10PM +0100, Miquel Raynal wrote:
> Hi Serge,
> 
> Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Thu, 12 Nov
> 2020 19:10:43 +0300:
> 
> > On Thu, Nov 12, 2020 at 04:43:01PM +0100, Miquel Raynal wrote:
> > > Hi Serge,
> > > 
> > > Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Thu, 12 Nov
> > > 2020 18:27:39 +0300:
> > >   
> > > > Hello Vignesh
> > > > 
> > > > On Thu, Nov 12, 2020 at 08:30:42PM +0530, Vignesh Raghavendra wrote:  
> > > > > 
> > > > > 
> > > > > On 11/12/20 1:57 PM, Miquel Raynal wrote:    
> > > > > > Hi Sergey,
> > > > > > 
> > > > > > Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Wed, 11 Nov
> > > > > > 2020 22:22:59 +0300:
> > > > > >     
> > > > > >> On Tue, Nov 10, 2020 at 04:35:56PM +0100, Miquel Raynal wrote:    
> > > > > >>> Hi Serge,
> > > > > >>>
> > > > > >>> Serge Semin <Sergey.Semin@baikalelectronics.ru> wrote on Tue, 10 Nov
> > > > > >>> 2020 14:38:27 +0300:
> > > > > >>>       
> > > > > >>>> Hello Miquel,
> > > > > >>>>
> > > > > >>>> A situation noted by the warning below won't cause any problem because
> > > > > >>>> the casting is done to a non-dereferenced variable. It is utilized
> > > > > >>>> as a pointer bias later in that function. Shall we just ignore the
> > > > > >>>> warning or still fix it somehow?      
> > > > > >>>       
> > > > > >>    
> > > > > >>> Do you think the cast to a !__iomem value is mandatory here?      
> > > > > >>
> > > > > >> It's not mandatory to have the casting with no __iomem, but wouldn't
> > > > > >> doing like this:
> > > > > >> + 	shift = (ssize_t __iomem)src & 0x3;
> > > > > >> be looking weird? Really, is there a good way to somehow extract the first
> > > > > >> two bits of a __iomem pointer without getting the sparse warning?    
> > > > > > 
> > > > > > I asked around me, what about trying uintptr_t?
> > > > > >     
> > > > >     
> > > >   
> > > > > One more way is to use __force to tell sparse that this casting is
> > > > > intentional:
> > > > > 
> > > > >        shift = (__force ssize_t)src & 0x3;    
> > > > 
> > > > Oh, great! That solution is actually much better than using some
> > > > currently unexplained sparse peculiarity! I was thinking about applying
> > > > some other attribute, but __force just didn't come to my mind. Thank
> > > > you very much for the suggestion. I'll post the fix with the solution
> > > > suggested by you.  
> > >   
> > 
> > > Is the ssize_t cast the right one btw? I would definitely prefer an
> > > unsigned type here.  
> > 
> > The reason of me deciding to use the ssize_t type here was to prevent
> > the types casting across the "shift", "chunk" and "len" variables
> > within this method. It seemed a bit better than having a standard type
> > like "unsigned int" here seeing the ssize_t type width won't exceed
> > the long type size anyway. Moreover since the "len" variable has got
> > the ssize_t type and I couldn't change it (the method is the map_info
> > callback), I've decided to stick with what is available and defined
> > "shift" and "chunk" as ssize_t-es. Another callback method
> > bt1_rom_map_read() in his module has been designed in the same way.
> > 
> > Do you think it's better to change it in favor of using a different
> > type like "unsigned int" here anyway?
> 

> I would say yes.
> 
> > If so for unification I'd need to
> > change bt1_rom_map_read() (though the "shift" variable has been
> > defined as "unsigned long" there in the first place because the offs
> > argument has got that type).
> 
> Fine.
> 
> > 
> > What to do with the __force attribute here? It does seem appropriate
> > even if for some mystical reasons we haven't got the sparse warning
> > for the unsigned types.
> 
> Yeah this is strange. I would, however, suggest not to add this keyword
> if we don't need it.

Ok. "unsigned int" it is then.

-Sergey

> 
> Thanks,
> Miquèl

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

end of thread, other threads:[~2020-11-12 16:22 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-02  4:42 drivers/mtd/maps/physmap-bt1-rom.c:78:18: sparse: sparse: cast removes address space '__iomem' of expression kernel test robot
2020-11-10 11:38 ` Serge Semin
2020-11-10 15:35   ` Miquel Raynal
2020-11-11 19:22     ` Serge Semin
2020-11-12  8:27       ` Miquel Raynal
2020-11-12 11:20         ` Serge Semin
2020-11-12 15:00         ` Vignesh Raghavendra
2020-11-12 15:27           ` Serge Semin
2020-11-12 15:43             ` Miquel Raynal
2020-11-12 16:10               ` Serge Semin
2020-11-12 16:15                 ` Miquel Raynal
2020-11-12 16:21                   ` Serge Semin

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).