media: usb: fix memory leak in af9005_identify_state
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
@@ -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
Quoted 13 lines · Navid Emamdoost
In
af9005_identify_statewhen returning-EIOthe allocated buffer should be released.Signed-off-by Navid Emamdoost <[email protected]>--- drivers/media/usb/dvb-usb/af9005.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/media/usb/dvb-usb/af9005.c +0
-0
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
-0deb_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
-0err:
Hi Hans,
Quoted 10 lines · Hans Verkuil
Quoted 8 lines · Navid Emamdoost
In
af9005_identify_statewhen returning-EIOthe allocated buffer should be released.Signed-off-by Navid Emamdoost <[email protected]>--- 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@@ -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
-0deb_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
-0err:
Signature · 1 line
Navid.
PATCH v2 1/1 media: usb: fix memory leak in af9005_identify_state
In reply to Hans VerkuilIn 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.
---
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
@@ -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