linux-ppp.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ricardo B. Marliere" <ricardo@marliere.net>
To: Yisen Zhuang <yisen.zhuang@huawei.com>,
	 Salil Mehta <salil.mehta@huawei.com>,
	 "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	 Loic Poulain <loic.poulain@linaro.org>,
	 Sergey Ryazanov <ryazanov.s.a@gmail.com>,
	 Johannes Berg <johannes@sipsolutions.net>,
	 Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	netdev@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-ppp@vger.kernel.org,
	 "Ricardo B. Marliere" <ricardo@marliere.net>
Subject: [PATCH net-next 1/6] net: hns: make hnae_class constant
Date: Sat, 02 Mar 2024 14:05:57 -0300	[thread overview]
Message-ID: <20240302-class_cleanup-net-next-v1-1-8fa378595b93@marliere.net> (raw)
In-Reply-To: <20240302-class_cleanup-net-next-v1-0-8fa378595b93@marliere.net>

Since commit 43a7206b0963 ("driver core: class: make class_register() take
a const *"), the driver core allows for struct class to be in read-only
memory, so move the hnae_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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net>
---
 drivers/net/ethernet/hisilicon/hns/hnae.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.c b/drivers/net/ethernet/hisilicon/hns/hnae.c
index 8a1027ad340d..d4293f76d69d 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.c
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.c
@@ -12,7 +12,9 @@
 
 #define cls_to_ae_dev(dev) container_of(dev, struct hnae_ae_dev, cls_dev)
 
-static struct class *hnae_class;
+static const struct class hnae_class = {
+	.name = "hnae",
+};
 
 static void
 hnae_list_add(spinlock_t *lock, struct list_head *node, struct list_head *head)
@@ -111,7 +113,7 @@ static struct hnae_ae_dev *find_ae(const struct fwnode_handle *fwnode)
 
 	WARN_ON(!fwnode);
 
-	dev = class_find_device(hnae_class, NULL, fwnode, __ae_match);
+	dev = class_find_device(&hnae_class, NULL, fwnode, __ae_match);
 
 	return dev ? cls_to_ae_dev(dev) : NULL;
 }
@@ -415,7 +417,7 @@ int hnae_ae_register(struct hnae_ae_dev *hdev, struct module *owner)
 	hdev->owner = owner;
 	hdev->id = (int)atomic_inc_return(&id);
 	hdev->cls_dev.parent = hdev->dev;
-	hdev->cls_dev.class = hnae_class;
+	hdev->cls_dev.class = &hnae_class;
 	hdev->cls_dev.release = hnae_release;
 	(void)dev_set_name(&hdev->cls_dev, "hnae%d", hdev->id);
 	ret = device_register(&hdev->cls_dev);
@@ -448,13 +450,12 @@ EXPORT_SYMBOL(hnae_ae_unregister);
 
 static int __init hnae_init(void)
 {
-	hnae_class = class_create("hnae");
-	return PTR_ERR_OR_ZERO(hnae_class);
+	return class_register(&hnae_class);
 }
 
 static void __exit hnae_exit(void)
 {
-	class_destroy(hnae_class);
+	class_unregister(&hnae_class);
 }
 
 subsys_initcall(hnae_init);

-- 
2.43.0


  reply	other threads:[~2024-03-02 17:06 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-02 17:05 [PATCH net-next 0/6] net: constify struct class usage Ricardo B. Marliere
2024-03-02 17:05 ` Ricardo B. Marliere [this message]
2024-03-04 17:52   ` [PATCH net-next 1/6] net: hns: make hnae_class constant Simon Horman
2024-03-02 17:05 ` [PATCH net-next 2/6] net: wan: framer: make framer_class constant Ricardo B. Marliere
2024-03-04 17:52   ` Simon Horman
2024-03-05  7:17     ` Herve Codina
2024-03-02 17:05 ` [PATCH net-next 3/6] net: ppp: make ppp_class constant Ricardo B. Marliere
2024-03-04 17:53   ` Simon Horman
2024-03-04 20:19   ` Breno Leitao
2024-03-02 17:06 ` [PATCH net-next 4/6] net: wwan: hwsim: make wwan_hwsim_class constant Ricardo B. Marliere
2024-03-02 17:06 ` [PATCH net-next 5/6] net: wwan: core: make wwan_class constant Ricardo B. Marliere
2024-03-02 17:06 ` [PATCH net-next 6/6] nfc: core: make nfc_class constant Ricardo B. Marliere
2024-03-04 17:53   ` Simon Horman
2024-03-04 20:19   ` Breno Leitao
2024-03-05 20:00 ` [PATCH net-next 0/6] net: constify struct class usage patchwork-bot+netdevbpf

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=20240302-class_cleanup-net-next-v1-1-8fa378595b93@marliere.net \
    --to=ricardo@marliere.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=johannes@sipsolutions.net \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-ppp@vger.kernel.org \
    --cc=loic.poulain@linaro.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ryazanov.s.a@gmail.com \
    --cc=salil.mehta@huawei.com \
    --cc=yisen.zhuang@huawei.com \
    /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;
as well as URLs for NNTP newsgroup(s).