* [PATCH] net: phy: core: make phy_class constant
@ 2024-03-05 18:18 Ricardo B. Marliere
2024-04-05 16:56 ` Vinod Koul
2024-04-06 9:19 ` Vinod Koul
0 siblings, 2 replies; 5+ messages in thread
From: Ricardo B. Marliere @ 2024-03-05 18:18 UTC (permalink / raw)
To: Vinod Koul, Kishon Vijay Abraham I
Cc: linux-phy, linux-kernel, Greg Kroah-Hartman, Ricardo B. Marliere
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 phy_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/phy/phy-core.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 7f9b4de772ee..5776d44fd32f 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -20,7 +20,12 @@
#include <linux/pm_runtime.h>
#include <linux/regulator/consumer.h>
-static struct class *phy_class;
+static void phy_release(struct device *dev);
+static const struct class phy_class = {
+ .name = "phy",
+ .dev_release = phy_release,
+};
+
static struct dentry *phy_debugfs_root;
static DEFINE_MUTEX(phy_provider_mutex);
static LIST_HEAD(phy_provider_list);
@@ -706,7 +711,7 @@ struct phy *of_phy_simple_xlate(struct device *dev,
struct phy *phy;
struct class_dev_iter iter;
- class_dev_iter_init(&iter, phy_class, NULL, NULL);
+ class_dev_iter_init(&iter, &phy_class, NULL, NULL);
while ((dev = class_dev_iter_next(&iter))) {
phy = to_phy(dev);
if (args->np != phy->dev.of_node)
@@ -969,7 +974,7 @@ struct phy *phy_create(struct device *dev, struct device_node *node,
device_initialize(&phy->dev);
mutex_init(&phy->mutex);
- phy->dev.class = phy_class;
+ phy->dev.class = &phy_class;
phy->dev.parent = dev;
phy->dev.of_node = node ?: dev->of_node;
phy->id = id;
@@ -1238,14 +1243,13 @@ static void phy_release(struct device *dev)
static int __init phy_core_init(void)
{
- phy_class = class_create("phy");
- if (IS_ERR(phy_class)) {
- pr_err("failed to create phy class --> %ld\n",
- PTR_ERR(phy_class));
- return PTR_ERR(phy_class);
- }
+ int err;
- phy_class->dev_release = phy_release;
+ err = class_register(&phy_class);
+ if (err) {
+ pr_err("failed to register phy class");
+ return err;
+ }
phy_debugfs_root = debugfs_create_dir("phy", NULL);
@@ -1256,6 +1260,6 @@ device_initcall(phy_core_init);
static void __exit phy_core_exit(void)
{
debugfs_remove_recursive(phy_debugfs_root);
- class_destroy(phy_class);
+ class_unregister(&phy_class);
}
module_exit(phy_core_exit);
---
base-commit: 00ca8a15dafa990d391abc37f2b8256ddf909b35
change-id: 20240305-class_cleanup-phy-668a148b2acd
Best regards,
--
Ricardo B. Marliere <ricardo@marliere.net>
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] net: phy: core: make phy_class constant
2024-03-05 18:18 [PATCH] net: phy: core: make phy_class constant Ricardo B. Marliere
@ 2024-04-05 16:56 ` Vinod Koul
2024-04-05 17:08 ` Ricardo B. Marliere
2024-04-06 9:19 ` Vinod Koul
1 sibling, 1 reply; 5+ messages in thread
From: Vinod Koul @ 2024-04-05 16:56 UTC (permalink / raw)
To: Ricardo B. Marliere
Cc: Kishon Vijay Abraham I, linux-phy, linux-kernel,
Greg Kroah-Hartman
On 05-03-24, 15:18, Ricardo B. Marliere wrote:
> 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 phy_class structure to be declared at build time
> placing it into read-only memory, instead of having to be dynamically
> allocated at boot time.
why is this tagged net: ...??
This has nothing to do with networking!
>
> 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/phy/phy-core.c | 26 +++++++++++++++-----------
> 1 file changed, 15 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index 7f9b4de772ee..5776d44fd32f 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
> @@ -20,7 +20,12 @@
> #include <linux/pm_runtime.h>
> #include <linux/regulator/consumer.h>
>
> -static struct class *phy_class;
> +static void phy_release(struct device *dev);
> +static const struct class phy_class = {
> + .name = "phy",
> + .dev_release = phy_release,
> +};
> +
> static struct dentry *phy_debugfs_root;
> static DEFINE_MUTEX(phy_provider_mutex);
> static LIST_HEAD(phy_provider_list);
> @@ -706,7 +711,7 @@ struct phy *of_phy_simple_xlate(struct device *dev,
> struct phy *phy;
> struct class_dev_iter iter;
>
> - class_dev_iter_init(&iter, phy_class, NULL, NULL);
> + class_dev_iter_init(&iter, &phy_class, NULL, NULL);
> while ((dev = class_dev_iter_next(&iter))) {
> phy = to_phy(dev);
> if (args->np != phy->dev.of_node)
> @@ -969,7 +974,7 @@ struct phy *phy_create(struct device *dev, struct device_node *node,
> device_initialize(&phy->dev);
> mutex_init(&phy->mutex);
>
> - phy->dev.class = phy_class;
> + phy->dev.class = &phy_class;
> phy->dev.parent = dev;
> phy->dev.of_node = node ?: dev->of_node;
> phy->id = id;
> @@ -1238,14 +1243,13 @@ static void phy_release(struct device *dev)
>
> static int __init phy_core_init(void)
> {
> - phy_class = class_create("phy");
> - if (IS_ERR(phy_class)) {
> - pr_err("failed to create phy class --> %ld\n",
> - PTR_ERR(phy_class));
> - return PTR_ERR(phy_class);
> - }
> + int err;
>
> - phy_class->dev_release = phy_release;
> + err = class_register(&phy_class);
> + if (err) {
> + pr_err("failed to register phy class");
> + return err;
> + }
>
> phy_debugfs_root = debugfs_create_dir("phy", NULL);
>
> @@ -1256,6 +1260,6 @@ device_initcall(phy_core_init);
> static void __exit phy_core_exit(void)
> {
> debugfs_remove_recursive(phy_debugfs_root);
> - class_destroy(phy_class);
> + class_unregister(&phy_class);
> }
> module_exit(phy_core_exit);
>
> ---
> base-commit: 00ca8a15dafa990d391abc37f2b8256ddf909b35
> change-id: 20240305-class_cleanup-phy-668a148b2acd
>
> Best regards,
> --
> Ricardo B. Marliere <ricardo@marliere.net>
--
~Vinod
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] net: phy: core: make phy_class constant
2024-04-05 16:56 ` Vinod Koul
@ 2024-04-05 17:08 ` Ricardo B. Marliere
2024-04-06 6:24 ` Vinod Koul
0 siblings, 1 reply; 5+ messages in thread
From: Ricardo B. Marliere @ 2024-04-05 17:08 UTC (permalink / raw)
To: Vinod Koul
Cc: Kishon Vijay Abraham I, linux-phy, linux-kernel,
Greg Kroah-Hartman
On 5 Apr 22:26, Vinod Koul wrote:
> On 05-03-24, 15:18, Ricardo B. Marliere wrote:
> > 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 phy_class structure to be declared at build time
> > placing it into read-only memory, instead of having to be dynamically
> > allocated at boot time.
>
> why is this tagged net: ...??
> This has nothing to do with networking!
Hi Vinod.
My mistake, it was due to poor local tree management. Please let me know
if you can review and take it as is, changing the subject line, or if
you want me to resend.
Best regards,
- Ricardo.
>
> >
> > 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/phy/phy-core.c | 26 +++++++++++++++-----------
> > 1 file changed, 15 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> > index 7f9b4de772ee..5776d44fd32f 100644
> > --- a/drivers/phy/phy-core.c
> > +++ b/drivers/phy/phy-core.c
> > @@ -20,7 +20,12 @@
> > #include <linux/pm_runtime.h>
> > #include <linux/regulator/consumer.h>
> >
> > -static struct class *phy_class;
> > +static void phy_release(struct device *dev);
> > +static const struct class phy_class = {
> > + .name = "phy",
> > + .dev_release = phy_release,
> > +};
> > +
> > static struct dentry *phy_debugfs_root;
> > static DEFINE_MUTEX(phy_provider_mutex);
> > static LIST_HEAD(phy_provider_list);
> > @@ -706,7 +711,7 @@ struct phy *of_phy_simple_xlate(struct device *dev,
> > struct phy *phy;
> > struct class_dev_iter iter;
> >
> > - class_dev_iter_init(&iter, phy_class, NULL, NULL);
> > + class_dev_iter_init(&iter, &phy_class, NULL, NULL);
> > while ((dev = class_dev_iter_next(&iter))) {
> > phy = to_phy(dev);
> > if (args->np != phy->dev.of_node)
> > @@ -969,7 +974,7 @@ struct phy *phy_create(struct device *dev, struct device_node *node,
> > device_initialize(&phy->dev);
> > mutex_init(&phy->mutex);
> >
> > - phy->dev.class = phy_class;
> > + phy->dev.class = &phy_class;
> > phy->dev.parent = dev;
> > phy->dev.of_node = node ?: dev->of_node;
> > phy->id = id;
> > @@ -1238,14 +1243,13 @@ static void phy_release(struct device *dev)
> >
> > static int __init phy_core_init(void)
> > {
> > - phy_class = class_create("phy");
> > - if (IS_ERR(phy_class)) {
> > - pr_err("failed to create phy class --> %ld\n",
> > - PTR_ERR(phy_class));
> > - return PTR_ERR(phy_class);
> > - }
> > + int err;
> >
> > - phy_class->dev_release = phy_release;
> > + err = class_register(&phy_class);
> > + if (err) {
> > + pr_err("failed to register phy class");
> > + return err;
> > + }
> >
> > phy_debugfs_root = debugfs_create_dir("phy", NULL);
> >
> > @@ -1256,6 +1260,6 @@ device_initcall(phy_core_init);
> > static void __exit phy_core_exit(void)
> > {
> > debugfs_remove_recursive(phy_debugfs_root);
> > - class_destroy(phy_class);
> > + class_unregister(&phy_class);
> > }
> > module_exit(phy_core_exit);
> >
> > ---
> > base-commit: 00ca8a15dafa990d391abc37f2b8256ddf909b35
> > change-id: 20240305-class_cleanup-phy-668a148b2acd
> >
> > Best regards,
> > --
> > Ricardo B. Marliere <ricardo@marliere.net>
>
> --
> ~Vinod
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] net: phy: core: make phy_class constant
2024-04-05 17:08 ` Ricardo B. Marliere
@ 2024-04-06 6:24 ` Vinod Koul
0 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2024-04-06 6:24 UTC (permalink / raw)
To: Ricardo B. Marliere
Cc: Kishon Vijay Abraham I, linux-phy, linux-kernel,
Greg Kroah-Hartman
On 05-04-24, 14:08, Ricardo B. Marliere wrote:
> On 5 Apr 22:26, Vinod Koul wrote:
> > On 05-03-24, 15:18, Ricardo B. Marliere wrote:
> > > 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 phy_class structure to be declared at build time
> > > placing it into read-only memory, instead of having to be dynamically
> > > allocated at boot time.
> >
> > why is this tagged net: ...??
> > This has nothing to do with networking!
>
> Hi Vinod.
>
> My mistake, it was due to poor local tree management. Please let me know
> if you can review and take it as is, changing the subject line, or if
> you want me to resend.
No I have applied this after dropping the net tag
--
~Vinod
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net: phy: core: make phy_class constant
2024-03-05 18:18 [PATCH] net: phy: core: make phy_class constant Ricardo B. Marliere
2024-04-05 16:56 ` Vinod Koul
@ 2024-04-06 9:19 ` Vinod Koul
1 sibling, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2024-04-06 9:19 UTC (permalink / raw)
To: Kishon Vijay Abraham I, Ricardo B. Marliere
Cc: linux-phy, linux-kernel, Greg Kroah-Hartman
On Tue, 05 Mar 2024 15:18:51 -0300, Ricardo B. Marliere wrote:
> 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 phy_class structure to be declared at build time
> placing it into read-only memory, instead of having to be dynamically
> allocated at boot time.
>
>
> [...]
Applied, thanks!
[1/1] net: phy: core: make phy_class constant
commit: db704bf6dccc8fef77ee4a8326bf2013b828205b
Best regards,
--
~Vinod
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-04-06 9:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-05 18:18 [PATCH] net: phy: core: make phy_class constant Ricardo B. Marliere
2024-04-05 16:56 ` Vinod Koul
2024-04-05 17:08 ` Ricardo B. Marliere
2024-04-06 6:24 ` Vinod Koul
2024-04-06 9:19 ` Vinod Koul
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox