Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2256545pxm; Fri, 4 Mar 2022 12:28:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzR5pfjWSzsiUYVHTyao3lDm3w8Zbvi+YUenYEU8ikz+3Lcc5IfyFW8p8V/Pj1BVpnCC8lc X-Received: by 2002:a17:90a:ab08:b0:1bc:3ece:bdc with SMTP id m8-20020a17090aab0800b001bc3ece0bdcmr434269pjq.32.1646425685104; Fri, 04 Mar 2022 12:28:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646425685; cv=none; d=google.com; s=arc-20160816; b=JZsyH5tEB4IbT95I8PCr/L1I35dF3qS3uEDDisBHPuZsx4NJxty8fy4Qxx0IyGGl+G FZ2ZNRUVsU9ICtFuVueeKZzfmH9AczgTbroK88gP6CTYTXB6ThPbdZA3lXifoky8rv8i Bbqxi3RmqMdOUdusTbMVcT+p1bhnqbu6LQJSaHP/r5O1vb1yhBiRo96u7AJ9U1tXfTDN LlJyVYhAv78MReS/DIJzG+O9sb6TcvBWHbSEIsu005ycSGzpvCdkYEXgF7qv0gJbDp0l 4DKPkObPW5DvO52P/ETKckqHILVYwbKoriW3+ps/ldDcGAVz5GoMalJNae5IWJKGkSV2 TiMw== 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=T7C9fiyEzdqJww9q8MHw/Ezwfh03XjAvosyY3fabJCA=; b=Z1arZuL/N1dnCHOtugN+9n7RmEnaAr4uAvUIHDahgwnuu5QkQ33SUZrgdvofuWzdj0 fXAvOLNamRLZhdFdWsCtWR6FLW3qtgXD8n7j0ShRAzmvVIDafrcLyPI57iiMwfltIEdV zBquupLRDNN7TLzH3HzVacKphoMfNlYIbwrj29UWONI9SMvO6LkEdOoZjhZjwI+rYyqk FnZiErLLKA/PMrj9ioR3KCCLx7WPw+RVZT/E7ddCPkM8ule1W6Hsf9dofIWhWv0OF38T O3LLDv6tGabjI/4En2qvL0o3Wjxlgjc/87kJ7ARK2kEQfhZJQ6o7N850upVoM+JbemHT SFVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jD1zyKxQ; 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 m1-20020a635801000000b003744257747csi5407396pgb.77.2022.03.04.12.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 12:28:05 -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=jD1zyKxQ; 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 8E76E21F810; Fri, 4 Mar 2022 11:36:36 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241272AbiCDRgb (ORCPT + 99 others); Fri, 4 Mar 2022 12:36:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241261AbiCDRgS (ORCPT ); Fri, 4 Mar 2022 12:36:18 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 044361D17A9 for ; Fri, 4 Mar 2022 09:34:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646415278; 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=T7C9fiyEzdqJww9q8MHw/Ezwfh03XjAvosyY3fabJCA=; b=jD1zyKxQMJfX4r0LWOEqBsIJkyElSXPxTLuNw6TpgX29uAlyOwb++GJlx/KPMWs8EYMvZj i3YnlfTeT2HgpDdOISaGnLNgVs59OJp+5kn1gaH5t8o43lell8A7JWEJMaPQDP589gxTI4 Y+gBa4WCXaVwyJCabhgL+3iTLcrKg50= 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-424-vDZVZTx9PuGg1UxPErrkZQ-1; Fri, 04 Mar 2022 12:34:37 -0500 X-MC-Unique: vDZVZTx9PuGg1UxPErrkZQ-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 98CE75EF; Fri, 4 Mar 2022 17:34:34 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.192.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAE9186595; Fri, 4 Mar 2022 17:34:30 +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 24/28] HID: bpf: only call hid_bpf_raw_event() if a ctx is available Date: Fri, 4 Mar 2022 18:28:48 +0100 Message-Id: <20220304172852.274126-25-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 the context is allocated the first time a program of type DEVICE_EVENT is attached to the device. To not add too much jumps in the code for the general device handling, call hid_bpf_raw_event() only if we know that a program has been attached once during the life of the device. Signed-off-by: Benjamin Tissoires --- new in v2 --- drivers/hid/hid-core.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index d0e015986e17..2b49f6064a40 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1751,10 +1751,13 @@ int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size, u8 *cdata; int ret = 0; - data = hid_bpf_raw_event(hid, data, &size); - if (IS_ERR(data)) { - ret = PTR_ERR(data); - goto out; + /* we pre-test if ctx is available here to cut the calls at the earliest */ + if (hid->bpf.ctx) { + data = hid_bpf_raw_event(hid, data, &size); + if (IS_ERR(data)) { + ret = PTR_ERR(data); + goto out; + } } report = hid_get_report(report_enum, data); -- 2.35.1