From patchwork Wed Nov 30 09:11:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 27698 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp816463wrr; Wed, 30 Nov 2022 01:18:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf4QZrQQ0vk4Opzj55Zpfu+HYj6UC8/rQ7XEHFQsnYPJ1DqvG4yMfwY0+hcqgy9KMUAxyONa X-Received: by 2002:a17:906:7096:b0:78c:fda3:c025 with SMTP id b22-20020a170906709600b0078cfda3c025mr42312728ejk.461.1669799885854; Wed, 30 Nov 2022 01:18:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669799885; cv=none; d=google.com; s=arc-20160816; b=qVLvpfEn11vBh/J/HoA43p9lt7fBUZp87TTtcN0Jd7kRD/JFyAszQHquUjeLucbBuO XXdvHYXn1uG3xYyy1+hyJFu0u6xZ3IO4hmnixZbFQewIVUzKAoPiKYVvGPDaQ5326FNf D2YWqUuCF3qP45va1eAgrYQlWLlDJw8UbLerAFph92Qs78JMzuHKAcVRbiFNNudz8zEY mAzzALrOkIrVIrimu7YoY1eDtD3IChMAIwQW6Ym/GsKbqcf6cm9npCQZVLkHzEBoabVE b4irdrt4sCk4wfUjiiwM2IGYsu6OU9ErFMFgTb/3nY+vaPEvN/qbh2dDypCAEG7z0d6u AFag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=7p0TR+QwsBeNP/Ee+cPuZAhRWS8pZfw3CvqXsw3RNIY=; b=znx8FfjS+RQrHK01WYBNkDHQV94Z6ckhsg2pWjLDYPHX0J4PMcgHHeyC+5r4mByiwf bq0UPMiQJr0gl+VN/WHrDO71b1ABrmMZ8itJeIQSqmAFekt04aQ3Trod0j/KmWywLTko F4+CZTqnU14a8UgG5i2SXmeD8b3zOf3akjMzhhCkz/5QtAnHfEC9PSuISz4yU/X82WZK jwHvsq8aUK1U6Nf5bNswERfVvS4k7ZJ8a2Ke4703ev54etnZauuRcIlco5c9YK6P4EdA lIS+E7MOwbReq+ObjHVG/tL0hhVOzJ5g9gyGs/8WzGrn6SqcT1e5aZaFvJ1dWYKZTc53 cqYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=l2+4CYAt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l21-20020a056402125500b0046ae3282cefsi890248edw.59.2022.11.30.01.17.41; Wed, 30 Nov 2022 01:18:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=l2+4CYAt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231345AbiK3JML (ORCPT + 99 others); Wed, 30 Nov 2022 04:12:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231314AbiK3JMK (ORCPT ); Wed, 30 Nov 2022 04:12:10 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88E3C48750; Wed, 30 Nov 2022 01:12:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669799529; x=1701335529; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=py1SBMBVVU48iDA5LU0KMlUzrgX30r8T7STfDBWamSk=; b=l2+4CYAt/r4oKkttAJ3g2Bl76Iroez1Fto4d/z7V1QBF3pYeXFb85kE6 IOw8DjWF1bKT5xq4qUZoRkEFSEhA9xvc2YY+EWctHtqzNmJyQuLIHKh8C oU0tM4jQy+p7GmSW6RDCI3S/5eicr9ftqzYa/Y8QMrZ/oSobjys9RCl9T m2xgySTRlNNyn6ot4+UtzwtrndMPVTlqT8Tiw1UFgJT0FMevzTG12DXwC kcovDjcyIgQBFMsRF/EmBNqa2cd7Jrr0sgqyv2oFMeG/Gbb8ja+nX3wzD vdGx5BPp2Y6dS/oJ8VEVMrqkCC7Fmcy7lkotV3q6nB4nFfPLEQ5Magk2r w==; X-IronPort-AV: E=McAfee;i="6500,9779,10546"; a="316499267" X-IronPort-AV: E=Sophos;i="5.96,205,1665471600"; d="scan'208";a="316499267" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2022 01:12:09 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10546"; a="750261351" X-IronPort-AV: E=Sophos;i="5.96,205,1665471600"; d="scan'208";a="750261351" Received: from cignatx-mobl1.ger.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.252.51.239]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2022 01:12:06 -0800 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: Russ Weight , Moritz Fischer , Wu Hao , Xu Yilun , Tom Rix , linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Matthew Gerlach Subject: [PATCH 1/1] fpga: m10bmc-sec: Fix probe rollback Date: Wed, 30 Nov 2022 11:11:58 +0200 Message-Id: <20221130091158.4732-1-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750912085216638317?= X-GMAIL-MSGID: =?utf-8?q?1750912085216638317?= Handle probe error rollbacks properly to avoid leaks. Fixes: 5cd339b370e2 ("fpga: m10bmc-sec: add max10 secure update functions") Reviewed-by: Matthew Gerlach Reviewed-by: Russ Weight Signed-off-by: Ilpo Järvinen Reviewed-by: Marco Pagani --- drivers/fpga/intel-m10-bmc-sec-update.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/fpga/intel-m10-bmc-sec-update.c b/drivers/fpga/intel-m10-bmc-sec-update.c index 79d48852825e..03f1bd81c434 100644 --- a/drivers/fpga/intel-m10-bmc-sec-update.c +++ b/drivers/fpga/intel-m10-bmc-sec-update.c @@ -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)