From patchwork Wed Dec 14 14:49:52 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: 33233 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp275953wrn; Wed, 14 Dec 2022 07:06:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXtk07eV4A0aAD5jknJJcGdr9608lBF2gUGZW+fvt5rct3SFmVO6rlIxrgJtiQakejALmA/R X-Received: by 2002:a17:907:d40b:b0:7c0:dd55:1dd4 with SMTP id vi11-20020a170907d40b00b007c0dd551dd4mr3244598ejc.42.1671030400730; Wed, 14 Dec 2022 07:06:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671030400; cv=none; d=google.com; s=arc-20160816; b=yL6DOuceTUblmcgoIVPEgeODoZevjwRDHg0brbk4vtcW2VnJvo0K7qMQyVn2dYOfFG OiY+NvLMos37/3HQxoyzcc+TgXAKvO7AslL9PPx9b6fHvFk7GAmDp1lS63Rxpoga7UxU dCgldhL28YqYH+CP9c7jSPDE1UUBCDTIlkxsGjp0/vtN7NMNf1NJkrjDvePpeBtJ359y 1DDepeGgugIIX1sTqhNGaxDAfTTDHICyNf+BgfXWQfMsLSuO9KMl6e+pyRdUT9ak/YQu vUVK06HEuUTaDATEXA25OzhqvKMV2eUusdYpGA5lcFj/rtYJnGRxH9NCELl9ioS7F6hO +iQw== 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=CMKkUm9EoW1v/EipPniqrQVVNfBsKuQ4FADQvEKyy6A=; b=Jks9jTcK8RdIiAcGk0iHGwwgVJJIPXu9bfB2YCRDqzW8YbH1U9UBTCjkzUeyEMsgql wNgwcsxb9T+5vM8pvGcntkq07yq7efQ1C+zODz+FjFHVGs2ykBMaCPrjkknSN26Swq7i Hxh9+rczpZXSb4W39sF8uBLAYfRA8A0xDK35zbr140wYg36jEXkza8LNmMexUqUcP4eo CEnly2Wktvh6WOO3Du0JXlc4Q3J0n9cHFC3+LdePQLB+JXgv6hLDeMp7+eZhY82M7NQT PeWx30Oge8Tidjl56y0YbNzD9lYoKaBJpsuXb7KJ42FbGWBunRVnmwlctYf90kblTNHM Rqaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ajJ3KAk6; 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 gh4-20020a170906e08400b00787803711f9si9218200ejb.353.2022.12.14.07.06.15; Wed, 14 Dec 2022 07:06:40 -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=ajJ3KAk6; 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 S238697AbiLNOuc (ORCPT + 99 others); Wed, 14 Dec 2022 09:50:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238363AbiLNOu3 (ORCPT ); Wed, 14 Dec 2022 09:50:29 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13FA42F3; Wed, 14 Dec 2022 06:50:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671029429; x=1702565429; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=XTkX6HcEGJ1UBW6COm+l+2Y+4S1QKisQtPhX0zyA/4c=; b=ajJ3KAk6t0Lpca42PuzNnOzTw8LloHU1gZ6WSgaULN61VsIwuuajU6zA muAg/w6iKjhtSVfFAHZTGeotfS7/cZwylnTZYOKqWRe0B/9P7oip5PYPj jrj5ir1hTV7XOIOoLAWsesylMjl//iseGVYJ7dq1J3Z9OsHc7FA9wzbxe DPdQv27d/HWaxOS+uShFpeDElNLVTblHrfUAt+RMb6pOzNo3K81+kRd9i T2WY4YTTJ92aDZbXJ1U/SseatWtYsPRORW3ZOSZWrstA3ONksCDIFfE9v relQmzwbvYkar6NKpB48LGKA06ONgab+aaGQkLhHFNyPShPBPi5wY+pn6 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="320278599" X-IronPort-AV: E=Sophos;i="5.96,244,1665471600"; d="scan'208";a="320278599" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2022 06:50:27 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="977856375" X-IronPort-AV: E=Sophos;i="5.96,244,1665471600"; d="scan'208";a="977856375" Received: from pnasahl-mobl.ger.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.252.61.89]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2022 06:50:11 -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 , Marco Pagani Subject: [PATCH v2 1/1] fpga: m10bmc-sec: Fix probe rollback Date: Wed, 14 Dec 2022 16:49:52 +0200 Message-Id: <20221214144952.8392-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,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?1752202373759169240?= X-GMAIL-MSGID: =?utf-8?q?1752202373759169240?= 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 Reviewed-by: Marco Pagani Signed-off-by: Ilpo Järvinen Acked-by: Xu Yilun --- I don't know if the previous one fell through cracks so resending this. v2: - Resending v1 with Marco's Rev-by 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)