Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+10 -13
+10 -13
drivers/input/input-mt.c
··· 39 39 int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots, 40 40 unsigned int flags) 41 41 { 42 - struct input_mt *mt = dev->mt; 43 - int i; 44 - 45 42 if (!num_slots) 46 43 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 + 49 48 /* Arbitrary limit for avoiding too large memory allocation. */ 50 49 if (num_slots > 1024) 51 50 return -EINVAL; 52 51 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); 54 54 if (!mt) 55 - goto err_mem; 55 + return -ENOMEM; 56 56 57 57 mt->num_slots = num_slots; 58 58 mt->flags = flags; ··· 86 86 unsigned int n2 = num_slots * num_slots; 87 87 mt->red = kcalloc(n2, sizeof(*mt->red), GFP_KERNEL); 88 88 if (!mt->red) 89 - goto err_mem; 89 + return -ENOMEM; 90 90 } 91 91 92 92 /* Mark slots as 'inactive' */ 93 - for (i = 0; i < num_slots; i++) 93 + for (unsigned int i = 0; i < num_slots; i++) 94 94 input_mt_set_value(&mt->slots[i], ABS_MT_TRACKING_ID, -1); 95 95 96 96 /* Mark slots as 'unused' */ 97 97 mt->frame = 1; 98 98 99 - dev->mt = mt; 99 + dev->mt = no_free_ptr(mt); 100 100 return 0; 101 - err_mem: 102 - kfree(mt); 103 - return -ENOMEM; 104 101 } 105 102 EXPORT_SYMBOL(input_mt_init_slots); 106 103