Skip to content

Commit b73d5dc

Browse files
Nicholas Mc GuireJiri Kosina
authored andcommitted
livepatch: samples: non static warnings fix
Sparse reported warnings about non-static symbols. For the variables a simple static attribute is fine - for the functions referenced by livepatch via klp_func the symbol-names must be unmodified in the symbol table and the patchable code has to be emitted. The resolution is to attach __used attribute to the shared statically declared functions. Link: https://lore.kernel.org/lkml/[email protected]/ Suggested-by: Joe Lawrence <[email protected]> Signed-off-by: Nicholas Mc Guire <[email protected]> Acked-by: Miroslav Benes <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent a6c3424 commit b73d5dc

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

samples/livepatch/livepatch-shadow-fix1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static int shadow_leak_ctor(void *obj, void *shadow_data, void *ctor_data)
7171
return 0;
7272
}
7373

74-
struct dummy *livepatch_fix1_dummy_alloc(void)
74+
static struct dummy *livepatch_fix1_dummy_alloc(void)
7575
{
7676
struct dummy *d;
7777
void *leak;
@@ -113,7 +113,7 @@ static void livepatch_fix1_dummy_leak_dtor(void *obj, void *shadow_data)
113113
__func__, d, *shadow_leak);
114114
}
115115

116-
void livepatch_fix1_dummy_free(struct dummy *d)
116+
static void livepatch_fix1_dummy_free(struct dummy *d)
117117
{
118118
void **shadow_leak;
119119

samples/livepatch/livepatch-shadow-fix2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct dummy {
5050
unsigned long jiffies_expire;
5151
};
5252

53-
bool livepatch_fix2_dummy_check(struct dummy *d, unsigned long jiffies)
53+
static bool livepatch_fix2_dummy_check(struct dummy *d, unsigned long jiffies)
5454
{
5555
int *shadow_count;
5656

@@ -78,7 +78,7 @@ static void livepatch_fix2_dummy_leak_dtor(void *obj, void *shadow_data)
7878
__func__, d, *shadow_leak);
7979
}
8080

81-
void livepatch_fix2_dummy_free(struct dummy *d)
81+
static void livepatch_fix2_dummy_free(struct dummy *d)
8282
{
8383
void **shadow_leak;
8484
int *shadow_count;

samples/livepatch/livepatch-shadow-mod.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ MODULE_DESCRIPTION("Buggy module for shadow variable demo");
9696
* Keep a list of all the dummies so we can clean up any residual ones
9797
* on module exit
9898
*/
99-
LIST_HEAD(dummy_list);
100-
DEFINE_MUTEX(dummy_list_mutex);
99+
static LIST_HEAD(dummy_list);
100+
static DEFINE_MUTEX(dummy_list_mutex);
101101

102102
struct dummy {
103103
struct list_head list;
104104
unsigned long jiffies_expire;
105105
};
106106

107-
noinline struct dummy *dummy_alloc(void)
107+
static __used noinline struct dummy *dummy_alloc(void)
108108
{
109109
struct dummy *d;
110110
void *leak;
@@ -129,15 +129,16 @@ noinline struct dummy *dummy_alloc(void)
129129
return d;
130130
}
131131

132-
noinline void dummy_free(struct dummy *d)
132+
static __used noinline void dummy_free(struct dummy *d)
133133
{
134134
pr_info("%s: dummy @ %p, expired = %lx\n",
135135
__func__, d, d->jiffies_expire);
136136

137137
kfree(d);
138138
}
139139

140-
noinline bool dummy_check(struct dummy *d, unsigned long jiffies)
140+
static __used noinline bool dummy_check(struct dummy *d,
141+
unsigned long jiffies)
141142
{
142143
return time_after(jiffies, d->jiffies_expire);
143144
}

0 commit comments

Comments
 (0)