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=1796383247; b=ogNERcBB+XqhQRXDhsFybO5kDq/ByaMe3b/ccvmyE3zhcDr6NTro+i9PhYw/TCgcTr6Y S+kigCgExhTJQvhWhMt2fsWXklzJjEyPJBsYQA8UxKEWzNHHe/ox4dVk0eQWhj5uF2cEV o8VkygiW+vYEZmhQaw7u/HLamkUOPBDQ8uY36I5NuLT+Ho7nibXR3NH3xVMDlMBXSbwQH 4VGT91T6wDtCtbtkNc5yAKc1BGJ2rY6z3/6o0T7z7ulUjPT/aSVUdlnKGDU1WpZspYtZg DrsPv3vOULL++6T2i0eZVZsGgHlNdJ1YP4bs3xVkR7fBuH4cFNpPMzbkEfNlDx3H63Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383247; 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=c/Rls1r5aqBRjrnx6LLRXbm2TF7XF9o0p7ntMWEj5Us=; b=xaSky876mHJa0O+RPkvoFtTO6+ZsMHYu1ZguFjBV7L8DotBO/cqH53N2Q5DMlAoAIB4M pM2ocIvtR4lzekdjTwL+9YAC1NhALmrNT56+3QknsZGfEcmSukXFyzJ4h2XS1SMzuUT1X RLMPQDE55dpgatX7dX9uPBSh5bqbxjw3eiTfP6o+iiWS+7XcMHmkNXz2LqckHFnG3Q9iA ctdh6VNL2d+7vDxt1jA4OwbEz6yVqDZlaTlcnZ9URzqHeHf3JX9iktrGaZD3hRCdAZMEy 4H3s/eOrsrSd/TNgwt5rPs7xg6T/rVfGHLcNo2rYwK3KxFnzVoKBKxQxHrE8ve+aBqA== 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=vkNzCnFY; 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 487A8606A337; Fri, 4 Dec 2026 11:20: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=vkNzCnFY Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1E251F000CE; Fri, 4 Dec 2026 11:20:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383247; bh=c/Rls1r5aqBRjrnx6LLRXbm2TF7XF9o0p7ntMWEj5Us=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vkNzCnFYEgfs18nYlqNyJ5i6NXUctGt0kxNr9m0rUSNaYLBT+aw/xlMZQJPvslbun i9seSXzXzv2YOAdbJU1or6QrkO0VZToh+N8IyrgDhXbDXKbty2Jl+HNRdFSzXIm1oP 8yHshmNW2XB6lXXZux2hHr1eGB3lD32SF+v5Wd08= 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 6.12 146/555] HID: vivaldi: Extract feature report value directly in vivaldi_feature_mapping() Date: Fri, 4 Dec 2026 19:03:09 +0900 Message-ID: <20261204100613.564819580@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-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