]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: em28xx: Fix possible memory leak of em28xx struct
authorIgor Matheus Andrade Torrente <igormtorrente@gmail.com>
Tue, 4 May 2021 18:32:49 +0000 (20:32 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 20 Jul 2021 14:15:44 +0000 (16:15 +0200)
[ Upstream commit ac5688637144644f06ed1f3c6d4dd8bb7db96020 ]

The em28xx struct kref isn't being decreased after an error in the
em28xx_ir_init, leading to a possible memory leak.

A kref_put and em28xx_shutdown_buttons is added to the error handler code.

Signed-off-by: Igor Matheus Andrade Torrente <igormtorrente@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/media/usb/em28xx/em28xx-input.c

index f84a1208d5d3290a682f55d1792de7d74c804481..3612f0d730ddd2e9a1e1dd2ff181e06e3b41ea3d 100644 (file)
@@ -736,7 +736,8 @@ static int em28xx_ir_init(struct em28xx *dev)
                        dev->board.has_ir_i2c = 0;
                        dev_warn(&dev->intf->dev,
                                 "No i2c IR remote control device found.\n");
-                       return -ENODEV;
+                       err = -ENODEV;
+                       goto ref_put;
                }
        }
 
@@ -751,7 +752,7 @@ static int em28xx_ir_init(struct em28xx *dev)
 
        ir = kzalloc(sizeof(*ir), GFP_KERNEL);
        if (!ir)
-               return -ENOMEM;
+               goto ref_put;
        rc = rc_allocate_device(RC_DRIVER_SCANCODE);
        if (!rc)
                goto error;
@@ -862,6 +863,9 @@ error:
        dev->ir = NULL;
        rc_free_device(rc);
        kfree(ir);
+ref_put:
+       em28xx_shutdown_buttons(dev);
+       kref_put(&dev->ref, em28xx_free_device);
        return err;
 }