From patchwork Tue Jun 20 14:46:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 110569 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3742241vqr; Tue, 20 Jun 2023 08:19:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Ops1zxBz5RIivBUyzlx7I7Y8ntdTtsWk/F6drejiydHmmYOuS3zGjl5HG3/xY6FN0O/dB X-Received: by 2002:a17:903:2281:b0:1b6:4bbd:c3b6 with SMTP id b1-20020a170903228100b001b64bbdc3b6mr3954775plh.9.1687274354139; Tue, 20 Jun 2023 08:19:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687274354; cv=none; d=google.com; s=arc-20160816; b=pSzeltRJQ4qHX7rjIXDZ6ZiVVXXxhY/P9O4HgafcnKszm+h2IjUxKHzw45Sp+ng+BP /pFAmO3bTPlxSP6a2e9Q1IJU+tNaacz+n/kQ80Ksn/y7Gdez05vOvZYPD4V7XX+kCN5B T5Tbrxf2vAaz8EBwHmYysQwAM9L7+C0xRtGd83K2kw3kwwvpYOTCLUPbijNFwiFm9l5v gkR/mOQ2QXkghq7xfvGAigkAb8TNUICRjREtr4nelZ1WXQJtVNKS8NkZIyWusCC2ME3v ZOCL4lcNl2uhTOOX+S9yO/EMHd4wu29PT+OIMz6+7ouFUm8jwtA6IOv7pn6LM+up6mz8 avCA== 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=yiGd7Vw7dy/ZntMnI4S+KgesYL3HNHXI1AeV3IdakaA=; b=DgsUIr2F0MeWKm4TjWPhAD2Q7PLA0uMUffvLaX7Ku7z5FFShcTCBoZSvrFD2uRznO2 CNk/Q/w3aK1zph/QYkGGoFgUBtmjPahNzspaE3KvfiWG9fewiNldT0H8XmakoKFZLg3t V71ZssLdoMUQ9/8nc1cHYq4pfPpca/hVubcgStS145NMiudnOGIjc14N9cGTEoUvAYDT ZHjtp6ecUL7LNY0Af/nIRdiCA6CGaJKjcHFMZXsyfs+90rlhgqYWNEzCWLXgZh73tRw5 gfhoY549pZwkK7qvCxX1H8RYeVGrEkZj81VW4lYtwcxaVXkZkYKOe9eFUBCfVu2SUnIi gnsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Fv0FEULd; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k13-20020a170902c40d00b001b02658db01si2234152plk.580.2023.06.20.08.18.58; Tue, 20 Jun 2023 08:19:14 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=Fv0FEULd; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233355AbjFTOqt (ORCPT + 99 others); Tue, 20 Jun 2023 10:46:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229966AbjFTOqs (ORCPT ); Tue, 20 Jun 2023 10:46:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7875D94; Tue, 20 Jun 2023 07:46:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0FA8A612B1; Tue, 20 Jun 2023 14:46:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B5D3C433C0; Tue, 20 Jun 2023 14:46:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687272406; bh=9h3moI3hmvBROUz5q1Axpk+rEonTaQjmob+V2t6yt90=; h=From:To:Cc:Subject:Date:From; b=Fv0FEULdwBVbcEb671R5392C7XGGHBM0hp/i2kxDhDumnr/REFDULU3rWv256UmVA mbeat6mvRL09BNYFa4dZ+9uVgCNElfJX/mEfdnLa+5dpx4GcbcY4oyq95ZT6b2B3Hl VEAKule0pTJzhUP82W0sHNN1cNP5PPpd+bHrz/eo= From: Greg Kroah-Hartman To: linux-integrity@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ivan Orlov , Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe , Greg Kroah-Hartman Subject: [PATCH] tpm: make all 'class' structures const Date: Tue, 20 Jun 2023 16:46:43 +0200 Message-ID: <20230620144642.584926-2-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4180; i=gregkh@linuxfoundation.org; h=from:subject; bh=VN6hocl/5QvlNrgSmEWZE73DMjrqR59jHD2825Axci0=; b=owGbwMvMwCRo6H6F97bub03G02pJDCkTd1/aXCjzKFjv09M+Tf2UeU0+Aiyf9yr1/p07s7Tm3 xVmV6OtHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjCRrGsMc4WXMMlV/592ZvuT s3WOu3Y6T2e9eoNhfqXQJwZLz/uv57P5ynqUalwx4d5XBAA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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?1769235393204333109?= X-GMAIL-MSGID: =?utf-8?q?1769235393204333109?= From: Ivan Orlov Now that the driver core allows for struct class to be in read-only memory, making all 'class' structures to be declared at build time placing them into read-only memory, instead of having to be dynamically allocated at load time. Cc: Peter Huewe Cc: Jarkko Sakkinen Cc: Jason Gunthorpe Cc: linux-integrity@vger.kernel.org Suggested-by: Greg Kroah-Hartman Signed-off-by: Ivan Orlov Signed-off-by: Greg Kroah-Hartman Acked-by: Jarkko Sakkinen --- drivers/char/tpm/tpm-chip.c | 11 ++++++++--- drivers/char/tpm/tpm-interface.c | 21 +++++++++------------ drivers/char/tpm/tpm.h | 4 ++-- drivers/char/tpm/tpm2-space.c | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index cd48033b804a..7c028f0b9d38 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -28,8 +28,13 @@ DEFINE_IDR(dev_nums_idr); static DEFINE_MUTEX(idr_lock); -struct class *tpm_class; -struct class *tpmrm_class; +const struct class tpm_class = { + .name = "tpm", + .shutdown_pre = tpm_class_shutdown, +}; +const struct class tpmrm_class = { + .name = "tmprm", +}; dev_t tpm_devt; static int tpm_request_locality(struct tpm_chip *chip) @@ -336,7 +341,7 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev, device_initialize(&chip->dev); - chip->dev.class = tpm_class; + chip->dev.class = &tpm_class; chip->dev.release = tpm_dev_release; chip->dev.parent = pdev; chip->dev.groups = chip->groups; diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index 586ca10b0d72..66b16d26eecc 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -476,18 +476,15 @@ static int __init tpm_init(void) { int rc; - tpm_class = class_create("tpm"); - if (IS_ERR(tpm_class)) { + rc = class_register(&tpm_class); + if (rc) { pr_err("couldn't create tpm class\n"); - return PTR_ERR(tpm_class); + return rc; } - tpm_class->shutdown_pre = tpm_class_shutdown; - - tpmrm_class = class_create("tpmrm"); - if (IS_ERR(tpmrm_class)) { + rc = class_register(&tpmrm_class); + if (rc) { pr_err("couldn't create tpmrm class\n"); - rc = PTR_ERR(tpmrm_class); goto out_destroy_tpm_class; } @@ -508,9 +505,9 @@ static int __init tpm_init(void) out_unreg_chrdev: unregister_chrdev_region(tpm_devt, 2 * TPM_NUM_DEVICES); out_destroy_tpmrm_class: - class_destroy(tpmrm_class); + class_unregister(&tpmrm_class); out_destroy_tpm_class: - class_destroy(tpm_class); + class_unregister(&tpm_class); return rc; } @@ -518,8 +515,8 @@ static int __init tpm_init(void) static void __exit tpm_exit(void) { idr_destroy(&dev_nums_idr); - class_destroy(tpm_class); - class_destroy(tpmrm_class); + class_unregister(&tpm_class); + class_unregister(&tpmrm_class); unregister_chrdev_region(tpm_devt, 2*TPM_NUM_DEVICES); tpm_dev_common_exit(); } diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 460bb85dd142..61445f1dc46d 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -230,8 +230,8 @@ enum tpm2_pt_props { * compiler warnings about stack frame size. */ #define TPM_MAX_RNG_DATA 128 -extern struct class *tpm_class; -extern struct class *tpmrm_class; +extern const struct class tpm_class; +extern const struct class tpmrm_class; extern dev_t tpm_devt; extern const struct file_operations tpm_fops; extern const struct file_operations tpmrm_fops; diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c index ffb35f0154c1..363afdd4d1d3 100644 --- a/drivers/char/tpm/tpm2-space.c +++ b/drivers/char/tpm/tpm2-space.c @@ -606,7 +606,7 @@ int tpm_devs_add(struct tpm_chip *chip) device_initialize(&chip->devs); chip->devs.parent = chip->dev.parent; - chip->devs.class = tpmrm_class; + chip->devs.class = &tpmrm_class; /* * Get extra reference on main device to hold on behalf of devs.