firmware: raspberrypi: fix possible memory leak in rpi_firmware_probe()
authorYang Yingliang <yangyingliang@huawei.com>
Thu, 17 Nov 2022 07:06:36 +0000 (15:06 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 23 Nov 2022 18:57:07 +0000 (19:57 +0100)
In rpi_firmware_probe(), if mbox_request_channel() fails, the 'fw' will
not be freed through rpi_firmware_delete(), fix this leak by calling
kfree() in the error path.

Fixes: 1e7c57355a3b ("firmware: raspberrypi: Keep count of all consumers")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20221117070636.3849773-1-yangyingliang@huawei.com
Acked-by: Joel Savitz <jsavitz@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/firmware/raspberrypi.c

index 4b8978b..dba315f 100644 (file)
@@ -272,6 +272,7 @@ static int rpi_firmware_probe(struct platform_device *pdev)
                int ret = PTR_ERR(fw->chan);
                if (ret != -EPROBE_DEFER)
                        dev_err(dev, "Failed to get mbox channel: %d\n", ret);
+               kfree(fw);
                return ret;
        }