Skip to content

Commit

Permalink
firmware_loader: move firmware sysctl to its own files
Browse files Browse the repository at this point in the history
Patch series "sysctl: 3rd set of kernel/sysctl cleanups", v2.

This is the third set of patches to help address cleaning the kitchen
seink in kernel/sysctl.c and to move sysctls away to where they are
actually implemented / used.

This patch (of 8):

kernel/sysctl.c is a kitchen sink where everyone leaves their dirty
dishes, this makes it very difficult to maintain.

To help with this maintenance let's start by moving sysctls to places
where they actually belong.  The proc sysctl maintainers do not want to
know what sysctl knobs you wish to add for your own piece of code, we
just care about the core logic.

So move the firmware configuration sysctl table to the only place where
it is used, and make it clear that if sysctls are disabled this is not
used.

[[email protected]: export register_firmware_config_sysctl and unregister_firmware_config_sysctl to modules]
[[email protected]: use EXPORT_SYMBOL_NS_GPL instead]
[[email protected]: fix that so it compiles]
  Link: https://lkml.kernel.org/r/[email protected]
[[email protected]: major commit log update to justify the move]

Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Xiaoming Ni <[email protected]>
Signed-off-by: Luis Chamberlain <[email protected]>
Signed-off-by: Stephen Rothwell <[email protected]>
Cc: Kees Cook <[email protected]>
Cc: Iurii Zaikin <[email protected]>
Cc: Eric Biederman <[email protected]>
Cc: Stephen Kitt <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Cc: "Theodore Ts'o" <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Petr Mladek <[email protected]>
Cc: Sergey Senozhatsky <[email protected]>
Cc: Steven Rostedt (VMware) <[email protected]>
Cc: John Ogness <[email protected]>
Cc: Douglas Gilbert <[email protected]>
Cc: James E.J. Bottomley <[email protected]>
Cc: Martin K. Petersen <[email protected]>
Cc: Lukas Middendorf <[email protected]>
Cc: Antti Palosaari <[email protected]>
Cc: Amir Goldstein <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Benjamin LaHaise <[email protected]>
Cc: Clemens Ladisch <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Jani Nikula <[email protected]>
Cc: Jani Nikula <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Joel Becker <[email protected]>
Cc: Joonas Lahtinen <[email protected]>
Cc: Joseph Qi <[email protected]>
Cc: Julia Lawall <[email protected]>
Cc: Mark Fasheh <[email protected]>
Cc: Paul Turner <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Phillip Potter <[email protected]>
Cc: Qing Wang <[email protected]>
Cc: Rodrigo Vivi <[email protected]>
Cc: Sebastian Reichel <[email protected]>
Cc: Suren Baghdasaryan <[email protected]>
Cc: Tetsuo Handa <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
nixiaoming authored and torvalds committed Jan 22, 2022
1 parent a8f5de8 commit 6aad36d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
7 changes: 6 additions & 1 deletion drivers/base/firmware_loader/fallback.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,16 @@ static struct class firmware_class = {

int register_sysfs_loader(void)
{
return class_register(&firmware_class);
int ret = class_register(&firmware_class);

if (ret != 0)
return ret;
return register_firmware_config_sysctl();
}

void unregister_sysfs_loader(void)
{
unregister_firmware_config_sysctl();
class_unregister(&firmware_class);
}

Expand Down
11 changes: 11 additions & 0 deletions drivers/base/firmware_loader/fallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ void fw_fallback_set_default_timeout(void);

int register_sysfs_loader(void);
void unregister_sysfs_loader(void);
#ifdef CONFIG_SYSCTL
extern int register_firmware_config_sysctl(void);
extern void unregister_firmware_config_sysctl(void);
#else
static inline int register_firmware_config_sysctl(void)
{
return 0;
}
static inline void unregister_firmware_config_sysctl(void) { }
#endif /* CONFIG_SYSCTL */

#else /* CONFIG_FW_LOADER_USER_HELPER */
static inline int firmware_fallback_sysfs(struct firmware *fw, const char *name,
struct device *device,
Expand Down
25 changes: 23 additions & 2 deletions drivers/base/firmware_loader/fallback_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <linux/kconfig.h>
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/export.h>
#include <linux/security.h>
#include <linux/highmem.h>
#include <linux/umh.h>
Expand All @@ -24,7 +25,7 @@ struct firmware_fallback_config fw_fallback_config = {
EXPORT_SYMBOL_NS_GPL(fw_fallback_config, FIRMWARE_LOADER_PRIVATE);

#ifdef CONFIG_SYSCTL
struct ctl_table firmware_config_table[] = {
static struct ctl_table firmware_config_table[] = {
{
.procname = "force_sysfs_fallback",
.data = &fw_fallback_config.force_sysfs_fallback,
Expand All @@ -45,4 +46,24 @@ struct ctl_table firmware_config_table[] = {
},
{ }
};
#endif

static struct ctl_table_header *firmware_config_sysct_table_header;
int register_firmware_config_sysctl(void)
{
firmware_config_sysct_table_header =
register_sysctl("kernel/firmware_config",
firmware_config_table);
if (!firmware_config_sysct_table_header)
return -ENOMEM;
return 0;
}
EXPORT_SYMBOL_NS_GPL(register_firmware_config_sysctl, FIRMWARE_LOADER_PRIVATE);

void unregister_firmware_config_sysctl(void)
{
unregister_sysctl_table(firmware_config_sysct_table_header);
firmware_config_sysct_table_header = NULL;
}
EXPORT_SYMBOL_NS_GPL(unregister_firmware_config_sysctl, FIRMWARE_LOADER_PRIVATE);

#endif /* CONFIG_SYSCTL */
1 change: 0 additions & 1 deletion include/linux/sysctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ extern int no_unaligned_warning;

extern struct ctl_table sysctl_mount_point[];
extern struct ctl_table random_table[];
extern struct ctl_table firmware_config_table[];

#else /* CONFIG_SYSCTL */
static inline struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Expand Down
7 changes: 0 additions & 7 deletions kernel/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2154,13 +2154,6 @@ static struct ctl_table kern_table[] = {
.mode = 0555,
.child = usermodehelper_table,
},
#ifdef CONFIG_FW_LOADER_USER_HELPER
{
.procname = "firmware_config",
.mode = 0555,
.child = firmware_config_table,
},
#endif
{
.procname = "overflowuid",
.data = &overflowuid,
Expand Down

0 comments on commit 6aad36d

Please sign in to comment.