[3/5] driver core: class: mark the struct class in struct class_interface constant

Message ID 2023040249-handball-gruffly-5da7@gregkh
State New
Headers
Series driver core: class: allow struct class to be static |

Commit Message

Greg KH April 2, 2023, 5:58 p.m. UTC
  The struct class pointer in struct class_interface is never modified, so
mark it as const so that no one accidentally tries to modify it in the
future.

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/base/class.c         | 2 +-
 include/linux/device/class.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
  

Comments

Rafael J. Wysocki April 3, 2023, 5:57 p.m. UTC | #1
On Sun, Apr 2, 2023 at 7:59 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> The struct class pointer in struct class_interface is never modified, so
> mark it as const so that no one accidentally tries to modify it in the
> future.
>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Acked-by: Rafael J. Wysocki <rafael@kernel.org>

> ---
>  drivers/base/class.c         | 2 +-
>  include/linux/device/class.h | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/base/class.c b/drivers/base/class.c
> index 05bce79d3d19..ad8b9f163fd2 100644
> --- a/drivers/base/class.c
> +++ b/drivers/base/class.c
> @@ -498,7 +498,7 @@ EXPORT_SYMBOL_GPL(class_interface_register);
>  void class_interface_unregister(struct class_interface *class_intf)
>  {
>         struct subsys_private *sp;
> -       struct class *parent = class_intf->class;
> +       const struct class *parent = class_intf->class;
>         struct class_dev_iter iter;
>         struct device *dev;
>
> diff --git a/include/linux/device/class.h b/include/linux/device/class.h
> index 4bf46f9bbb56..53287aa105b8 100644
> --- a/include/linux/device/class.h
> +++ b/include/linux/device/class.h
> @@ -217,7 +217,7 @@ ssize_t show_class_attr_string(const struct class *class, const struct class_att
>
>  struct class_interface {
>         struct list_head        node;
> -       struct class            *class;
> +       const struct class      *class;
>
>         int (*add_dev)          (struct device *, struct class_interface *);
>         void (*remove_dev)      (struct device *, struct class_interface *);
> --
> 2.40.0
>
  

Patch

diff --git a/drivers/base/class.c b/drivers/base/class.c
index 05bce79d3d19..ad8b9f163fd2 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -498,7 +498,7 @@  EXPORT_SYMBOL_GPL(class_interface_register);
 void class_interface_unregister(struct class_interface *class_intf)
 {
 	struct subsys_private *sp;
-	struct class *parent = class_intf->class;
+	const struct class *parent = class_intf->class;
 	struct class_dev_iter iter;
 	struct device *dev;
 
diff --git a/include/linux/device/class.h b/include/linux/device/class.h
index 4bf46f9bbb56..53287aa105b8 100644
--- a/include/linux/device/class.h
+++ b/include/linux/device/class.h
@@ -217,7 +217,7 @@  ssize_t show_class_attr_string(const struct class *class, const struct class_att
 
 struct class_interface {
 	struct list_head	node;
-	struct class		*class;
+	const struct class	*class;
 
 	int (*add_dev)		(struct device *, struct class_interface *);
 	void (*remove_dev)	(struct device *, struct class_interface *);