diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 7b16c5322673ed7502ddbd3c160cdcff582328c4..d3516912309091369276e0c3f41b4907ff037c76 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -455,7 +455,7 @@ extern void uart_handle_cts_change(struct uart_port *uport,
 extern void uart_insert_char(struct uart_port *port, unsigned int status,
 		 unsigned int overrun, unsigned int ch, unsigned int flag);
 
-#ifdef SUPPORT_SYSRQ
+#if defined(SUPPORT_SYSRQ) && defined(CONFIG_MAGIC_SYSRQ_SERIAL)
 static inline int
 uart_handle_sysrq_char(struct uart_port *port, unsigned int ch)
 {
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 58a22ca10f33c5f116e870f92110c60481a99a71..08bc93a55c939321db5f46f41a7e8b0823df465b 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -396,6 +396,11 @@ config MAGIC_SYSRQ_DEFAULT_ENABLE
 	  This may be set to 1 or 0 to enable or disable them all, or
 	  to a bitmask as described in Documentation/sysrq.txt.
 
+config MAGIC_SYSRQ_SERIAL
+	bool "Enable magic SysRq key over serial"
+	depends on MAGIC_SYSRQ
+	default y
+
 config DEBUG_KERNEL
 	bool "Kernel debugging"
 	help