Skip to content

Commit 96173d6

Browse files
committed
Input: ff-memless - 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-5-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent cec6b33 commit 96173d6

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

drivers/input/ff-memless.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,11 @@ static void ml_ff_destroy(struct ff_device *ff)
503503
int input_ff_create_memless(struct input_dev *dev, void *data,
504504
int (*play_effect)(struct input_dev *, void *, struct ff_effect *))
505505
{
506-
struct ml_device *ml;
507506
struct ff_device *ff;
508507
int error;
509508
int i;
510509

511-
ml = kzalloc(sizeof(struct ml_device), GFP_KERNEL);
510+
struct ml_device *ml __free(kfree) = kzalloc(sizeof(*ml), GFP_KERNEL);
512511
if (!ml)
513512
return -ENOMEM;
514513

@@ -521,13 +520,10 @@ int input_ff_create_memless(struct input_dev *dev, void *data,
521520
set_bit(FF_GAIN, dev->ffbit);
522521

523522
error = input_ff_create(dev, FF_MEMLESS_EFFECTS);
524-
if (error) {
525-
kfree(ml);
523+
if (error)
526524
return error;
527-
}
528525

529526
ff = dev->ff;
530-
ff->private = ml;
531527
ff->upload = ml_ff_upload;
532528
ff->playback = ml_ff_playback;
533529
ff->set_gain = ml_ff_set_gain;
@@ -544,6 +540,8 @@ int input_ff_create_memless(struct input_dev *dev, void *data,
544540
for (i = 0; i < FF_MEMLESS_EFFECTS; i++)
545541
ml->states[i].effect = &ff->effects[i];
546542

543+
ff->private = no_free_ptr(ml);
544+
547545
return 0;
548546
}
549547
EXPORT_SYMBOL_GPL(input_ff_create_memless);

0 commit comments

Comments
 (0)