* [PATCH 0/2] mips: constify struct class usage
@ 2024-03-05 13:37 Ricardo B. Marliere
2024-03-05 13:37 ` [PATCH 1/2] mips: mt: make mt_class constant Ricardo B. Marliere
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ricardo B. Marliere @ 2024-03-05 13:37 UTC (permalink / raw
To: Thomas Bogendoerfer
Cc: linux-mips, linux-kernel, Greg Kroah-Hartman, Ricardo B. Marliere
This is a simple and straight forward cleanup series that aims to make the
class structures in mips constant. This has been possible since 2023 [1].
[1]: https://lore.kernel.org/all/2023040248-customary-release-4aec@gregkh/
Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net>
---
Ricardo B. Marliere (2):
mips: mt: make mt_class constant
mips: sibyte: make tb_class constant
arch/mips/include/asm/mips_mt.h | 2 +-
arch/mips/kernel/mips-mt.c | 14 ++++----------
arch/mips/kernel/rtlx-mt.c | 8 ++++----
arch/mips/sibyte/common/sb_tbprof.c | 21 +++++++++------------
4 files changed, 18 insertions(+), 27 deletions(-)
---
base-commit: fdf0df8c936c0822570e067009dee6824ff3a2be
change-id: 20240305-class_cleanup-mips-a77ae01ea4fc
Best regards,
--
Ricardo B. Marliere <ricardo@marliere.net>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] mips: mt: make mt_class constant
2024-03-05 13:37 [PATCH 0/2] mips: constify struct class usage Ricardo B. Marliere
@ 2024-03-05 13:37 ` Ricardo B. Marliere
2024-03-05 13:37 ` [PATCH 2/2] mips: sibyte: make tb_class constant Ricardo B. Marliere
2024-03-07 16:21 ` [PATCH 0/2] mips: constify struct class usage Thomas Bogendoerfer
2 siblings, 0 replies; 4+ messages in thread
From: Ricardo B. Marliere @ 2024-03-05 13:37 UTC (permalink / raw
To: Thomas Bogendoerfer
Cc: linux-mips, 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 mt_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>
---
KTODO: use device_register instead of device_create?
---
arch/mips/include/asm/mips_mt.h | 2 +-
arch/mips/kernel/mips-mt.c | 14 ++++----------
arch/mips/kernel/rtlx-mt.c | 8 ++++----
3 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/arch/mips/include/asm/mips_mt.h b/arch/mips/include/asm/mips_mt.h
index b444523ecd50..28917f1582b3 100644
--- a/arch/mips/include/asm/mips_mt.h
+++ b/arch/mips/include/asm/mips_mt.h
@@ -26,6 +26,6 @@ static inline void mips_mt_set_cpuoptions(void) { }
#endif
struct class;
-extern struct class *mt_class;
+extern const struct class mt_class;
#endif /* __ASM_MIPS_MT_H */
diff --git a/arch/mips/kernel/mips-mt.c b/arch/mips/kernel/mips-mt.c
index c07d64438b5b..c938ba208fc0 100644
--- a/arch/mips/kernel/mips-mt.c
+++ b/arch/mips/kernel/mips-mt.c
@@ -229,19 +229,13 @@ void mips_mt_set_cpuoptions(void)
}
}
-struct class *mt_class;
+const struct class mt_class = {
+ .name = "mt",
+};
static int __init mips_mt_init(void)
{
- struct class *mtc;
-
- mtc = class_create("mt");
- if (IS_ERR(mtc))
- return PTR_ERR(mtc);
-
- mt_class = mtc;
-
- return 0;
+ return class_register(&mt_class);
}
subsys_initcall(mips_mt_init);
diff --git a/arch/mips/kernel/rtlx-mt.c b/arch/mips/kernel/rtlx-mt.c
index 38c6925a1bea..ff7535de42ca 100644
--- a/arch/mips/kernel/rtlx-mt.c
+++ b/arch/mips/kernel/rtlx-mt.c
@@ -95,11 +95,11 @@ int __init rtlx_module_init(void)
atomic_set(&channel_wqs[i].in_open, 0);
mutex_init(&channel_wqs[i].mutex);
- dev = device_create(mt_class, NULL, MKDEV(major, i), NULL,
+ dev = device_create(&mt_class, NULL, MKDEV(major, i), NULL,
"%s%d", RTLX_MODULE_NAME, i);
if (IS_ERR(dev)) {
while (i--)
- device_destroy(mt_class, MKDEV(major, i));
+ device_destroy(&mt_class, MKDEV(major, i));
err = PTR_ERR(dev);
goto out_chrdev;
@@ -127,7 +127,7 @@ int __init rtlx_module_init(void)
out_class:
for (i = 0; i < RTLX_CHANNELS; i++)
- device_destroy(mt_class, MKDEV(major, i));
+ device_destroy(&mt_class, MKDEV(major, i));
out_chrdev:
unregister_chrdev(major, RTLX_MODULE_NAME);
@@ -139,7 +139,7 @@ void __exit rtlx_module_exit(void)
int i;
for (i = 0; i < RTLX_CHANNELS; i++)
- device_destroy(mt_class, MKDEV(major, i));
+ device_destroy(&mt_class, MKDEV(major, i));
unregister_chrdev(major, RTLX_MODULE_NAME);
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] mips: sibyte: make tb_class constant
2024-03-05 13:37 [PATCH 0/2] mips: constify struct class usage Ricardo B. Marliere
2024-03-05 13:37 ` [PATCH 1/2] mips: mt: make mt_class constant Ricardo B. Marliere
@ 2024-03-05 13:37 ` Ricardo B. Marliere
2024-03-07 16:21 ` [PATCH 0/2] mips: constify struct class usage Thomas Bogendoerfer
2 siblings, 0 replies; 4+ messages in thread
From: Ricardo B. Marliere @ 2024-03-05 13:37 UTC (permalink / raw
To: Thomas Bogendoerfer
Cc: linux-mips, 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 tb_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>
---
KTODO: use device_register instead of device_create?
---
arch/mips/sibyte/common/sb_tbprof.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/arch/mips/sibyte/common/sb_tbprof.c b/arch/mips/sibyte/common/sb_tbprof.c
index 408db45efdc8..af5333986900 100644
--- a/arch/mips/sibyte/common/sb_tbprof.c
+++ b/arch/mips/sibyte/common/sb_tbprof.c
@@ -535,13 +535,14 @@ static const struct file_operations sbprof_tb_fops = {
.llseek = default_llseek,
};
-static struct class *tb_class;
+static const struct class tb_class = {
+ .name = "sb_tracebuffer",
+};
static struct device *tb_dev;
static int __init sbprof_tb_init(void)
{
struct device *dev;
- struct class *tbc;
int err;
if (register_chrdev(SBPROF_TB_MAJOR, DEVNAME, &sbprof_tb_fops)) {
@@ -550,15 +551,11 @@ static int __init sbprof_tb_init(void)
return -EIO;
}
- tbc = class_create("sb_tracebuffer");
- if (IS_ERR(tbc)) {
- err = PTR_ERR(tbc);
+ err = class_register(&tb_class);
+ if (err)
goto out_chrdev;
- }
-
- tb_class = tbc;
- dev = device_create(tbc, NULL, MKDEV(SBPROF_TB_MAJOR, 0), NULL, "tb");
+ dev = device_create(&tb_class, NULL, MKDEV(SBPROF_TB_MAJOR, 0), NULL, "tb");
if (IS_ERR(dev)) {
err = PTR_ERR(dev);
goto out_class;
@@ -573,7 +570,7 @@ static int __init sbprof_tb_init(void)
return 0;
out_class:
- class_destroy(tb_class);
+ class_unregister(&tb_class);
out_chrdev:
unregister_chrdev(SBPROF_TB_MAJOR, DEVNAME);
@@ -582,9 +579,9 @@ static int __init sbprof_tb_init(void)
static void __exit sbprof_tb_cleanup(void)
{
- device_destroy(tb_class, MKDEV(SBPROF_TB_MAJOR, 0));
+ device_destroy(&tb_class, MKDEV(SBPROF_TB_MAJOR, 0));
unregister_chrdev(SBPROF_TB_MAJOR, DEVNAME);
- class_destroy(tb_class);
+ class_unregister(&tb_class);
}
module_init(sbprof_tb_init);
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] mips: constify struct class usage
2024-03-05 13:37 [PATCH 0/2] mips: constify struct class usage Ricardo B. Marliere
2024-03-05 13:37 ` [PATCH 1/2] mips: mt: make mt_class constant Ricardo B. Marliere
2024-03-05 13:37 ` [PATCH 2/2] mips: sibyte: make tb_class constant Ricardo B. Marliere
@ 2024-03-07 16:21 ` Thomas Bogendoerfer
2 siblings, 0 replies; 4+ messages in thread
From: Thomas Bogendoerfer @ 2024-03-07 16:21 UTC (permalink / raw
To: Ricardo B. Marliere; +Cc: linux-mips, linux-kernel, Greg Kroah-Hartman
On Tue, Mar 05, 2024 at 10:37:49AM -0300, Ricardo B. Marliere wrote:
> This is a simple and straight forward cleanup series that aims to make the
> class structures in mips constant. This has been possible since 2023 [1].
>
> [1]: https://lore.kernel.org/all/2023040248-customary-release-4aec@gregkh/
>
> Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net>
> ---
> Ricardo B. Marliere (2):
> mips: mt: make mt_class constant
> mips: sibyte: make tb_class constant
>
> arch/mips/include/asm/mips_mt.h | 2 +-
> arch/mips/kernel/mips-mt.c | 14 ++++----------
> arch/mips/kernel/rtlx-mt.c | 8 ++++----
> arch/mips/sibyte/common/sb_tbprof.c | 21 +++++++++------------
> 4 files changed, 18 insertions(+), 27 deletions(-)
> ---
> base-commit: fdf0df8c936c0822570e067009dee6824ff3a2be
> change-id: 20240305-class_cleanup-mips-a77ae01ea4fc
series applied to mips-next.
Thomas.
--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-03-07 16:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-05 13:37 [PATCH 0/2] mips: constify struct class usage Ricardo B. Marliere
2024-03-05 13:37 ` [PATCH 1/2] mips: mt: make mt_class constant Ricardo B. Marliere
2024-03-05 13:37 ` [PATCH 2/2] mips: sibyte: make tb_class constant Ricardo B. Marliere
2024-03-07 16:21 ` [PATCH 0/2] mips: constify struct class usage Thomas Bogendoerfer
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 read-only IMAP folder(s) and NNTP newsgroup(s).