]> git.baikalelectronics.ru Git - kernel.git/commit
sh: mm: Fix unprotected access to struct device
authorJacopo Mondi <jacopo+renesas@jmondi.org>
Wed, 18 Apr 2018 09:42:35 +0000 (11:42 +0200)
committerRich Felker <dalias@libc.org>
Sat, 5 May 2018 20:51:46 +0000 (16:51 -0400)
commit65ff4a9ceaececcddc0aee588dd8782485ad2abd
tree8749be4653afdecc99b127e272e27118e553157e
parent64daa394d0325c3f264cdd0fd8588b5ca15eeb56
sh: mm: Fix unprotected access to struct device

With commit 5ee5dcee51cf8a4f285782af ("arch/sh: make the DMA mapping
operations observe dev->dma_pfn_offset") the generic DMA allocation
function on which the SH 'dma_alloc_coherent()' function relies on,
accesses the 'dma_pfn_offset' field of struct device.

Unfortunately the 'dma_generic_alloc_coherent()' function is called from
several places with a NULL struct device argument, halting the CPU
during the boot process.

This patch fixes the issue by protecting access to dev->dma_pfn_offset,
with a trivial check for validity. It also passes a valid 'struct device'
in the 'platform_resource_setup_memory()' function which is the main user
of 'dma_alloc_coherent()', and inserts a WARN_ON() check to remind to future
(and existing) bogus users of this function to provide a valid 'struct device'
whenever possible.

Fixes: 5ee5dcee51cf8a4f285782af ("arch/sh: make the DMA mapping operations observe dev->dma_pfn_offset")
Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Rich Felker <dalias@libc.org>
arch/sh/mm/consistent.c