[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220304172852.274126-24-benjamin.tissoires@redhat.com>
Date: Fri, 4 Mar 2022 18:28:47 +0100
From: Benjamin Tissoires <benjamin.tissoires@...hat.com>
To: Greg KH <gregkh@...uxfoundation.org>,
Jiri Kosina <jikos@...nel.org>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>, Shuah Khan <shuah@...nel.org>,
Dave Marchevsky <davemarchevsky@...com>,
Joe Stringer <joe@...ium.io>
Cc: Tero Kristo <tero.kristo@...ux.intel.com>,
linux-kernel@...r.kernel.org, linux-input@...r.kernel.org,
netdev@...r.kernel.org, bpf@...r.kernel.org,
linux-kselftest@...r.kernel.org,
Benjamin Tissoires <benjamin.tissoires@...hat.com>
Subject: [PATCH bpf-next v2 23/28] HID: bpf: compute only the required buffer size for the device
There is no point in using 16 kB of memory if the device needs less
for all of its reports (uwhich is usually the case).
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@...hat.com>
---
new in v2
---
drivers/hid/hid-bpf.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/hid-bpf.c b/drivers/hid/hid-bpf.c
index b8c0060f3180..d56fbad990ed 100644
--- a/drivers/hid/hid-bpf.c
+++ b/drivers/hid/hid-bpf.c
@@ -61,11 +61,24 @@ static int hid_reconnect(struct hid_device *hdev)
static int hid_bpf_link_attach(struct hid_device *hdev, enum bpf_hid_attach_type type)
{
int err = 0;
+ unsigned int i, j, max_report_len = 0;
+
+ /* compute the maximum report length for this device */
+ for (i = 0; i < HID_REPORT_TYPES; i++) {
+ struct hid_report_enum *report_enum = hdev->report_enum + i;
+
+ for (j = 0; j < HID_MAX_IDS; j++) {
+ struct hid_report *report = report_enum->report_id_hash[j];
+
+ if (report)
+ max_report_len = max(max_report_len, hid_report_len(report));
+ }
+ }
switch (type) {
case BPF_HID_ATTACH_DEVICE_EVENT:
if (!hdev->bpf.ctx) {
- hdev->bpf.ctx = bpf_hid_allocate_ctx(hdev, HID_BPF_MAX_BUFFER_SIZE);
+ hdev->bpf.ctx = bpf_hid_allocate_ctx(hdev, max_report_len);
if (IS_ERR(hdev->bpf.ctx)) {
err = PTR_ERR(hdev->bpf.ctx);
hdev->bpf.ctx = NULL;
--
2.35.1
Powered by blists - more mailing lists