Commit d1220e47 authored by Haotian Zhang's avatar Haotian Zhang Committed by Alexandre Belloni
Browse files

rtc: gamecube: Check the return value of ioremap()



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: 86559400 ("rtc: gamecube: Add a RTC driver for the GameCube, Wii and Wii U")
Signed-off-by: default avatarHaotian Zhang <vulab@iscas.ac.cn>
Reviewed-by: default avatarLink Mauve <kernel@linkmauve.fr>
Link: https://patch.msgid.link/20251126080625.1752-1-vulab@iscas.ac.cn


Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 22a6db42
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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