mm/memory.c: check return value of ioremap_prot [Linux 4.18]

This Linux kernel change "mm/memory.c: check return value of ioremap_prot" is included in the Linux 4.18 release. This change is authored by jie [at] chenjie6 [at] <jie [at] chenjie6 [at]> on Fri Aug 10 17:23:06 2018 -0700. The commit for this change in Linux stable tree is 24eee1e (patch).

mm/memory.c: check return value of ioremap_prot

ioremap_prot() can return NULL which could lead to an oops.

Link:[email protected]
Signed-off-by: chen jie <[email protected]>
Reviewed-by: Andrew Morton <[email protected]>
Cc: Li Zefan <[email protected]>
Cc: chenjie <[email protected]>
Cc: Yang Shi <[email protected]>
Cc: Alexey Dobriyan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>

There are 3 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 mm/memory.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/memory.c b/mm/memory.c
index dab1511..c5e87a3 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4395,6 +4395,9 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
        return -EINVAL;

    maddr = ioremap_prot(phys_addr, PAGE_ALIGN(len + offset), prot);
+   if (!maddr)
+       return -ENOMEM;
    if (write)
        memcpy_toio(maddr + offset, buf, len);

Leave a Reply

Your email address will not be published. Required fields are marked *