From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>,
Hans de Goede <hdegoede@redhat.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 6/8] Input: mt - make use of __free() cleanup facility
Date: Wed, 6 Nov 2024 23:15:33 -0800 [thread overview]
Message-ID: <20241107071538.195340-7-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20241107071538.195340-1-dmitry.torokhov@gmail.com>
Annotate allocated memory with __free(kfree) to simplify the code and
make sure memory is released appropriately.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/input-mt.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c
index 45e41fc9059c..337006dd9dcf 100644
--- a/drivers/input/input-mt.c
+++ b/drivers/input/input-mt.c
@@ -39,20 +39,20 @@ static void copy_abs(struct input_dev *dev, unsigned int dst, unsigned int src)
int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
unsigned int flags)
{
- struct input_mt *mt = dev->mt;
- int i;
-
if (!num_slots)
return 0;
- if (mt)
- return mt->num_slots != num_slots ? -EINVAL : 0;
+
+ if (dev->mt)
+ return dev->mt->num_slots != num_slots ? -EINVAL : 0;
+
/* Arbitrary limit for avoiding too large memory allocation. */
if (num_slots > 1024)
return -EINVAL;
- mt = kzalloc(struct_size(mt, slots, num_slots), GFP_KERNEL);
+ struct input_mt *mt __free(kfree) =
+ kzalloc(struct_size(mt, slots, num_slots), GFP_KERNEL);
if (!mt)
- goto err_mem;
+ return -ENOMEM;
mt->num_slots = num_slots;
mt->flags = flags;
@@ -86,21 +86,18 @@ int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
unsigned int n2 = num_slots * num_slots;
mt->red = kcalloc(n2, sizeof(*mt->red), GFP_KERNEL);
if (!mt->red)
- goto err_mem;
+ return -ENOMEM;
}
/* Mark slots as 'inactive' */
- for (i = 0; i < num_slots; i++)
+ for (unsigned int i = 0; i < num_slots; i++)
input_mt_set_value(&mt->slots[i], ABS_MT_TRACKING_ID, -1);
/* Mark slots as 'unused' */
mt->frame = 1;
- dev->mt = mt;
+ dev->mt = no_free_ptr(mt);
return 0;
-err_mem:
- kfree(mt);
- return -ENOMEM;
}
EXPORT_SYMBOL(input_mt_init_slots);
--
2.47.0.277.g8800431eea-goog
next prev parent reply other threads:[~2024-11-07 7:15 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-07 7:15 [PATCH 0/8] Convert input core to use new cleanup facilities Dmitry Torokhov
2024-11-07 7:15 ` [PATCH 1/8] Input: ff-core - convert locking to guard notation Dmitry Torokhov
2024-11-07 7:15 ` [PATCH 2/8] Input: ff-core - make use of __free() cleanup facility Dmitry Torokhov
[not found] ` <CGME20241220123701eucas1p23125e0738985ffe35cbe9624dff08972@eucas1p2.samsung.com>
2024-12-20 12:36 ` Marek Szyprowski
2024-12-20 17:22 ` Dmitry Torokhov
2024-12-20 17:38 ` Marek Szyprowski
2024-12-20 17:39 ` Dmitry Torokhov
2024-12-20 17:50 ` Marek Szyprowski
2024-11-07 7:15 ` [PATCH 3/8] Input: ff-memless - convert locking to guard notation Dmitry Torokhov
2024-11-07 7:15 ` [PATCH 4/8] Input: ff-memless - make use of __free() cleanup facility Dmitry Torokhov
2024-11-07 7:15 ` [PATCH 5/8] Input: mt - convert locking to guard notation Dmitry Torokhov
2024-11-07 7:15 ` Dmitry Torokhov [this message]
2024-11-07 7:15 ` [PATCH 7/8] Input: poller " Dmitry Torokhov
2024-11-07 7:15 ` [PATCH 8/8] Input: use guard notation in input core Dmitry Torokhov
2024-12-17 21:59 ` [PATCH 0/8] Convert input core to use new cleanup facilities Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241107071538.195340-7-dmitry.torokhov@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=bentiss@kernel.org \
--cc=hdegoede@redhat.com \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®