Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

misc: pvpanic: Check devm_ioport_map() for NULL

Inconveniently devm_ioport_map() and devm_ioremap_resource()
return errors differently, i.e. former uses simply NULL pointer,
while the latter an error pointer.

Due to this, we have to check each of them separately.

Fixes: f104060813fe ("misc: pvpanic: Combine ACPI and platform drivers")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20201228184313.57610-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Andy Shevchenko and committed by
Greg Kroah-Hartman
afded6d8 b8b54ad9

+15 -4
+15 -4
drivers/misc/pvpanic.c
··· 55 55 struct resource *res; 56 56 57 57 res = platform_get_mem_or_io(pdev, 0); 58 - if (res && resource_type(res) == IORESOURCE_IO) 58 + if (!res) 59 + return -EINVAL; 60 + 61 + switch (resource_type(res)) { 62 + case IORESOURCE_IO: 59 63 base = devm_ioport_map(dev, res->start, resource_size(res)); 60 - else 64 + if (!base) 65 + return -ENOMEM; 66 + break; 67 + case IORESOURCE_MEM: 61 68 base = devm_ioremap_resource(dev, res); 62 - if (IS_ERR(base)) 63 - return PTR_ERR(base); 69 + if (IS_ERR(base)) 70 + return PTR_ERR(base); 71 + break; 72 + default: 73 + return -EINVAL; 74 + } 64 75 65 76 atomic_notifier_chain_register(&panic_notifier_list, 66 77 &pvpanic_panic_nb);