From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
To: "Jiri Kosina" <jikos@kernel.org>,
"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Ahelenia Ziemiańska" <nabijaczleweli@nabijaczleweli.xyz>,
"Ping Cheng" <pinglinux@gmail.com>,
"Aaron Armstrong Skomra" <skomra@gmail.com>,
"Jason Gerecke" <killertofu@gmail.com>,
"Peter Hutterer" <peter.hutterer@who-t.net>
Cc: linux-input@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org,
Benjamin Tissoires <benjamin.tissoires@redhat.com>
Subject: [PATCH 01/12] HID: core: statically allocate read buffers
Date: Wed, 26 Jan 2022 17:18:21 +0100 [thread overview]
Message-ID: <20220126161832.3193805-2-benjamin.tissoires@redhat.com> (raw)
In-Reply-To: <20220126161832.3193805-1-benjamin.tissoires@redhat.com>
This is a preparation patch for rethinking the generic processing
of HID reports.
We can actually pre-allocate all of our memory instead of dynamically
allocating/freeing it whenever we parse a report.
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
drivers/hid/hid-core.c | 12 +++++-------
include/linux/hid.h | 1 +
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index f1aed5bbd000..75e7b8447bf7 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -101,7 +101,7 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned
field = kzalloc((sizeof(struct hid_field) +
usages * sizeof(struct hid_usage) +
- usages * sizeof(unsigned)), GFP_KERNEL);
+ 2 * usages * sizeof(unsigned int)), GFP_KERNEL);
if (!field)
return NULL;
@@ -109,6 +109,7 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned
report->field[field->index] = field;
field->usage = (struct hid_usage *)(field + 1);
field->value = (s32 *)(field->usage + usages);
+ field->new_value = (s32 *)(field->value + usages);
field->report = report;
return field;
@@ -1541,9 +1542,8 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
__s32 max = field->logical_maximum;
__s32 *value;
- value = kmalloc_array(count, sizeof(__s32), GFP_ATOMIC);
- if (!value)
- return;
+ value = field->new_value;
+ memset(value, 0, count * sizeof(__s32));
for (n = 0; n < count; n++) {
@@ -1557,7 +1557,7 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
value[n] >= min && value[n] <= max &&
value[n] - min < field->maxusage &&
field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
- goto exit;
+ return;
}
for (n = 0; n < count; n++) {
@@ -1581,8 +1581,6 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
}
memcpy(field->value, value, count * sizeof(__s32));
-exit:
- kfree(value);
}
/*
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 7487b0586fe6..3fbfe0986659 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -476,6 +476,7 @@ struct hid_field {
unsigned report_count; /* number of this field in the report */
unsigned report_type; /* (input,output,feature) */
__s32 *value; /* last known value(s) */
+ __s32 *new_value; /* newly read value(s) */
__s32 logical_minimum;
__s32 logical_maximum;
__s32 physical_minimum;
--
2.33.1
next prev parent reply other threads:[~2022-01-26 16:18 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-26 16:18 [PATCH 00/12] HID: fix for generic input processing Benjamin Tissoires
2022-01-26 16:18 ` Benjamin Tissoires [this message]
2022-01-26 16:18 ` [PATCH 02/12] HID: core: de-duplicate some code in hid_input_field() Benjamin Tissoires
2022-01-26 16:18 ` [PATCH 03/12] HID: core: split data fetching from processing " Benjamin Tissoires
2022-01-26 16:18 ` [PATCH 04/12] HID: input: tag touchscreens as such if the physical is not there Benjamin Tissoires
2022-01-26 16:18 ` [PATCH 05/12] HID: input: rework spaghetti code with switch statements Benjamin Tissoires
2022-01-26 16:18 ` [PATCH 06/12] HID: input: move up out-of-range processing of input values Benjamin Tissoires
2022-01-26 16:18 ` [PATCH 07/12] HID: compute an ordered list of input fields to process Benjamin Tissoires
2022-01-26 16:18 ` [PATCH 08/12] HID: core: for input reports, process the usages by priority list Benjamin Tissoires
2022-01-26 16:18 ` [PATCH 09/12] HID: input: enforce Invert usage to be processed before InRange Benjamin Tissoires
2022-01-26 16:18 ` [PATCH 10/12] HID: input: remove the need for HID_QUIRK_INVERT Benjamin Tissoires
[not found] ` <CAF8JNhLCXT7N4DubYYT12eMphDH-6U69ci7zFisJfZwsviJGkQ@mail.gmail.com>
2022-02-02 9:54 ` Benjamin Tissoires
2022-01-26 16:18 ` [PATCH 11/12] HID: input: accommodate priorities for slotted devices Benjamin Tissoires
2022-01-26 16:18 ` [PATCH 12/12] Input: docs: add more details on the use of BTN_TOOL Benjamin Tissoires
2022-02-09 6:22 ` Peter Hutterer
2022-02-14 10:48 ` Benjamin Tissoires
2022-02-08 19:19 ` [PATCH 00/12] HID: fix for generic input processing Angela Czubak
2022-02-14 10:51 ` Angela Czubak
2022-02-14 11:03 ` Benjamin Tissoires
2022-02-14 10:53 ` Benjamin Tissoires
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=20220126161832.3193805-2-benjamin.tissoires@redhat.com \
--to=benjamin.tissoires@redhat.com \
--cc=corbet@lwn.net \
--cc=dmitry.torokhov@gmail.com \
--cc=jikos@kernel.org \
--cc=killertofu@gmail.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nabijaczleweli@nabijaczleweli.xyz \
--cc=peter.hutterer@who-t.net \
--cc=pinglinux@gmail.com \
--cc=skomra@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).