- Refresh
  patches.suse/kgr-0029-kgr-allow-stacking-of-patches.patch.
- Refresh
  patches.suse/kgr-0031-kgr-try-to-apply-skipped-patches-when-a-module-is-lo.patch.
- Refresh
  patches.suse/kgr-0032-kgr-handle-patched-modules-that-are-being-removed.patch.
- Refresh
  patches.suse/kgr-0033-kgr-handle-module-load-and-removal-for-non-finished-.patch.
- Refresh
  patches.suse/kgr-0034-kgr-remove-patch-from-global-list-when-being-removed.patch.
- Refresh
  patches.suse/kgr-0035-kgr-fix-patch-stacking-also-when-loading-module.patch.
- Refresh patches.suse/kgr-0037-kgr-allow-replace_all.patch.
- Refresh
  patches.suse/kgr-0038-kgr-make-it-possible-to-avoid-lazy-switching.patch.
- Refresh patches.suse/kgr-0039-kgr-fix-ugly-race.patch.

Just a small cleanup.

suse-commit: 6183b16e9d8d2cb6363a3849660066cdaa99cb85
diff --git a/kernel/kgraft.c b/kernel/kgraft.c
index 2813f32..7451475 100644
--- a/kernel/kgraft.c
+++ b/kernel/kgraft.c
@@ -315,11 +315,11 @@
 	schedule_on_each_cpu(kgr_handle_irq_cpu);
 }
 
-static unsigned long kgr_get_old_fun(const struct kgr_patch_fun *patch_fun)
+static struct kgr_patch_fun *
+kgr_get_last_pf(const struct kgr_patch_fun *patch_fun)
 {
 	const char *name = patch_fun->name;
-	unsigned long last_new_fun = 0;
-	struct kgr_patch_fun *pf;
+	struct kgr_patch_fun *pf, *last_pf = NULL;
 	struct kgr_patch *p;
 
 	list_for_each_entry(p, &patches, list) {
@@ -328,12 +328,19 @@
 				continue;
 
 			if (!strcmp(pf->name, name))
-				last_new_fun = (unsigned long)pf->new_fun;
+				last_pf = pf;
 		}
 	}
 
-	if (last_new_fun)
-		return ftrace_function_to_fentry(last_new_fun);
+	return last_pf;
+}
+
+static unsigned long kgr_get_old_fun(const struct kgr_patch_fun *patch_fun)
+{
+	struct kgr_patch_fun *pf = kgr_get_last_pf(patch_fun);
+
+	if (pf)
+		return ftrace_function_to_fentry((unsigned long)pf->new_fun);
 
 	return patch_fun->loc_name;
 }
@@ -342,24 +349,12 @@
  * Obtain the "previous" (in the sense of patch stacking) value of ftrace_ops
  * so that it can be put back properly in case of reverting the patch
  */
-static struct ftrace_ops *kgr_get_old_fops(const struct kgr_patch_fun *patch_fun)
+static struct ftrace_ops *
+kgr_get_old_fops(const struct kgr_patch_fun *patch_fun)
 {
-	const char *name = patch_fun->name;
-	struct ftrace_ops *last_new_fops = NULL;
-	struct kgr_patch_fun *pf;
-	struct kgr_patch *p;
+	struct kgr_patch_fun *pf = kgr_get_last_pf(patch_fun);
 
-	list_for_each_entry(p, &patches, list) {
-		kgr_for_each_patch_fun(p, pf) {
-			if (pf->state != KGR_PATCH_APPLIED)
-				continue;
-
-			if (!strcmp(pf->name, name))
-				last_new_fops = &pf->ftrace_ops_fast;
-		}
-	}
-
-	return last_new_fops;
+	return pf ? &pf->ftrace_ops_fast : NULL;
 }
 
 static int kgr_init_ftrace_ops(struct kgr_patch_fun *patch_fun)