Skip to content

Commit 8f6b886

Browse files
pmladekJiri Kosina
authored andcommitted
livepatch/sample: Use the right type for the leaking data pointer
The "leak" pointer, in the sample of shadow variable API, is allocated as sizeof(int). Let's help developers and static analyzers with understanding the code by using the appropriate pointer type. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Petr Mladek <pmladek@suse.com> Reviewed-by: Joe Lawrence <joe.lawrence@redhat.com> Acked-by: Miroslav Benes <mbenes@suse.cz> Reviewed-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent f838767 commit 8f6b886

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

samples/livepatch/livepatch-shadow-fix1.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ struct dummy {
5252
*/
5353
static int shadow_leak_ctor(void *obj, void *shadow_data, void *ctor_data)
5454
{
55-
void **shadow_leak = shadow_data;
56-
void *leak = ctor_data;
55+
int **shadow_leak = shadow_data;
56+
int *leak = ctor_data;
5757

5858
*shadow_leak = leak;
5959
return 0;
@@ -62,7 +62,7 @@ static int shadow_leak_ctor(void *obj, void *shadow_data, void *ctor_data)
6262
static struct dummy *livepatch_fix1_dummy_alloc(void)
6363
{
6464
struct dummy *d;
65-
void *leak;
65+
int *leak;
6666

6767
d = kzalloc(sizeof(*d), GFP_KERNEL);
6868
if (!d)
@@ -76,7 +76,7 @@ static struct dummy *livepatch_fix1_dummy_alloc(void)
7676
* variable. A patched dummy_free routine can later fetch this
7777
* pointer to handle resource release.
7878
*/
79-
leak = kzalloc(sizeof(int), GFP_KERNEL);
79+
leak = kzalloc(sizeof(*leak), GFP_KERNEL);
8080
if (!leak) {
8181
kfree(d);
8282
return NULL;
@@ -94,7 +94,7 @@ static struct dummy *livepatch_fix1_dummy_alloc(void)
9494
static void livepatch_fix1_dummy_leak_dtor(void *obj, void *shadow_data)
9595
{
9696
void *d = obj;
97-
void **shadow_leak = shadow_data;
97+
int **shadow_leak = shadow_data;
9898

9999
kfree(*shadow_leak);
100100
pr_info("%s: dummy @ %p, prevented leak @ %p\n",
@@ -103,7 +103,7 @@ static void livepatch_fix1_dummy_leak_dtor(void *obj, void *shadow_data)
103103

104104
static void livepatch_fix1_dummy_free(struct dummy *d)
105105
{
106-
void **shadow_leak;
106+
int **shadow_leak;
107107

108108
/*
109109
* Patch: fetch the saved SV_LEAK shadow variable, detach and

samples/livepatch/livepatch-shadow-fix2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static bool livepatch_fix2_dummy_check(struct dummy *d, unsigned long jiffies)
5959
static void livepatch_fix2_dummy_leak_dtor(void *obj, void *shadow_data)
6060
{
6161
void *d = obj;
62-
void **shadow_leak = shadow_data;
62+
int **shadow_leak = shadow_data;
6363

6464
kfree(*shadow_leak);
6565
pr_info("%s: dummy @ %p, prevented leak @ %p\n",
@@ -68,7 +68,7 @@ static void livepatch_fix2_dummy_leak_dtor(void *obj, void *shadow_data)
6868

6969
static void livepatch_fix2_dummy_free(struct dummy *d)
7070
{
71-
void **shadow_leak;
71+
int **shadow_leak;
7272
int *shadow_count;
7373

7474
/* Patch: copy the memory leak patch from the fix1 module. */

samples/livepatch/livepatch-shadow-mod.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct dummy {
9595
static __used noinline struct dummy *dummy_alloc(void)
9696
{
9797
struct dummy *d;
98-
void *leak;
98+
int *leak;
9999

100100
d = kzalloc(sizeof(*d), GFP_KERNEL);
101101
if (!d)
@@ -105,7 +105,7 @@ static __used noinline struct dummy *dummy_alloc(void)
105105
msecs_to_jiffies(1000 * EXPIRE_PERIOD);
106106

107107
/* Oops, forgot to save leak! */
108-
leak = kzalloc(sizeof(int), GFP_KERNEL);
108+
leak = kzalloc(sizeof(*leak), GFP_KERNEL);
109109
if (!leak) {
110110
kfree(d);
111111
return NULL;

0 commit comments

Comments
 (0)