#include <linux/compiler.h>
 #include <linux/linkage.h>
 #include <linux/irqflags.h>
+#include <linux/signal.h>
+#include <linux/ratelimit.h>
 #include <linux/reboot.h>
 
 struct pt_regs;
 
 extern void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
 
+#define show_unhandled_signals_ratelimited()                           \
+({                                                                     \
+       static DEFINE_RATELIMIT_STATE(_rs,                              \
+                                     DEFAULT_RATELIMIT_INTERVAL,       \
+                                     DEFAULT_RATELIMIT_BURST);         \
+       bool __show_ratelimited = false;                                \
+       if (show_unhandled_signals && __ratelimit(&_rs))                \
+               __show_ratelimited = true;                              \
+       __show_ratelimited;                                             \
+})
+
 #define UDBG_UNDEFINED (1 << 0)
 #define UDBG_SYSCALL   (1 << 1)
 #define UDBG_BADABORT  (1 << 2)
 
        if (call_undef_hook(regs) == 0)
                return;
 
-       if (show_unhandled_signals && unhandled_signal(current, SIGILL) &&
-           printk_ratelimit()) {
+       if (show_unhandled_signals_ratelimited() && unhandled_signal(current, SIGILL)) {
                pr_info("%s[%d]: undefined instruction: pc=%p\n",
                        current->comm, task_pid_nr(current), pc);
                dump_instr(KERN_INFO, regs);
        }
 #endif
 
-       if (show_unhandled_signals && printk_ratelimit()) {
+       if (show_unhandled_signals_ratelimited()) {
                pr_info("%s[%d]: syscall %d\n", current->comm,
                        task_pid_nr(current), (int)regs->syscallno);
                dump_instr("", regs);
 
 {
        struct siginfo si;
 
-       if (show_unhandled_signals && unhandled_signal(tsk, sig) &&
-           printk_ratelimit()) {
+       if (show_unhandled_signals_ratelimited() && unhandled_signal(tsk, sig)) {
                pr_info("%s[%d]: unhandled %s (%d) at 0x%08lx, esr 0x%03x\n",
                        tsk->comm, task_pid_nr(tsk), fault_name(esr), sig,
                        addr, esr);