Skip to contentSkip to conversation

nvmem: nintendo-otp: Fix potential NULL pointer dereference in nintendo_otp_probe()

PATCH In review Haotian Zhang 3 participants 3 messages Dec 10, 2025 – Jan 5 NVMEM framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmem: nintendo-otp: Fix potential NULL pointer dereference in nintendo_otp_probe()

of_match_device() may return NULL if no match is found. Dereferencing the return value of_id in nintendo_otp_probe() without a check could lead to a NULL pointer dereference.

Add a check for of_id and return -ENODEV upon failure.

Fixes 3683b761fe3a ("nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP")
---
 drivers/nvmem/nintendo-otp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/nvmem/nintendo-otp.c +3 -0
index 355e7f1fc6d5..89b15a58bf88 100644
@@ -87,6 +87,9 @@ static int nintendo_otp_probe(struct platform_device *pdev)
 		.root_only = true,
 	};
 
+	if (!of_id)
+		return -ENODEV;
+
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
Signature · 1 line
2.50.1.windows.1
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 29 lines · Haotian Zhang

of_match_device() may return NULL if no match is found. Dereferencing the return value of_id in nintendo_otp_probe() without a check could lead to a NULL pointer dereference.

Add a check for of_id and return -ENODEV upon failure.

Fixes 3683b761fe3a ("nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP")
---
 drivers/nvmem/nintendo-otp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/nvmem/nintendo-otp.c +3 -0
index 355e7f1fc6d5..89b15a58bf88 100644
@@ -87,6 +87,9 @@ static int nintendo_otp_probe(struct platform_device *pdev)
 		.root_only = true,
 	};
 
+	if (!of_id)
+		return -ENODEV;
+
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;
Signature · 1 line
2.50.1.windows.1

Thank you for that, this patch is:

Signature · 1 line
Link Mauve
#2 lore raw
In reply to Haotian Zhang
Quoted 2 lines · Haotian Zhang

of_match_device() may return NULL if no match is found. Dereferencing the return value of_id in nintendo_otp_probe()

This does not make sense, nintendo_otp_probe() will never be called without a dt compatible match.

Why do you think this will be null?

--srini

Quoted 24 lines

without a check could lead to a NULL pointer dereference.

Add a check for of_id and return -ENODEV upon failure.

Fixes 3683b761fe3a ("nvmem: nintendo-otp: Add new driver for the Wii and Wii U OTP")
---
 drivers/nvmem/nintendo-otp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/nvmem/nintendo-otp.c +3 -0
index 355e7f1fc6d5..89b15a58bf88 100644
@@ -87,6 +87,9 @@ static int nintendo_otp_probe(struct platform_device *pdev)
 		.root_only = true,
 	};
 
+	if (!of_id)
+		return -ENODEV;
+
 	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
 		return -ENOMEM;