2024-03-07 11:46:19

by Ricardo B. Marliere

[permalink] [raw]
Subject: [PATCH 0/2] mips: constify struct class usage

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 <[email protected]>
---
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 <[email protected]>



2024-03-07 12:26:10

by Ricardo B. Marliere

[permalink] [raw]
Subject: [PATCH 1/2] mips: mt: make mt_class constant

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 <[email protected]>
Suggested-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Ricardo B. Marliere <[email protected]>
---
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


2024-03-07 16:21:59

by Thomas Bogendoerfer

[permalink] [raw]
Subject: Re: [PATCH 0/2] mips: constify struct class usage

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 <[email protected]>
> ---
> 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 ]