Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2227632pxm; Fri, 4 Mar 2022 11:50:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjU+qrcU2zp6tY/OvVQKLvicR+YPwiSgWD91YGv/8kRdwnuGbALqyf7pJisC5DJRI8X5GD X-Received: by 2002:a17:90b:1d83:b0:1bf:39d7:207d with SMTP id pf3-20020a17090b1d8300b001bf39d7207dmr414694pjb.130.1646423458730; Fri, 04 Mar 2022 11:50:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646423458; cv=none; d=google.com; s=arc-20160816; b=SCZ8oCIiDWPFlEoRyMI1XGFkrSxxGdHoob09tko1g+J9s6FOgZ76RmqNlem/xe5VmF bRnzmoHOrEZ+YRf1V2+cJngRDn2EjTw7fCidCecAzicDiZOV7W7wNTh+y7Kd2jiPlvIb pmZ9e6ZloRiYgWShZ3UisWed8n4bgbZF+F9npFRKjpQh+2v+mRrritR28h5o5YheJtHx qbvkTfmAJK+P7OvuXnJh0CGUCaziY1QOHi9CqARDbfLV/50LIvq74bgbzXnd1/Phu5zh QucccPdNIwsqMswv3DmLAcqKCV7Ya4NsfLsEJwYrugkfD7PBSJzUvQ96gPvDMe2aAhjx 1mKA== 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=6D49UDKOrGqHPDx4/UWVPGxY1Jg6fRi4v4NPaaelVcs=; b=YKzRhT//f2rHQs9yc3avYKdj1h8tDmibLrckV7ee6mVqfw+RCWM5ad6Xq4n3nLjPP5 /5YlxNcErcc9I3PJ6lBvxifGvIb0b2gMax00GprEj+Oe3Q9v/EQsfO9AVlQzM+evglCy Q+vio8xFGmxpK0YaL/N8Xt1I76edSHw8sFifQEk0FrjNe/7R4/ArKGIVeUALHPSqdczN hRRjfsDBpxBS4Wzy7WJ21pPH/iHZRN0Pe8bKWc10heRxvG5tCrifsPEtK7Qad2fU0bMz 41SxmYa2HVsSbnF5vVNNcTPFhLiORXKzSDPsUXzvTaFqnpLu2LgsXhvkNrGdaq4yWorU loDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=REs4LvZQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id z20-20020a1709028f9400b0014d5b6f56c2si5495709plo.191.2022.03.04.11.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 11:50:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=REs4LvZQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 507A4233E4A; Fri, 4 Mar 2022 11:20:30 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234947AbiCDRge (ORCPT + 99 others); Fri, 4 Mar 2022 12:36:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241251AbiCDRgR (ORCPT ); Fri, 4 Mar 2022 12:36:17 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C0CD21D0D7A for ; Fri, 4 Mar 2022 09:34:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646415275; 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=6D49UDKOrGqHPDx4/UWVPGxY1Jg6fRi4v4NPaaelVcs=; b=REs4LvZQVmXvZ4E5QTyuszPIGSWDWZJYO9c/RMVmiIYpsOCcVtsCrqlEHB7iIe1UWXwF3s eD4MKYaI/DlrPjqQjzILv8+8EkybTxjHwU5+3GrD7CtFxtOMagnXAutswlIHmnAQaRx6Lm jP2lyw42GT1tteFREkGMomKslBRrFI4= 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-635-4zNjMA1AP86pw5KyP-IlSg-1; Fri, 04 Mar 2022 12:34:32 -0500 X-MC-Unique: 4zNjMA1AP86pw5KyP-IlSg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5AC7C5EF; Fri, 4 Mar 2022 17:34:30 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.192.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 50EE986595; Fri, 4 Mar 2022 17:34:26 +0000 (UTC) From: Benjamin Tissoires To: Greg KH , Jiri Kosina , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Shuah Khan , Dave Marchevsky , Joe Stringer Cc: Tero Kristo , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, Benjamin Tissoires Subject: [PATCH bpf-next v2 23/28] HID: bpf: compute only the required buffer size for the device Date: Fri, 4 Mar 2022 18:28:47 +0100 Message-Id: <20220304172852.274126-24-benjamin.tissoires@redhat.com> In-Reply-To: <20220304172852.274126-1-benjamin.tissoires@redhat.com> References: <20220304172852.274126-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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