]> git.baikalelectronics.ru Git - kernel.git/commitdiff
fpga: m10bmc-sec: Fix probe rollback
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Wed, 14 Dec 2022 14:49:52 +0000 (16:49 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Feb 2023 10:28:22 +0000 (11:28 +0100)
commit 60ce26d10e5850f33cc76fce52f5377045e75a15 upstream.

Handle probe error rollbacks properly to avoid leaks.

Fixes: 78e2f1b87c41 ("fpga: m10bmc-sec: add max10 secure update functions")
Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com>
Reviewed-by: Russ Weight <russell.h.weight@intel.com>
Reviewed-by: Marco Pagani <marpagan@redhat.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: stable@vger.kernel.org
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20221214144952.8392-1-ilpo.jarvinen@linux.intel.com
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/fpga/intel-m10-bmc-sec-update.c

index 79d48852825ef47b35d2400cd1b91c874f6a5677..03f1bd81c434d634d0418e34f136152c910f3ed4 100644 (file)
@@ -574,20 +574,27 @@ static int m10bmc_sec_probe(struct platform_device *pdev)
        len = scnprintf(buf, SEC_UPDATE_LEN_MAX, "secure-update%d",
                        sec->fw_name_id);
        sec->fw_name = kmemdup_nul(buf, len, GFP_KERNEL);
-       if (!sec->fw_name)
-               return -ENOMEM;
+       if (!sec->fw_name) {
+               ret = -ENOMEM;
+               goto fw_name_fail;
+       }
 
        fwl = firmware_upload_register(THIS_MODULE, sec->dev, sec->fw_name,
                                       &m10bmc_ops, sec);
        if (IS_ERR(fwl)) {
                dev_err(sec->dev, "Firmware Upload driver failed to start\n");
-               kfree(sec->fw_name);
-               xa_erase(&fw_upload_xa, sec->fw_name_id);
-               return PTR_ERR(fwl);
+               ret = PTR_ERR(fwl);
+               goto fw_uploader_fail;
        }
 
        sec->fwl = fwl;
        return 0;
+
+fw_uploader_fail:
+       kfree(sec->fw_name);
+fw_name_fail:
+       xa_erase(&fw_upload_xa, sec->fw_name_id);
+       return ret;
 }
 
 static int m10bmc_sec_remove(struct platform_device *pdev)