public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH 1/3] staging: greybus: raw: make raw_class constant
@ 2023-10-05 13:58 Greg Kroah-Hartman
  2023-10-05 13:58 ` [PATCH 2/3] staging: greybus: authentication: make cap_class constant Greg Kroah-Hartman
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Greg Kroah-Hartman @ 2023-10-05 13:58 UTC (permalink / raw)
  To: greybus-dev, linux-staging
  Cc: linux-kernel, Greg Kroah-Hartman, Johan Hovold, Alex Elder

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: Johan Hovold <johan@kernel.org>
Cc: Alex Elder <elder@kernel.org>
Cc: greybus-dev@lists.linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/staging/greybus/raw.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/greybus/raw.c b/drivers/staging/greybus/raw.c
index 8bca8cb12cc6..a00978c8e1d2 100644
--- a/drivers/staging/greybus/raw.c
+++ b/drivers/staging/greybus/raw.c
@@ -32,7 +32,10 @@ struct raw_data {
 	u8 data[];
 };
 
-static struct class *raw_class;
+static const struct class raw_class = {
+	.name = "gb_raw",
+};
+
 static int raw_major;
 static const struct file_operations raw_fops;
 static DEFINE_IDA(minors);
@@ -195,7 +198,7 @@ static int gb_raw_probe(struct gb_bundle *bundle,
 	if (retval)
 		goto error_connection_disable;
 
-	raw->device = device_create(raw_class, &connection->bundle->dev,
+	raw->device = device_create(&raw_class, &connection->bundle->dev,
 				    raw->dev, raw, "gb!raw%d", minor);
 	if (IS_ERR(raw->device)) {
 		retval = PTR_ERR(raw->device);
@@ -229,7 +232,7 @@ static void gb_raw_disconnect(struct gb_bundle *bundle)
 	struct raw_data *temp;
 
 	// FIXME - handle removing a connection when the char device node is open.
-	device_destroy(raw_class, raw->dev);
+	device_destroy(&raw_class, raw->dev);
 	cdev_del(&raw->cdev);
 	gb_connection_disable(connection);
 	ida_simple_remove(&minors, MINOR(raw->dev));
@@ -340,11 +343,9 @@ static int raw_init(void)
 	dev_t dev;
 	int retval;
 
-	raw_class = class_create("gb_raw");
-	if (IS_ERR(raw_class)) {
-		retval = PTR_ERR(raw_class);
+	retval = class_register(&raw_class);
+	if (retval)
 		goto error_class;
-	}
 
 	retval = alloc_chrdev_region(&dev, 0, NUM_MINORS, "gb_raw");
 	if (retval < 0)
@@ -361,7 +362,7 @@ static int raw_init(void)
 error_gb:
 	unregister_chrdev_region(dev, NUM_MINORS);
 error_chrdev:
-	class_destroy(raw_class);
+	class_unregister(&raw_class);
 error_class:
 	return retval;
 }
@@ -371,7 +372,7 @@ static void __exit raw_exit(void)
 {
 	greybus_deregister(&gb_raw_driver);
 	unregister_chrdev_region(MKDEV(raw_major, 0), NUM_MINORS);
-	class_destroy(raw_class);
+	class_unregister(&raw_class);
 	ida_destroy(&minors);
 }
 module_exit(raw_exit);
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] staging: greybus: authentication: make cap_class constant
  2023-10-05 13:58 [PATCH 1/3] staging: greybus: raw: make raw_class constant Greg Kroah-Hartman
@ 2023-10-05 13:58 ` Greg Kroah-Hartman
  2023-10-05 15:50   ` Johan Hovold
  2023-10-05 13:58 ` [PATCH 3/3] staging: greybus: fw-management: make fw_mgmt_class constant Greg Kroah-Hartman
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Greg Kroah-Hartman @ 2023-10-05 13:58 UTC (permalink / raw)
  To: greybus-dev, linux-staging
  Cc: linux-kernel, Greg Kroah-Hartman, Johan Hovold, Alex Elder

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: Johan Hovold <johan@kernel.org>
Cc: Alex Elder <elder@kernel.org>
Cc: greybus-dev@lists.linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/staging/greybus/authentication.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/greybus/authentication.c b/drivers/staging/greybus/authentication.c
index 7e01790a4659..b67315641d18 100644
--- a/drivers/staging/greybus/authentication.c
+++ b/drivers/staging/greybus/authentication.c
@@ -36,7 +36,10 @@ struct gb_cap {
 	dev_t			dev_num;
 };
 
-static struct class *cap_class;
+static const struct class cap_class = {
+	.name = "gb_authenticate",
+};
+
 static dev_t cap_dev_num;
 static DEFINE_IDA(cap_minors_map);
 static LIST_HEAD(cap_list);
@@ -336,7 +339,7 @@ int gb_cap_connection_init(struct gb_connection *connection)
 		goto err_remove_ida;
 
 	/* Add a soft link to the previously added char-dev within the bundle */
-	cap->class_device = device_create(cap_class, cap->parent, cap->dev_num,
+	cap->class_device = device_create(&cap_class, cap->parent, cap->dev_num,
 					  NULL, "gb-authenticate-%d", minor);
 	if (IS_ERR(cap->class_device)) {
 		ret = PTR_ERR(cap->class_device);
@@ -370,7 +373,7 @@ void gb_cap_connection_exit(struct gb_connection *connection)
 
 	cap = gb_connection_get_data(connection);
 
-	device_destroy(cap_class, cap->dev_num);
+	device_destroy(&cap_class, cap->dev_num);
 	cdev_del(&cap->cdev);
 	ida_simple_remove(&cap_minors_map, MINOR(cap->dev_num));
 
@@ -402,9 +405,9 @@ int cap_init(void)
 {
 	int ret;
 
-	cap_class = class_create("gb_authenticate");
-	if (IS_ERR(cap_class))
-		return PTR_ERR(cap_class);
+	ret = class_register(&cap_class);
+	if (ret)
+		return ret;
 
 	ret = alloc_chrdev_region(&cap_dev_num, 0, NUM_MINORS,
 				  "gb_authenticate");
@@ -414,13 +417,13 @@ int cap_init(void)
 	return 0;
 
 err_remove_class:
-	class_destroy(cap_class);
+	class_unregister(&cap_class);
 	return ret;
 }
 
 void cap_exit(void)
 {
 	unregister_chrdev_region(cap_dev_num, NUM_MINORS);
-	class_destroy(cap_class);
+	class_unregister(&cap_class);
 	ida_destroy(&cap_minors_map);
 }
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] staging: greybus: fw-management: make fw_mgmt_class constant
  2023-10-05 13:58 [PATCH 1/3] staging: greybus: raw: make raw_class constant Greg Kroah-Hartman
  2023-10-05 13:58 ` [PATCH 2/3] staging: greybus: authentication: make cap_class constant Greg Kroah-Hartman
@ 2023-10-05 13:58 ` Greg Kroah-Hartman
  2023-10-05 15:51   ` Johan Hovold
  2023-10-05 15:49 ` [PATCH 1/3] staging: greybus: raw: make raw_class constant Johan Hovold
  2023-10-06 13:12 ` Deepak R Varma
  3 siblings, 1 reply; 8+ messages in thread
From: Greg Kroah-Hartman @ 2023-10-05 13:58 UTC (permalink / raw)
  To: greybus-dev, linux-staging
  Cc: linux-kernel, Greg Kroah-Hartman, Johan Hovold, Alex Elder

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: Johan Hovold <johan@kernel.org>
Cc: Alex Elder <elder@kernel.org>
Cc: greybus-dev@lists.linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/staging/greybus/fw-management.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/greybus/fw-management.c b/drivers/staging/greybus/fw-management.c
index cd9141e4b794..93137a3c4907 100644
--- a/drivers/staging/greybus/fw-management.c
+++ b/drivers/staging/greybus/fw-management.c
@@ -55,7 +55,10 @@ struct fw_mgmt {
  */
 #define NUM_MINORS		U8_MAX
 
-static struct class *fw_mgmt_class;
+static const struct class fw_mgmt_class = {
+	.name = "gb_fw_mgmt",
+};
+
 static dev_t fw_mgmt_dev_num;
 static DEFINE_IDA(fw_mgmt_minors_map);
 static LIST_HEAD(fw_mgmt_list);
@@ -629,7 +632,7 @@ int gb_fw_mgmt_connection_init(struct gb_connection *connection)
 		goto err_remove_ida;
 
 	/* Add a soft link to the previously added char-dev within the bundle */
-	fw_mgmt->class_device = device_create(fw_mgmt_class, fw_mgmt->parent,
+	fw_mgmt->class_device = device_create(&fw_mgmt_class, fw_mgmt->parent,
 					      fw_mgmt->dev_num, NULL,
 					      "gb-fw-mgmt-%d", minor);
 	if (IS_ERR(fw_mgmt->class_device)) {
@@ -664,7 +667,7 @@ void gb_fw_mgmt_connection_exit(struct gb_connection *connection)
 
 	fw_mgmt = gb_connection_get_data(connection);
 
-	device_destroy(fw_mgmt_class, fw_mgmt->dev_num);
+	device_destroy(&fw_mgmt_class, fw_mgmt->dev_num);
 	cdev_del(&fw_mgmt->cdev);
 	ida_simple_remove(&fw_mgmt_minors_map, MINOR(fw_mgmt->dev_num));
 
@@ -696,9 +699,9 @@ int fw_mgmt_init(void)
 {
 	int ret;
 
-	fw_mgmt_class = class_create("gb_fw_mgmt");
-	if (IS_ERR(fw_mgmt_class))
-		return PTR_ERR(fw_mgmt_class);
+	ret = class_register(&fw_mgmt_class);
+	if (ret)
+		return ret;
 
 	ret = alloc_chrdev_region(&fw_mgmt_dev_num, 0, NUM_MINORS,
 				  "gb_fw_mgmt");
@@ -708,13 +711,13 @@ int fw_mgmt_init(void)
 	return 0;
 
 err_remove_class:
-	class_destroy(fw_mgmt_class);
+	class_unregister(&fw_mgmt_class);
 	return ret;
 }
 
 void fw_mgmt_exit(void)
 {
 	unregister_chrdev_region(fw_mgmt_dev_num, NUM_MINORS);
-	class_destroy(fw_mgmt_class);
+	class_unregister(&fw_mgmt_class);
 	ida_destroy(&fw_mgmt_minors_map);
 }
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] staging: greybus: raw: make raw_class constant
  2023-10-05 13:58 [PATCH 1/3] staging: greybus: raw: make raw_class constant Greg Kroah-Hartman
  2023-10-05 13:58 ` [PATCH 2/3] staging: greybus: authentication: make cap_class constant Greg Kroah-Hartman
  2023-10-05 13:58 ` [PATCH 3/3] staging: greybus: fw-management: make fw_mgmt_class constant Greg Kroah-Hartman
@ 2023-10-05 15:49 ` Johan Hovold
  2023-10-06 13:12 ` Deepak R Varma
  3 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2023-10-05 15:49 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: greybus-dev, linux-staging, linux-kernel, Alex Elder

On Thu, Oct 05, 2023 at 03:58:34PM +0200, Greg Kroah-Hartman wrote:
> 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: Johan Hovold <johan@kernel.org>
> Cc: Alex Elder <elder@kernel.org>
> Cc: greybus-dev@lists.linaro.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Reviewed-by: Johan Hovold <johan@kernel.org>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] staging: greybus: authentication: make cap_class constant
  2023-10-05 13:58 ` [PATCH 2/3] staging: greybus: authentication: make cap_class constant Greg Kroah-Hartman
@ 2023-10-05 15:50   ` Johan Hovold
  0 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2023-10-05 15:50 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: greybus-dev, linux-staging, linux-kernel, Alex Elder

On Thu, Oct 05, 2023 at 03:58:35PM +0200, Greg Kroah-Hartman wrote:
> 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: Johan Hovold <johan@kernel.org>
> Cc: Alex Elder <elder@kernel.org>
> Cc: greybus-dev@lists.linaro.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Reviewed-by: Johan Hovold <johan@kernel.org>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] staging: greybus: fw-management: make fw_mgmt_class constant
  2023-10-05 13:58 ` [PATCH 3/3] staging: greybus: fw-management: make fw_mgmt_class constant Greg Kroah-Hartman
@ 2023-10-05 15:51   ` Johan Hovold
  0 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2023-10-05 15:51 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: greybus-dev, linux-staging, linux-kernel, Alex Elder

On Thu, Oct 05, 2023 at 03:58:36PM +0200, Greg Kroah-Hartman wrote:
> 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: Johan Hovold <johan@kernel.org>
> Cc: Alex Elder <elder@kernel.org>
> Cc: greybus-dev@lists.linaro.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Reviewed-by: Johan Hovold <johan@kernel.org>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] staging: greybus: raw: make raw_class constant
  2023-10-05 13:58 [PATCH 1/3] staging: greybus: raw: make raw_class constant Greg Kroah-Hartman
                   ` (2 preceding siblings ...)
  2023-10-05 15:49 ` [PATCH 1/3] staging: greybus: raw: make raw_class constant Johan Hovold
@ 2023-10-06 13:12 ` Deepak R Varma
  2023-10-06 13:20   ` Greg Kroah-Hartman
  3 siblings, 1 reply; 8+ messages in thread
From: Deepak R Varma @ 2023-10-06 13:12 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: greybus-dev, linux-staging, linux-kernel, Johan Hovold,
	Alex Elder

On Thu, Oct 05, 2023 at 03:58:34PM +0200, Greg Kroah-Hartman wrote:
> Now that the driver core allows for struct class to be in read-only

Hello Greg,
When you say "Now", has anything changed recently that facilitates this
improvement? Where can I read more about this change?

Thank you,
deepak.

> 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: Johan Hovold <johan@kernel.org>
> Cc: Alex Elder <elder@kernel.org>
> Cc: greybus-dev@lists.linaro.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] staging: greybus: raw: make raw_class constant
  2023-10-06 13:12 ` Deepak R Varma
@ 2023-10-06 13:20   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 8+ messages in thread
From: Greg Kroah-Hartman @ 2023-10-06 13:20 UTC (permalink / raw)
  To: Deepak R Varma
  Cc: greybus-dev, linux-staging, linux-kernel, Johan Hovold,
	Alex Elder

On Fri, Oct 06, 2023 at 06:42:00PM +0530, Deepak R Varma wrote:
> On Thu, Oct 05, 2023 at 03:58:34PM +0200, Greg Kroah-Hartman wrote:
> > Now that the driver core allows for struct class to be in read-only
> 
> Hello Greg,
> When you say "Now", has anything changed recently that facilitates this
> improvement?

Yes.  Well, it showed up in the 6.4 kernel, so not that long ago.

> Where can I read more about this change?

Running:
	git log --oneline --author=gregkh v6.3..v6.4 drivers/base/
will show you the some of work that happened here to make this possible.
There was work done to the driver core, and the kobject core in earlier
kernel releases that the changes in 6.4 built on top of.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-10-06 13:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-05 13:58 [PATCH 1/3] staging: greybus: raw: make raw_class constant Greg Kroah-Hartman
2023-10-05 13:58 ` [PATCH 2/3] staging: greybus: authentication: make cap_class constant Greg Kroah-Hartman
2023-10-05 15:50   ` Johan Hovold
2023-10-05 13:58 ` [PATCH 3/3] staging: greybus: fw-management: make fw_mgmt_class constant Greg Kroah-Hartman
2023-10-05 15:51   ` Johan Hovold
2023-10-05 15:49 ` [PATCH 1/3] staging: greybus: raw: make raw_class constant Johan Hovold
2023-10-06 13:12 ` Deepak R Varma
2023-10-06 13:20   ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox