Skip to contentSkip to conversation

pinctrl: ns2: Fix potential NULL dereference

PATCH In review Young Xiao 3 participants 3 messages May 29, 2019 – Jun 7, 2019

Subsystems (3)
lore
Share & tools
lore

Young Xiao

author
#0 lore raw

PATCH 1/1 pinctrl: ns2: Fix potential NULL dereference

platform_get_resource() may fail and return NULL, so we should better check it's return value to avoid a NULL pointer dereference a bit later in the code.

---
 drivers/pinctrl/bcm/pinctrl-ns2-mux.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pinctrl/bcm/pinctrl-ns2-mux.c +2 -0
index 4b5cf0e..2bf6af7 100644
@@ -1048,6 +1048,8 @@ static int ns2_pinmux_probe(struct platform_device *pdev)
 		return PTR_ERR(pinctrl->base0);
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+	if (!res)
+		return -EINVAL;
 	pinctrl->base1 = devm_ioremap_nocache(&pdev->dev, res->start,
 					resource_size(res));
 	if (!pinctrl->base1) {
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Young Xiao

platform_get_resource() may fail and return NULL, so we should better check it's return value to avoid a NULL pointer dereference a bit later in the code.

---
 drivers/pinctrl/bcm/pinctrl-ns2-mux.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pinctrl/bcm/pinctrl-ns2-mux.c +0 -0
index 4b5cf0e..2bf6af7 100644

drivers/pinctrl/bcm/pinctrl-ns2-mux.c static int ns2_pinmux_probe(struct platform_device *pdev) · line 1052

Quoted 5 lines
drivers/pinctrl/bcm/pinctrl-ns2-mux.c +2 -0
@@ -1048,6 +1048,8 @@ static int ns2_pinmux_probe(struct platform_device *pdev)
 		return PTR_ERR(pinctrl->base0);
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+	if (!res)
+		return -EINVAL;

Right, usually not needed if devm_ioremap_resource is used since it was checked there. But in this case, I do think it needs to be checked. This change looks good to me. Thanks.

drivers/pinctrl/bcm/pinctrl-ns2-mux.c static int ns2_pinmux_probe(struct platform_device *pdev) · line 1055

Quoted 4 lines
drivers/pinctrl/bcm/pinctrl-ns2-mux.c +0 -0
 	pinctrl->base1 = devm_ioremap_nocache(&pdev->dev, res->start,
 					resource_size(res));
 	if (!pinctrl->base1) {