Skip to contentSkip to conversation

media: usb: fix memory leak in af9005_identify_state

PATCH Superseded Navid Emamdoost 2 participants 4 messages Sep 13, 2019 – Oct 9, 2019 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: usb: fix memory leak in af9005_identify_state

In af9005_identify_state when returning -EIO the allocated buffer should be released.

---
 drivers/media/usb/dvb-usb/af9005.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/usb/dvb-usb/af9005.c +3 -1
index 02697d86e8c1..aee500beaab6 100644
@@ -975,8 +975,10 @@ static int af9005_identify_state(struct usb_device *udev,
 		*cold = 1;
 	else if (reply == 0x02)
 		*cold = 0;
-	else
+	else {
+		kfree(buf);
 		return -EIO;
+	}
 	deb_info("Identify state cold = %d\n", *cold);
 
 err:
Signature · 1 line
2.17.1
#1 lore raw
Quoted 13 lines · Navid Emamdoost

In af9005_identify_state when returning -EIO the allocated buffer should be released.

---
 drivers/media/usb/dvb-usb/af9005.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/usb/dvb-usb/af9005.c +0 -0
index 02697d86e8c1..aee500beaab6 100644

drivers/media/usb/dvb-usb/af9005.c static int af9005_identify_state(struct usb_device *udev, · line 981

Quoted 8 lines
drivers/media/usb/dvb-usb/af9005.c +3 -1
@@ -975,8 +975,10 @@ static int af9005_identify_state(struct usb_device *udev,
 		*cold = 1;
 	else if (reply == 0x02)
 		*cold = 0;
-	else
+	else {
+		kfree(buf);
 		return -EIO;
+	}

Why not just set ret = -EIO; here?

You only need to add a

	if (!ret)

drivers/media/usb/dvb-usb/af9005.c static int af9005_identify_state(struct usb_device *udev, · line 982

Quoted 1 line
drivers/media/usb/dvb-usb/af9005.c +0 -0
 	deb_info("Identify state cold = %d\n", *cold);

before this line.

So this becomes:

        else
                ret = -EIO;
        if (!ret)
                deb_info("Identify state cold = %d\n", *cold);

Regards,

Hans

Quoted 3 lines
drivers/media/usb/dvb-usb/af9005.c +0 -0
 err:
 
#2 lore raw

Hi Hans,

Quoted 10 lines · Hans Verkuil
Quoted 8 lines · Navid Emamdoost

In af9005_identify_state when returning -EIO the allocated buffer should be released.

---
 drivers/media/usb/dvb-usb/af9005.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 16 lines

drivers/media/usb/dvb-usb/af9005.c static int af9005_identify_state(struct usb_device *udev, · line 981

Quoted 13 lines
drivers/media/usb/dvb-usb/af9005.c +3 -1
index 02697d86e8c1..aee500beaab6 100644
@@ -975,8 +975,10 @@ static int af9005_identify_state(struct usb_device *udev,
              *cold = 1;
      else if (reply == 0x02)
              *cold = 0;
-     else
+     else {
+             kfree(buf);
              return -EIO;
+     }

Why not just set ret = -EIO; here?

This makes sense. I will send a v2.

Quoted 22 lines

You only need to add a

        if (!ret)

drivers/media/usb/dvb-usb/af9005.c static int af9005_identify_state(struct usb_device *udev, · line 982

Quoted 1 line
drivers/media/usb/dvb-usb/af9005.c +0 -0
      deb_info("Identify state cold = %d\n", *cold);

before this line.

So this becomes:

        else
                ret = -EIO;
        if (!ret)
                deb_info("Identify state cold = %d\n", *cold);

Regards,

Hans

Quoted 3 lines
drivers/media/usb/dvb-usb/af9005.c +0 -0
 err:
 
Signature · 1 line
Navid.
#3 lore raw

PATCH v2 1/1 media: usb: fix memory leak in af9005_identify_state

In reply to Hans Verkuil

In af9005_identify_state when returning -EIO the allocated buffer should be released. Replace the "return -EIO" with assignment into ret and move deb_info() under a check.

Fixes af4e067e1dcf ("V4L/DVB (5625): Add support for the AF9005 demodulator from Afatech")

---
Changes in v2:
-- Reused the error handling to release buf -- Added Fixes tag

---
 drivers/media/usb/dvb-usb/af9005.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/media/usb/dvb-usb/af9005.c +4 -3
index 02697d86e8c1..bc6e7659c37b 100644
@@ -975,9 +975,10 @@ static int af9005_identify_state(struct usb_device *udev,
 		*cold = 1;
 	else if (reply == 0x02)
 		*cold = 0;
-	else
-		return -EIO;
-	deb_info("Identify state cold = %d\n", *cold);
+	else
+		ret = -EIO;
+	if (!ret)
+		deb_info("Identify state cold = %d\n", *cold);
 
 err:
 	kfree(buf);
Signature · 1 line
2.17.1