Re: [PATCH v5 11/13] module: Move sysfs support into a separate file

From: Christophe Leroy
Date: Thu Feb 10 2022 - 09:00:57 EST




Le 09/02/2022 à 18:11, Aaron Tomlin a écrit :
> No functional change.
>
> This patch migrates module sysfs support out of core code into
> kernel/module/sysfs.c. In addition simple code refactoring to
> make this possible.
>
> Signed-off-by: Aaron Tomlin <atomlin@xxxxxxxxxx>
> ---
> kernel/module/Makefile | 1 +
> kernel/module/internal.h | 24 ++
> kernel/module/main.c | 458 +--------------------------------------
> kernel/module/sysfs.c | 425 ++++++++++++++++++++++++++++++++++++
> 4 files changed, 453 insertions(+), 455 deletions(-)
> create mode 100644 kernel/module/sysfs.c

Checkpatch:

total: 0 errors, 2 warnings, 10 checks, 946 lines checked


>
> diff --git a/kernel/module/Makefile b/kernel/module/Makefile
> index c6be08060252..c30141c37eb3 100644
> --- a/kernel/module/Makefile
> +++ b/kernel/module/Makefile
> @@ -14,4 +14,5 @@ obj-$(CONFIG_STRICT_MODULE_RWX) += strict_rwx.o
> obj-$(CONFIG_DEBUG_KMEMLEAK) += debug_kmemleak.o
> obj-$(CONFIG_KALLSYMS) += kallsyms.o
> obj-$(CONFIG_PROC_FS) += procfs.o
> +obj-$(CONFIG_SYSFS) += sysfs.o
> endif
> diff --git a/kernel/module/internal.h b/kernel/module/internal.h
> index b67ce836746a..52d30bf6d6b0 100644
> --- a/kernel/module/internal.h
> +++ b/kernel/module/internal.h
> @@ -35,6 +35,9 @@
> extern struct mutex module_mutex;
> extern struct list_head modules;
>
> +extern struct module_attribute *modinfo_attrs[];
> +extern size_t modinfo_attrs_count;

Can't this come in sysfs.c as well ?

> +
> /* Provided by the linker */
> extern const struct kernel_symbol __start___ksymtab[];
> extern const struct kernel_symbol __stop___ksymtab[];
> @@ -206,3 +209,24 @@ static inline char *find_kallsyms_symbol(struct module *mod, unsigned long addr,
> return NULL;
> }
> #endif /* CONFIG_KALLSYMS */
> +
> +#ifdef CONFIG_SYSFS
> +int mod_sysfs_setup(struct module *mod, const struct load_info *info,
> + struct kernel_param *kparam, unsigned int num_params);
> +void mod_sysfs_fini(struct module *mod);
> +void module_remove_modinfo_attrs(struct module *mod, int end);
> +void del_usage_links(struct module *mod);
> +void init_param_lock(struct module *mod);

Why don't we move mod_sysfs_teardown() here as well ?

It looks strange to move mod_sysfs_setup() and not mod_sysfs_teardown()

> +#else /* !CONFIG_SYSFS */
> +static int mod_sysfs_setup(struct module *mod,
> + const struct load_info *info,
> + struct kernel_param *kparam,
> + unsigned int num_params)
> +{
> + return 0;
> +}
> +static inline void mod_sysfs_fini(struct module *mod) { }
> +static inline void module_remove_modinfo_attrs(struct module *mod, int end) { }
> +static inline void del_usage_links(struct module *mod) { }
> +static inline void init_param_lock(struct module *mod) { }
> +#endif /* CONFIG_SYSFS */