]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rtc: gamecube: Check the return value of ioremap()
authorHaotian Zhang <vulab@iscas.ac.cn>
Wed, 26 Nov 2025 08:06:25 +0000 (16:06 +0800)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Mon, 8 Dec 2025 21:54:17 +0000 (22:54 +0100)
The function ioremap() in gamecube_rtc_read_offset_from_sram() can fail
and return NULL, which is dereferenced without checking, leading to a
NULL pointer dereference.

Add a check for the return value of ioremap() and return -ENOMEM on
failure.

Fixes: 86559400b3ef ("rtc: gamecube: Add a RTC driver for the GameCube, Wii and Wii U")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
Reviewed-by: Link Mauve <kernel@linkmauve.fr>
Link: https://patch.msgid.link/20251126080625.1752-1-vulab@iscas.ac.cn
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-gamecube.c

index c828bc8e05b9cc48eebdf05343e2eb1b2e62dd8c..045d5d45ab4b071809f2c3a199429933a83e32b9 100644 (file)
@@ -242,6 +242,10 @@ static int gamecube_rtc_read_offset_from_sram(struct priv *d)
        }
 
        hw_srnprot = ioremap(res.start, resource_size(&res));
+       if (!hw_srnprot) {
+               pr_err("failed to ioremap hw_srnprot\n");
+               return -ENOMEM;
+       }
        old = ioread32be(hw_srnprot);
 
        /* TODO: figure out why we use this magic constant.  I obtained it by