Skip to contentSkip to conversation

driver core: class: allow struct class to be static

PATCH In review Greg Kroah-Hartman 5 participants 13 messages Apr 2, 2023 – Apr 4, 2023

Subsystems (11)
lore
Share & tools
lore

Greg Kroah-Hartman

author maintainer
#0 lore raw

cover driver core: class: allow struct class to be static

There's been a semi-slow drip of driver core struct class changes recently, and here's the final bit to the core that makes it possible for 'struct class' to be moved into read-only memory. And as proof, the last patch in the series does just that for the tty classes.

After this series, there's some tree-wide cleanups needed to move away from the class_create() api back to class_register() to move the structures into read-only memory. The class_create() api was a good idea when it was created (as struct class was a dynamic structure), but that got changed a long time ago and that's not necessary anymore. But that can wait for after 6.4-rc1 is out as they can all go through the different relevant subsystems if wanted.

All of these apply on top of my latest driver-core.git driver-core-next branch (or linux-next), as they require the current set of struct class and struct bus_type reworks and have been tested locally (I'm typing this and will send them out on a kernel running these changes).

Greg Kroah-Hartman (5):
driver core: class: mark class_release() as taking a const * driver core: class: make class_register() take a const * driver core: class: mark the struct class in struct class_interface
constant
driver core: class: remove struct class_interface * from callbacks
tty: make tty_class a static const structure

 drivers/base/base.h                      |  2 +-
 drivers/base/class.c                     | 14 +++++++-------
 drivers/base/core.c                      | 10 ++++------
 drivers/hwmon/drivetemp.c                |  4 ++--
 drivers/net/rionet.c                     |  3 +--
 drivers/ntb/hw/mscc/ntb_hw_switchtec.c   |  6 ++----
 drivers/pcmcia/cs.c                      |  2 +-
 drivers/pcmcia/ds.c                      |  6 ++----
 drivers/pcmcia/rsrc_nonstatic.c          |  6 ++----
 drivers/rapidio/devices/rio_mport_cdev.c |  7 ++-----
 drivers/rapidio/rio_cm.c                 |  8 ++------
 drivers/scsi/ses.c                       |  6 ++----
 drivers/scsi/sg.c                        |  8 ++++----
 drivers/tty/pty.c                        |  2 +-
 drivers/tty/tty_io.c                     | 24 +++++++++++-------------
 drivers/tty/vt/vt.c                      |  2 +-
 include/linux/device/class.h             | 10 +++++-----
 include/linux/tty.h                      |  2 +-
 kernel/time/alarmtimer.c                 |  3 +--
 19 files changed, 52 insertions(+), 73 deletions(-)
Signature · 1 line
2.40.0
author maintainer
#1 lore raw

PATCH 1/5 driver core: class: mark class_release() as taking a const *

The struct class callback, class_release(), is only called in 2 places, the pcmcia cardservices code, and in the class driver core code. Both places it is safe to mark the structure as a const *, to allow us to in the future mark all struct class usages as constant and move into read-only memory.

Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/base/class.c         | 2 +-
 drivers/pcmcia/cs.c          | 2 +-
 include/linux/device/class.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/base/class.c +1 -1
index 65502bd7d5c5..53fc7052340c 100644
@@ -235,7 +235,7 @@ void class_unregister(const struct class *cls)
 }
 EXPORT_SYMBOL_GPL(class_unregister);
 
