From: Ingo Molnar <mingo@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ingo Molnar <mingo2.kernel.org@gmail.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH] x86/mm: Clean up types in xlate_dev_mem_ptr() some more
Date: Fri, 8 May 2015 12:50:55 +0200 [thread overview]
Message-ID: <20150508105055.GA14063@gmail.com> (raw)
In-Reply-To: <CA+55aFxp8xV1Osk9N3auCLccGovAaJUVKpMN4QdVyFOXTSh7XQ@mail.gmail.com>
* Linus Torvalds <torvalds@linux-foundation.org> wrote:
> Ugh, I pulled, but:
>
> On Wed, May 6, 2015 at 5:58 AM, Ingo Molnar <mingo2.kernel.org@gmail.com> wrote:
> >
> > Ingo Molnar (1):
> > x86/mm: Clean up types in xlate_dev_mem_ptr()
> >
> > diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
> > index fdf617c00e2f..4bf037b20f47 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)
> > {
> > + unsigned long start = phys & PAGE_MASK;
> > + unsigned long offset = phys & ~PAGE_MASK;
> > + unsigned long vaddr;
>
> That "unsigned long vaddr" is just stupid and not a cleanup.
>
> It causes two pointless casts:
>
> > + 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 (void *)vaddr;
>
> neither of which is helpful in the least. And the "vaddr += offset"
> would work equally well in "void *", gcc is perfectly happy to treat
> "void *" arithmetic as byte offsets, it's both documented and
> already extensively used in the kernel.
Yeah, not sure why I didn't notice that, I love void * arithmetics.
> So the cleanup to use "start/offset" is a good cleanup, but you
> should have kept "addr" as a pointer.
Something like the patch below?
Thanks,
Ingo
===================>
>From 562bfca4c80175d1d18eef5c3f4bb8dda53c03e4 Mon Sep 17 00:00:00 2001
From: Ingo Molnar <mingo@kernel.org>
Date: Fri, 8 May 2015 12:43:53 +0200
Subject: [PATCH] x86/mm: Clean up types in xlate_dev_mem_ptr() some more
So Linus noticed that in:
94d4b4765b7d ("x86/mm: Clean up types in xlate_dev_mem_ptr()")
... I added two nonsensical casts, due to the poor type choice
for 'vaddr'.
Change it to 'void *' and take advantage of void * arithmetics.
This removes the casts.
( Also remove a nonsensical return line from unxlate_dev_mem_ptr()
while at it. )
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
arch/x86/mm/ioremap.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index 70e7444c6835..27ff21216dfa 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -353,18 +353,18 @@ void *xlate_dev_mem_ptr(phys_addr_t phys)
{
unsigned long start = phys & PAGE_MASK;
unsigned long offset = phys & ~PAGE_MASK;
- unsigned long vaddr;
+ void *vaddr;
/* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
if (page_is_ram(start >> PAGE_SHIFT))
return __va(phys);
- vaddr = (unsigned long)ioremap_cache(start, PAGE_SIZE);
+ vaddr = ioremap_cache(start, PAGE_SIZE);
/* Only add the offset on success and return NULL if the ioremap() failed: */
if (vaddr)
vaddr += offset;
- return (void *)vaddr;
+ return vaddr;
}
void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
@@ -373,7 +373,6 @@ void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
return;
iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
- return;
}
static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
prev parent reply other threads:[~2015-05-08 10:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-06 12:58 [GIT PULL] x86 fixes Ingo Molnar
2015-05-06 18:14 ` Linus Torvalds
2015-05-08 10:50 ` Ingo Molnar [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150508105055.GA14063@gmail.com \
--to=mingo@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo2.kernel.org@gmail.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).