return sysrq_enabled || sysrq_always_enabled;
 }
 
+/**
+ * sysrq_mask - Getter for sysrq_enabled mask.
+ *
+ * Return: 1 if sysrq is always enabled, enabled sysrq_key_op mask otherwise.
+ */
+int sysrq_mask(void)
+{
+       if (sysrq_always_enabled)
+               return 1;
+       return sysrq_enabled;
+}
+
 /*
  * A value of 1 means 'all', other nonzero values are an op mask:
  */
 
                void __user *buffer, size_t *lenp, loff_t *ppos);
 
 #ifdef CONFIG_MAGIC_SYSRQ
-/* Note: sysrq code uses its own private copy */
-static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
-
 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
-                               void __user *buffer, size_t *lenp,
-                               loff_t *ppos)
-{
-       int error;
-
-       error = proc_dointvec(table, write, buffer, lenp, ppos);
-       if (error)
-               return error;
-
-       if (write)
-               sysrq_toggle_support(__sysrq_enabled);
-
-       return 0;
-}
-
+                       void __user *buffer, size_t *lenp, loff_t *ppos);
 #endif
 
 static struct ctl_table kern_table[];
 #ifdef CONFIG_MAGIC_SYSRQ
        {
                .procname       = "sysrq",
-               .data           = &__sysrq_enabled,
+               .data           = NULL,
                .maxlen         = sizeof (int),
                .mode           = 0644,
                .proc_handler   = sysrq_sysctl_handler,
 }
 #endif
 
+#ifdef CONFIG_MAGIC_SYSRQ
+static int sysrq_sysctl_handler(struct ctl_table *table, int write,
+                               void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+       int tmp, ret;
+
+       tmp = sysrq_mask();
+
+       ret = __do_proc_dointvec(&tmp, table, write, buffer,
+                              lenp, ppos, NULL, NULL);
+       if (ret || !write)
+               return ret;
+
+       if (write)
+               sysrq_toggle_support(tmp);
+
+       return 0;
+}
+#endif
+
 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
                                     void __user *buffer,
                                     size_t *lenp, loff_t *ppos,