Skip to content

Commit 5bb6e29

Browse files
committed
Input: mt - make use of __free() cleanup facility
Annotate allocated memory with __free(kfree) to simplify the code and make sure memory is released appropriately. Link: https://lore.kernel.org/r/20241107071538.195340-7-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 4e3929c commit 5bb6e29

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

drivers/input/input-mt.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ static void copy_abs(struct input_dev *dev, unsigned int dst, unsigned int src)
3939
int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
4040
unsigned int flags)
4141
{
42-
struct input_mt *mt = dev->mt;
43-
int i;
44-
4542
if (!num_slots)
4643
return 0;
47-
if (mt)
48-
return mt->num_slots != num_slots ? -EINVAL : 0;
44+
45+
if (dev->mt)
46+
return dev->mt->num_slots != num_slots ? -EINVAL : 0;
47+
4948
/* Arbitrary limit for avoiding too large memory allocation. */
5049
if (num_slots > 1024)
5150
return -EINVAL;
5251

53-
mt = kzalloc(struct_size(mt, slots, num_slots), GFP_KERNEL);
52+
struct input_mt *mt __free(kfree) =
53+
kzalloc(struct_size(mt, slots, num_slots), GFP_KERNEL);
5454
if (!mt)
55-
goto err_mem;
55+
return -ENOMEM;
5656

5757
mt->num_slots = num_slots;
5858
mt->flags = flags;
@@ -86,21 +86,18 @@ int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
8686
unsigned int n2 = num_slots * num_slots;
8787
mt->red = kcalloc(n2, sizeof(*mt->red), GFP_KERNEL);
8888
if (!mt->red)
89-
goto err_mem;
89+
return -ENOMEM;
9090
}
9191

9292
/* Mark slots as 'inactive' */
93-
for (i = 0; i < num_slots; i++)
93+
for (unsigned int i = 0; i < num_slots; i++)
9494
input_mt_set_value(&mt->slots[i], ABS_MT_TRACKING_ID, -1);
9595

9696
/* Mark slots as 'unused' */
9797
mt->frame = 1;
9898

99-
dev->mt = mt;
99+
dev->mt = no_free_ptr(mt);
100100
return 0;
101-
err_mem:
102-
kfree(mt);
103-
return -ENOMEM;
104101
}
105102
EXPORT_SYMBOL(input_mt_init_slots);
106103

0 commit comments

Comments
 (0)