Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2598966pxb; Thu, 3 Feb 2022 09:51:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzp0CDNVvGb0v9SzHvhbc/vv+XXC+5f4RcXEiHUQeQEd9yT8Q6tuMD9Yv075CwNEaJ0PLIL X-Received: by 2002:a17:907:d28:: with SMTP id gn40mr26420963ejc.750.1643910686503; Thu, 03 Feb 2022 09:51:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643910686; cv=none; d=google.com; s=arc-20160816; b=xax1tYlLVSMBWHwbTLxKhspHWotpztkxfy8BjamDf4GoNpVIibkoiziRx6fGXaFOYS TQQO4ejoWaMLuoSmJLwA5OdBBHfjs6ruUD9yCrOrsZ1/Fg3sFo1EYO3CgXHNrHG+Frt6 mB72LGGNpa7afCW6j+0mUlbY+I/JBUW2fW9/QKAHYG5VjMYHF3AK+cjEcT8o/R2UPgja dPAEkLLmifCU5aCs6bMMjnn1k7rjkdYCjEmEJ7JVnLPcvA04/U04EooVcJ7667s0dqpl rabmgE1b2s3PY9LXdoaCEggNFTbFkDjo/Ayj0eOR8JpLaYXx1915HKjBpc2rl8WntHe8 SJIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2G3/sS/C1EPSPkBFd3nsE75tTouY/LNBfeLI0lhMMcQ=; b=nyC7KEJsGkhTLUi2RDNGmA3d1IPnF8/qtsUBnJr0/OO4NQq6f7MJlqxTXxLUt/O8sN +WIin0SKPuM3EtKKS6qi4MBEMfuwrZ3GPb+oiTjFyORcL4CkGHcGPqwpvqxUbXVTI4dd fCB03L/lpUyTprjK2+ug0ACgzY4f8nNjyQbOMGxyrkmkYOrnL4uc3auFFJb6pwx7O4A1 NKHGXXBftAvY4jomRF0Sxm97Onmn+k6VRUZihleKozhcsublN9ywv+XzSWczry5IrdHG bDjDQct15s4ySON18jM77nUx6y7SY7Q2cgfOgRMWgPpgxIN2DqN9qt8wpW31hvcUKCyL Tf9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gQslpc8l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw21si18210138ejc.311.2022.02.03.09.50.59; Thu, 03 Feb 2022 09:51:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gQslpc8l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351245AbiBCOfC (ORCPT + 99 others); Thu, 3 Feb 2022 09:35:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:29369 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351313AbiBCOds (ORCPT ); Thu, 3 Feb 2022 09:33:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643898827; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2G3/sS/C1EPSPkBFd3nsE75tTouY/LNBfeLI0lhMMcQ=; b=gQslpc8l+nspgJCgk/EOrir7Ek2z7KQ/wXOIwYL1YV2StQ+PT4M4W98lAZh/SC9X1Ys16+ lkJRpKfuqGeTXbbwKg3ywsPtWSDZF9UAMBqMLIJS5Cv2ncFaAWHsfGCyrx8bPPrgOj0OwV yzVw/Hal/UPWrVa2QTQBEIXtBadKFPc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-619-bW39gFqeM-i7cBZ6HGeAtA-1; Thu, 03 Feb 2022 09:33:42 -0500 X-MC-Unique: bW39gFqeM-i7cBZ6HGeAtA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8EDA78145E4; Thu, 3 Feb 2022 14:33:39 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.192.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 085347D4AF; Thu, 3 Feb 2022 14:33:11 +0000 (UTC) From: Benjamin Tissoires To: Jiri Kosina , Dmitry Torokhov , Jonathan Corbet , =?UTF-8?q?Ahelenia=20Ziemia=C5=84ska?= , Ping Cheng , Aaron Armstrong Skomra , Jason Gerecke , Peter Hutterer Cc: linux-input@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH v2 08/12] HID: core: for input reports, process the usages by priority list Date: Thu, 3 Feb 2022 15:32:22 +0100 Message-Id: <20220203143226.4023622-9-benjamin.tissoires@redhat.com> In-Reply-To: <20220203143226.4023622-1-benjamin.tissoires@redhat.com> References: <20220203143226.4023622-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we have a list of fields/usages by priority order, walk through that list to process the inputs instead of using the order provided by the manufacturer. Note that this changes the way we update the values in the struct hid_field: Previously, once a field was processed, we updated the new values. Now we need to wait for the entire report to be processed to update the values. I don't think it will be an issue: because we were relying on the device ordering, there were no guarantees to have a field stored before an other. Which is why we introduced .report() in drivers to have those values updated. Signed-off-by: Benjamin Tissoires --- drivers/hid/hid-core.c | 45 +++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index b38528118642..db925794fbe6 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1657,17 +1657,48 @@ static void hid_process_report(struct hid_device *hid, int interrupt) { unsigned int a; + struct hid_field_entry *entry; struct hid_field *field; - for (a = 0; a < report->maxfield; a++) { - field = report->field[a]; + /* first retrieve all incoming values in data */ + for (a = 0; a < report->maxfield; a++) + hid_input_fetch_field(hid, field = report->field[a], data); + + if (!list_empty(&report->field_entry_list)) { + /* INPUT_REPORT, we have a priority list of fields */ + list_for_each_entry(entry, + &report->field_entry_list, + list) { + field = entry->field; + + if (field->flags & HID_MAIN_ITEM_VARIABLE) + hid_process_event(hid, + field, + &field->usage[entry->index], + field->new_value[entry->index], + interrupt); + else + hid_input_array_field(hid, field, interrupt); + } - hid_input_fetch_field(hid, field, data); + /* we need to do the memcpy at the end for var items */ + for (a = 0; a < report->maxfield; a++) { + field = report->field[a]; - if (field->flags & HID_MAIN_ITEM_VARIABLE) - hid_input_var_field(hid, field, interrupt); - else - hid_input_array_field(hid, field, interrupt); + if (field->flags & HID_MAIN_ITEM_VARIABLE) + memcpy(field->value, field->new_value, + field->report_count * sizeof(__s32)); + } + } else { + /* FEATURE_REPORT, regular processing */ + for (a = 0; a < report->maxfield; a++) { + field = report->field[a]; + + if (field->flags & HID_MAIN_ITEM_VARIABLE) + hid_input_var_field(hid, field, interrupt); + else + hid_input_array_field(hid, field, interrupt); + } } } -- 2.33.1