-static void class_create_release(struct class *cls)
+static void class_create_release(const struct class *cls)
 {
 	pr_debug("%s called for %s\n", __func__, cls->name);
 	kfree(cls);
drivers/pcmcia/cs.c +1 -1
index e3224e49c43f..5658745c398f 100644
@@ -824,7 +824,7 @@ static int pcmcia_socket_uevent(const struct device *dev,
 
 static struct completion pcmcia_unload;
 
-static void pcmcia_release_socket_class(struct class *data)
+static void pcmcia_release_socket_class(const struct class *data)
 {
 	complete(&pcmcia_unload);
 }
include/linux/device/class.h +1 -1
index 7e4a1a6329f4..f3c418fa129a 100644
@@ -58,7 +58,7 @@ struct class {
 	int (*dev_uevent)(const struct device *dev, struct kobj_uevent_env *env);
 	char *(*devnode)(const struct device *dev, umode_t *mode);
 
-	void (*class_release)(struct class *class);
+	void (*class_release)(const struct class *class);
 	void (*dev_release)(struct device *dev);
 
 	int (*shutdown_pre)(struct device *dev);
Signature · 1 line
2.40.0
maintainer Acked-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] driver core: class: mark class_release() as taking a const *

Quoted 9 lines · Greg Kroah-Hartman

The struct class callback, class_release(), is only called in 2 places, the pcmcia cardservices code, and in the class driver core code. Both places it is safe to mark the structure as a const *, to allow us to in the future mark all struct class usages as constant and move into read-only memory.

Cc "Rafael J. Wysocki" <[email protected]>
Quoted 48 lines
---
 drivers/base/class.c         | 2 +-
 drivers/pcmcia/cs.c          | 2 +-
 include/linux/device/class.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/base/class.c +1 -1
index 65502bd7d5c5..53fc7052340c 100644
@@ -235,7 +235,7 @@ void class_unregister(const struct class *cls)
 }
 EXPORT_SYMBOL_GPL(class_unregister);
 
-static void class_create_release(struct class *cls)
+static void class_create_release(const struct class *cls)
 {
        pr_debug("%s called for %s\n", __func__, cls->name);
        kfree(cls);
drivers/pcmcia/cs.c +1 -1
index e3224e49c43f..5658745c398f 100644
@@ -824,7 +824,7 @@ static int pcmcia_socket_uevent(const struct device *dev,
 
 static struct completion pcmcia_unload;
 
-static void pcmcia_release_socket_class(struct class *data)
+static void pcmcia_release_socket_class(const struct class *data)
 {
        complete(&pcmcia_unload);
 }
include/linux/device/class.h +1 -2
index 7e4a1a6329f4..f3c418fa129a 100644
@@ -58,7 +58,7 @@ struct class {
        int (*dev_uevent)(const struct device *dev, struct kobj_uevent_env *env);
        char *(*devnode)(const struct device *dev, umode_t *mode);
 
-       void (*class_release)(struct class *class);
+       void (*class_release)(const struct class *class);
        void (*dev_release)(struct device *dev);
 
        int (*shutdown_pre)(struct device *dev);
--

2.40.0

author maintainer
#3 lore raw

PATCH 2/5 driver core: class: make class_register() take a const *

In reply to Greg Kroah-Hartman

Now that the class code is cleaned up to not modify the class pointer registered with it, change class_register() to take a const * to allow the structure to be placed into read-only memory.

Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/base/base.h          | 2 +-
 drivers/base/class.c         | 6 +++---
 include/linux/device/class.h | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/base/base.h +1 -1
index e96f3343fd7c..eb4c0ace9242 100644
@@ -54,7 +54,7 @@ struct subsys_private {
 	struct device *dev_root;
 
 	struct kset glue_dirs;
-	struct class *class;
+	const struct class *class;
 
 	struct lock_class_key lock_key;
 };
drivers/base/class.c +3 -3
index 53fc7052340c..05bce79d3d19 100644
@@ -93,7 +93,7 @@ static ssize_t class_attr_store(struct kobject *kobj, struct attribute *attr,
 static void class_release(struct kobject *kobj)
 {
 	struct subsys_private *cp = to_subsys_private(kobj);
-	struct class *class = cp->class;
+	const struct class *class = cp->class;
 
 	pr_debug("class '%s': release.\n", class->name);
 
@@ -110,7 +110,7 @@ static void class_release(struct kobject *kobj)
 static const struct kobj_ns_type_operations *class_child_ns_type(const struct kobject *kobj)
 {
 	const struct subsys_private *cp = to_subsys_private(kobj);
-	struct class *class = cp->class;
+	const struct class *class = cp->class;
 
 	return class->ns_type;
 }
@@ -175,7 +175,7 @@ static void klist_class_dev_put(struct klist_node *n)
 	put_device(dev);
 }
 
-int class_register(struct class *cls)
+int class_register(const struct class *cls)
 {
 	struct subsys_private *cp;
 	struct lock_class_key *key;
include/linux/device/class.h +1 -1
index f3c418fa129a..4bf46f9bbb56 100644
@@ -76,7 +76,7 @@ struct class_dev_iter {
 	const struct device_type	*type;
 };
 
-int __must_check class_register(struct class *class);
+int __must_check class_register(const struct class *class);
 void class_unregister(const struct class *class);
 bool class_is_registered(const struct class *class);
 
Signature · 1 line
2.40.0
maintainer Acked-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] driver core: class: make class_register() take a const *

Quoted 7 lines · Greg Kroah-Hartman

Now that the class code is cleaned up to not modify the class pointer registered with it, change class_register() to take a const * to allow the structure to be placed into read-only memory.

Cc "Rafael J. Wysocki" <[email protected]>
Quoted 66 lines
---
 drivers/base/base.h          | 2 +-
 drivers/base/class.c         | 6 +++---
 include/linux/device/class.h | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/base/base.h +1 -1
index e96f3343fd7c..eb4c0ace9242 100644
@@ -54,7 +54,7 @@ struct subsys_private {
        struct device *dev_root;
 
        struct kset glue_dirs;
-       struct class *class;
+       const struct class *class;
 
        struct lock_class_key lock_key;
 };
drivers/base/class.c +3 -3
index 53fc7052340c..05bce79d3d19 100644
@@ -93,7 +93,7 @@ static ssize_t class_attr_store(struct kobject *kobj, struct attribute *attr,
 static void class_release(struct kobject *kobj)
 {
        struct subsys_private *cp = to_subsys_private(kobj);
-       struct class *class = cp->class;
+       const struct class *class = cp->class;
 
        pr_debug("class '%s': release.\n", class->name);
 
@@ -110,7 +110,7 @@ static void class_release(struct kobject *kobj)
 static const struct kobj_ns_type_operations *class_child_ns_type(const struct kobject *kobj)
 {
        const struct subsys_private *cp = to_subsys_private(kobj);
-       struct class *class = cp->class;
+       const struct class *class = cp->class;
 
        return class->ns_type;
 }
@@ -175,7 +175,7 @@ static void klist_class_dev_put(struct klist_node *n)
        put_device(dev);
 }
 
-int class_register(struct class *cls)
+int class_register(const struct class *cls)
 {
        struct subsys_private *cp;
        struct lock_class_key *key;
include/linux/device/class.h +1 -2
index f3c418fa129a..4bf46f9bbb56 100644
@@ -76,7 +76,7 @@ struct class_dev_iter {
        const struct device_type        *type;
 };
 
-int __must_check class_register(struct class *class);
+int __must_check class_register(const struct class *class);
 void class_unregister(const struct class *class);
 bool class_is_registered(const struct class *class);
 
--

2.40.0

author maintainer
#5 lore raw

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

In reply to Greg Kroah-Hartman

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" <[email protected]>
---
 drivers/base/class.c         | 2 +-
 include/linux/device/class.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/base/class.c +1 -1
index 05bce79d3d19..ad8b9f163fd2 100644
@@ -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;
 
include/linux/device/class.h +1 -1
index 4bf46f9bbb56..53287aa105b8 100644
@@ -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 *);
Signature · 1 line
2.40.0
maintainer Acked-by on v1 3/5
#6 lore raw

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

Quoted 7 lines · Greg Kroah-Hartman

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" <[email protected]>
Quoted 34 lines
---
 drivers/base/class.c         | 2 +-
 include/linux/device/class.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/base/class.c +1 -1
index 05bce79d3d19..ad8b9f163fd2 100644
@@ -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;
 
include/linux/device/class.h +1 -2
index 4bf46f9bbb56..53287aa105b8 100644
@@ -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

author maintainer
#7 lore raw

PATCH 4/5 driver core: class: remove struct class_interface * from callbacks

In reply to Greg Kroah-Hartman

The add_dev and remove_dev callbacks in struct class_interface currently pass in a pointer back to the class_interface structure that is calling them, but none of the callback implementations actually use this pointer as it is pointless (the structure is known, the driver passed it in in the first place if it is really needed again.)

So clean this up and just remove the pointer from the callbacks and fix up all callback functions.

Cc Jean Delvare <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Kurt Schwemmer <[email protected]>
Cc Logan Gunthorpe <[email protected]>
Cc Jon Mason <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Allen Hubbe <[email protected]>
Cc Dominik Brodowski <[email protected]>
Cc Matt Porter <[email protected]>
Cc Alexandre Bounine <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Doug Gilbert <[email protected]>
Cc John Stultz <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Wang Weiyang <[email protected]>
Cc Yang Yingliang <[email protected]>
Cc Jakob Koschel <[email protected]>
Cc Cai Xinchen <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>

---
Note, subsystem maintainers, this should go through my driver-core tree as it's part of a larger cleanup of 'struct class' handling. I'm cc:ing you all to get reviews to verify I didn't do something foolish, but it has passed 0-day bot build testing already (which caught many foolish mistakes of mine...)

 drivers/base/class.c                     |  4 ++--
 drivers/base/core.c                      | 10 ++++------
 drivers/hwmon/drivetemp.c                |  4 ++--
 drivers/net/rionet.c                     |  3 +--
 drivers/ntb/hw/mscc/ntb_hw_switchtec.c   |  6 ++----
 drivers/pcmcia/ds.c                      |  6 ++----
 drivers/pcmcia/rsrc_nonstatic.c          |  6 ++----
 drivers/rapidio/devices/rio_mport_cdev.c |  7 ++-----
 drivers/rapidio/rio_cm.c                 |  8 ++------
 drivers/scsi/ses.c                       |  6 ++----
 drivers/scsi/sg.c                        |  8 ++++----
 include/linux/device/class.h             |  4 ++--
 kernel/time/alarmtimer.c                 |  3 +--
 13 files changed, 28 insertions(+), 47 deletions(-)
drivers/base/class.c +2 -2
index ad8b9f163fd2..ac1808d1a2e8 100644
@@ -486,7 +486,7 @@ int class_interface_register(struct class_interface *class_intf)
 	if (class_intf->add_dev) {
 		class_dev_iter_init(&iter, parent, NULL, NULL);
 		while ((dev = class_dev_iter_next(&iter)))
-			class_intf->add_dev(dev, class_intf);
+			class_intf->add_dev(dev);
 		class_dev_iter_exit(&iter);
 	}
 	mutex_unlock(&sp->mutex);
@@ -514,7 +514,7 @@ void class_interface_unregister(struct class_interface *class_intf)
 	if (class_intf->remove_dev) {
 		class_dev_iter_init(&iter, parent, NULL, NULL);
 		while ((dev = class_dev_iter_next(&iter)))
-			class_intf->remove_dev(dev, class_intf);
+			class_intf->remove_dev(dev);
 		class_dev_iter_exit(&iter);
 	}
 	mutex_unlock(&sp->mutex);
drivers/base/core.c +4 -6
index 64d188be4df9..7a42d1b6b721 100644
@@ -541,8 +541,7 @@ static struct class devlink_class = {
 	.dev_release = devlink_dev_release,
 };
 
-static int devlink_add_symlinks(struct device *dev,
-				struct class_interface *class_intf)
+static int devlink_add_symlinks(struct device *dev)
 {
 	int ret;
 	size_t len;
@@ -591,8 +590,7 @@ static int devlink_add_symlinks(struct device *dev,
 	return ret;
 }
 
-static void devlink_remove_symlinks(struct device *dev,
-				   struct class_interface *class_intf)
+static void devlink_remove_symlinks(struct device *dev)
 {
 	struct device_link *link = to_devlink(dev);
 	size_t len;
@@ -3647,7 +3645,7 @@ int device_add(struct device *dev)
 		/* notify any interfaces that the device is here */
 		list_for_each_entry(class_intf, &sp->interfaces, node)
 			if (class_intf->add_dev)
-				class_intf->add_dev(dev, class_intf);
+				class_intf->add_dev(dev);
 		mutex_unlock(&sp->mutex);
 		subsys_put(sp);
 	}
@@ -3805,7 +3803,7 @@ void device_del(struct device *dev)
 		/* notify any interfaces that the device is now gone */
 		list_for_each_entry(class_intf, &sp->interfaces, node)
 			if (class_intf->remove_dev)
-				class_intf->remove_dev(dev, class_intf);
+				class_intf->remove_dev(dev);
 		/* remove the device from the class list */
 		klist_del(&dev->p->knode_class);
 		mutex_unlock(&sp->mutex);
drivers/hwmon/drivetemp.c +2 -2
index 8e5759b42390..86171031ddc5 100644
@@ -550,7 +550,7 @@ static const struct hwmon_chip_info drivetemp_chip_info = {
  * The device argument points to sdev->sdev_dev. Its parent is
  * sdev->sdev_gendev, which we can use to get the scsi_device pointer.
  */
-static int drivetemp_add(struct device *dev, struct class_interface *intf)
+static int drivetemp_add(struct device *dev)
 {
 	struct scsi_device *sdev = to_scsi_device(dev->parent);
 	struct drivetemp_data *st;
@@ -585,7 +585,7 @@ static int drivetemp_add(struct device *dev, struct class_interface *intf)
 	return err;
 }
 
-static void drivetemp_remove(struct device *dev, struct class_interface *intf)
+static void drivetemp_remove(struct device *dev)
 {
 	struct drivetemp_data *st, *tmp;
 
drivers/net/rionet.c +1 -2
index fbcb9d05da64..4eececc94513 100644
@@ -662,8 +662,7 @@ static int rionet_shutdown(struct notifier_block *nb, unsigned long code,
 	return NOTIFY_DONE;
 }
 
-static void rionet_remove_mport(struct device *dev,
-				struct class_interface *class_intf)
+static void rionet_remove_mport(struct device *dev)
 {
 	struct rio_mport *mport = to_rio_mport(dev);
 	struct net_device *ndev;
drivers/ntb/hw/mscc/ntb_hw_switchtec.c +2 -4
index 88ae18b0efa8..d6bbcc7b5b90 100644
@@ -1470,8 +1470,7 @@ static int switchtec_ntb_reinit_peer(struct switchtec_ntb *sndev)
 	return rc;
 }
 
-static int switchtec_ntb_add(struct device *dev,
-			     struct class_interface *class_intf)
+static int switchtec_ntb_add(struct device *dev)
 {
 	struct switchtec_dev *stdev = to_stdev(dev);
 	struct switchtec_ntb *sndev;
@@ -1541,8 +1540,7 @@ static int switchtec_ntb_add(struct device *dev,
 	return rc;
 }
 
-static void switchtec_ntb_remove(struct device *dev,
-				 struct class_interface *class_intf)
+static void switchtec_ntb_remove(struct device *dev)
 {
 	struct switchtec_dev *stdev = to_stdev(dev);
 	struct switchtec_ntb *sndev = stdev->sndev;
drivers/pcmcia/ds.c +2 -4
index c8087efa5e4a..d500e5dbbc3f 100644
@@ -1335,8 +1335,7 @@ static struct pcmcia_callback pcmcia_bus_callback = {
 	.resume = pcmcia_bus_resume,
 };
 
-static int pcmcia_bus_add_socket(struct device *dev,
-					   struct class_interface *class_intf)
+static int pcmcia_bus_add_socket(struct device *dev)
 {
 	struct pcmcia_socket *socket = dev_get_drvdata(dev);
 	int ret;
@@ -1369,8 +1368,7 @@ static int pcmcia_bus_add_socket(struct device *dev,
 	return 0;
 }
 
-static void pcmcia_bus_remove_socket(struct device *dev,
-				     struct class_interface *class_intf)
+static void pcmcia_bus_remove_socket(struct device *dev)
 {
 	struct pcmcia_socket *socket = dev_get_drvdata(dev);
 
drivers/pcmcia/rsrc_nonstatic.c +2 -4
index ad1141fddb4c..471e0c5815f3 100644
@@ -1200,8 +1200,7 @@ static const struct attribute_group rsrc_attributes = {
 	.attrs = pccard_rsrc_attributes,
 };
 
-static int pccard_sysfs_add_rsrc(struct device *dev,
-					   struct class_interface *class_intf)
+static int pccard_sysfs_add_rsrc(struct device *dev)
 {
 	struct pcmcia_socket *s = dev_get_drvdata(dev);
 
@@ -1210,8 +1209,7 @@ static int pccard_sysfs_add_rsrc(struct device *dev,
 	return sysfs_create_group(&dev->kobj, &rsrc_attributes);
 }
 
-static void pccard_sysfs_remove_rsrc(struct device *dev,
-					       struct class_interface *class_intf)
+static void pccard_sysfs_remove_rsrc(struct device *dev)
 {
 	struct pcmcia_socket *s = dev_get_drvdata(dev);
 
drivers/rapidio/devices/rio_mport_cdev.c +2 -5
index deb96c3160a7..a115730ebf14 100644
@@ -2536,10 +2536,8 @@ static void mport_cdev_remove(struct mport_dev *md)
 /*
  * mport_add_mport() - Add rio_mport from LDM device struct
  * @dev:		Linux device model struct
- * @class_intf:	Linux class_interface
  */
-static int mport_add_mport(struct device *dev,
-		struct class_interface *class_intf)
+static int mport_add_mport(struct device *dev)
 {
 	struct rio_mport *mport = NULL;
 	struct mport_dev *chdev = NULL;
@@ -2559,8 +2557,7 @@ static int mport_add_mport(struct device *dev,
  * mport_remove_mport() - Remove rio_mport from global list
  * TODO remove device from global mport_dev list
  */
-static void mport_remove_mport(struct device *dev,
-		struct class_interface *class_intf)
+static void mport_remove_mport(struct device *dev)
 {
 	struct rio_mport *mport = NULL;
 	struct mport_dev *chdev;
drivers/rapidio/rio_cm.c +2 -6
index acaf9cda014c..49f8d111e546 100644
@@ -2087,13 +2087,11 @@ static int riocm_cdev_add(dev_t devno)
 /*
  * riocm_add_mport - add new local mport device into channel management core
  * @dev: device object associated with mport
- * @class_intf: class interface
  *
  * When a new mport device is added, CM immediately reserves inbound and
  * outbound RapidIO mailboxes that will be used.
  */
-static int riocm_add_mport(struct device *dev,
-			   struct class_interface *class_intf)
+static int riocm_add_mport(struct device *dev)
 {
 	int rc;
 	int i;
@@ -2166,14 +2164,12 @@ static int riocm_add_mport(struct device *dev,
 /*
  * riocm_remove_mport - remove local mport device from channel management core
  * @dev: device object associated with mport
- * @class_intf: class interface
  *
  * Removes a local mport device from the list of registered devices that provide
  * channel management services. Returns an error if the specified mport is not
  * registered with the CM core.
  */
-static void riocm_remove_mport(struct device *dev,
-			       struct class_interface *class_intf)
+static void riocm_remove_mport(struct device *dev)
 {
 	struct rio_mport *mport = to_rio_mport(dev);
 	struct cm_dev *cm;
drivers/scsi/ses.c +2 -4
index b11a9162e73a..57feb0cae896 100644
@@ -663,8 +663,7 @@ static void ses_match_to_enclosure(struct enclosure_device *edev,
 	}
 }
 
-static int ses_intf_add(struct device *cdev,
-			struct class_interface *intf)
+static int ses_intf_add(struct device *cdev)
 {
 	struct scsi_device *sdev = to_scsi_device(cdev->parent);
 	struct scsi_device *tmp_sdev;
@@ -869,8 +868,7 @@ static void ses_intf_remove_enclosure(struct scsi_device *sdev)
 	enclosure_unregister(edev);
 }
 
-static void ses_intf_remove(struct device *cdev,
-			    struct class_interface *intf)
+static void ses_intf_remove(struct device *cdev)
 {
 	struct scsi_device *sdev = to_scsi_device(cdev->parent);
 
drivers/scsi/sg.c +4 -4
index 4997f880d4a4..037f8c98a6d3 100644
@@ -96,8 +96,8 @@ static int scatter_elem_sz_prev = SG_SCATTER_SZ;
 
 #define SG_SECTOR_SZ 512
 
-static int sg_add_device(struct device *, struct class_interface *);
-static void sg_remove_device(struct device *, struct class_interface *);
+static int sg_add_device(struct device *);
+static void sg_remove_device(struct device *);
 
 static DEFINE_IDR(sg_index_idr);
 static DEFINE_RWLOCK(sg_index_lock);	/* Also used to lock
@@ -1488,7 +1488,7 @@ sg_alloc(struct scsi_device *scsidp)
 }
 
 static int
-sg_add_device(struct device *cl_dev, struct class_interface *cl_intf)
+sg_add_device(struct device *cl_dev)
 {
 	struct scsi_device *scsidp = to_scsi_device(cl_dev->parent);
 	Sg_device *sdp = NULL;
@@ -1578,7 +1578,7 @@ sg_device_destroy(struct kref *kref)
 }
 
 static void
-sg_remove_device(struct device *cl_dev, struct class_interface *cl_intf)
+sg_remove_device(struct device *cl_dev)
 {
 	struct scsi_device *scsidp = to_scsi_device(cl_dev->parent);
 	Sg_device *sdp = dev_get_drvdata(cl_dev);
include/linux/device/class.h +2 -2
index 53287aa105b8..9deeaeb457bb 100644
@@ -219,8 +219,8 @@ struct class_interface {
 	struct list_head	node;
 	const struct class	*class;
 
-	int (*add_dev)		(struct device *, struct class_interface *);
-	void (*remove_dev)	(struct device *, struct class_interface *);
+	int (*add_dev)		(struct device *dev);
+	void (*remove_dev)	(struct device *dev);
 };
 
 int __must_check class_interface_register(struct class_interface *);
kernel/time/alarmtimer.c +1 -2
index 7e5dff602585..82b28ab0f328 100644
@@ -81,8 +81,7 @@ struct rtc_device *alarmtimer_get_rtcdev(void)
 }
 EXPORT_SYMBOL_GPL(alarmtimer_get_rtcdev);
 
-static int alarmtimer_rtc_add_device(struct device *dev,
-				struct class_interface *class_intf)
+static int alarmtimer_rtc_add_device(struct device *dev)
 {
 	unsigned long flags;
 	struct rtc_device *rtc = to_rtc_device(dev);
Signature · 1 line
2.40.0
maintainer Acked-by on v1 4/5
#8 lore raw

Re: [PATCH 4/5] driver core: class: remove struct class_interface * from callbacks

Quoted 45 lines · Greg Kroah-Hartman

The add_dev and remove_dev callbacks in struct class_interface currently pass in a pointer back to the class_interface structure that is calling them, but none of the callback implementations actually use this pointer as it is pointless (the structure is known, the driver passed it in in the first place if it is really needed again.)

So clean this up and just remove the pointer from the callbacks and fix up all callback functions.

Cc Jean Delvare <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Kurt Schwemmer <[email protected]>
Cc Logan Gunthorpe <[email protected]>
Cc Jon Mason <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Allen Hubbe <[email protected]>
Cc Dominik Brodowski <[email protected]>
Cc Matt Porter <[email protected]>
Cc Alexandre Bounine <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Doug Gilbert <[email protected]>
Cc John Stultz <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Wang Weiyang <[email protected]>
Cc Yang Yingliang <[email protected]>
Cc Jakob Koschel <[email protected]>
Cc Cai Xinchen <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>

---
Note, subsystem maintainers, this should go through my driver-core tree as it's part of a larger cleanup of 'struct class' handling. I'm cc:ing you all to get reviews to verify I didn't do something foolish, but it has passed 0-day bot build testing already (which caught many foolish mistakes of mine...)

Quoted 5 lines
 drivers/base/class.c                     |  4 ++--
 drivers/base/core.c                      | 10 ++++------
 drivers/hwmon/drivetemp.c                |  4 ++--
 drivers/net/rionet.c                     |  3 +--
 drivers/ntb/hw/mscc/ntb_hw_switchtec.c   |  6 ++----

For the switchtec changes:

Thanks!

Logan

maintainer Acked-by on v1 4/5
#9 lore raw

Re: [PATCH 4/5] driver core: class: remove struct class_interface * from callbacks

In reply to Greg Kroah-Hartman
Quoted 30 lines · Greg Kroah-Hartman

The add_dev and remove_dev callbacks in struct class_interface currently pass in a pointer back to the class_interface structure that is calling them, but none of the callback implementations actually use this pointer as it is pointless (the structure is known, the driver passed it in in the first place if it is really needed again.)

So clean this up and just remove the pointer from the callbacks and fix up all callback functions.

Cc Jean Delvare <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Kurt Schwemmer <[email protected]>
Cc Logan Gunthorpe <[email protected]>
Cc Jon Mason <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Allen Hubbe <[email protected]>
Cc Dominik Brodowski <[email protected]>
Cc Matt Porter <[email protected]>
Cc Alexandre Bounine <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Doug Gilbert <[email protected]>
Cc John Stultz <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Stephen Boyd <[email protected]>
Quoted 8 lines
Cc Hans de Goede <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Wang Weiyang <[email protected]>
Cc Yang Yingliang <[email protected]>
Cc Jakob Koschel <[email protected]>
Cc Cai Xinchen <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Quoted 345 lines

---
Note, subsystem maintainers, this should go through my driver-core tree as it's part of a larger cleanup of 'struct class' handling. I'm cc:ing you all to get reviews to verify I didn't do something foolish, but it has passed 0-day bot build testing already (which caught many foolish mistakes of mine...)

 drivers/base/class.c                     |  4 ++--
 drivers/base/core.c                      | 10 ++++------
 drivers/hwmon/drivetemp.c                |  4 ++--
 drivers/net/rionet.c                     |  3 +--
 drivers/ntb/hw/mscc/ntb_hw_switchtec.c   |  6 ++----
 drivers/pcmcia/ds.c                      |  6 ++----
 drivers/pcmcia/rsrc_nonstatic.c          |  6 ++----
 drivers/rapidio/devices/rio_mport_cdev.c |  7 ++-----
 drivers/rapidio/rio_cm.c                 |  8 ++------
 drivers/scsi/ses.c                       |  6 ++----
 drivers/scsi/sg.c                        |  8 ++++----
 include/linux/device/class.h             |  4 ++--
 kernel/time/alarmtimer.c                 |  3 +--
 13 files changed, 28 insertions(+), 47 deletions(-)
drivers/base/class.c +2 -2
index ad8b9f163fd2..ac1808d1a2e8 100644
@@ -486,7 +486,7 @@ int class_interface_register(struct class_interface *class_intf)
        if (class_intf->add_dev) {
                class_dev_iter_init(&iter, parent, NULL, NULL);
                while ((dev = class_dev_iter_next(&iter)))
-                       class_intf->add_dev(dev, class_intf);
+                       class_intf->add_dev(dev);
                class_dev_iter_exit(&iter);
        }
        mutex_unlock(&sp->mutex);
@@ -514,7 +514,7 @@ void class_interface_unregister(struct class_interface *class_intf)
        if (class_intf->remove_dev) {
                class_dev_iter_init(&iter, parent, NULL, NULL);
                while ((dev = class_dev_iter_next(&iter)))
-                       class_intf->remove_dev(dev, class_intf);
+                       class_intf->remove_dev(dev);
                class_dev_iter_exit(&iter);
        }
        mutex_unlock(&sp->mutex);
drivers/base/core.c +4 -6
index 64d188be4df9..7a42d1b6b721 100644
@@ -541,8 +541,7 @@ static struct class devlink_class = {
        .dev_release = devlink_dev_release,
 };
 
-static int devlink_add_symlinks(struct device *dev,
-                               struct class_interface *class_intf)
+static int devlink_add_symlinks(struct device *dev)
 {
        int ret;
        size_t len;
@@ -591,8 +590,7 @@ static int devlink_add_symlinks(struct device *dev,
        return ret;
 }
 
-static void devlink_remove_symlinks(struct device *dev,
-                                  struct class_interface *class_intf)
+static void devlink_remove_symlinks(struct device *dev)
 {
        struct device_link *link = to_devlink(dev);
        size_t len;
@@ -3647,7 +3645,7 @@ int device_add(struct device *dev)
                /* notify any interfaces that the device is here */
                list_for_each_entry(class_intf, &sp->interfaces, node)
                        if (class_intf->add_dev)
-                               class_intf->add_dev(dev, class_intf);
+                               class_intf->add_dev(dev);
                mutex_unlock(&sp->mutex);
                subsys_put(sp);
        }
@@ -3805,7 +3803,7 @@ void device_del(struct device *dev)
                /* notify any interfaces that the device is now gone */
                list_for_each_entry(class_intf, &sp->interfaces, node)
                        if (class_intf->remove_dev)
-                               class_intf->remove_dev(dev, class_intf);
+                               class_intf->remove_dev(dev);
                /* remove the device from the class list */
                klist_del(&dev->p->knode_class);
                mutex_unlock(&sp->mutex);
drivers/hwmon/drivetemp.c +2 -2
index 8e5759b42390..86171031ddc5 100644
@@ -550,7 +550,7 @@ static const struct hwmon_chip_info drivetemp_chip_info = {
  * The device argument points to sdev->sdev_dev. Its parent is
  * sdev->sdev_gendev, which we can use to get the scsi_device pointer.
  */
-static int drivetemp_add(struct device *dev, struct class_interface *intf)
+static int drivetemp_add(struct device *dev)
 {
        struct scsi_device *sdev = to_scsi_device(dev->parent);
        struct drivetemp_data *st;
@@ -585,7 +585,7 @@ static int drivetemp_add(struct device *dev, struct class_interface *intf)
        return err;
 }
 
-static void drivetemp_remove(struct device *dev, struct class_interface *intf)
+static void drivetemp_remove(struct device *dev)
 {
        struct drivetemp_data *st, *tmp;
 
drivers/net/rionet.c +1 -2
index fbcb9d05da64..4eececc94513 100644
@@ -662,8 +662,7 @@ static int rionet_shutdown(struct notifier_block *nb, unsigned long code,
        return NOTIFY_DONE;
 }
 
-static void rionet_remove_mport(struct device *dev,
-                               struct class_interface *class_intf)
+static void rionet_remove_mport(struct device *dev)
 {
        struct rio_mport *mport = to_rio_mport(dev);
        struct net_device *ndev;
drivers/ntb/hw/mscc/ntb_hw_switchtec.c +2 -4
index 88ae18b0efa8..d6bbcc7b5b90 100644
@@ -1470,8 +1470,7 @@ static int switchtec_ntb_reinit_peer(struct switchtec_ntb *sndev)
        return rc;
 }
 
-static int switchtec_ntb_add(struct device *dev,
-                            struct class_interface *class_intf)
+static int switchtec_ntb_add(struct device *dev)
 {
        struct switchtec_dev *stdev = to_stdev(dev);
        struct switchtec_ntb *sndev;
@@ -1541,8 +1540,7 @@ static int switchtec_ntb_add(struct device *dev,
        return rc;
 }
 
-static void switchtec_ntb_remove(struct device *dev,
-                                struct class_interface *class_intf)
+static void switchtec_ntb_remove(struct device *dev)
 {
        struct switchtec_dev *stdev = to_stdev(dev);
        struct switchtec_ntb *sndev = stdev->sndev;
drivers/pcmcia/ds.c +2 -4
index c8087efa5e4a..d500e5dbbc3f 100644
@@ -1335,8 +1335,7 @@ static struct pcmcia_callback pcmcia_bus_callback = {
        .resume = pcmcia_bus_resume,
 };
 
-static int pcmcia_bus_add_socket(struct device *dev,
-                                          struct class_interface *class_intf)
+static int pcmcia_bus_add_socket(struct device *dev)
 {
        struct pcmcia_socket *socket = dev_get_drvdata(dev);
        int ret;
@@ -1369,8 +1368,7 @@ static int pcmcia_bus_add_socket(struct device *dev,
        return 0;
 }
 
-static void pcmcia_bus_remove_socket(struct device *dev,
-                                    struct class_interface *class_intf)
+static void pcmcia_bus_remove_socket(struct device *dev)
 {
        struct pcmcia_socket *socket = dev_get_drvdata(dev);
 
drivers/pcmcia/rsrc_nonstatic.c +2 -4
index ad1141fddb4c..471e0c5815f3 100644
@@ -1200,8 +1200,7 @@ static const struct attribute_group rsrc_attributes = {
        .attrs = pccard_rsrc_attributes,
 };
 
-static int pccard_sysfs_add_rsrc(struct device *dev,
-                                          struct class_interface *class_intf)
+static int pccard_sysfs_add_rsrc(struct device *dev)
 {
        struct pcmcia_socket *s = dev_get_drvdata(dev);
 
@@ -1210,8 +1209,7 @@ static int pccard_sysfs_add_rsrc(struct device *dev,
        return sysfs_create_group(&dev->kobj, &rsrc_attributes);
 }
 
-static void pccard_sysfs_remove_rsrc(struct device *dev,
-                                              struct class_interface *class_intf)
+static void pccard_sysfs_remove_rsrc(struct device *dev)
 {
        struct pcmcia_socket *s = dev_get_drvdata(dev);
 
drivers/rapidio/devices/rio_mport_cdev.c +2 -5
index deb96c3160a7..a115730ebf14 100644
@@ -2536,10 +2536,8 @@ static void mport_cdev_remove(struct mport_dev *md)
 /*
  * mport_add_mport() - Add rio_mport from LDM device struct
  * @dev:               Linux device model struct
- * @class_intf:        Linux class_interface
  */
-static int mport_add_mport(struct device *dev,
-               struct class_interface *class_intf)
+static int mport_add_mport(struct device *dev)
 {
        struct rio_mport *mport = NULL;
        struct mport_dev *chdev = NULL;
@@ -2559,8 +2557,7 @@ static int mport_add_mport(struct device *dev,
  * mport_remove_mport() - Remove rio_mport from global list
  * TODO remove device from global mport_dev list
  */
-static void mport_remove_mport(struct device *dev,
-               struct class_interface *class_intf)
+static void mport_remove_mport(struct device *dev)
 {
        struct rio_mport *mport = NULL;
        struct mport_dev *chdev;
drivers/rapidio/rio_cm.c +2 -6
index acaf9cda014c..49f8d111e546 100644
@@ -2087,13 +2087,11 @@ static int riocm_cdev_add(dev_t devno)
 /*
  * riocm_add_mport - add new local mport device into channel management core
  * @dev: device object associated with mport
- * @class_intf: class interface
  *
  * When a new mport device is added, CM immediately reserves inbound and
  * outbound RapidIO mailboxes that will be used.
  */
-static int riocm_add_mport(struct device *dev,
-                          struct class_interface *class_intf)
+static int riocm_add_mport(struct device *dev)
 {
        int rc;
        int i;
@@ -2166,14 +2164,12 @@ static int riocm_add_mport(struct device *dev,
 /*
  * riocm_remove_mport - remove local mport device from channel management core
  * @dev: device object associated with mport
- * @class_intf: class interface
  *
  * Removes a local mport device from the list of registered devices that provide
  * channel management services. Returns an error if the specified mport is not
  * registered with the CM core.
  */
-static void riocm_remove_mport(struct device *dev,
-                              struct class_interface *class_intf)
+static void riocm_remove_mport(struct device *dev)
 {
        struct rio_mport *mport = to_rio_mport(dev);
        struct cm_dev *cm;
drivers/scsi/ses.c +2 -4
index b11a9162e73a..57feb0cae896 100644
@@ -663,8 +663,7 @@ static void ses_match_to_enclosure(struct enclosure_device *edev,
        }
 }
 
-static int ses_intf_add(struct device *cdev,
-                       struct class_interface *intf)
+static int ses_intf_add(struct device *cdev)
 {
        struct scsi_device *sdev = to_scsi_device(cdev->parent);
        struct scsi_device *tmp_sdev;
@@ -869,8 +868,7 @@ static void ses_intf_remove_enclosure(struct scsi_device *sdev)
        enclosure_unregister(edev);
 }
 
-static void ses_intf_remove(struct device *cdev,
-                           struct class_interface *intf)
+static void ses_intf_remove(struct device *cdev)
 {
        struct scsi_device *sdev = to_scsi_device(cdev->parent);
 
drivers/scsi/sg.c +4 -4
index 4997f880d4a4..037f8c98a6d3 100644
@@ -96,8 +96,8 @@ static int scatter_elem_sz_prev = SG_SCATTER_SZ;
 
 #define SG_SECTOR_SZ 512
 
-static int sg_add_device(struct device *, struct class_interface *);
-static void sg_remove_device(struct device *, struct class_interface *);
+static int sg_add_device(struct device *);
+static void sg_remove_device(struct device *);
 
 static DEFINE_IDR(sg_index_idr);
 static DEFINE_RWLOCK(sg_index_lock);   /* Also used to lock
@@ -1488,7 +1488,7 @@ sg_alloc(struct scsi_device *scsidp)
 }
 
 static int
-sg_add_device(struct device *cl_dev, struct class_interface *cl_intf)
+sg_add_device(struct device *cl_dev)
 {
        struct scsi_device *scsidp = to_scsi_device(cl_dev->parent);
        Sg_device *sdp = NULL;
@@ -1578,7 +1578,7 @@ sg_device_destroy(struct kref *kref)
 }
 
 static void
-sg_remove_device(struct device *cl_dev, struct class_interface *cl_intf)
+sg_remove_device(struct device *cl_dev)
 {
        struct scsi_device *scsidp = to_scsi_device(cl_dev->parent);
        Sg_device *sdp = dev_get_drvdata(cl_dev);
include/linux/device/class.h +2 -2
index 53287aa105b8..9deeaeb457bb 100644
@@ -219,8 +219,8 @@ struct class_interface {
        struct list_head        node;
        const struct class      *class;
 
-       int (*add_dev)          (struct device *, struct class_interface *);
-       void (*remove_dev)      (struct device *, struct class_interface *);
+       int (*add_dev)          (struct device *dev);
+       void (*remove_dev)      (struct device *dev);
 };
 
 int __must_check class_interface_register(struct class_interface *);
kernel/time/alarmtimer.c +1 -3
index 7e5dff602585..82b28ab0f328 100644
@@ -81,8 +81,7 @@ struct rtc_device *alarmtimer_get_rtcdev(void)
 }
 EXPORT_SYMBOL_GPL(alarmtimer_get_rtcdev);
 
-static int alarmtimer_rtc_add_device(struct device *dev,
-                               struct class_interface *class_intf)
+static int alarmtimer_rtc_add_device(struct device *dev)
 {
        unsigned long flags;
        struct rtc_device *rtc = to_rtc_device(dev);
--

2.40.0

maintainer Acked-by on v1 4/5
#10 lore raw

Re: [PATCH 4/5] driver core: class: remove struct class_interface * from callbacks

In reply to Greg Kroah-Hartman
Quoted 45 lines · Greg Kroah-Hartman

The add_dev and remove_dev callbacks in struct class_interface currently pass in a pointer back to the class_interface structure that is calling them, but none of the callback implementations actually use this pointer as it is pointless (the structure is known, the driver passed it in in the first place if it is really needed again.)

So clean this up and just remove the pointer from the callbacks and fix up all callback functions.

Cc Jean Delvare <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Kurt Schwemmer <[email protected]>
Cc Logan Gunthorpe <[email protected]>
Cc Jon Mason <[email protected]>
Cc Dave Jiang <[email protected]>
Cc Allen Hubbe <[email protected]>
Cc Dominik Brodowski <[email protected]>
Cc Matt Porter <[email protected]>
Cc Alexandre Bounine <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Doug Gilbert <[email protected]>
Cc John Stultz <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Hans de Goede <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Wang Weiyang <[email protected]>
Cc Yang Yingliang <[email protected]>
Cc Jakob Koschel <[email protected]>
Cc Cai Xinchen <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>

---
Note, subsystem maintainers, this should go through my driver-core tree as it's part of a larger cleanup of 'struct class' handling. I'm cc:ing you all to get reviews to verify I didn't do something foolish, but it has passed 0-day bot build testing already (which caught many foolish mistakes of mine...)

Quoted 3 lines
  drivers/base/class.c                     |  4 ++--
  drivers/base/core.c                      | 10 ++++------
  drivers/hwmon/drivetemp.c                |  4 ++--

For hwmon:

Quoted 331 lines
  drivers/net/rionet.c                     |  3 +--
  drivers/ntb/hw/mscc/ntb_hw_switchtec.c   |  6 ++----
  drivers/pcmcia/ds.c                      |  6 ++----
  drivers/pcmcia/rsrc_nonstatic.c          |  6 ++----
  drivers/rapidio/devices/rio_mport_cdev.c |  7 ++-----
  drivers/rapidio/rio_cm.c                 |  8 ++------
  drivers/scsi/ses.c                       |  6 ++----
  drivers/scsi/sg.c                        |  8 ++++----
  include/linux/device/class.h             |  4 ++--
  kernel/time/alarmtimer.c                 |  3 +--
  13 files changed, 28 insertions(+), 47 deletions(-)
drivers/base/class.c +2 -2
index ad8b9f163fd2..ac1808d1a2e8 100644
@@ -486,7 +486,7 @@ int class_interface_register(struct class_interface *class_intf)
  	if (class_intf->add_dev) {
  		class_dev_iter_init(&iter, parent, NULL, NULL);
  		while ((dev = class_dev_iter_next(&iter)))
-			class_intf->add_dev(dev, class_intf);
+			class_intf->add_dev(dev);
  		class_dev_iter_exit(&iter);
  	}
  	mutex_unlock(&sp->mutex);
@@ -514,7 +514,7 @@ void class_interface_unregister(struct class_interface *class_intf)
  	if (class_intf->remove_dev) {
  		class_dev_iter_init(&iter, parent, NULL, NULL);
  		while ((dev = class_dev_iter_next(&iter)))
-			class_intf->remove_dev(dev, class_intf);
+			class_intf->remove_dev(dev);
  		class_dev_iter_exit(&iter);
  	}
  	mutex_unlock(&sp->mutex);
drivers/base/core.c +4 -6
index 64d188be4df9..7a42d1b6b721 100644
@@ -541,8 +541,7 @@ static struct class devlink_class = {
  	.dev_release = devlink_dev_release,
  };
 
-static int devlink_add_symlinks(struct device *dev,
-				struct class_interface *class_intf)
+static int devlink_add_symlinks(struct device *dev)
  {
  	int ret;
  	size_t len;
@@ -591,8 +590,7 @@ static int devlink_add_symlinks(struct device *dev,
  	return ret;
  }
 
-static void devlink_remove_symlinks(struct device *dev,
-				   struct class_interface *class_intf)
+static void devlink_remove_symlinks(struct device *dev)
  {
  	struct device_link *link = to_devlink(dev);
  	size_t len;
@@ -3647,7 +3645,7 @@ int device_add(struct device *dev)
  		/* notify any interfaces that the device is here */
  		list_for_each_entry(class_intf, &sp->interfaces, node)
  			if (class_intf->add_dev)
-				class_intf->add_dev(dev, class_intf);
+				class_intf->add_dev(dev);
  		mutex_unlock(&sp->mutex);
  		subsys_put(sp);
  	}
@@ -3805,7 +3803,7 @@ void device_del(struct device *dev)
  		/* notify any interfaces that the device is now gone */
  		list_for_each_entry(class_intf, &sp->interfaces, node)
  			if (class_intf->remove_dev)
-				class_intf->remove_dev(dev, class_intf);
+				class_intf->remove_dev(dev);
  		/* remove the device from the class list */
  		klist_del(&dev->p->knode_class);
  		mutex_unlock(&sp->mutex);
drivers/hwmon/drivetemp.c +2 -2
index 8e5759b42390..86171031ddc5 100644
@@ -550,7 +550,7 @@ static const struct hwmon_chip_info drivetemp_chip_info = {
   * The device argument points to sdev->sdev_dev. Its parent is
   * sdev->sdev_gendev, which we can use to get the scsi_device pointer.
   */
-static int drivetemp_add(struct device *dev, struct class_interface *intf)
+static int drivetemp_add(struct device *dev)
  {
  	struct scsi_device *sdev = to_scsi_device(dev->parent);
  	struct drivetemp_data *st;
@@ -585,7 +585,7 @@ static int drivetemp_add(struct device *dev, struct class_interface *intf)
  	return err;
  }
 
-static void drivetemp_remove(struct device *dev, struct class_interface *intf)
+static void drivetemp_remove(struct device *dev)
  {
  	struct drivetemp_data *st, *tmp;
 
drivers/net/rionet.c +1 -2
index fbcb9d05da64..4eececc94513 100644
@@ -662,8 +662,7 @@ static int rionet_shutdown(struct notifier_block *nb, unsigned long code,
  	return NOTIFY_DONE;
  }
 
-static void rionet_remove_mport(struct device *dev,
-				struct class_interface *class_intf)
+static void rionet_remove_mport(struct device *dev)
  {
  	struct rio_mport *mport = to_rio_mport(dev);
  	struct net_device *ndev;
drivers/ntb/hw/mscc/ntb_hw_switchtec.c +2 -4
index 88ae18b0efa8..d6bbcc7b5b90 100644
@@ -1470,8 +1470,7 @@ static int switchtec_ntb_reinit_peer(struct switchtec_ntb *sndev)
  	return rc;
  }
 
-static int switchtec_ntb_add(struct device *dev,
-			     struct class_interface *class_intf)
+static int switchtec_ntb_add(struct device *dev)
  {
  	struct switchtec_dev *stdev = to_stdev(dev);
  	struct switchtec_ntb *sndev;
@@ -1541,8 +1540,7 @@ static int switchtec_ntb_add(struct device *dev,
  	return rc;
  }
 
-static void switchtec_ntb_remove(struct device *dev,
-				 struct class_interface *class_intf)
+static void switchtec_ntb_remove(struct device *dev)
  {
  	struct switchtec_dev *stdev = to_stdev(dev);
  	struct switchtec_ntb *sndev = stdev->sndev;
drivers/pcmcia/ds.c +2 -4
index c8087efa5e4a..d500e5dbbc3f 100644
@@ -1335,8 +1335,7 @@ static struct pcmcia_callback pcmcia_bus_callback = {
  	.resume = pcmcia_bus_resume,
  };
 
-static int pcmcia_bus_add_socket(struct device *dev,
-					   struct class_interface *class_intf)
+static int pcmcia_bus_add_socket(struct device *dev)
  {
  	struct pcmcia_socket *socket = dev_get_drvdata(dev);
  	int ret;
@@ -1369,8 +1368,7 @@ static int pcmcia_bus_add_socket(struct device *dev,
  	return 0;
  }
 
-static void pcmcia_bus_remove_socket(struct device *dev,
-				     struct class_interface *class_intf)
+static void pcmcia_bus_remove_socket(struct device *dev)
  {
  	struct pcmcia_socket *socket = dev_get_drvdata(dev);
 
drivers/pcmcia/rsrc_nonstatic.c +2 -4
index ad1141fddb4c..471e0c5815f3 100644
@@ -1200,8 +1200,7 @@ static const struct attribute_group rsrc_attributes = {
  	.attrs = pccard_rsrc_attributes,
  };
 
-static int pccard_sysfs_add_rsrc(struct device *dev,
-					   struct class_interface *class_intf)
+static int pccard_sysfs_add_rsrc(struct device *dev)
  {
  	struct pcmcia_socket *s = dev_get_drvdata(dev);
 
@@ -1210,8 +1209,7 @@ static int pccard_sysfs_add_rsrc(struct device *dev,
  	return sysfs_create_group(&dev->kobj, &rsrc_attributes);
  }
 
-static void pccard_sysfs_remove_rsrc(struct device *dev,
-					       struct class_interface *class_intf)
+static void pccard_sysfs_remove_rsrc(struct device *dev)
  {
  	struct pcmcia_socket *s = dev_get_drvdata(dev);
 
drivers/rapidio/devices/rio_mport_cdev.c +2 -5
index deb96c3160a7..a115730ebf14 100644
@@ -2536,10 +2536,8 @@ static void mport_cdev_remove(struct mport_dev *md)
  /*
   * mport_add_mport() - Add rio_mport from LDM device struct
   * @dev:		Linux device model struct
- * @class_intf:	Linux class_interface
   */
-static int mport_add_mport(struct device *dev,
-		struct class_interface *class_intf)
+static int mport_add_mport(struct device *dev)
  {
  	struct rio_mport *mport = NULL;
  	struct mport_dev *chdev = NULL;
@@ -2559,8 +2557,7 @@ static int mport_add_mport(struct device *dev,
   * mport_remove_mport() - Remove rio_mport from global list
   * TODO remove device from global mport_dev list
   */
-static void mport_remove_mport(struct device *dev,
-		struct class_interface *class_intf)
+static void mport_remove_mport(struct device *dev)
  {
  	struct rio_mport *mport = NULL;
  	struct mport_dev *chdev;
drivers/rapidio/rio_cm.c +2 -6
index acaf9cda014c..49f8d111e546 100644
@@ -2087,13 +2087,11 @@ static int riocm_cdev_add(dev_t devno)
  /*
   * riocm_add_mport - add new local mport device into channel management core
   * @dev: device object associated with mport
- * @class_intf: class interface
   *
   * When a new mport device is added, CM immediately reserves inbound and
   * outbound RapidIO mailboxes that will be used.
   */
-static int riocm_add_mport(struct device *dev,
-			   struct class_interface *class_intf)
+static int riocm_add_mport(struct device *dev)
  {
  	int rc;
  	int i;
@@ -2166,14 +2164,12 @@ static int riocm_add_mport(struct device *dev,
  /*
   * riocm_remove_mport - remove local mport device from channel management core
   * @dev: device object associated with mport
- * @class_intf: class interface
   *
   * Removes a local mport device from the list of registered devices that provide
   * channel management services. Returns an error if the specified mport is not
   * registered with the CM core.
   */
-static void riocm_remove_mport(struct device *dev,
-			       struct class_interface *class_intf)
+static void riocm_remove_mport(struct device *dev)
  {
  	struct rio_mport *mport = to_rio_mport(dev);
  	struct cm_dev *cm;
drivers/scsi/ses.c +2 -4
index b11a9162e73a..57feb0cae896 100644
@@ -663,8 +663,7 @@ static void ses_match_to_enclosure(struct enclosure_device *edev,
  	}
  }
 
-static int ses_intf_add(struct device *cdev,
-			struct class_interface *intf)
+static int ses_intf_add(struct device *cdev)
  {
  	struct scsi_device *sdev = to_scsi_device(cdev->parent);
  	struct scsi_device *tmp_sdev;
@@ -869,8 +868,7 @@ static void ses_intf_remove_enclosure(struct scsi_device *sdev)
  	enclosure_unregister(edev);
  }
 
-static void ses_intf_remove(struct device *cdev,
-			    struct class_interface *intf)
+static void ses_intf_remove(struct device *cdev)
  {
  	struct scsi_device *sdev = to_scsi_device(cdev->parent);
 
drivers/scsi/sg.c +4 -4
index 4997f880d4a4..037f8c98a6d3 100644
@@ -96,8 +96,8 @@ static int scatter_elem_sz_prev = SG_SCATTER_SZ;
 
  #define SG_SECTOR_SZ 512
 
-static int sg_add_device(struct device *, struct class_interface *);
-static void sg_remove_device(struct device *, struct class_interface *);
+static int sg_add_device(struct device *);
+static void sg_remove_device(struct device *);
 
  static DEFINE_IDR(sg_index_idr);
  static DEFINE_RWLOCK(sg_index_lock);	/* Also used to lock
@@ -1488,7 +1488,7 @@ sg_alloc(struct scsi_device *scsidp)
  }
 
  static int
-sg_add_device(struct device *cl_dev, struct class_interface *cl_intf)
+sg_add_device(struct device *cl_dev)
  {
  	struct scsi_device *scsidp = to_scsi_device(cl_dev->parent);
  	Sg_device *sdp = NULL;
@@ -1578,7 +1578,7 @@ sg_device_destroy(struct kref *kref)
  }
 
  static void
-sg_remove_device(struct device *cl_dev, struct class_interface *cl_intf)
+sg_remove_device(struct device *cl_dev)
  {
  	struct scsi_device *scsidp = to_scsi_device(cl_dev->parent);
  	Sg_device *sdp = dev_get_drvdata(cl_dev);
include/linux/device/class.h +2 -2
index 53287aa105b8..9deeaeb457bb 100644
@@ -219,8 +219,8 @@ struct class_interface {
  	struct list_head	node;
  	const struct class	*class;
 
-	int (*add_dev)		(struct device *, struct class_interface *);
-	void (*remove_dev)	(struct device *, struct class_interface *);
+	int (*add_dev)		(struct device *dev);
+	void (*remove_dev)	(struct device *dev);
  };
 
  int __must_check class_interface_register(struct class_interface *);
kernel/time/alarmtimer.c +1 -2
index 7e5dff602585..82b28ab0f328 100644
@@ -81,8 +81,7 @@ struct rtc_device *alarmtimer_get_rtcdev(void)
  }
  EXPORT_SYMBOL_GPL(alarmtimer_get_rtcdev);
 
-static int alarmtimer_rtc_add_device(struct device *dev,
-				struct class_interface *class_intf)
+static int alarmtimer_rtc_add_device(struct device *dev)
  {
  	unsigned long flags;
  	struct rtc_device *rtc = to_rtc_device(dev);
author maintainer
#11 lore raw

PATCH 5/5 tty: make tty_class a static const structure

In reply to Greg Kroah-Hartman

Now that the driver core allows for struct class to be in read-only memory, move the tty_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time.

Cc Jiri Slaby <[email protected]>
Cc "Ilpo Järvinen" <[email protected]>

---
Jiri and Ilpo, this is part of the larger driver-core changes to make it possible to move struct class into read-only memory and is used as proof that this all works properly. I'll take it throught the driver-core tree as it shoudn't conflict with any tty.git changes.

 drivers/tty/pty.c    |  2 +-
 drivers/tty/tty_io.c | 24 +++++++++++-------------
 drivers/tty/vt/vt.c  |  2 +-
 include/linux/tty.h  |  2 +-
 4 files changed, 14 insertions(+), 16 deletions(-)
drivers/tty/pty.c +1 -1
index 07394fdaf522..2b1c8ab99dba 100644
@@ -931,7 +931,7 @@ static void __init unix98_pty_init(void)
 	if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
 	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
 		panic("Couldn't register /dev/ptmx driver");
-	device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");
+	device_create(&tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");
 }
 
 #else
drivers/tty/tty_io.c +11 -13
index 1382d9050ce8..44e0d53aa0b8 100644
@@ -3070,7 +3070,7 @@ static struct device *tty_get_device(struct tty_struct *tty)
 {
 	dev_t devt = tty_devnum(tty);
 
-	return class_find_device_by_devt(tty_class, devt);
+	return class_find_device_by_devt(&tty_class, devt);
 }
 
 
@@ -3143,8 +3143,6 @@ int tty_put_char(struct tty_struct *tty, unsigned char ch)
 }
 EXPORT_SYMBOL_GPL(tty_put_char);
 
-struct class *tty_class;
-
 static int tty_cdev_add(struct tty_driver *driver, dev_t dev,
 		unsigned int index, unsigned int count)
 {
@@ -3239,7 +3237,7 @@ struct device *tty_register_device_attr(struct tty_driver *driver,
 		return ERR_PTR(-ENOMEM);
 
 	dev->devt = devt;
-	dev->class = tty_class;
+	dev->class = &tty_class;
 	dev->parent = device;
 	dev->release = tty_device_create_release;
 	dev_set_name(dev, "%s", name);
@@ -3294,8 +3292,7 @@ EXPORT_SYMBOL_GPL(tty_register_device_attr);
  */
 void tty_unregister_device(struct tty_driver *driver, unsigned index)
 {
-	device_destroy(tty_class,
-		MKDEV(driver->major, driver->minor_start) + index);
+	device_destroy(&tty_class, MKDEV(driver->major, driver->minor_start) + index);
 	if (!(driver->flags & TTY_DRIVER_DYNAMIC_ALLOC)) {
 		cdev_del(driver->cdevs[index]);
 		driver->cdevs[index] = NULL;
@@ -3510,13 +3507,14 @@ static char *tty_devnode(const struct device *dev, umode_t *mode)
 	return NULL;
 }
 
+const struct class tty_class = {
+	.name		= "tty",
+	.devnode	= tty_devnode,
+};
+
 static int __init tty_class_init(void)
 {
-	tty_class = class_create("tty");
-	if (IS_ERR(tty_class))
-		return PTR_ERR(tty_class);
-	tty_class->devnode = tty_devnode;
-	return 0;
+	return class_register(&tty_class);
 }
 
 postcore_initcall(tty_class_init);
@@ -3643,13 +3641,13 @@ int __init tty_init(void)
 	if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) ||
 	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0)
 		panic("Couldn't register /dev/tty driver\n");
-	device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty");
+	device_create(&tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty");
 
 	cdev_init(&console_cdev, &console_fops);
 	if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) ||
 	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0)
 		panic("Couldn't register /dev/console driver\n");
-	consdev = device_create_with_groups(tty_class, NULL,
+	consdev = device_create_with_groups(&tty_class, NULL,
 					    MKDEV(TTYAUX_MAJOR, 1), NULL,
 					    cons_dev_groups, "console");
 	if (IS_ERR(consdev))
drivers/tty/vt/vt.c +1 -1
index 5496bf4b76ec..02f4b6be8584 100644
@@ -3539,7 +3539,7 @@ int __init vty_init(const struct file_operations *console_fops)
 	if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) ||
 	    register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
 		panic("Couldn't register /dev/tty0 driver\n");
-	tty0dev = device_create_with_groups(tty_class, NULL,
+	tty0dev = device_create_with_groups(&tty_class, NULL,
 					    MKDEV(TTY_MAJOR, 0), NULL,
 					    vt_dev_groups, "tty0");
 	if (IS_ERR(tty0dev))
include/linux/tty.h +1 -1
index 093935e97f42..121eb4b0d325 100644
@@ -387,7 +387,7 @@ extern struct ktermios tty_std_termios;
 
 int vcs_init(void);
 
-extern struct class *tty_class;
+extern const struct class tty_class;
 
 /**
  *	tty_kref_get		-	get a tty reference
Signature · 1 line
2.40.0
maintainer Reviewed-by on v1 5/5
#12 lore raw

Re: [PATCH 5/5] tty: make tty_class a static const structure

Quoted 5 lines · Greg Kroah-Hartman

Now that the driver core allows for struct class to be in read-only memory, move the tty_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time.

Quoted 8 lines
Cc Jiri Slaby <[email protected]>
Cc "Ilpo Järvinen" <[email protected]>

---
Jiri and Ilpo, this is part of the larger driver-core changes to make it possible to move struct class into read-only memory and is used as proof that this all works properly. I'll take it throught the driver-core tree as it shoudn't conflict with any tty.git changes.

FWIW

thanks,

Signature · 2 lines
js
suse labs