hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/samples/livepatch/livepatch-shadow-fix2.c
....@@ -1,18 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2017 Joe Lawrence <joe.lawrence@redhat.com>
3
- *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License
6
- * as published by the Free Software Foundation; either version 2
7
- * of the License, or (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
164 */
175
186 /*
....@@ -50,7 +38,7 @@
5038 unsigned long jiffies_expire;
5139 };
5240
53
-bool livepatch_fix2_dummy_check(struct dummy *d, unsigned long jiffies)
41
+static bool livepatch_fix2_dummy_check(struct dummy *d, unsigned long jiffies)
5442 {
5543 int *shadow_count;
5644
....@@ -71,16 +59,16 @@
7159 static void livepatch_fix2_dummy_leak_dtor(void *obj, void *shadow_data)
7260 {
7361 void *d = obj;
74
- void **shadow_leak = shadow_data;
62
+ int **shadow_leak = shadow_data;
7563
7664 kfree(*shadow_leak);
7765 pr_info("%s: dummy @ %p, prevented leak @ %p\n",
7866 __func__, d, *shadow_leak);
7967 }
8068
81
-void livepatch_fix2_dummy_free(struct dummy *d)
69
+static void livepatch_fix2_dummy_free(struct dummy *d)
8270 {
83
- void **shadow_leak;
71
+ int **shadow_leak;
8472 int *shadow_count;
8573
8674 /* Patch: copy the memory leak patch from the fix1 module. */
....@@ -129,25 +117,13 @@
129117
130118 static int livepatch_shadow_fix2_init(void)
131119 {
132
- int ret;
133
-
134
- ret = klp_register_patch(&patch);
135
- if (ret)
136
- return ret;
137
- ret = klp_enable_patch(&patch);
138
- if (ret) {
139
- WARN_ON(klp_unregister_patch(&patch));
140
- return ret;
141
- }
142
- return 0;
120
+ return klp_enable_patch(&patch);
143121 }
144122
145123 static void livepatch_shadow_fix2_exit(void)
146124 {
147125 /* Cleanup any existing SV_COUNTER shadow variables */
148126 klp_shadow_free_all(SV_COUNTER, NULL);
149
-
150
- WARN_ON(klp_unregister_patch(&patch));
151127 }
152128
153129 module_init(livepatch_shadow_fix2_init);