Skip to content

Commit 79ac8df

Browse files
committed
Input: sysrq: mv sysrq into drivers/tty/sysrq.c
Move both sysrq ctl_table and supported sysrq_sysctl_handler helper function into drivers/tty/sysrq.c. Replaced the __do_proc_dointvec in helper function with do_proc_dointvec_minmax as the former is local to kernel/sysctl.c. Here we use the minmax version of do_proc_dointvec because do_proc_dointvec is static and calling do_proc_dointvec_minmax with a NULL min and max is the same as calling do_proc_dointvec. This is part of a greater effort to move ctl tables into their respective subsystems which will reduce the merge conflicts in kernel/sysctl.c. Reviewed-by: Kees Cook <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Joel Granados <[email protected]>
1 parent 8e5f04b commit 79ac8df

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

drivers/tty/sysrq.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,47 @@ int sysrq_toggle_support(int enable_mask)
11201120
}
11211121
EXPORT_SYMBOL_GPL(sysrq_toggle_support);
11221122

1123+
static int sysrq_sysctl_handler(const struct ctl_table *table, int write,
1124+
void *buffer, size_t *lenp, loff_t *ppos)
1125+
{
1126+
int tmp, ret;
1127+
struct ctl_table t = *table;
1128+
1129+
tmp = sysrq_mask();
1130+
t.data = &tmp;
1131+
1132+
/*
1133+
* Behaves like do_proc_dointvec as t does not have min nor max.
1134+
*/
1135+
ret = proc_dointvec_minmax(&t, write, buffer, lenp, ppos);
1136+
1137+
if (ret || !write)
1138+
return ret;
1139+
1140+
if (write)
1141+
sysrq_toggle_support(tmp);
1142+
1143+
return 0;
1144+
}
1145+
1146+
static const struct ctl_table sysrq_sysctl_table[] = {
1147+
{
1148+
.procname = "sysrq",
1149+
.data = NULL,
1150+
.maxlen = sizeof(int),
1151+
.mode = 0644,
1152+
.proc_handler = sysrq_sysctl_handler,
1153+
},
1154+
};
1155+
1156+
static int __init init_sysrq_sysctl(void)
1157+
{
1158+
register_sysctl_init("kernel", sysrq_sysctl_table);
1159+
return 0;
1160+
}
1161+
1162+
subsys_initcall(init_sysrq_sysctl);
1163+
11231164
static int __sysrq_swap_key_ops(u8 key, const struct sysrq_key_op *insert_op_p,
11241165
const struct sysrq_key_op *remove_op_p)
11251166
{

kernel/sysctl.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <linux/kernel.h>
3232
#include <linux/kobject.h>
3333
#include <linux/net.h>
34-
#include <linux/sysrq.h>
3534
#include <linux/highuid.h>
3635
#include <linux/writeback.h>
3736
#include <linux/ratelimit.h>
@@ -964,26 +963,6 @@ int proc_dou8vec_minmax(const struct ctl_table *table, int write,
964963
}
965964
EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
966965

967-
#ifdef CONFIG_MAGIC_SYSRQ
968-
static int sysrq_sysctl_handler(const struct ctl_table *table, int write,
969-
void *buffer, size_t *lenp, loff_t *ppos)
970-
{
971-
int tmp, ret;
972-
973-
tmp = sysrq_mask();
974-
975-
ret = __do_proc_dointvec(&tmp, table, write, buffer,
976-
lenp, ppos, NULL, NULL);
977-
if (ret || !write)
978-
return ret;
979-
980-
if (write)
981-
sysrq_toggle_support(tmp);
982-
983-
return 0;
984-
}
985-
#endif
986-
987966
static int __do_proc_doulongvec_minmax(void *data,
988967
const struct ctl_table *table, int write,
989968
void *buffer, size_t *lenp, loff_t *ppos,
@@ -1612,15 +1591,6 @@ static const struct ctl_table kern_table[] = {
16121591
.proc_handler = proc_dostring,
16131592
},
16141593
#endif
1615-
#ifdef CONFIG_MAGIC_SYSRQ
1616-
{
1617-
.procname = "sysrq",
1618-
.data = NULL,
1619-
.maxlen = sizeof (int),
1620-
.mode = 0644,
1621-
.proc_handler = sysrq_sysctl_handler,
1622-
},
1623-
#endif
16241594
#ifdef CONFIG_PROC_SYSCTL
16251595
{
16261596
.procname = "cad_pid",

0 commit comments

Comments
 (0)