Skip to contentSkip to conversation

staging: gpib: ines: Check the return value of ioremap()

PATCH In review Haotian Zhang 2 participants 2 messages Nov 26, 2025 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: gpib: ines: Check the return value of ioremap()

The function ioremap() in ines_gpib_config() 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 bb1bd92fa0f2 ("staging: gpib: Add ines GPIB driver")
---
 drivers/staging/gpib/ines/ines_gpib.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/staging/gpib/ines/ines_gpib.c +5 -0
index c851fd014f48..362a6310cab1 100644
@@ -1144,6 +1144,11 @@ static int ines_gpib_config(struct pcmcia_device *link)
 		return -ENODEV;
 	}
 	virt = ioremap(link->resource[2]->start, resource_size(link->resource[2]));
+	if (!virt) {
+		dev_warn(&link->dev, "ioremap failed\n");
+		ines_gpib_release(link);
+		return -ENOMEM;
+	}
 	writeb((link->resource[2]->start >> 2) & 0xff, virt + 0xf0); // IOWindow base
 	iounmap(virt);
 
Signature · 1 line
2.50.1.windows.1
maintainer
#1 lore raw
Quoted 11 lines · Haotian Zhang

The function ioremap() in ines_gpib_config() 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 bb1bd92fa0f2 ("staging: gpib: Add ines GPIB driver")
---
 drivers/staging/gpib/ines/ines_gpib.c | 5 +++++

This file has now moved :(

And do you have this hardware to test this with? If so, a lot more cleanup can be done in this function.

thanks,

greg k-h