diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 020df7b6ff90c..2f916cbde76e4 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2904,16 +2904,21 @@ static int get_modules_for_addrs(struct module ***mods, unsigned long *addrs, u3
 	u32 i, err = 0;
 
 	for (i = 0; i < addrs_cnt; i++) {
+		bool skip_add = false;
 		struct module *mod;
 
 		scoped_guard(rcu) {
 			mod = __module_address(addrs[i]);
-			/* Either no module or we it's already stored  */
-			if (!mod || has_module(&arr, mod))
-				continue;
+			/* Either no module or it's already stored  */
+			if (!mod || has_module(&arr, mod)) {
+				skip_add = true;
+				break; /* scoped_guard */
+			}
 			if (!try_module_get(mod))
 				err = -EINVAL;
 		}
+		if (skip_add)
+			continue;
 		if (err)
 			break;
 		err = add_module(&arr, mod);
diff --git a/localversion-rt b/localversion-rt
index ad3da1bcab7e8..0efe7ba1930e1 100644
--- a/localversion-rt
+++ b/localversion-rt
@@ -1 +1 @@
--rt4
+-rt5
