rtc: gamecube: Check the return value of ioremap()
PATCH 1/1 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.
--- drivers/rtc/rtc-gamecube.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/rtc/rtc-gamecube.c +4 -0
@@ -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
Signature · 1 line
2.50.1.windows.1
Good catch!
Quoted 18 lines · Haotian Zhang
The function
ioremap()ingamecube_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-ENOMEMon failure.Fixes 86559400b3ef ("rtc: gamecube: Add a RTC driver for the GameCube, Wii and Wii U")Signed-off-by Haotian Zhang <[email protected]>--- drivers/rtc/rtc-gamecube.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/rtc/rtc-gamecube.c +0
-0
drivers/rtc/rtc-gamecube.c static int gamecube_rtc_read_offset_from_sram(struct priv *d) · line 246
Quoted 5 lines
drivers/rtc/rtc-gamecube.c +2
-0@@ -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" );
The error messages on lines 240 and 276 start with a lowercase letter, please use the same case for this message. From a quick grep through the kernel, it seems we use either lowercase or uppercase, but I’d prefer to keep the case consistent in this driver at least.
Quoted 8 lines
drivers/rtc/rtc-gamecube.c +2
-0+return -ENOMEM ; + } old =ioread32be (hw_srnprot);/* TODO: figure out why we use this magic constant. I obtained it by Signature · 1 line
2.50.1.windows.1
With that change:
Signature · 1 line
Link Mauve
PATCH v2 1/1 rtc: gamecube: Check the return value of ioremap()
In reply to Haotian ZhangThe 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.
---
Changes in v2:
-Use lowercase for error message to match existing style.
--- drivers/rtc/rtc-gamecube.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/rtc/rtc-gamecube.c +4 -0
@@ -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
Signature · 1 line
2.50.1.windows.1
Hi,
Quoted 9 lines · Haotian Zhang
The function
ioremap()ingamecube_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-ENOMEMon failure.Fixes 86559400b3ef ("rtc: gamecube: Add a RTC driver for the GameCube, Wii and Wii U")Signed-off-by Haotian Zhang <[email protected]>
You forgot to carry my R-b, but here it is again:
Quoted 25 lines
---
Changes in v2:
-Use lowercase for error message to match existing style.--- drivers/rtc/rtc-gamecube.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/rtc/rtc-gamecube.c +4
-0@@ -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 Signature · 1 line
2.50.1.windows.1
Signature · 1 line
Link Mauve
Quoted 8 lines · Haotian Zhang
The function
ioremap()ingamecube_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-ENOMEMon failure.[...]
Applied, thanks!
[1/1] rtc: gamecube: Check the return value of ioremap()
https://git.kernel.org/abelloni/c/d1220e47e4bd
Best regards,
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com