From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379947; b=0vHlOrPDpRLqXc8kFV5wDM01LqpsPQpqbljdHg4Z91a1xuNEVY/UXkmTE0OAqjMsy/86 V4VlpuIa0BVCHN6JSla1AcFHo1/b5LqoxJ3FaW0rb94wjLo1hcHkIGw2c10jYeLoYWEWQ M0adL8zYpbCzybKJueDMGECUTTfo/2Uc0J75Qa+m91jIRfIMSTXc3laAI2zXV3Ry08Rnp 2NFT+G18xeSZB2eNC5E8lLamgmXdORQlxyMwb9V8MpxgUY3Jrq0bZ7T9pvFQrL54nk7Kq EteGChDJ4SAOoXH0F34V+ekVHcpA3nrhcSEBzsIEfdlYu+6kb4ie14fUfyZVa6gTKqA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379947; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=Js0VqjjopbtzrTt+MObFrsf9M+zsjcZVK+WZ+W6PcYI=; b=bBF7nB8iJ1qlRJPVeeqA0fXMkACtzcDG6q9DkBJ0ZCEX+eCNC87MvzKOm3iesAozD9lb R6NcCVCqBg68XHz8rEGdzTKVzzZyAe6xccQNV52h3tM93QUXsHK12uyZ/p5qep6rkxNXx m/GIKg4ZRBR8UN/2C4z1QEBFrM8lUmr09ojizCZHrmDIUfxOpJ8QeU7L/wF1+m0FeEY12 o/4BI+FEzd/CmVSGCtpePC/F/Q8gd3IcntocSRz5I8FZbKNPbRMWor8m1mwB2jMFmL0Ae YSs+nrkw48912mQ7CWqUiP87m7UVo9KGmC29C9vohATFsW0WRGJO2gjULX0wObZNpUg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=neSSpXIM; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42543606A322; Fri, 4 Dec 2026 10:25:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=neSSpXIM Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88A6E1F000C2; Fri, 4 Dec 2026 10:25:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379947; bh=Js0VqjjopbtzrTt+MObFrsf9M+zsjcZVK+WZ+W6PcYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=neSSpXIMFvh2rmMTtptSR0iFAJJp9cwp/VQUDUT/durFqm1UjGxzAxBizDY0tYqeg H4Thg1h8MLLAXFxZFvXqDKlVN7/fp0JbYfaFMez8GVfUhXvd/SBcK37Pnf1ER97QU6 VtiE8yCo0MXMUBLWzS3xD89FQsfGz0xDGEACCkEM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dmitry Torokhov , Tzung-Bi Shih , Sean OBrien , Shashikirana H K , Benjamin Tissoires , Sasha Levin Subject: [PATCH 7.3 055/742] HID: vivaldi: Extract feature report value directly in vivaldi_feature_mapping() Date: Fri, 4 Dec 2026 18:58:39 +0900 Message-ID: <20261204100636.538375232@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shashikirana H K [ Upstream commit 8dbf66b011135422a28ee32da1d6aacbe08ddd7a ] Currently vivaldi_feature_mapping() passes the raw buffer returned by hid_hw_raw_request() to hid_report_raw_event() with the descriptor-declared report_len just to populate field->value[usage->usage_index]. Since vivaldi_feature_mapping() already has the target report, field, and usage in hand, and nothing else consumes field->value[] for this report, verify that hid_hw_raw_request() returns the expected report_len, ensure usage->usage_index is within field->report_count, and extract the value directly using hid_field_extract(). Also use __free(kfree) to simplify buffer cleanup. Suggested-by: Dmitry Torokhov Fixes: 33bbe04a15f2 ("HID: google: extract Vivaldi hid feature mapping for use in hid-hammer") Cc: Tzung-Bi Shih Cc: Sean O'Brien Signed-off-by: Shashikirana H K Link: https://patch.msgid.link/20261013-upstream-vivaldi-fix-v2-1-ecc20329d24c@chromium.org Signed-off-by: Benjamin Tissoires Signed-off-by: Sasha Levin --- drivers/hid/hid-vivaldi-common.c | 72 ++++++++++++-------------------- 1 file changed, 26 insertions(+), 46 deletions(-) diff --git a/drivers/hid/hid-vivaldi-common.c b/drivers/hid/hid-vivaldi-common.c index b12bb5cc091aa..1359a107e63bd 100644 --- a/drivers/hid/hid-vivaldi-common.c +++ b/drivers/hid/hid-vivaldi-common.c @@ -5,11 +5,13 @@ * Copyright (C) 2022 Google, Inc */ +#include #include #include #include #include #include +#include #include #include "hid-vivaldi-common.h" @@ -33,13 +35,14 @@ void vivaldi_feature_mapping(struct hid_device *hdev, { struct vivaldi_data *data = hid_get_drvdata(hdev); struct hid_report *report = field->report; - u8 *report_data, *buf; - u32 report_len; unsigned int fn_key; + unsigned int offset; + u32 report_len; int ret; if (field->logical != HID_USAGE_FN_ROW_PHYSMAP || - (usage->hid & HID_USAGE_PAGE) != HID_UP_ORDINAL) + (usage->hid & HID_USAGE_PAGE) != HID_UP_ORDINAL || + usage->usage_index >= field->report_count) return; fn_key = usage->hid & HID_USAGE; @@ -49,54 +52,31 @@ void vivaldi_feature_mapping(struct hid_device *hdev, if (fn_key > data->num_function_row_keys) data->num_function_row_keys = fn_key; - report_data = buf = hid_alloc_report_buf(report, GFP_KERNEL); - if (!report_data) + u8 *buf __free(kfree) = hid_alloc_report_buf(report, GFP_KERNEL); + if (!buf) return; - report_len = hid_report_len(report); - if (!report->id) { - /* - * hid_hw_raw_request() will stuff report ID (which will be 0) - * into the first byte of the buffer even for unnumbered - * reports, so we need to account for this to avoid getting - * -EOVERFLOW in return. - * Note that hid_alloc_report_buf() adds 7 bytes to the size - * so we can safely say that we have space for an extra byte. - */ - report_len++; - } - - ret = hid_hw_raw_request(hdev, report->id, report_data, - report_len, HID_FEATURE_REPORT, - HID_REQ_GET_REPORT); - if (ret < 0) { - dev_warn(&hdev->dev, "failed to fetch feature %d\n", - field->report->id); - goto out; - } - - if (!report->id) { - /* - * Undo the damage from hid_hw_raw_request() for unnumbered - * reports. - */ - report_data++; - report_len--; - } - - ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, report_data, - report_len, report_len, 0); - if (ret) { - dev_warn(&hdev->dev, "failed to report feature %d\n", - field->report->id); - goto out; + /* + * hid_hw_raw_request() will stuff report ID (which will be 0) + * into the first byte of the buffer even for unnumbered + * reports, so we need to account for this to avoid getting + * -EOVERFLOW in return. + * Note that hid_alloc_report_buf() adds 7 bytes to the size + * so we can safely say that we have space for an extra byte. + */ + report_len = hid_report_len(report) + !report->id; + + ret = hid_hw_raw_request(hdev, report->id, buf, report_len, + HID_FEATURE_REPORT, HID_REQ_GET_REPORT); + if (ret != report_len) { + dev_warn(&hdev->dev, "failed to fetch feature %d: %d\n", + report->id, ret); + return; } + offset = field->report_offset + usage->usage_index * field->report_size; data->function_row_physmap[fn_key - MIN_FN_ROW_KEY] = - field->value[usage->usage_index]; - -out: - kfree(buf); + hid_field_extract(hdev, buf + 1, offset, field->report_size); } EXPORT_SYMBOL_GPL(vivaldi_feature_mapping); -- 2.53.0