Skip to contentSkip to conversation

ppdev: check ida_simple_get() return value

PATCH In review Bo Liu 2 participants 2 messages Sep 7, 2022 – Sep 9, 2022

Subsystems (2)
lore
Share & tools
lore

Bo Liu

author
#0 lore raw

PATCH 1/1 ppdev: check ida_simple_get() return value

As ida_simple_get() can fail, we should check the return value.

---
 drivers/char/ppdev.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/char/ppdev.c +5 -0
index 38b46c7d1737..13b58b6823ee 100644
@@ -300,6 +300,11 @@ static int register_device(int minor, struct pp_struct *pp)
 	}
 
 	index = ida_simple_get(&ida_index, 0, 0, GFP_KERNEL);
+	if (index < 0) {
+		rc = index;
+		goto err;
+	}
+
 	memset(&ppdev_cb, 0, sizeof(ppdev_cb));
 	ppdev_cb.irq_func = pp_irq;
 	ppdev_cb.flags = (pp->flags & PP_EXCL) ? PARPORT_FLAG_EXCL : 0;
Signature · 1 line
2.27.0
maintainer
#1 lore raw
Quoted 26 lines · Bo Liu

As ida_simple_get() can fail, we should check the return value.

---
 drivers/char/ppdev.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/char/ppdev.c +5 -0
index 38b46c7d1737..13b58b6823ee 100644
@@ -300,6 +300,11 @@ static int register_device(int minor, struct pp_struct *pp)
 	}
 
 	index = ida_simple_get(&ida_index, 0, 0, GFP_KERNEL);
+	if (index < 0) {
+		rc = index;
+		goto err;
+	}
+
 	memset(&ppdev_cb, 0, sizeof(ppdev_cb));
 	ppdev_cb.irq_func = pp_irq;
 	ppdev_cb.flags = (pp->flags & PP_EXCL) ? PARPORT_FLAG_EXCL : 0;
Signature · 1 line
2.27.0

You just leaked a memory reference here :(

How did you test this? What tool caused this to be changed? Please fix up your tool to not add problems when it is attempting to fix problems, as that's a never-ending cycle we do not want to be in :(

thanks,

greg k-h