From b5b6c054621ccc97771e326f2d4ce8a008b13805 Mon Sep 17 00:00:00 2001 From: Leonardo Di Giovanna Date: Fri, 17 May 2024 20:00:45 +0900 Subject: [PATCH] Handle ioremap error in short example Signed-off-by: Leonardo Di Giovanna --- short/short.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/short/short.c b/short/short.c index 24690d934..0bf0e7d90 100644 --- a/short/short.c +++ b/short/short.c @@ -583,7 +583,12 @@ int short_init(void) /* also, ioremap it */ short_base = (unsigned long) ioremap(short_base, SHORT_NR_PORTS); - /* Hmm... we should check the return value */ + if (!short_base) { + release_mem_region(short_base, SHORT_NR_PORTS); + printk(KERN_INFO "short: can't remap I/O mem address 0x%lx\n", + short_base); + return -ENOMEM; + } } /* Here we register our device - should not fail thereafter */ result = register_chrdev(major, "short", &short_fops);