From patchwork Thu Jan 26 21:08:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 48899 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp487660wrn; Thu, 26 Jan 2023 13:10:44 -0800 (PST) X-Google-Smtp-Source: AK7set+jkHzeNO8qcgrrn0APi/An5gj5+VewRJ8IP6GRaOERCskzfwiYogmVZO2jIlGVjEn1ewNs X-Received: by 2002:a17:906:e096:b0:878:4d11:f868 with SMTP id gh22-20020a170906e09600b008784d11f868mr4467999ejb.2.1674767444438; Thu, 26 Jan 2023 13:10:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674767444; cv=none; d=google.com; s=arc-20160816; b=eHD/t6fW0+QyYAjD1YzRETQyWtkeo1GKK4YHghwcCwQMsHCT0FRwWDn5SZd/aRFdcI b+71AHvaDMQ6wLnWGTcp7vURBsMfp3IFubG2+Y9RBokNHXr/SPNtPJlLO0rD7YDobGMl yB1yCo5j7EkRTjJgUNoo4DzhesxeEnkBSHKzLyjjA1Ifc2gsURRZ9jz6tlKJa71HR3wO snzJ/LRzJlss6PoqM6ucVRAucJYxWRYA7rahhq6VQsXcaVZj+xt54ZWW7sIqt5L/QOy3 mhKDQvjdlJvBSvEEmRJQc8B8oBraLeuGysnrLYwc2IoSfy+E32UPPI6vSN1tbxPLLCwe bKXg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+mq+uUeCHrDPWFnwLg2XZ5ZnwCg8EmjbRBNrw7PrWWQ=; b=NJKtmWTZ+JM8cqJ4WRjcc6A/3KQQqCYVxV10uQva+PWg9jSeaNKDI5bbnHMBH/y36v ae/f+6ht8OeOK3j14APxHU2eKsdP+53HeObRpKqjvWCqxfaUUWSUESlBORH5jzjJqxEq kwCoDfPGEZskrhqjUM5iFgmo36ssn/gv4+Rz9ByLvYLQ2Qwu5u6FuMUOIb1u54jCnaap 6H2TqU37djA4WeAnHlKpQZD95RH1zxvt1+K0iucwLoZfKcLami6Vwf1mx5dptR7P2JMx sY/Fo0ViEMI2eAJosIl1+kUy4Nz+DXzKeWmyxTz5/ZFpFujSHHndfivsooA6JGptn6Ds BWFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=b1neWj9U; 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=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id uj20-20020a170907c99400b00871a3ecd7d8si2194125ejc.351.2023.01.26.13.10.20; Thu, 26 Jan 2023 13:10:44 -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=@ibm.com header.s=pp1 header.b=b1neWj9U; 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=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232787AbjAZVId (ORCPT + 99 others); Thu, 26 Jan 2023 16:08:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232783AbjAZVI0 (ORCPT ); Thu, 26 Jan 2023 16:08:26 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FD2C3403F; Thu, 26 Jan 2023 13:08:20 -0800 (PST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30QKjk1L005515; Thu, 26 Jan 2023 21:08:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=+mq+uUeCHrDPWFnwLg2XZ5ZnwCg8EmjbRBNrw7PrWWQ=; b=b1neWj9Ua36XB6hx0ssooKQx1eguCh81tHDFhujFC2TNff1niHIu0JIrt7zSeQFJrYFF LUNzykEIR29bWgmjOoUPGl3TaUx3L5Rm45gKIMSNAz8M3T4Vmti8EpGaCmI+76P7t0+O xW9v2Mg5Cx0HW2FLKMkuJWL0Alod+KfB5hQDGGye1eoGNvAZ7D9WRMMWGbwL7D3LxfIw rdrlhZzb19FG9guHK/Wu9nJoeAGAkwrpPx47/juWT6jRVkaoQcIgZeI29QyxJPNtPa3K K3u/yhw+TswKQUYgOl1P8SikGAEYJH59V6UuXbNegMnJRk/kxUtsL0eB7FyGX6O6mejs sQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3nc0ucrdvx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 26 Jan 2023 21:08:16 +0000 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 30QKt3Cs012098; Thu, 26 Jan 2023 21:08:16 GMT Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3nc0ucrdvp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 26 Jan 2023 21:08:16 +0000 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 30QL4lMZ025665; Thu, 26 Jan 2023 21:08:15 GMT Received: from smtprelay06.dal12v.mail.ibm.com ([9.208.130.100]) by ppma02dal.us.ibm.com (PPS) with ESMTPS id 3n87p7y35j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 26 Jan 2023 21:08:15 +0000 Received: from smtpav05.wdc07v.mail.ibm.com (smtpav05.wdc07v.mail.ibm.com [10.39.53.232]) by smtprelay06.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 30QL8DPd31195462 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Jan 2023 21:08:14 GMT Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BB01058063; Thu, 26 Jan 2023 21:08:13 +0000 (GMT) Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7D3915805F; Thu, 26 Jan 2023 21:08:12 +0000 (GMT) Received: from slate16.aus.stglabs.ibm.com (unknown [9.160.3.213]) by smtpav05.wdc07v.mail.ibm.com (Postfix) with ESMTP; Thu, 26 Jan 2023 21:08:12 +0000 (GMT) From: Eddie James To: linux-integrity@vger.kernel.org Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, stefanb@linux.ibm.com, eajames@linux.ibm.com Subject: [PATCH v3 1/2] tpm: Use managed allocation for bios event log Date: Thu, 26 Jan 2023 15:08:09 -0600 Message-Id: <20230126210810.881119-2-eajames@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230126210810.881119-1-eajames@linux.ibm.com> References: <20230126210810.881119-1-eajames@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: iwH1BWMtMax_V1_rlD64QmVl6B3or2Xd X-Proofpoint-ORIG-GUID: gn_vLukJEEy3ceATWVIQHXF6EpAlptIg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-26_09,2023-01-26_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1015 suspectscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 mlxscore=0 bulkscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301260198 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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?1756120947748050294?= X-GMAIL-MSGID: =?utf-8?q?1756120947748050294?= Since the bios event log is freed in the device release function, let devres handle the deallocation. This will allow other memory allocation/mapping functions to be used for the bios event log. Signed-off-by: Eddie James Tested-by: Jarkko Sakkinen Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/eventlog/acpi.c | 5 +++-- drivers/char/tpm/eventlog/efi.c | 13 +++++++------ drivers/char/tpm/eventlog/of.c | 3 ++- drivers/char/tpm/tpm-chip.c | 1 - 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/char/tpm/eventlog/acpi.c b/drivers/char/tpm/eventlog/acpi.c index 0913d3eb8d51..40360e599bc3 100644 --- a/drivers/char/tpm/eventlog/acpi.c +++ b/drivers/char/tpm/eventlog/acpi.c @@ -14,6 +14,7 @@ * Access to the event log extended by the TCG BIOS of PC platform */ +#include #include #include #include @@ -135,7 +136,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip) } /* malloc EventLog space */ - log->bios_event_log = kmalloc(len, GFP_KERNEL); + log->bios_event_log = devm_kmalloc(&chip->dev, len, GFP_KERNEL); if (!log->bios_event_log) return -ENOMEM; @@ -160,7 +161,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip) return format; err: - kfree(log->bios_event_log); + devm_kfree(&chip->dev, log->bios_event_log); log->bios_event_log = NULL; return ret; } diff --git a/drivers/char/tpm/eventlog/efi.c b/drivers/char/tpm/eventlog/efi.c index e6cb9d525e30..4e9d7c2bf32e 100644 --- a/drivers/char/tpm/eventlog/efi.c +++ b/drivers/char/tpm/eventlog/efi.c @@ -6,6 +6,7 @@ * Thiebaud Weksteen */ +#include #include #include @@ -55,7 +56,7 @@ int tpm_read_log_efi(struct tpm_chip *chip) } /* malloc EventLog space */ - log->bios_event_log = kmemdup(log_tbl->log, log_size, GFP_KERNEL); + log->bios_event_log = devm_kmemdup(&chip->dev, log_tbl->log, log_size, GFP_KERNEL); if (!log->bios_event_log) { ret = -ENOMEM; goto out; @@ -76,7 +77,7 @@ int tpm_read_log_efi(struct tpm_chip *chip) MEMREMAP_WB); if (!final_tbl) { pr_err("Could not map UEFI TPM final log\n"); - kfree(log->bios_event_log); + devm_kfree(&chip->dev, log->bios_event_log); ret = -ENOMEM; goto out; } @@ -91,11 +92,11 @@ int tpm_read_log_efi(struct tpm_chip *chip) * Allocate memory for the 'combined log' where we will append the * 'final events log' to. */ - tmp = krealloc(log->bios_event_log, - log_size + final_events_log_size, - GFP_KERNEL); + tmp = devm_krealloc(&chip->dev, log->bios_event_log, + log_size + final_events_log_size, + GFP_KERNEL); if (!tmp) { - kfree(log->bios_event_log); + devm_kfree(&chip->dev, log->bios_event_log); ret = -ENOMEM; goto out; } diff --git a/drivers/char/tpm/eventlog/of.c b/drivers/char/tpm/eventlog/of.c index a9ce66d09a75..741ab2204b11 100644 --- a/drivers/char/tpm/eventlog/of.c +++ b/drivers/char/tpm/eventlog/of.c @@ -10,6 +10,7 @@ * Read the event log created by the firmware on PPC64 */ +#include #include #include #include @@ -65,7 +66,7 @@ int tpm_read_log_of(struct tpm_chip *chip) return -EIO; } - log->bios_event_log = kmemdup(__va(base), size, GFP_KERNEL); + log->bios_event_log = devm_kmemdup(&chip->dev, __va(base), size, GFP_KERNEL); if (!log->bios_event_log) return -ENOMEM; diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 741d8f3e8fb3..b99f55f2d4fd 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -267,7 +267,6 @@ static void tpm_dev_release(struct device *dev) idr_remove(&dev_nums_idr, chip->dev_num); mutex_unlock(&idr_lock); - kfree(chip->log.bios_event_log); kfree(chip->work_space.context_buf); kfree(chip->work_space.session_buf); kfree(chip->allocated_banks);