Skip to content

Commit e0b3e0b

Browse files
mjruhltorvalds
authored andcommitted
io-mapping: indicate mapping failure
The !ATOMIC_IOMAP version of io_maping_init_wc will always return success, even when the ioremap fails. Since the ATOMIC_IOMAP version returns NULL when the init fails, and callers check for a NULL return on error this is unexpected. During a device probe, where the ioremap failed, a crash can look like this: BUG: unable to handle page fault for address: 0000000000210000 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page Oops: 0002 [#1] PREEMPT SMP CPU: 0 PID: 177 Comm: RIP: 0010:fill_page_dma [i915] gen8_ppgtt_create [i915] i915_ppgtt_create [i915] intel_gt_init [i915] i915_gem_init [i915] i915_driver_probe [i915] pci_device_probe really_probe driver_probe_device The remap failure occurred much earlier in the probe. If it had been propagated, the driver would have exited with an error. Return NULL on ioremap failure. [[email protected]: detect ioremap_wc() errors earlier] Fixes: cafaf14 ("io-mapping: Always create a struct to hold metadata about the io-mapping") Signed-off-by: Michael J. Ruhl <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Andy Shevchenko <[email protected]> Cc: Chris Wilson <[email protected]> Cc: Daniel Vetter <[email protected]> Cc: <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent d178770 commit e0b3e0b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

include/linux/io-mapping.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,12 @@ io_mapping_init_wc(struct io_mapping *iomap,
107107
resource_size_t base,
108108
unsigned long size)
109109
{
110+
iomap->iomem = ioremap_wc(base, size);
111+
if (!iomap->iomem)
112+
return NULL;
113+
110114
iomap->base = base;
111115
iomap->size = size;
112-
iomap->iomem = ioremap_wc(base, size);
113116
#if defined(pgprot_noncached_wc) /* archs can't agree on a name ... */
114117
iomap->prot = pgprot_noncached_wc(PAGE_KERNEL);
115118
#elif defined(pgprot_writecombine)

0 commit comments

Comments
 (0)