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: ff-core - make use of __free() cleanup facility

Annotate allocated memory with __free(kfree) to simplify the code and
make sure memory is released appropriately.

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/20241107071538.195340-3-dmitry.torokhov@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+7 -13
+7 -13
drivers/input/ff-core.c
··· 290 290 */ 291 291 int input_ff_create(struct input_dev *dev, unsigned int max_effects) 292 292 { 293 - struct ff_device *ff; 294 - size_t ff_dev_size; 295 293 int i; 296 294 297 295 if (!max_effects) { ··· 302 304 return -EINVAL; 303 305 } 304 306 305 - ff_dev_size = struct_size(ff, effect_owners, max_effects); 306 - if (ff_dev_size == SIZE_MAX) /* overflow */ 307 - return -EINVAL; 308 - 309 - ff = kzalloc(ff_dev_size, GFP_KERNEL); 307 + struct ff_device *ff __free(kfree) = 308 + kzalloc(struct_size(ff, effect_owners, max_effects), 309 + GFP_KERNEL); 310 310 if (!ff) 311 311 return -ENOMEM; 312 312 313 - ff->effects = kcalloc(max_effects, sizeof(struct ff_effect), 314 - GFP_KERNEL); 315 - if (!ff->effects) { 316 - kfree(ff); 313 + ff->effects = kcalloc(max_effects, sizeof(*ff->effects), GFP_KERNEL); 314 + if (!ff->effects) 317 315 return -ENOMEM; 318 - } 319 316 320 317 ff->max_effects = max_effects; 321 318 mutex_init(&ff->mutex); 322 319 323 - dev->ff = ff; 324 320 dev->flush = input_ff_flush; 325 321 dev->event = input_ff_event; 326 322 __set_bit(EV_FF, dev->evbit); ··· 326 334 /* we can emulate RUMBLE with periodic effects */ 327 335 if (test_bit(FF_PERIODIC, ff->ffbit)) 328 336 __set_bit(FF_RUMBLE, dev->ffbit); 337 + 338 + dev->ff = no_free_ptr(ff); 329 339 330 340 return 0; 331 341 }