From patchwork Wed Jul 3 21:37:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 809589 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 816D51940A2; Wed, 3 Jul 2024 21:38:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042688; cv=none; b=A7a9xqkEIyFaJfOtLgzQcY6lfrF9zN2MgfmLJlqxnJhxgsPg/AQhM6tbcfBlXFzyXENcvzlEWazEZm/ivii7WUArB17GhKZmBwBZFOlIEYOkO7+X9LiyCSaeU1yFJ9r3QUPHDUYNirwi3rxne77D1ptuPxUd7hXBWwAF8aIq3EE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042688; c=relaxed/simple; bh=GlsgRKS0Vge58JDAIhBVWh6io5q7xcR19bX1ZhvfVzs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tdX7m3vgjaRCaiQFAaS7OSgyxECloirePjkK80FLpdMVrKosLBHnFJ9LlNo7Bz+7DztQOycH0pfp3nvrB62iCAxQhqlHBC6B68KChXO2czTsrgdRX+wDvD8ytLn7beQCS20npw97fLMm4Z0nHayLDTCj5aQwNEANt9yusjTsxdM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RtVlalNM; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RtVlalNM" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-73aba5230b6so15203a12.1; Wed, 03 Jul 2024 14:38:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720042686; x=1720647486; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rTvHP/zEyqQZs4J1JDZsqVRaoeYMy5eTUMNrxsyDLMg=; b=RtVlalNMcZjD7TvnrYGYlllJnYYHrYgnz4p1cnyKmn2/uC1ewKNUQPbXRuH+vyu1/n NmcukGysjAVmgfEKat8jXm1eG64mqPAxCXj7TSlImFLBr2EmVHuCzCXKPFWh8Sqc6axA TEL3sbU3ESHQLVcsjdFIz7pjeZC1P0wLFQnhXleS49WtVb62QjQ7B0hISpaQaf0bxLSc FyMp7kXPmmPH3M4ln2Y8Bl36uX6Zkdm3397fdUhkOGH3gBkQqXC+RSlbmHmYqjWJPcKj kGbpzMhcUuxPfRMYdBi69gh01RKyv+6C8hU0CfJCHjSy/gsP9RtmQr6A7PFVFwtxSDq7 EU2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042686; x=1720647486; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rTvHP/zEyqQZs4J1JDZsqVRaoeYMy5eTUMNrxsyDLMg=; b=IEbfSqdhJsQ20w560HSaNYGrrizpGmq5819lRB7JpnOihhk3VBIf9NFtFUGOgqJPyJ Jy0eLYfxUriNahE/lurM9OoFDtOOgYhonskfw8tsaWzbubrTjWu1yt5vMglHqmm+e1Oa +9wSiRm+EjpZ/UD9ZaMxPh4vv8okN9QVrNc89JIbmwrpdOGjQ6DTnsixqibRDvEDv/nK zXdWUYrz4dgbAY6SkKDLyfwE05iPkcC1ONEaCbppmjRyN6VmqKaqZcHpbhbcqDzb+vpN bEkFXtXx5vFri2feyTNwIQSGWvuOLwPX2I/dlYyuT8oGpoMYldO61/wz4EkBpydFaCax dW2Q== X-Forwarded-Encrypted: i=1; AJvYcCW5zzhkIN1VF+mX0b/TSTDtlaWEspmn0wojKNu8sE6XpW+w1lxXUesVU2KkP8Ua6F1G8Mu9Ry1v+/zL7KjhgyV2YLxIPDOJUcpgowXr X-Gm-Message-State: AOJu0YymIHVePg6nBxjKlhgOW9szsvELsVyJ+JhAyaxuDfTxTQfndYuW qyDMRInI8QM1buw4K3bW3DT+KTse8U1OvWDtTOQk8SbGEmxlTa95bFISIg== X-Google-Smtp-Source: AGHT+IEZl1MGu/jG2Mj1/oSOl1eodan6Z1ZmUfct2BcPNQ1pYybBsYEokOgcASYuNg5WldzOS5QnnA== X-Received: by 2002:a05:6a21:6da1:b0:1b6:dd1e:da51 with SMTP id adf61e73a8af0-1c0bff5a968mr4684954637.21.1720042686386; Wed, 03 Jul 2024 14:38:06 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:dd06:1fb8:e932:1ed8]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70801e631f0sm10886376b3a.4.2024.07.03.14.38.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:38:05 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Benjamin Tissoires , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/7] Input: evdev - remove ->event() method Date: Wed, 3 Jul 2024 14:37:48 -0700 Message-ID: <20240703213756.3375978-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog In-Reply-To: <20240703213756.3375978-1-dmitry.torokhov@gmail.com> References: <20240703213756.3375978-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Input core favors ->events() (batch) method over ->event() method if the former is defined, so there is no point in defining evdev_event() as it is never called. Remove it. Signed-off-by: Dmitry Torokhov Reviewed-by: Jeff LaBundy --- drivers/input/evdev.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index 51e0c4954600..05abcd45b5d4 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -308,17 +308,6 @@ static void evdev_events(struct input_handle *handle, rcu_read_unlock(); } -/* - * Pass incoming event to all connected clients. - */ -static void evdev_event(struct input_handle *handle, - unsigned int type, unsigned int code, int value) -{ - struct input_value vals[] = { { type, code, value } }; - - evdev_events(handle, vals, 1); -} - static int evdev_fasync(int fd, struct file *file, int on) { struct evdev_client *client = file->private_data; @@ -1418,7 +1407,6 @@ static const struct input_device_id evdev_ids[] = { MODULE_DEVICE_TABLE(input, evdev_ids); static struct input_handler evdev_handler = { - .event = evdev_event, .events = evdev_events, .connect = evdev_connect, .disconnect = evdev_disconnect, From patchwork Wed Jul 3 21:37:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 810179 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4DB519415E; Wed, 3 Jul 2024 21:38:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042690; cv=none; b=N9KfrwsD94+AVMv0Z/QNtq8uk7yKjMaj1GlE6FGk0ArQNImO1Jp02aRIaEBd7e2tzvoFmqyJ06TB6/v+A5cEYrkyLYiBGc0ux6W3rnb5kpXKBWEutNQnrPwivdtjfKmUsUo6iL3EmyRYYE7YK3CHp4L1SsB5xW7myVYUSYhZlSY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042690; c=relaxed/simple; bh=YIFleg+R00NGRRL18iImGLmyOLoJZnxEQaxjf7Y/HqA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U40wOGQrsPiqMmq07bRhC8iRQe6unCsU6uTI8kAqEGRjXVzIc8GHfTAth+5eb0W5KJhOc1m/ZLV4QGr3h2v4dKkFK8VhT1YmEAkGhJ4RqJ5/6KP4fc9q1/vZszrUPd6TneBc1UKTZlD7lYyRCP5HF3EReEoBNNiLMOdIhCIKVlo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aCu13OoD; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aCu13OoD" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-70af4868d3dso12701b3a.3; Wed, 03 Jul 2024 14:38:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720042688; x=1720647488; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oNymPC6bH94Z2+TzJb2KNwf0SwZ3m76uCy9hLMGkTp8=; b=aCu13OoDCy3GM0FNuVr9k1BHY5T/K+A85VGcH/0IecSPRKDRnb+16tG9etTt8bZ8IX fGRQrrjrqC6pG37oMTka2TgoXn4pubJyILUdHahX/nz9Bbpm2f2KiS0qRXjzgA9cUTli Wj2uRRXYKOSSrZwOSNNXSC3gE8k/Ywar3VJerPPDSaOEOjNW8GXHHD8M+bTvBwa+KN8h psEzecD7+aTgeZX2Wm/XqEkobZVIC2zfxTOcU9CYyJGQ4l3PafzooO8AHeEUuMsB5Dm9 sHMRU2iX0vdZ7g+M119gzKwV2EXC1bvh/QUkyxXMA13qobEWTLNFj2ZNFj4dlygZ8eEc 1B6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042688; x=1720647488; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oNymPC6bH94Z2+TzJb2KNwf0SwZ3m76uCy9hLMGkTp8=; b=Fj9R9H8B704Mjdid+uyyOqJXGoZEG2Vwc8BfXDSNw+XSf7LxrbHF9NktD/j7t8Xw3I YN0qTjbSo4rO6xwvt1yKgwT3D4YiI2/6I1vaom0fIpeH9ar97mkEVPgG3Zn4uQuA18db 7m1OtO/MSOLNbiG+jghukWy+bwFcRTcnbxXEM0dxLtPUNqBc90q4G8BroCgDO9dC3wXb QhYpRGnsodEZG5vsz494GMNFe+Hh7vjrPQlXezbndM2tZxhku+ulnW2qot/LXuN/ZSaS mshKdF/hVLWkxSKxN5Rc9QoHvst65xdphR7bCWxS6hhYUjF2EMhEqpMwaN9pdiGMh1qw KHyg== X-Forwarded-Encrypted: i=1; AJvYcCUob0uVayPaLUVwiccIuWaWYxdiSO6eluVv0ykvIt0DVsFPGEFdgW7UOBfyjX6UCRhSQ4Uq2QwczCVH+t5h7rPwb9xZO+AW8Jq5Vw9P X-Gm-Message-State: AOJu0YwicHts0FHPGRoNuzkdEd7w+Kp0Hr9wcngky9jOgOD8DkilGJNX sY+YrtnILM80Qk9U5nsyz5teW1HWTiLqF/bdrLMDEAjFkuz1OwjtB7+NfA== X-Google-Smtp-Source: AGHT+IHwdBP+b9trbBSuCVo08uEFmEiA6ywKIg/9HRA1SKsmPdX0ZyzKzt+f9k6caosUH/EfBgayLg== X-Received: by 2002:a05:6a00:2394:b0:6ec:f2e7:21a8 with SMTP id d2e1a72fcca58-70aaaee2a38mr12265080b3a.21.1720042687678; Wed, 03 Jul 2024 14:38:07 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:dd06:1fb8:e932:1ed8]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70801e631f0sm10886376b3a.4.2024.07.03.14.38.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:38:06 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Benjamin Tissoires , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/7] Input: make sure input handlers define only one processing method Date: Wed, 3 Jul 2024 14:37:49 -0700 Message-ID: <20240703213756.3375978-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog In-Reply-To: <20240703213756.3375978-1-dmitry.torokhov@gmail.com> References: <20240703213756.3375978-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Input core expects input handlers to be either filters, or regular handlers, but not both. Additionally, for regular handlers it does not make sense to define both single event method and batch method. Refuse registering handler if it defines more than one method. Signed-off-by: Dmitry Torokhov Reviewed-by: Jeff LaBundy --- drivers/input/input.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/input/input.c b/drivers/input/input.c index fd4997ba263c..7e4f8824f4fd 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -2517,6 +2517,26 @@ void input_unregister_device(struct input_dev *dev) } EXPORT_SYMBOL(input_unregister_device); +static int input_handler_check_methods(const struct input_handler *handler) +{ + int count = 0; + + if (handler->filter) + count++; + if (handler->events) + count++; + if (handler->event) + count++; + + if (count > 1) { + pr_err("%s: only one event processing method can be defined (%s)\n", + __func__, handler->name); + return -EINVAL; + } + + return 0; +} + /** * input_register_handler - register a new input handler * @handler: handler to be registered @@ -2530,6 +2550,10 @@ int input_register_handler(struct input_handler *handler) struct input_dev *dev; int error; + error = input_handler_check_methods(handler); + if (error) + return error; + error = mutex_lock_interruptible(&input_mutex); if (error) return error; From patchwork Wed Jul 3 21:37:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 809588 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7627194A42; Wed, 3 Jul 2024 21:38:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042691; cv=none; b=goF0A/UgfyHfwIlnw+NFQCFKq5/EjWjoMSxHhOeKcJf/UdxCl+dq9DtB0z/ojew3Jop7IL9k+71i22fqgmY7y9eEyLDtN6xU6CpCwhsPTI0GL0sS2NPVRT+KgSv1iAbRB8aTyfqoCoRTkHTAXKD5VvXJEwOQib29POW4JkrXLf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042691; c=relaxed/simple; bh=qn1bfiZa9Wt1bHCvSu7/CFvYP8ZtrUUyc8t5ef9UDEs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M4DjqQHqywJrw/+1PaV8kUOK4iDHxrXC/p4DuZul2HkDOdkcIE1WXXEYBZ8IT8sW2ciwrW6mJIzQ2WtQ4qFW6IUg88DrYIaU4Y/eZVyqNyMtE0UPTQDHk2UXGluZuTmgxcwETyg/hcJnsceb+PS09Eb68OECdxElxb/lCz9giNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cm1aOsHm; arc=none smtp.client-ip=209.85.215.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cm1aOsHm" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-75c5bdab7faso544329a12.1; Wed, 03 Jul 2024 14:38:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720042689; x=1720647489; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O0a0Jx1WOSLgu2QcRu/CLQEgd8mBLORvujCrOGKL+DU=; b=cm1aOsHmTLuCvWXhWoHUUklH57sB/vYbYQogpsL62th5qrX9OdpQpgs8yBE8a9RcH/ X1go63LmHMu6eoZxlI/nvXDt5sgAaVXchI2e9I6iTAkqz7piejoEFnddpzCV89OYjJgK 10BStvTiiW/MHxUh/2DCnL0jreTRNrelrWi9Dg0COraELDCcrP2yF0KVhwYyioq9aRh5 ZLcgQVIucag1uz/ip55uf237h6EuO+yhHScF2+s7AoZwafhtOERqGMlmKKNkbPu8h/ha 7z88X+zH2kLJIGmeJT9mpUIus8puNFukS8wX1D139N2OqeVGP3q0vEUxx3h7CJUJ0wGE 5MgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042689; x=1720647489; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O0a0Jx1WOSLgu2QcRu/CLQEgd8mBLORvujCrOGKL+DU=; b=jAVTzQcO0R64gPyzFs0qBC+GGN+mNQYQqikDsd/y4/sbO8aaA7P3ohpMPkjkJzxQGG at7L7+8ddBnRPVC6rt+5mhIq3moe5O1MlFbHXBmUxudvZ8kXkA+samGqg1l37W3B4GZL SnVfcLFfcY1wwy0e4ZFw9WUpGU4dQS9MDPGwVNYIQ0f0CjUpeyvMqZfiEY39UrD8ayS0 3mZc3DqH+9nCD39eerBseY08gdxzq5LYHYEPo5JjhXG9yH3EojD4LtWzp/6WmmmqvOaL CZRkh2bKWRhEy7FjCYngiXnqALZ1rMdDaLNppW0cAcJ3LAnsl5Zm6oXKUHfR94c8hVaO mffA== X-Forwarded-Encrypted: i=1; AJvYcCU4zAmzv/enSemXXzscU0Hrcgx1TUkgr28NcGTHDciWxjcL3sMMLs43IVh+7YAbUIeoZ9HuGx2W42ketTZXFxST02BQ/JrXC1OpKgZt X-Gm-Message-State: AOJu0YxRLepLYdJUUS1KT7mRF15SxYj/En1tM3OTjtv0cQu1UVjfTd2S yGv/NQ22LQbrJtlzMCiN0yZ+epOVx9Ccuj2klTICOC3jolmIK/7/lcYksQ== X-Google-Smtp-Source: AGHT+IFvY+WSk5ZcoZUXAb4aXd46QfdkMD7q7yJlJTblyGPzWOYoJXmppABuQT9YQlMiXavUOlp1Iw== X-Received: by 2002:a05:6a20:4307:b0:1bd:233f:e60e with SMTP id adf61e73a8af0-1bef6140792mr14926722637.19.1720042688619; Wed, 03 Jul 2024 14:38:08 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:dd06:1fb8:e932:1ed8]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70801e631f0sm10886376b3a.4.2024.07.03.14.38.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:38:08 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Benjamin Tissoires , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH v2 3/7] Input: make events() method return number of events processed Date: Wed, 3 Jul 2024 14:37:50 -0700 Message-ID: <20240703213756.3375978-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog In-Reply-To: <20240703213756.3375978-1-dmitry.torokhov@gmail.com> References: <20240703213756.3375978-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In preparation to consolidating filtering and event processing in the input core change events() method to return number of events processed by it. Signed-off-by: Dmitry Torokhov Reviewed-by: Jeff LaBundy --- drivers/input/evdev.c | 6 ++++-- include/linux/input.h | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index 05abcd45b5d4..a8ce3d140722 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -288,8 +288,8 @@ static void evdev_pass_values(struct evdev_client *client, /* * Pass incoming events to all connected clients. */ -static void evdev_events(struct input_handle *handle, - const struct input_value *vals, unsigned int count) +static unsigned int evdev_events(struct input_handle *handle, + struct input_value *vals, unsigned int count) { struct evdev *evdev = handle->private; struct evdev_client *client; @@ -306,6 +306,8 @@ static void evdev_events(struct input_handle *handle, evdev_pass_values(client, vals, count, ev_time); rcu_read_unlock(); + + return count; } static int evdev_fasync(int fd, struct file *file, int on) diff --git a/include/linux/input.h b/include/linux/input.h index c22ac465254b..89a0be6ee0e2 100644 --- a/include/linux/input.h +++ b/include/linux/input.h @@ -275,7 +275,8 @@ struct input_handle; * it may not sleep * @events: event sequence handler. This method is being called by * input core with interrupts disabled and dev->event_lock - * spinlock held and so it may not sleep + * spinlock held and so it may not sleep. The method must return + * number of events passed to it. * @filter: similar to @event; separates normal event handlers from * "filters". * @match: called after comparing device's id with handler's id_table @@ -312,8 +313,8 @@ struct input_handler { void *private; void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value); - void (*events)(struct input_handle *handle, - const struct input_value *vals, unsigned int count); + unsigned int (*events)(struct input_handle *handle, + struct input_value *vals, unsigned int count); bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value); bool (*match)(struct input_handler *handler, struct input_dev *dev); int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id); From patchwork Wed Jul 3 21:37:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 810178 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB333194AC2; Wed, 3 Jul 2024 21:38:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042692; cv=none; b=lqTqv5Ov/TjfsJ2jJ06K3aGDaycSrY926Zs17GABbLZgC3rVLD26NoCrZw5g3qWm4G/5ujyE1psiU0AC32YbnqeG0sA92mZh943sNA7aLG5BrrhresgROwUM5aSb3Jtd+t/9ajTubyDV+rD1V7AdmEhYK+OZKABLiZnkw2a3CNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042692; c=relaxed/simple; bh=93BG1Oebqq4+AkDSHpvLyUcw+spU7y6yxysIeAtqQcY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gOZ5Ig2YFpGa4Nz3spAbLbphQP9pTd855g7Jk/CIyycaeUbCwxrONC+DNrleKfYWX+vmuVCYnyshJPdlXs+g78vdsloY+YaP+CObVBC3kximAfE8xe1c/czlQRlOSgREj4uLViUn5DBYU8eVIjsMUiSoY1DGXCzK6TPmkcS8jrA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=G0/f1hQP; arc=none smtp.client-ip=209.85.215.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G0/f1hQP" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-6e7b121be30so3526291a12.1; Wed, 03 Jul 2024 14:38:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720042690; x=1720647490; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GBBVw8f8tnVHi/QRxdBxtSwkH9QahZ7XU4RUYJ2m6T8=; b=G0/f1hQPf61I4syTqGO6uIX2WQRhPHyKpJ67AIfOVydrMLPRUrOobS6oaK2Yk3yKdc Jkikm5GHGL6IjcaaKwmHn7SVjnkxcX/8DT/Xjp1WqtSIRiVv69LBlhTL5deGtRJvriQ6 f/NxrTYV5TblA+Rn7plcCIAgdARo1CWtCmXBxg2ydNNdi8VDR/G+eVSN+yiOSg1AwNnO zGdovDsBVItx7m6Kg6bp3ZCDxZkuFMZwWIFcsSNlDNyX6HjWcNewcrY0/A1Fxm2DeyUu +vrPhrlaxS7VuyV8xhfcwedRXv4fIt9QctiPYVlz/OuzF7evwszWgrd9zJUs+YPJhj2L S2CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042690; x=1720647490; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GBBVw8f8tnVHi/QRxdBxtSwkH9QahZ7XU4RUYJ2m6T8=; b=ct65BKkM/yYbLT1XyOw3ZG92JBW2bXRaloM58DZG6DlFxgR3f1FkR6El9wq2h4jGuU r9bAvZyI+et23LhgNft+ak1owd3lnvUR/AtjQEatrF0xhrV82hKjjUh2lHRt/o7Z4uas pmfxr/1BNr+EPbseaQey60LdzcAHD9k49riyHVLZS7vY8ngMslQrrnfMNDpl7O78oT4C nDsbbge5BNs4RFFzwbsmzqKckoc2NMBQOwg1daaawQ6VtkY8CchOAh3fhxhmkkR3XUzy BbIcXYX1FbaSKTs/p98Kqhegvu5UeuDInXznXlku7JhW9Kw/cy0HqmL5lnVyfytxuFnT Eluw== X-Forwarded-Encrypted: i=1; AJvYcCVOsaF4lI9y54SmilgATflpqYNmzpGFmY1EP5arRUqRJ3gHFz8DxKzwLXubgk16h32ljtyGsfHtjccq00puqweOaRkDoarKTqAAlGqR X-Gm-Message-State: AOJu0YzYAM2SRWUNwAm6GZy9XC+RzgB7vMEKTswPFubeQo7L3ZMhD5/W N+o44HGUxlQnytTV13IeNSOU+5m3wRmKL6/o4IlYTSFSgJ/7m/bwWd+t+w== X-Google-Smtp-Source: AGHT+IHsCV2Ha5qyz2cPswVjeEC5t+kbTormlOkz02WP+7QgFP3xlPypwVm4tfVB4Y31yPFn10/Q3w== X-Received: by 2002:a05:6a20:3ca5:b0:1be:e1d1:7ea8 with SMTP id adf61e73a8af0-1bef60f2070mr13463547637.1.1720042689799; Wed, 03 Jul 2024 14:38:09 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:dd06:1fb8:e932:1ed8]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70801e631f0sm10886376b3a.4.2024.07.03.14.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:38:09 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Benjamin Tissoires , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH v2 4/7] Input: simplify event handling logic Date: Wed, 3 Jul 2024 14:37:51 -0700 Message-ID: <20240703213756.3375978-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog In-Reply-To: <20240703213756.3375978-1-dmitry.torokhov@gmail.com> References: <20240703213756.3375978-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Streamline event handling code by providing batch implementations for filtering and event processing and using them in place of the main event handler, as needed, instead of having complex branching logic in the middle of the event processing code. Signed-off-by: Dmitry Torokhov Reviewed-by: Jeff LaBundy --- drivers/input/input.c | 109 ++++++++++++++++++++++++++---------------- 1 file changed, 68 insertions(+), 41 deletions(-) diff --git a/drivers/input/input.c b/drivers/input/input.c index 7e4f8824f4fd..40a04154f99d 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -99,45 +99,13 @@ static void input_stop_autorepeat(struct input_dev *dev) del_timer(&dev->timer); } -/* - * Pass event first through all filters and then, if event has not been - * filtered out, through all open handles. This function is called with - * dev->event_lock held and interrupts disabled. - */ -static unsigned int input_to_handler(struct input_handle *handle, - struct input_value *vals, unsigned int count) -{ - struct input_handler *handler = handle->handler; - struct input_value *end = vals; - struct input_value *v; - - if (handler->filter) { - for (v = vals; v != vals + count; v++) { - if (handler->filter(handle, v->type, v->code, v->value)) - continue; - if (end != v) - *end = *v; - end++; - } - count = end - vals; - } - - if (!count) - return 0; - - if (handler->events) - handler->events(handle, vals, count); - else if (handler->event) - for (v = vals; v != vals + count; v++) - handler->event(handle, v->type, v->code, v->value); - - return count; -} - /* * Pass values first through all filters and then, if event has not been - * filtered out, through all open handles. This function is called with - * dev->event_lock held and interrupts disabled. + * filtered out, through all open handles. This order is achieved by placing + * filters at the head of the list of handles attached to the device, and + * placing regular handles at the tail of the list. + * + * This function is called with dev->event_lock held and interrupts disabled. */ static void input_pass_values(struct input_dev *dev, struct input_value *vals, unsigned int count) @@ -154,11 +122,12 @@ static void input_pass_values(struct input_dev *dev, handle = rcu_dereference(dev->grab); if (handle) { - count = input_to_handler(handle, vals, count); + count = handle->handler->events(handle, vals, count); } else { list_for_each_entry_rcu(handle, &dev->h_list, d_node) if (handle->open) { - count = input_to_handler(handle, vals, count); + count = handle->handler->events(handle, vals, + count); if (!count) break; } @@ -2537,6 +2506,57 @@ static int input_handler_check_methods(const struct input_handler *handler) return 0; } +/* + * An implementation of input_handler's events() method that simply + * invokes handler->event() method for each event one by one. + */ +static unsigned int input_handler_events_default(struct input_handle *handle, + struct input_value *vals, + unsigned int count) +{ + struct input_handler *handler = handle->handler; + struct input_value *v; + + for (v = vals; v != vals + count; v++) + handler->event(handle, v->type, v->code, v->value); + + return count; +} + +/* + * An implementation of input_handler's events() method that invokes + * handler->filter() method for each event one by one and removes events + * that were filtered out from the "vals" array. + */ +static unsigned int input_handler_events_filter(struct input_handle *handle, + struct input_value *vals, + unsigned int count) +{ + struct input_handler *handler = handle->handler; + struct input_value *end = vals; + struct input_value *v; + + for (v = vals; v != vals + count; v++) { + if (handler->filter(handle, v->type, v->code, v->value)) + continue; + if (end != v) + *end = *v; + end++; + } + + return end - vals; +} + +/* + * An implementation of input_handler's events() method that does nothing. + */ +static unsigned int input_handler_events_null(struct input_handle *handle, + struct input_value *vals, + unsigned int count) +{ + return count; +} + /** * input_register_handler - register a new input handler * @handler: handler to be registered @@ -2554,12 +2574,19 @@ int input_register_handler(struct input_handler *handler) if (error) return error; + INIT_LIST_HEAD(&handler->h_list); + + if (handler->filter) + handler->events = input_handler_events_filter; + else if (handler->event) + handler->events = input_handler_events_default; + else if (!handler->events) + handler->events = input_handler_events_null; + error = mutex_lock_interruptible(&input_mutex); if (error) return error; - INIT_LIST_HEAD(&handler->h_list); - list_add_tail(&handler->node, &input_handler_list); list_for_each_entry(dev, &input_dev_list, node) From patchwork Wed Jul 3 21:37:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 809587 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 133B8191F84; Wed, 3 Jul 2024 21:38:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042693; cv=none; b=eeMxLPEuDxs0sGl3upVVQsesQjcn1uzdTNogp/WbNgmRHN+jCsffvX45PGGXnAT44iHDEMgjM2YSjEFBX+R4nS7LWUD+CabRmi919uJVFJNQ/y49ulXDHZa+OovbyWYs3o4n2O6oFfdvsWUNQzRkSWAk7CI8J+Bsni5MWUKHVzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042693; c=relaxed/simple; bh=9htig+76vR8Q2ec9CymnaE6JlyNDJ4x/azABzTbbc6U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WvXuqPMCab3+LpWWuUZuMI/H8/Og/4xWN06YRmzdqt0XBcAdiFHO+X3IXUBf/YecMIbdJsSHEnt0LfzOCIMn4Yfc5mkMTMXRFnFjcpZJBb669frlzHY8Fef6cStuIlRLzqlp5c6NRSErlvO/gFTYOMMEu6yRmlSe9Hhc7c6pp/8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OCgb0vlB; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OCgb0vlB" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-70673c32118so13929b3a.3; Wed, 03 Jul 2024 14:38:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720042691; x=1720647491; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G9Hur8Z7nhDnxTtwckIAZ72uTwrIRPql8qqveD+op3g=; b=OCgb0vlBIGuId58WJlpZO1nCuW5pkIfgv1d9rZNsdMd+b0Sen3ExrDFj1Tt57ItNGc 1UGFN79XSY7aVv139AGJ3OUGOw2TmcvNPTWAPkdAxciuFh+Z6lLk/sPV7v6zuFwgPNWf BruAt4oYtrIHogkrstFv9HG256GPGLcliCSzQgCEHfm9CMW/j04rZvZjIMGkw8wbaSLt lOnSA/RLFd/Y2sNCSOiPIJuDx0/T6RvbAfkjpgUCEhQ+8X3T8RhFXwQ/8ggUBNBHPLQh enhpzdYeh8BHemI89KMp9sOg0FRlfiLLVthPk4LFsHcqr1My7Zo/BUB0NbueCzi4CTZg BAHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042691; x=1720647491; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G9Hur8Z7nhDnxTtwckIAZ72uTwrIRPql8qqveD+op3g=; b=A7QY5ydGc5fKccLlvjlmrBDNUXosyEVhihIj+5ElBY2j2btEAOIUGZdxdoPojW0x4U 9+RnmXKXbUtU9d553cevEziRE+AntDlGnQLs7fsal1j/Hvl+aq8lbJv1KL5hTHC/37ot G/19c3m/esQF5Tfq7M7gpTcKYLZMbv9O2w5/Rs2Rk6Po94n83qO/vgnVIB50Q8axB5Li VP3mfrvkWF5zqbZHcy0W+02hef9JD8s2iv6puaVLyz4f+NqoDj7uaZ4ym5zD0yHXgJNG ur++LSyBWOEubvPFt1HSqIMzZAe7o3vtIGDXXeD8O6/Yg3w+pGSfqvJWxx9A3i6rD0mh KYpg== X-Forwarded-Encrypted: i=1; AJvYcCUXaeMRvgVnB12SIA+Dt+izgol+8KqI7U1hkJpwt9f5zCmIj+1+ZliYE5xp5it/3AZBI72rsqFqwul6dXNlBIHu14lvG2mojEl2eHFs X-Gm-Message-State: AOJu0Yxh06H5fktFQXK7Qs1NF8EwVBamKEHFmy4aO6e6ib6vP+lUyKvX Q2sj22/fiqwUicbIQcOOxfYNAComRmhKDEnkVBVxMzMbYq0mvkhhgPtVZQ== X-Google-Smtp-Source: AGHT+IH4lse7TtifD2jfH2POv9oSlVGoriLNoCBkoIPuCIJmz7LPyIMqiPe9o9OVDG4ht2Spw+w1yA== X-Received: by 2002:a05:6a21:187:b0:1be:f71e:2196 with SMTP id adf61e73a8af0-1bef71e56femr12654749637.27.1720042690988; Wed, 03 Jul 2024 14:38:10 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:dd06:1fb8:e932:1ed8]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70801e631f0sm10886376b3a.4.2024.07.03.14.38.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:38:10 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Benjamin Tissoires , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH v2 5/7] Input: rearrange input_alloc_device() to prepare for preallocating of vals Date: Wed, 3 Jul 2024 14:37:52 -0700 Message-ID: <20240703213756.3375978-6-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog In-Reply-To: <20240703213756.3375978-1-dmitry.torokhov@gmail.com> References: <20240703213756.3375978-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In preparation to have dev->vals memory pre-allocated rearrange code in input_alloc_device() so that it allows handling multiple points of failure. Signed-off-by: Dmitry Torokhov Reviewed-by: Jeff LaBundy --- drivers/input/input.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/input/input.c b/drivers/input/input.c index 40a04154f99d..9981fdfaee9f 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -1982,21 +1982,28 @@ struct input_dev *input_allocate_device(void) struct input_dev *dev; dev = kzalloc(sizeof(*dev), GFP_KERNEL); - if (dev) { - dev->dev.type = &input_dev_type; - dev->dev.class = &input_class; - device_initialize(&dev->dev); - mutex_init(&dev->mutex); - spin_lock_init(&dev->event_lock); - timer_setup(&dev->timer, NULL, 0); - INIT_LIST_HEAD(&dev->h_list); - INIT_LIST_HEAD(&dev->node); - - dev_set_name(&dev->dev, "input%lu", - (unsigned long)atomic_inc_return(&input_no)); - - __module_get(THIS_MODULE); - } + if (!dev) + return NULL; + + mutex_init(&dev->mutex); + spin_lock_init(&dev->event_lock); + timer_setup(&dev->timer, NULL, 0); + INIT_LIST_HEAD(&dev->h_list); + INIT_LIST_HEAD(&dev->node); + + dev->dev.type = &input_dev_type; + dev->dev.class = &input_class; + device_initialize(&dev->dev); + /* + * From this point on we can no longer simply "kfree(dev)", we need + * to use input_free_device() so that device core properly frees its + * resources associated with the input device. + */ + + dev_set_name(&dev->dev, "input%lu", + (unsigned long)atomic_inc_return(&input_no)); + + __module_get(THIS_MODULE); return dev; } From patchwork Wed Jul 3 21:37:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 810177 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7655B19415E; Wed, 3 Jul 2024 21:38:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042694; cv=none; b=bFyR8IWb37Jlw99SeniuSjKTP+12vQzXVOw1QGw8aQrHIACEJ+qXMlx71rkuL3Mdub4/K+YyEbGVoLuJn8tGqOqKNz2+Mf8/fi8nwt9jjegzt3dHVHKUuR9ERQ9zqHsNNO2TWMT1HQ2JM1qWC/q4pqe/PLS6+zXhAHdvhyXpaW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042694; c=relaxed/simple; bh=q+QrJBtJ9Ru3AkGe9faD1DkMjCMtANc9rET3Xa76QL8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LY0OEFFd5sJF5E/Lv3djxl2ocJi6oi38fiAUhtr66hphz8KQ0RdE/C15O1fI/KX4g2MdzX/BckXZQ/YZCnPtxxsu/puHv/pXdygl3QWsJvuGYlwwCCwU06WL+AOJKfPcN27igq1RYYHkRnilL1gF2xSEiMOT9ROGTWacxJzWucc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VEasnpxc; arc=none smtp.client-ip=209.85.215.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VEasnpxc" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-711b1512aeaso4403186a12.3; Wed, 03 Jul 2024 14:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720042692; x=1720647492; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RAbVgj6nnqU9EhhwABC3OfN6AUT4/aiKn495mgpM2Zs=; b=VEasnpxcLCDlyIfYYiFhDUQVkjMo0esb7PKNf5hcXN61WagyY/Tz6GdRak/XE9sTkQ UGHM80g5poyzL0XIAw/CWPgBnox54CPpUYeAhZcFmGp1simqWiyVi3NTv8F0dljRSavE uOXA1jSVXooSXraBaYKEvqRRtxLRnFlJn0BYdURqsQKhz+uzMXXAaQHT3Eb9gjP8/DH3 5BF/D+xSnlns2wII5AzU/b/TooWMl/il4n1qMmfdxSGiCWFEezSocsR8l34UUjYuLb0w c2Lge+P2o8SYjsqe+6lwNyMLZDhfCmQsj+aGH0r0eJp2D/FdhVUHsbAg+udhnT3SP4Nv rBpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042692; x=1720647492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RAbVgj6nnqU9EhhwABC3OfN6AUT4/aiKn495mgpM2Zs=; b=mI2I/Z9RUxRc18iL6su3ff7Lq//jVpXhQKcJLMkykdEkmoYJGdJDNZKevVojJ7MYB3 2rRAWbWNXIO3gHz3OK29agM3UGxycd/MvZ3LM5UNZVVlt70MSkH8gS1pWH0AwEsZa2Wy LEVm4e+kgpEw/BOFfmPyZtoWQWXhSiEo6FsXKJR9yOV7tPNN6maP1kUkSHY8rSNY0LnX eXmaGx/45z9IQa15N3kd7wbf+4nVR+gz5IMmG791efvG+VZ4B4G/6W+/TZrl+ZiTS6SX CwqA2JU1j2kJg+tHkX5KGu7OIUfkCogcWXArIcVWFQ8dVENogBnB8ce9t4fKMjlTGtHP 8uhQ== X-Forwarded-Encrypted: i=1; AJvYcCWLcoujXwpIj5ukgaDs1rZoBhzFiy29fXz9ldcMxGHRdgjAtU1N3viY3WRaW7NBQTK3EVEycMvWPWD8+T0a15C0yegqweFQh7/lP3Bw X-Gm-Message-State: AOJu0Yzqdj4LasezxZydTvIm2A6zqo4g4vTmZ5oiaNG/zwJ6oqXqskTy ZNUdHqJcnv08qZ3QcTta7847RLW6sF4ZirCfh9dUCvHf7V8GLtcs0VczbA== X-Google-Smtp-Source: AGHT+IHGF9sjbwVCkKE54mdplTZfQXmbT9G4nqgBwzZEgaTPdyk47G2mFUKtjnW5HiJkPQkdyNzKuw== X-Received: by 2002:a05:6a20:a106:b0:1bd:22e0:f725 with SMTP id adf61e73a8af0-1bef611b976mr17946211637.29.1720042692143; Wed, 03 Jul 2024 14:38:12 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:dd06:1fb8:e932:1ed8]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70801e631f0sm10886376b3a.4.2024.07.03.14.38.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:38:11 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Benjamin Tissoires , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH v2 6/7] Input: preallocate memory to hold event values Date: Wed, 3 Jul 2024 14:37:53 -0700 Message-ID: <20240703213756.3375978-7-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog In-Reply-To: <20240703213756.3375978-1-dmitry.torokhov@gmail.com> References: <20240703213756.3375978-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Preallocate memory for holding event values (input_dev->vals) so that there is no need to check if it was allocated or not in the event processing code. The amount of memory will be adjusted after input device has been fully set up upon registering device with the input core. Signed-off-by: Dmitry Torokhov Reviewed-by: Jeff LaBundy --- drivers/input/input.c | 61 +++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/drivers/input/input.c b/drivers/input/input.c index 9981fdfaee9f..4e12fa79883e 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -323,9 +323,6 @@ static void input_event_dispose(struct input_dev *dev, int disposition, if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event) dev->event(dev, type, code, value); - if (!dev->vals) - return; - if (disposition & INPUT_PASS_TO_HANDLERS) { struct input_value *v; @@ -1985,6 +1982,18 @@ struct input_dev *input_allocate_device(void) if (!dev) return NULL; + /* + * Start with space for SYN_REPORT + 7 EV_KEY/EV_MSC events + 2 spare, + * see input_estimate_events_per_packet(). We will tune the number + * when we register the device. + */ + dev->max_vals = 10; + dev->vals = kcalloc(dev->max_vals, sizeof(*dev->vals), GFP_KERNEL); + if (!dev->vals) { + kfree(dev); + return NULL; + } + mutex_init(&dev->mutex); spin_lock_init(&dev->event_lock); timer_setup(&dev->timer, NULL, 0); @@ -2344,6 +2353,35 @@ bool input_device_enabled(struct input_dev *dev) } EXPORT_SYMBOL_GPL(input_device_enabled); +static int input_device_tune_vals(struct input_dev *dev) +{ + struct input_value *vals; + unsigned int packet_size; + unsigned int max_vals; + + packet_size = input_estimate_events_per_packet(dev); + if (dev->hint_events_per_packet < packet_size) + dev->hint_events_per_packet = packet_size; + + max_vals = dev->hint_events_per_packet + 2; + if (dev->max_vals >= max_vals) + return 0; + + vals = kcalloc(max_vals, sizeof(*vals), GFP_KERNEL); + if (!vals) + return -ENOMEM; + + spin_lock_irq(&dev->event_lock); + dev->max_vals = max_vals; + swap(dev->vals, vals); + spin_unlock_irq(&dev->event_lock); + + /* Because of swap() above, this frees the old vals memory */ + kfree(vals); + + return 0; +} + /** * input_register_device - register device with input core * @dev: device to be registered @@ -2371,7 +2409,6 @@ int input_register_device(struct input_dev *dev) { struct input_devres *devres = NULL; struct input_handler *handler; - unsigned int packet_size; const char *path; int error; @@ -2399,16 +2436,9 @@ int input_register_device(struct input_dev *dev) /* Make sure that bitmasks not mentioned in dev->evbit are clean. */ input_cleanse_bitmasks(dev); - packet_size = input_estimate_events_per_packet(dev); - if (dev->hint_events_per_packet < packet_size) - dev->hint_events_per_packet = packet_size; - - dev->max_vals = dev->hint_events_per_packet + 2; - dev->vals = kcalloc(dev->max_vals, sizeof(*dev->vals), GFP_KERNEL); - if (!dev->vals) { - error = -ENOMEM; + error = input_device_tune_vals(dev); + if (error) goto err_devres_free; - } /* * If delay and period are pre-set by the driver, then autorepeating @@ -2428,7 +2458,7 @@ int input_register_device(struct input_dev *dev) error = device_add(&dev->dev); if (error) - goto err_free_vals; + goto err_devres_free; path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); pr_info("%s as %s\n", @@ -2458,9 +2488,6 @@ int input_register_device(struct input_dev *dev) err_device_del: device_del(&dev->dev); -err_free_vals: - kfree(dev->vals); - dev->vals = NULL; err_devres_free: devres_free(devres); return error; From patchwork Wed Jul 3 21:37:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 809586 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02B4E1957F5; Wed, 3 Jul 2024 21:38:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042695; cv=none; b=GmjIvRPdOfPX0tUisAw7zecqIy8qkb20BJFUJ5jTgRv5DRcR9zVNmtzkDqRiozEA9y/NZH3jN+O2iMZiG+eIOH5mAqsKlzDlWu4dh+J2HPp1st2GVMAX3n9z/AtkBuLNAJMPAtW0DDao8blYOBUvIQYri85Qun5PzQR65ooAzdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720042695; c=relaxed/simple; bh=9qZegVREjpcFu6rFG6b8BVPY7mtyy65rRh3gEusvRXA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A7WTjkGEhIl/2uQpAxZUSUtLBClJ5K4s24UAN7CRrk8iZLbwH7WRbz4NkBiavg7POWWROKPhmZmKRHk9aLP4YCwleZPMYHm8Wr0bYqOktFJpU6MXLDj5JnzwQVeDoemkfUDDT5D/L2shx29WoKKeWT/xdSzAFtXz16Mv6BLxYwU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ksKqERoU; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ksKqERoU" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-70af9f7104cso13171b3a.3; Wed, 03 Jul 2024 14:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720042693; x=1720647493; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HWYq2mldW21wrkhKd5QkzgDqjV6XraGfPZcmcYa5WyI=; b=ksKqERoUS6l9fwGO9CtyBNg517m4i3dExqRDPbfUspJewgcgjH6Tf5juAZgY2MuU+M 4iyN/HhzVuqyiuArICmI9f2wHVWc0hiEWmfbaQC28mkhuVB0245th/PMKgi45Vt+PI3i WXCbotBAYv2d8O546qakMXi5qXCCbYxK6OM0H0YCf3J//3SnJzN7znA3gjTSioqY+9Jf QgSrtcP8UXT/3FbUSpTnvGzV2vyjENdaS7y8fcdugJDz/koD2lJ88MP7iBR9uCt/AIry U9bv9d3Bp6e626UJrrud5mTxmK1OUuZQYUksRTX8vQxk7v7OU+fBp301Az5viXs7bk4V AXDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720042693; x=1720647493; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HWYq2mldW21wrkhKd5QkzgDqjV6XraGfPZcmcYa5WyI=; b=XSRQFbnqOD8OPOPHykDnyGX9wUNavdgfNxoNDWBZGz4G+8xmU2oLQFkbv+kZfZDhTR Sjy4I9LNuoKy4PqbSXH2BA43Iz5KzzllAktWWWitPzHABYUFdueJWkXgDE/K3YeFBc82 d3lvP9NogEk5jQS1DZvsmH24PKTHVHsKEcH//OslhA1Afx7IdFbGVlUaRL/I8XmNuXNB WRcs5LQCwgiIaZJpLMjpU9nhzFVqrj0wyH2h7MO63Y/O1/H7V372WWuThNujlZXsvDzL yaJMCDYQeX6IInROZi0bhpItRbIw5TdamZcCrJmXuALqM9gzLY+P9HR7u6QozEyb77ka NVMA== X-Forwarded-Encrypted: i=1; AJvYcCXcbyN6ZHunNDlrCTQg22sH8j2iLWFLYTkHtkx88O2K7PmlUigQidM+Z7HDnJH+kCSsohvx5+268QJLNFTggxKDnHOHxrtNI4sAbGOA X-Gm-Message-State: AOJu0Yx3prIkJPL2EhiEeczA15B2yMlAEsAGqsaVKXvcqHQt9vwTdPEw q9reacqU1I+JWotIQgxQpiGLYnsxkJO12DcXxkcfdfgyn5VzTmXJ+S7xew== X-Google-Smtp-Source: AGHT+IHEhh69PLG82n5vY+BtpFKKfrj5gUjcs0d1FiHfumZ7TE5MvFAeQiyfQMc6wRbTOJrZGW+8ZQ== X-Received: by 2002:a05:6a00:23d6:b0:705:c273:d19 with SMTP id d2e1a72fcca58-70aaad3b4b5mr15035807b3a.12.1720042692969; Wed, 03 Jul 2024 14:38:12 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:dd06:1fb8:e932:1ed8]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70801e631f0sm10886376b3a.4.2024.07.03.14.38.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 14:38:12 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Benjamin Tissoires , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] Input: do not check number of events in input_pass_values() Date: Wed, 3 Jul 2024 14:37:54 -0700 Message-ID: <20240703213756.3375978-8-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog In-Reply-To: <20240703213756.3375978-1-dmitry.torokhov@gmail.com> References: <20240703213756.3375978-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that the input_dev->vals array is always there we can be assured that input_pass_values() is always called with a non-0 number of events. Remove the check. Signed-off-by: Dmitry Torokhov Reviewed-by: Jeff LaBundy --- drivers/input/input.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/input/input.c b/drivers/input/input.c index 4e12fa79883e..54c57b267b25 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -115,9 +115,6 @@ static void input_pass_values(struct input_dev *dev, lockdep_assert_held(&dev->event_lock); - if (!count) - return; - rcu_read_lock(); handle = rcu_dereference(dev->grab);