public inbox for linux-rtc@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtc: gamecube: Check the return value of ioremap()
@ 2025-11-26  1:20 Haotian Zhang
  2025-11-26  7:33 ` Link Mauve
  2025-11-26  8:06 ` [PATCH v2] " Haotian Zhang
  0 siblings, 2 replies; 5+ messages in thread
From: Haotian Zhang @ 2025-11-26  1:20 UTC (permalink / raw)
  To: alexandre.belloni; +Cc: linkmauve, linux-rtc, linux-kernel, Haotian Zhang

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>
---
 drivers/rtc/rtc-gamecube.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/rtc/rtc-gamecube.c b/drivers/rtc/rtc-gamecube.c
index c828bc8e05b9..cd7714437107 100644
--- a/drivers/rtc/rtc-gamecube.c
+++ b/drivers/rtc/rtc-gamecube.c
@@ -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
-- 
2.50.1.windows.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] rtc: gamecube: Check the return value of ioremap()
  2025-11-26  1:20 [PATCH] rtc: gamecube: Check the return value of ioremap() Haotian Zhang
@ 2025-11-26  7:33 ` Link Mauve
  2025-11-26  8:06 ` [PATCH v2] " Haotian Zhang
  1 sibling, 0 replies; 5+ messages in thread
From: Link Mauve @ 2025-11-26  7:33 UTC (permalink / raw)
  To: Haotian Zhang; +Cc: alexandre.belloni, linkmauve, linux-rtc, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1533 bytes --]

Good catch!

On Wed, Nov 26, 2025 at 09:20:19AM +0800, Haotian Zhang wrote:
> 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>
> ---
>  drivers/rtc/rtc-gamecube.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/rtc/rtc-gamecube.c b/drivers/rtc/rtc-gamecube.c
> index c828bc8e05b9..cd7714437107 100644
> --- a/drivers/rtc/rtc-gamecube.c
> +++ b/drivers/rtc/rtc-gamecube.c
> @@ -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.

> +		return -ENOMEM;
> +	}
>  	old = ioread32be(hw_srnprot);
>  
>  	/* TODO: figure out why we use this magic constant.  I obtained it by
> -- 
> 2.50.1.windows.1
> 

With that change:
Reviewed-by: Link Mauve <kernel@linkmauve.fr>

-- 
Link Mauve

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] rtc: gamecube: Check the return value of ioremap()
  2025-11-26  1:20 [PATCH] rtc: gamecube: Check the return value of ioremap() Haotian Zhang
  2025-11-26  7:33 ` Link Mauve
@ 2025-11-26  8:06 ` Haotian Zhang
  2025-11-26  8:14   ` Link Mauve
  2025-12-08 22:10   ` Alexandre Belloni
  1 sibling, 2 replies; 5+ messages in thread
From: Haotian Zhang @ 2025-11-26  8:06 UTC (permalink / raw)
  To: alexandre.belloni; +Cc: linkmauve, linux-rtc, linux-kernel, Haotian Zhang

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>
---
Changes in v2:
  -Use lowercase for error message to match existing style.
---
 drivers/rtc/rtc-gamecube.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/rtc/rtc-gamecube.c b/drivers/rtc/rtc-gamecube.c
index c828bc8e05b9..045d5d45ab4b 100644
--- a/drivers/rtc/rtc-gamecube.c
+++ b/drivers/rtc/rtc-gamecube.c
@@ -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
-- 
2.50.1.windows.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] rtc: gamecube: Check the return value of ioremap()
  2025-11-26  8:06 ` [PATCH v2] " Haotian Zhang
@ 2025-11-26  8:14   ` Link Mauve
  2025-12-08 22:10   ` Alexandre Belloni
  1 sibling, 0 replies; 5+ messages in thread
From: Link Mauve @ 2025-11-26  8:14 UTC (permalink / raw)
  To: Haotian Zhang; +Cc: alexandre.belloni, linkmauve, linux-rtc, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1369 bytes --]

Hi,

On Wed, Nov 26, 2025 at 04:06:25PM +0800, Haotian Zhang wrote:
> 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>

You forgot to carry my R-b, but here it is again:
Reviewed-by: Link Mauve <kernel@linkmauve.fr>

> ---
> Changes in v2:
>   -Use lowercase for error message to match existing style.
> ---
>  drivers/rtc/rtc-gamecube.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/rtc/rtc-gamecube.c b/drivers/rtc/rtc-gamecube.c
> index c828bc8e05b9..045d5d45ab4b 100644
> --- a/drivers/rtc/rtc-gamecube.c
> +++ b/drivers/rtc/rtc-gamecube.c
> @@ -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
> -- 
> 2.50.1.windows.1
> 

-- 
Link Mauve

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] rtc: gamecube: Check the return value of ioremap()
  2025-11-26  8:06 ` [PATCH v2] " Haotian Zhang
  2025-11-26  8:14   ` Link Mauve
@ 2025-12-08 22:10   ` Alexandre Belloni
  1 sibling, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2025-12-08 22:10 UTC (permalink / raw)
  To: Haotian Zhang; +Cc: linkmauve, linux-rtc, linux-kernel

On Wed, 26 Nov 2025 16:06:25 +0800, Haotian Zhang wrote:
> 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.
> 
> [...]

Applied, thanks!

[1/1] rtc: gamecube: Check the return value of ioremap()
      https://git.kernel.org/abelloni/c/d1220e47e4bd

Best regards,

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-12-08 22:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-26  1:20 [PATCH] rtc: gamecube: Check the return value of ioremap() Haotian Zhang
2025-11-26  7:33 ` Link Mauve
2025-11-26  8:06 ` [PATCH v2] " Haotian Zhang
2025-11-26  8:14   ` Link Mauve
2025-12-08 22:10   ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox