mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] driver: base: class: remove device from class on registration
Date: Thu, 20 Mar 2025 06:20:27 +0100	[thread overview]
Message-ID: <20250320052027.1731144-1-a.fatoum@pengutronix.de> (raw)

class_remove_device is the exception and normally, a device class
doesn't change for the lifetime of a device after it's set the first
time and removal from a class is done alongside removal of the device
itself.

Let's therefore move the removal from class into core driver code.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/base/class.c       | 11 -----------
 drivers/base/driver.c      |  2 ++
 drivers/watchdog/wd_core.c |  2 +-
 include/device.h           |  2 --
 net/eth.c                  |  2 --
 5 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index d0765e496f9e..b7cc58ce0750 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -48,14 +48,3 @@ int class_register_device(struct class *class,
 	class_add_device(class, class_dev);
 	return 0;
 }
-
-void class_unregister_device(struct device *class_dev)
-{
-	list_del(&class_dev->class_list);
-	unregister_device(class_dev);
-}
-
-void class_remove_device(struct class *class, struct device *dev)
-{
-	list_del(&dev->class_list);
-}
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 603fc9d9cb0a..6363b3948f1d 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -265,6 +265,7 @@ int register_device(struct device *new_device)
 	INIT_LIST_HEAD(&new_device->parameters);
 	INIT_LIST_HEAD(&new_device->active);
 	INIT_LIST_HEAD(&new_device->bus_list);
+	INIT_LIST_HEAD(&new_device->class_list);
 
 	if (new_device->bus) {
 		if (!new_device->parent)
@@ -318,6 +319,7 @@ int unregister_device(struct device *old_dev)
 
 	list_del(&old_dev->list);
 	list_del(&old_dev->bus_list);
+	list_del(&old_dev->class_list);
 	list_del(&old_dev->active);
 
 	/* remove device from parents child list */
diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c
index 27371672f39c..6e239edf612d 100644
--- a/drivers/watchdog/wd_core.c
+++ b/drivers/watchdog/wd_core.c
@@ -255,7 +255,7 @@ int watchdog_deregister(struct watchdog *wd)
 		poller_async_unregister(&wd->poller);
 	}
 
-	class_remove_device(&watchdog_class, &wd->dev);
+	list_del_init(&wd->dev.class_list);
 
 	return 0;
 }
diff --git a/include/device.h b/include/device.h
index d3936d3b3ad6..e0c130551f9a 100644
--- a/include/device.h
+++ b/include/device.h
@@ -128,11 +128,9 @@ void class_register(struct class *class);
 	pure_initcall(register_##_name);
 
 int class_add_device(struct class *class, struct device *dev);
-void class_remove_device(struct class *class, struct device *dev);
 
 int class_register_device(struct class *class, struct device *class_dev,
 			  const char *name);
-void class_unregister_device(struct device *class_dev);
 
 extern struct list_head class_list;
 #define class_for_each_device(class, dev) list_for_each_entry((dev), &(class)->devices, class_list)
diff --git a/net/eth.c b/net/eth.c
index e4025753518c..bc2527de3670 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -539,8 +539,6 @@ void eth_unregister(struct eth_device *edev)
 	if (IS_ENABLED(CONFIG_OFDEVICE))
 		free_const(edev->nodepath);
 
-	class_remove_device(&eth_class, &edev->dev);
-
 	free(edev->devname);
 
 	unregister_device(&edev->dev);
-- 
2.39.5




                 reply	other threads:[~2025-03-20  5:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20250320052027.1731144-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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