All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch for 4.0] x86: silence warning in /dev/mem support
@ 2015-04-16  8:04 Pavel Machek
  2015-04-16 10:09 ` Ingo Molnar
  2015-04-20 10:13 ` [tip:x86/urgent] x86/mm: Clean up types in xlate_dev_mem_ptr() tip-bot for Ingo Molnar
  0 siblings, 2 replies; 7+ messages in thread
From: Pavel Machek @ 2015-04-16  8:04 UTC (permalink / raw)
  To: tglx, mingo, hpa, jgross, roland, akpm, linux-kernel

The compiler is right, the code is tricky, but it is also correct
AFAICT.

Signed-off-by: Pavel Machek <pavel@ucw.cz>

diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index fdf617c..8a8dce8 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -341,7 +341,7 @@ void *xlate_dev_mem_ptr(phys_addr_t phys)
 
 	addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
 	if (addr)
-		addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
+		addr = (void *)((unsigned long)addr | (unsigned long) (phys & ~PAGE_MASK));
 
 	return addr;
 }


-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* Re: [patch for 4.0] x86: silence warning in /dev/mem support
  2015-04-16  8:04 [patch for 4.0] x86: silence warning in /dev/mem support Pavel Machek
@ 2015-04-16 10:09 ` Ingo Molnar
  2015-04-16 10:15   ` Pavel Machek
  2015-04-20 10:13 ` [tip:x86/urgent] x86/mm: Clean up types in xlate_dev_mem_ptr() tip-bot for Ingo Molnar
  1 sibling, 1 reply; 7+ messages in thread
From: Ingo Molnar @ 2015-04-16 10:09 UTC (permalink / raw)
  To: Pavel Machek; +Cc: tglx, mingo, hpa, jgross, roland, akpm, linux-kernel


* Pavel Machek <pavel@ucw.cz> wrote:

> The compiler is right, the code is tricky, but it is also correct
> AFAICT.
> 
> Signed-off-by: Pavel Machek <pavel@ucw.cz>
> 
> diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
> index fdf617c..8a8dce8 100644
> --- a/arch/x86/mm/ioremap.c
> +++ b/arch/x86/mm/ioremap.c
> @@ -341,7 +341,7 @@ void *xlate_dev_mem_ptr(phys_addr_t phys)
>  
>  	addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
>  	if (addr)
> -		addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
> +		addr = (void *)((unsigned long)addr | (unsigned long) (phys & ~PAGE_MASK));

What warning did it generate and which compiler version?

Thanks,

	Ingo

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

* Re: [patch for 4.0] x86: silence warning in /dev/mem support
  2015-04-16 10:09 ` Ingo Molnar
@ 2015-04-16 10:15   ` Pavel Machek
  2015-04-17  8:39     ` Ingo Molnar
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Machek @ 2015-04-16 10:15 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: tglx, mingo, hpa, jgross, roland, akpm, linux-kernel

On Thu 2015-04-16 12:09:54, Ingo Molnar wrote:
> 
> * Pavel Machek <pavel@ucw.cz> wrote:
> 
> > The compiler is right, the code is tricky, but it is also correct
> > AFAICT.
> > 
> > Signed-off-by: Pavel Machek <pavel@ucw.cz>
> > 
> > diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
> > index fdf617c..8a8dce8 100644
> > --- a/arch/x86/mm/ioremap.c
> > +++ b/arch/x86/mm/ioremap.c
> > @@ -341,7 +341,7 @@ void *xlate_dev_mem_ptr(phys_addr_t phys)
> >  
> >  	addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
> >  	if (addr)
> > -		addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
> > +		addr = (void *)((unsigned long)addr | (unsigned long) (phys & ~PAGE_MASK));
> 
> What warning did it generate and which compiler version?


  CC      arch/x86/mm/ioremap.o
  arch/x86/mm/ioremap.c: In function ‘xlate_dev_mem_ptr’:
  arch/x86/mm/ioremap.c:363:10: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
               ^
  LD      arch/x86/mm/built-in.o
		 
pavel@amd:/data/l/linux$ gcc --version
gcc (Debian 4.9.2-10) 4.9.2

(Patch should apply to today's 4.1-rc0, too).

Best regards,
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* Re: [patch for 4.0] x86: silence warning in /dev/mem support
  2015-04-16 10:15   ` Pavel Machek
@ 2015-04-17  8:39     ` Ingo Molnar
  2015-04-17  8:48       ` Pavel Machek
  0 siblings, 1 reply; 7+ messages in thread
From: Ingo Molnar @ 2015-04-17  8:39 UTC (permalink / raw)
  To: Pavel Machek; +Cc: tglx, mingo, hpa, jgross, roland, akpm, linux-kernel


* Pavel Machek <pavel@ucw.cz> wrote:

> On Thu 2015-04-16 12:09:54, Ingo Molnar wrote:
> > 
> > * Pavel Machek <pavel@ucw.cz> wrote:
> > 
> > > The compiler is right, the code is tricky, but it is also correct
> > > AFAICT.
> > > 
> > > Signed-off-by: Pavel Machek <pavel@ucw.cz>
> > > 
> > > diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
> > > index fdf617c..8a8dce8 100644
> > > --- a/arch/x86/mm/ioremap.c
> > > +++ b/arch/x86/mm/ioremap.c
> > > @@ -341,7 +341,7 @@ void *xlate_dev_mem_ptr(phys_addr_t phys)
> > >  
> > >  	addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
> > >  	if (addr)
> > > -		addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
> > > +		addr = (void *)((unsigned long)addr | (unsigned long) (phys & ~PAGE_MASK));
> > 
> > What warning did it generate and which compiler version?
> 
> 
>   CC      arch/x86/mm/ioremap.o
>   arch/x86/mm/ioremap.c: In function ‘xlate_dev_mem_ptr’:
>   arch/x86/mm/ioremap.c:363:10: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
>      addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
>                ^
>   LD      arch/x86/mm/built-in.o
> 		 
> pavel@amd:/data/l/linux$ gcc --version
> gcc (Debian 4.9.2-10) 4.9.2

So this code has not been changed for a year or so in theory, and I've 
never seen this warning with GCC 4.9.1. I'm wondering how it 
triggered. Could you send me your .config that triggers this?

Must have been introduced in:

  4707a341b4af /dev/mem: Use more consistent data types

Thanks,

	Ingo

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

* Re: [patch for 4.0] x86: silence warning in /dev/mem support
  2015-04-17  8:39     ` Ingo Molnar
@ 2015-04-17  8:48       ` Pavel Machek
  2015-04-20  6:52         ` Ingo Molnar
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Machek @ 2015-04-17  8:48 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: tglx, mingo, hpa, jgross, roland, akpm, linux-kernel

Hi!

> >   CC      arch/x86/mm/ioremap.o
> >   arch/x86/mm/ioremap.c: In function ‘xlate_dev_mem_ptr’:
> >   arch/x86/mm/ioremap.c:363:10: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
> >      addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
> >                ^
> >   LD      arch/x86/mm/built-in.o
> > 		 
> > pavel@amd:/data/l/linux$ gcc --version
> > gcc (Debian 4.9.2-10) 4.9.2
> 
> So this code has not been changed for a year or so in theory, and I've 
> never seen this warning with GCC 4.9.1. I'm wondering how it 
> triggered. Could you send me your .config that triggers this?

Config sent in private email. 32-bit kernel.

Best regards,
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* Re: [patch for 4.0] x86: silence warning in /dev/mem support
  2015-04-17  8:48       ` Pavel Machek
@ 2015-04-20  6:52         ` Ingo Molnar
  0 siblings, 0 replies; 7+ messages in thread
From: Ingo Molnar @ 2015-04-20  6:52 UTC (permalink / raw)
  To: Pavel Machek; +Cc: tglx, mingo, hpa, jgross, roland, akpm, linux-kernel


* Pavel Machek <pavel@ucw.cz> wrote:

> Hi!
> 
> > >   CC      arch/x86/mm/ioremap.o
> > >   arch/x86/mm/ioremap.c: In function ‘xlate_dev_mem_ptr’:
> > >   arch/x86/mm/ioremap.c:363:10: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
> > >      addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
> > >                ^
> > >   LD      arch/x86/mm/built-in.o
> > > 		 
> > > pavel@amd:/data/l/linux$ gcc --version
> > > gcc (Debian 4.9.2-10) 4.9.2
> > 
> > So this code has not been changed for a year or so in theory, and I've 
> > never seen this warning with GCC 4.9.1. I'm wondering how it 
> > triggered. Could you send me your .config that triggers this?
> 
> Config sent in private email. 32-bit kernel.

Ah, I see, the key is:

  CONFIG_HIGHMEM64G=y

and neither x86 defconfig nor allyesconfig/allmodconfig selects 
HIGHMEM64G apparently, so this was rarely triggered.

Thanks,

	Ingo

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

* [tip:x86/urgent] x86/mm: Clean up types in xlate_dev_mem_ptr()
  2015-04-16  8:04 [patch for 4.0] x86: silence warning in /dev/mem support Pavel Machek
  2015-04-16 10:09 ` Ingo Molnar
@ 2015-04-20 10:13 ` tip-bot for Ingo Molnar
  1 sibling, 0 replies; 7+ messages in thread
From: tip-bot for Ingo Molnar @ 2015-04-20 10:13 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, tglx, pavel, hpa, mingo

Commit-ID:  94d4b4765b7ddb8478b0d57663cf7a08e2263bbf
Gitweb:     http://git.kernel.org/tip/94d4b4765b7ddb8478b0d57663cf7a08e2263bbf
Author:     Ingo Molnar <mingo@kernel.org>
AuthorDate: Fri, 23 Nov 2012 19:19:07 +0100
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 20 Apr 2015 08:41:37 +0200

x86/mm: Clean up types in xlate_dev_mem_ptr()

Pavel Machek reported the following compiler warning on
x86/32 CONFIG_HIGHMEM64G=y builds:

  arch/x86/mm/ioremap.c:344:10: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Clean up the types in this function by using a single natural type for
internal calculations (unsigned long), to make it more apparent what's
happening, and also to remove fragile casts.

Reported-by: Pavel Machek <pavel@ucw.cz>
Cc: jgross@suse.com
Cc: roland@purestorage.com
Link: http://lkml.kernel.org/r/20150416080440.GA507@amd
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/mm/ioremap.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index fdf617c..4bf037b 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -332,18 +332,20 @@ EXPORT_SYMBOL(iounmap);
  */
 void *xlate_dev_mem_ptr(phys_addr_t phys)
 {
-	void *addr;
-	unsigned long start = phys & PAGE_MASK;
+	unsigned long start  = phys &  PAGE_MASK;
+	unsigned long offset = phys & ~PAGE_MASK;
+	unsigned long vaddr;
 
 	/* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
 	if (page_is_ram(start >> PAGE_SHIFT))
 		return __va(phys);
 
-	addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
-	if (addr)
-		addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
+	vaddr = (unsigned long)ioremap_cache(start, PAGE_SIZE);
+	/* Only add the offset on success and return NULL if the ioremap() failed: */
+	if (vaddr)
+		vaddr += offset;
 
-	return addr;
+	return (void *)vaddr;
 }
 
 void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)

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

end of thread, other threads:[~2015-04-20 10:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-16  8:04 [patch for 4.0] x86: silence warning in /dev/mem support Pavel Machek
2015-04-16 10:09 ` Ingo Molnar
2015-04-16 10:15   ` Pavel Machek
2015-04-17  8:39     ` Ingo Molnar
2015-04-17  8:48       ` Pavel Machek
2015-04-20  6:52         ` Ingo Molnar
2015-04-20 10:13 ` [tip:x86/urgent] x86/mm: Clean up types in xlate_dev_mem_ptr() tip-bot for Ingo Molnar

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.