Linux Integrity Measurement development
 help / color / mirror / Atom feed
From: "Jarkko Sakkinen" <jarkko@kernel.org>
To: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	<linux-integrity@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>,
	"Ivan Orlov" <ivan.orlov0322@gmail.com>,
	"Peter Huewe" <peterhuewe@gmx.de>,
	"Jason Gunthorpe" <jgg@ziepe.ca>
Subject: Re: [PATCH] tpm: make all 'class' structures const
Date: Tue, 11 Jul 2023 03:53:51 +0300	[thread overview]
Message-ID: <CTYXL4O99AHB.2P41COJDMW4JS@suppilovahvero> (raw)
In-Reply-To: <20230620144642.584926-2-gregkh@linuxfoundation.org>

On Tue Jun 20, 2023 at 5:46 PM EEST, Greg Kroah-Hartman wrote:
> From: Ivan Orlov <ivan.orlov0322@gmail.com>
>
> 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 <peterhuewe@gmx.de>
> Cc: Jarkko Sakkinen <jarkko@kernel.org>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: linux-integrity@vger.kernel.org
> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  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.
> -- 
> 2.41.0

Acked-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko

      reply	other threads:[~2023-07-11  0:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-20 14:46 [PATCH] tpm: make all 'class' structures const Greg Kroah-Hartman
2023-07-11  0:53 ` Jarkko Sakkinen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CTYXL4O99AHB.2P41COJDMW4JS@suppilovahvero \
    --to=jarkko@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=ivan.orlov0322@gmail.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox