From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 AD82A434E55 for ; Mon, 3 Aug 2026 18:46:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782800; cv=none; b=oakqURo+2/fU4zpE1M7lZqZENolqqmvyv1xmFUxAonSerLh1dQ5gH0PccuPfvZrdMQp7ga5QvNeTzINSg1GTHrfl1Kc2ub1oCQyoCk0a5mpPwTKMKkXIhCe9g7FykucSO41QT4q92cLazeDgTWUOLsLuL6lftxviU4a8+DHE5kQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782800; c=relaxed/simple; bh=zTvGTNkJ/wqnyMbPR7YJxhbtHyE5HaI2GyeFefAOijU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=V1QMVTt2C7virc3/fLmh8o4ahg9muXYUXV+nSa+B3W6z4oij8qZ3C+OfpsGAIdvUgM4ifHghV6gBOqapN39YA1Gwd08/AigZouYlZo6qQaxIVUNUip5NCrrWkSfPm0rzVmU3pgWdDBTsDdontXY0xM5Ah4DGp30nfIwpYH39hzk= 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=aeHBCcSV; arc=none smtp.client-ip=209.85.216.53 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="aeHBCcSV" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-383cb94f742so3755686a91.3 for ; Mon, 03 Aug 2026 11:46:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782795; x=1786387595; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=fDX03Rc6Co4fp263PbZY9y3DOwf1pY8yl2EntzRzQTY=; b=aeHBCcSVl8t3n8TKdHm7kuAHzkasUis4mHZl0wezNnlQ5w0kjis1D0fjUKjcNnSF4i ZfefXAmM/4qqqFkxUQ/po4R9Evh9RawpGWQYTisgsTcQYJ7ZnQ/mGeItv/GZPMmeWb5n g0xey8asHyNrsahRlwFBwi9FE62JIR3f6q6Djin0ZUPKa/zyjuncnfhV1Rdf51MW3Q8U PU0eARE2hgHLvUbQPRN/iiCIol1CA0EfkwcJAXQa5k6XJCGOMrCxMRfYBrbA9MXN652m 8MGOwODxSbWFoye0EyWHCaj/YywuL1WMcFmZVI8AoD42fXRDxxQLUDAX+bOisAbD5+AN py9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782796; x=1786387596; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=fDX03Rc6Co4fp263PbZY9y3DOwf1pY8yl2EntzRzQTY=; b=d9fuGhJXS8QcBx2zO0NOi7bMykFAGj0dTdk2+He8/2rY5KKSu5FFRW6xJR6Uj9NYxJ hUOJxmEGTV83tGCUkfl4iXC9BsSa3LzF9v1Py6n7hAwwJ5O85AU3/VUL/WqxIQKcZK0d iJOaY7OnIir6Y8CCrFkNFG3YPBKnMZ7frySapv9/E5xqu3CTwlqSkPNf9QZKKG94/xz/ ZVV0xlS7dqgd92N7J2P90JaHiH2M7b2XIoXIxqk2hXJh6nl+Ge69+EiTbTA6Pw5I3VH6 2OqqwZpEeG/BPdaEP/JMetVd2+HREys15GoVrVCMMs+1ZelTR0xOTU7DYPoHAWOgN8tb R6BQ== X-Forwarded-Encrypted: i=1; AHgh+RraXYG9SeQZrM9RB2ZB9n7kISfDk1Ft5p5HoANRDtNcM0Bfi0LoFVDzNWGlQESh8oIiqY3tuX/SU8onnNQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yw7laYVtZGkxHEFBIYg9cvhAgtR23ZO97X2hod2SC5cd9RUFXph R25mHo6r/plUFFkaJDd+abfkhKFG2TJs1viPoFbop3WtlquN1R84ELxL X-Gm-Gg: AR+sD13D9Fp9f64vtMiO/kIi9chC/5jxddSObsn4HFiHrnBXZLmrwpujgQXl4SmkBzV /Nc9Q/DIvGgmBYATVTMnPCZXGeoyJ/k4N7IpTmTvLjkiJcYMq+QzamwTIN+TraDptO0FI/xg/V7 mnIDHwG3CJZ42ziK5g3MxdtA4nQFrVXCdTuIKJcUglHL89DblYlulaHMLDjzL4NmUqN6js38Bk+ unLxaBLbbbhOWZOMlpwIjvA0XbmKhBIYi0jXQG7J/3h3Mr42WgOljDufvlpl74m7v8Zz2u+2Arr n/E4yJ0aqZvQ8S5U2u4TcC5zX2jYgu1hDZz7B+9PsF7w5g9s4kUqMX3dCPkZb+RwqHv4XlDkHJP F3hLp1fYlpx273PI+ZP9FMwvgM/AVsuROwEYGhW6EjsRdDDVb5LTVYM6mj51zfEN2Q5EPgnmurL SQ2hnl4wE7nW6n7K12FxN75Mkbyou4Z+n2fV3KAgUA9PJ5NVeSPV3+zddmGultl6VwXqLK/sXnl P1vPGx1dHk1NdwQq8O74EkGhFRxygzl9uaJ2i1xAJrdgfcVLB5J X-Received: by 2002:a17:90b:540b:b0:38e:e9b:ffa7 with SMTP id 98e67ed59e1d1-38fbc51f1e4mr10231317a91.28.1785782795558; Mon, 03 Aug 2026 11:46:35 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:35 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:26 -0700 Subject: [PATCH 01/21] HID: core: automatically initialize generic FF if no other FF is present Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-1-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f Some HID drivers initialize their own force-feedback support within their .input_configured() callback. In such cases, we should skip the generic PID force-feedback initialization to avoid conflicts and redundant setup. Add hid_has_ff_input() helper and use it to check for existing FF capabilities before calling hdev->ff_init(). Since we now have a dynamic way to detect if force-feedback is needed, the HID_CONNECT_FF flag is redundant for conflict resolution and can be ignored in the core initialization logic. Generic PID support will now be attempted by default for any claimed input device that doesn't already have FF capabilities. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-core.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index f107f5103b35..2767a171eae9 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -2287,6 +2287,18 @@ static const BIN_ATTR_RO(report_descriptor, HID_MAX_= DESCRIPTOR_SIZE); =20 static const DEVICE_ATTR_RO(country); =20 +static bool hid_has_ff_input(struct hid_device *hdev) +{ + struct hid_input *hidinput; + + list_for_each_entry(hidinput, &hdev->inputs, list) { + if (test_bit(EV_FF, hidinput->input->evbit)) + return true; + } + + return false; +} + int hid_connect(struct hid_device *hdev, unsigned int connect_mask) { static const char *types[] =3D { "Device", "Pointer", "Mouse", "Device", @@ -2336,7 +2348,8 @@ int hid_connect(struct hid_device *hdev, unsigned int= connect_mask) hid_process_ordering(hdev); =20 if ((hdev->claimed & HID_CLAIMED_INPUT) && - (connect_mask & HID_CONNECT_FF) && hdev->ff_init) + (connect_mask & HID_CONNECT_FF) && hdev->ff_init && + !hid_has_ff_input(hdev)) hdev->ff_init(hdev); =20 len =3D 0; --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.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 E268E43553A for ; Mon, 3 Aug 2026 18:46:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782800; cv=none; b=Pz2CfAOrlEjlebDeYbFuniBlZJZ2fo3tXRqzHVInqdgHf7W/FytaVHy6OBFj4Jafko1PdgF0PXgnZFEn3dhNZlQYH+cXvplLSgys50sKI+qazTzqgdL3T3nM5s0cmbw5rWQ1Ef0jBl7Mgmw959yyPk6ZON/uRfqj2LH2H3zEUrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782800; c=relaxed/simple; bh=8u/qkG7wp8Tnfhp3mb6hbztJWkMu+m5Wx8tTB2tw9fQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KtAefqsdX69/eX0Kn4yh4pfC+p7o8x/NutrevTtIMr7JrAyKYk+tLdmbwrrTIj8WCkSTG2jHzrhzZDGdGd2chRd8kOwWzslGDhdUHbc9StUDo7aHQsJXdP+8RQzaAmFuRKTpcJHcXihxlijYWQXe1uISUVBAVsElfmlszGetDj0= 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=FU9DXDhc; arc=none smtp.client-ip=209.85.215.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="FU9DXDhc" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-cbb85186d43so1772642a12.3 for ; Mon, 03 Aug 2026 11:46:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782797; x=1786387597; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=PsWWvcYaCFCv1CbGg2pDl41UZP3CmZipcaKgtx2duHQ=; b=FU9DXDhc/5buxFJkdpsreQ0cc7Y05Bpy143T5BEAlgLMTH/41nfavtZOm6uWGNgiF8 vvvK8BUfVMmW7XKtlAdnlpT/MgYVyexeci4qiJAaiCDodCtvr650r+O9aK/pk5AteIpE L/eg388NsXU1KbEv8L1nerRVscDQKSoYvvyJRnwtLMkp6R1j6RsgX9b2REp4+PXeYMkM Am1rygwQJHsfbnpTaNKJ89Uu5I3+RMGcywADapf5iXjNgop9dUPkH3ML03K3K3QMvN2J GovlCJeF0z2ntizWH3hyfr/vQnD6raA/MeS7ddJwROvNxW9As23fl12qAC2aJ+s5Slqj iLRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782797; x=1786387597; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=PsWWvcYaCFCv1CbGg2pDl41UZP3CmZipcaKgtx2duHQ=; b=mqyf5B//nb/bQW4ewRiXptg7+aPEWsV9bGYrEMGLEsmd0UfDTLNpAcThh2eO1DDt+z ssCL+Gu6rwaMKzRULE+EO94rjhrNC9CjiowJVfoS3gjQKzP8mJkr8SSCu3lMk/qdihWe po2BjNZtlnMkFxI1vTNcFE6uJfe5dnghwdzF99VyrtjRODR6MFGizmVXZeAq2IFlfq/J V2SIVnfFPiifKZbCtb/lU1sH8azuVR2Tl99LL+C3WcTt0fZSz1RJGoYTz8/v5gj0P7f2 W7hqtJUXNCmj+kBCM/0kTGQvFuRmGZO6N1fQor9NQLwt8T1p5QeUFkwaTK8MHw5m9jk6 y3Nw== X-Forwarded-Encrypted: i=1; AHgh+RpyhjppWLUuqh5eBM/F5OGG2j0Ldb/8mLWfoTEPcuVbB+w1SfNTLssWI2yfJwCDXjdzP6V8r6aLvvMWUiA=@vger.kernel.org X-Gm-Message-State: AOJu0YyJyumgwdOHQdlb3m50Cyk9RnILOARJPkd4tcsLu4WYf8R6atwm AZAbgLLb0I5OEI6iEFYpaCjRFBj40ZXvGSOVqz1FK4IkBndho5SUrgXq X-Gm-Gg: AR+sD13I45jLcSimJAY7BzetiWq90LWkl0hd1snIB8xgPbPqUSlucA59lrKThbMLjTe qcQe33GblvJR/giv+7fm5279H+n6vGgEDnCcbRJKzXX7ZAq6TboVHct5YkJD+0DNsmViyIpr7A3 Ob0csYmUHxaeZRivaIkq/OGkzATjdJ1u9gac2mQ5jTvaLsozsvPECnCyk/HiyzWpwaRAwsIOkVC fxhpPNKRcSPZG2DWeR9ViBcbDCNm8BZ7H+qFS7lrEP72euJ4jvAJNDyvXDTAgj1uAiTMcqEQ8BE HDImHYjk34YMG6rxSXsnBaQsJ8qkOhre2P7wIsd5wZn4I7CVp8YIh1mbdAJSus45cmBVjq6QThX MiyAiPXoVnMaO1iXst2nhzJmiH+0E/tMTY2rt5diDCSkSO0O1Fy8bd/5oRSl/aIWhc0te1wEzIS Uehu/IvtstX2wmMF6BOLZw9Rbb/gUh8WNGoJ4N9rejwZEw7VS02FtATwfQDS6tjVXuTWTkk+Qex mFWF4D6PlIjgt8w8atCitkYfPLat9hBcdXXLnxMUsTh2UzJX0ou X-Received: by 2002:a05:6a20:7f8a:b0:3c3:875d:c531 with SMTP id adf61e73a8af0-3c92a598347mr11161616637.6.1785782796909; Mon, 03 Aug 2026 11:46:36 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:36 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:27 -0700 Subject: [PATCH 02/21] HID: add documentation and Coccinelle script for FF registration race Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-2-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f HID drivers that rely on the HID core to register input devices must ensure that all private data and capabilities (like force-feedback) are fully initialized before registration. When hid_hw_start() is called with HID_CONNECT_HIDINPUT, the input device is registered immediately. This is racy if the driver attempts to augment the input device in probe() after starting the hardware. The correct way to handle this is to use the .input_configured() callback. Add documentation and a Coccinelle script to detect and prevent this anti-pattern. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- Documentation/hid/hidintro.rst | 50 ++++++++++++++++++++++++++++++++= ++++ scripts/coccinelle/hid/ff_race.cocci | 34 ++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/Documentation/hid/hidintro.rst b/Documentation/hid/hidintro.rst index 73523e315ebd..5d367dfca0b8 100644 --- a/Documentation/hid/hidintro.rst +++ b/Documentation/hid/hidintro.rst @@ -522,3 +522,53 @@ This should really be your last resort. vendor: 0x093a product: 0x2510 ... + +Input Device Registration and Lifecycle +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +HID drivers that rely on the HID core to register input devices (by using = the +``HID_CONNECT_HIDINPUT`` flag, which is part of ``HID_CONNECT_DEFAULT``) +must be aware of the registration timing. + +When ``hid_hw_start(hdev, flags)`` is called with ``HID_CONNECT_HIDINPUT``, +the HID core immediately parses the report descriptor, allocates ``input_d= ev`` +structures, and calls ``input_register_device()`` for each of them. + +This means the input device becomes **live and visible to userspace** befo= re +``hid_hw_start()`` returns. + +If a driver needs to perform additional configuration on the input device = (such +as adding force-feedback support, setting extra bits in ``evbit``, or +assigning custom event handlers), doing so in the ``probe`` function after +``hid_hw_start()`` is **incorrect and racy**. Userspace may trigger +callbacks (like ``play_effect``) via ioctls immediately after registration, +leading to potential NULL pointer dereferences if the driver hasn't finish= ed +initializing its private data. + +The correct way to augment an input device before it is registered is to u= se the +``.input_configured`` callback in ``struct hid_driver``. This hook is +called by the HID core after the ``input_dev`` is fully formed but **befor= e** +``input_register_device()`` is invoked. + +Example: + +.. code-block:: c + + static int my_input_configured(struct hid_device *hdev, struct hid_inp= ut *hidinput) + { + struct input_dev *input =3D hidinput->input; + + /* Initialize private data and capabilities here */ + set_bit(EV_FF, input->evbit); + return input_ff_create_memless(input, NULL, my_play_effect); + } + + static struct hid_driver my_driver =3D { + .name =3D "my_driver", + .probe =3D my_probe, + .input_configured =3D my_input_configured, + }; + +Drivers that require even more control over the lifecycle should mask out +``HID_CONNECT_HIDINPUT`` and call ``input_register_device()`` manually +when they are ready. diff --git a/scripts/coccinelle/hid/ff_race.cocci b/scripts/coccinelle/hid/= ff_race.cocci new file mode 100644 index 000000000000..479f5d1e3184 --- /dev/null +++ b/scripts/coccinelle/hid/ff_race.cocci @@ -0,0 +1,34 @@ +/// Detect HID drivers that initialize force-feedback after hid_hw_start() +/// when HID_CONNECT_HIDINPUT is used. This is a lifecycle violation as +/// the input device is already registered. +// +// Confidence: High +// Copyright: (C) 2026 Gemini. GPLv2. + +virtual report + +@r@ +identifier probe_fn; +expression hdev, flags; +position p1, p2; +@@ + +probe_fn(struct hid_device *hdev, ...) { + <... + hid_hw_start@p1(hdev, flags) + ... + \(input_ff_create\|input_ff_create_memless\)@p2(...) + ...> +} + +@script:python depends on report@ +p1 << r.p1; +p2 << r.p2; +flags << r.flags; +@@ + +# Check if flags include HID_CONNECT_HIDINPUT (0x01) or HID_CONNECT_DEFAUL= T (0x0f) +# Note: HID_CONNECT_DEFAULT is 0x0f, HID_CONNECT_HIDINPUT is 0x01 +if "HID_CONNECT_HIDINPUT" in flags or "HID_CONNECT_DEFAULT" in flags: + msg =3D "WARNING: force-feedback initialized after hid_hw_start() with= HID_CONNECT_HIDINPUT. Input device is already registered at this point. Us= e .input_configured() instead." + coccilib.report.print_report(p2[0], msg) --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 659EE437115 for ; Mon, 3 Aug 2026 18:46:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782802; cv=none; b=fTNRQjxkTB2/Y49p4KamQARS48I3M7yMjsrKXQ9LB6otvv1RBjmkaAo9Vlizo5xp9tXYlARq5L5oP74MDii9G4WnW6MZeNnL8Mb5dsZB1GHbYPZuMNBaxOYA3waXuiWmVPPEYQr0OfjA8DmTLdL3eJKrFMbs/0QyvlRshsN9SX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782802; c=relaxed/simple; bh=qUdUerWZwKVXSv6CIvxcpUQFOknhL3yaUu9ghBMZ6OY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BnP1RFG9GUeHZGDMUHJLYeAwfwSNw2AISyY7+APn0YXaFS7HnvmiZnAZ/r2+R7cg06qgm9CxF6WeB+l3GId3Sg76HAqtoVaaurLmYCLZDES0mzsQkF1f9WWcSBFaF89NqiFPWLnH3CeNlOtSPRQWn44dRGdwGsfeUKMn14kmFE0= 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=CwNyiCWJ; arc=none smtp.client-ip=209.85.216.46 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="CwNyiCWJ" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-38e071ed6aeso2827646a91.0 for ; Mon, 03 Aug 2026 11:46:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782798; x=1786387598; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Xe1aQNIISsGkO8ixPfjdrXZ79Mm8F+hvVCxfc95I8z4=; b=CwNyiCWJcP0h4N3lRmUbnuoSMyPhbdYxGYueTwIzCvzspMhbJjTHFIK1vJ4AAZLtpL GlWRiTW5TJT/onvO/RLRNuWpIlniYmKZyCgcQgofab8czQzB/l0lrATflh6zBRF9hZjF DYyKL/CpjAu8X3YB6Xj6dkXU6f+IEEHCaeAIifFs5b9u+1/Nef9lcXPjJyaIFMeQwswb LduNyiftwL2/0RcvZh5d+iOdoVFC7dkFVppOa9VNwHhl+xUtibg2/A4udbugr+gYWPYJ jHbNeBcJO2Gj0Qqd+cKHAonKLMcRYgAZjBLM4bej1h2S/PGdw3OhFn2f183aT5us0nVD XNZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782798; x=1786387598; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Xe1aQNIISsGkO8ixPfjdrXZ79Mm8F+hvVCxfc95I8z4=; b=qnpUVxxJ87XpeJ8JEQPaz+37KL4tMBsEsGuK4JqBm4B34VTHGstzNBaSbhjalydovB 11oBCihBNUbSSd3LrGr/G3E4iHusYv6fBUe7d/BtT3rN3kmT55ssDxY2DqoSdFCHErql 3GSdbiwTlCL+5N+onX3PP7x3ZmB2dgScUEc/E7zsSYu2aXtL8iQqtkCKoIFZZBzXfk8k 8XIPB1mXViBE7vXgQ7dM4JztuQx2l7fWshq26Jfe0Nmkm0iFH78yt4G2hRTW3ptD7nOT suOhSU+Ox6UF6BS+8g4cgyDhLL+XUSp/5ejmNQLIxj6TzfUvOAoNohA9BOJ4pSG7R0y6 knDQ== X-Forwarded-Encrypted: i=1; AHgh+RrXzcHRM/5+K3r12xeKVR0E0bELpqawYBuKF7MjpE3idfMpT4CgSesuHzSKJ3/EQYxV54v7YCIDwRJUEYo=@vger.kernel.org X-Gm-Message-State: AOJu0YzN89v1W5dnkXJtf/XE+pacQ1srMlR3PwZBJQm2P1cqO03DXqHX lSSwONzGA0mPKQv0IE/xY4R66F3VCT1t3m/i7C6JJbSxDQVschfDrFCG X-Gm-Gg: AR+sD11GMzXB2gZdLY7Smsn5wSsTpjpXn5zgZw7NrM2NlADLcy/JfMTMDtRkvZFrKE+ nV1jsT0jxq2hHCWd63Vez2X6cEOy35obq5TtcJ7i92Dxd9lKFs6rfgIjAEaayJoHVspgxhmZmV+ OqY7f2cr9fdIZmpOR/o8qkQMsUx0M3PESdfe+rHYLtU2BYvvEd7/HI1CIQDQYrJD00Buh7g3hxA AMMJZPEWJKB/wxv/LOngweSOikkbHIrA8mGPhqsAktLvX89u1n+iMkEYgYs/p/6xzSVsUaKfaTG tLJZS3XB18EaYYjnzPBjXo4XoEtrVZYU+rQ+vLXN26HpCep59HjVZYa0hu7+jyeBA+ZouCjcX+Y ZCyfLKmhcMtJEqdR5wq9bMMK5Q1fwEZhFsMObfa7o8dHHeA37ERUJI/S9yPRa73Ya2H4HhhzrJC eRcSsA3V8tGMmaXwnhtBX4BgoL8dm+cge3PocIn8YBXFQZZW+ZPua+S0ht00TVvyqpDScOaxp7B 4Vf52E0YvBsinqw9aGzW42QHN6lR+/raUxVE5csCar/maR9cHS4 X-Received: by 2002:a17:90b:1808:b0:38e:fea2:df53 with SMTP id 98e67ed59e1d1-38fbc40df10mr10254715a91.4.1785782798371; Mon, 03 Aug 2026 11:46:38 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:37 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:28 -0700 Subject: [PATCH 03/21] HID: axff: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-3-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_hw_start() with HID_CONNECT_DEFAULT. This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-axff.c | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/drivers/hid/hid-axff.c b/drivers/hid/hid-axff.c index 3c5c2bf02425..2f46447086df 100644 --- a/drivers/hid/hid-axff.c +++ b/drivers/hid/hid-axff.c @@ -59,30 +59,24 @@ static int axff_play(struct input_dev *dev, void *data,= struct ff_effect *effect return 0; } =20 -static int axff_init(struct hid_device *hid) +static int ax_input_configured(struct hid_device *hid, struct hid_input *h= idinput) { struct axff_device *axff; struct hid_report *report; - struct hid_input *hidinput; - struct list_head *report_list =3D&hid->report_enum[HID_OUTPUT_REPORT].rep= ort_list; - struct input_dev *dev; + struct list_head *report_list =3D &hid->report_enum[HID_OUTPUT_REPORT].re= port_list; + struct input_dev *dev =3D hidinput->input; int field_count =3D 0; int i, j; int error; =20 - if (list_empty(&hid->inputs)) { - hid_err(hid, "no inputs found\n"); - return -ENODEV; - } - hidinput =3D list_first_entry(&hid->inputs, struct hid_input, list); - dev =3D hidinput->input; + if (!list_is_first(&hidinput->list, &hid->inputs)) + return 0; =20 - if (list_empty(report_list)) { + report =3D list_first_entry_or_null(report_list, struct hid_report, list); + if (!report) { hid_err(hid, "no output reports found\n"); return -ENODEV; } - - report =3D list_first_entry(report_list, struct hid_report, list); for (i =3D 0; i < report->maxfield; i++) { for (j =3D 0; j < report->field[i]->report_count; j++) { report->field[i]->value[j] =3D 0x00; @@ -100,13 +94,13 @@ static int axff_init(struct hid_device *hid) if (!axff) return -ENOMEM; =20 + axff->report =3D report; set_bit(FF_RUMBLE, dev->ffbit); =20 error =3D input_ff_create_memless(dev, axff, axff_play); if (error) goto err_free_mem; =20 - axff->report =3D report; hid_hw_request(hid, axff->report, HID_REQ_SET_REPORT); =20 hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun= \n"); @@ -118,7 +112,8 @@ static int axff_init(struct hid_device *hid) return error; } #else -static inline int axff_init(struct hid_device *hid) +static inline int ax_input_configured(struct hid_device *hid, + struct hid_input *hidinput) { return 0; } @@ -136,23 +131,11 @@ static int ax_probe(struct hid_device *hdev, const st= ruct hid_device_id *id) return error; } =20 - error =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); + error =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT); if (error) { hid_err(hdev, "hw start failed\n"); return error; } - - error =3D axff_init(hdev); - if (error) { - /* - * Do not fail device initialization completely as device - * may still be partially operable, just warn. - */ - hid_warn(hdev, - "Failed to enable force feedback support, error: %d\n", - error); - } - /* * We need to start polling device right away, otherwise * it will go into a coma. @@ -185,6 +168,7 @@ static struct hid_driver ax_driver =3D { .id_table =3D ax_devices, .probe =3D ax_probe, .remove =3D ax_remove, + .input_configured =3D ax_input_configured, }; module_hid_driver(ax_driver); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 12CC143801C for ; Mon, 3 Aug 2026 18:46:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782804; cv=none; b=IY1ztoi4NT454I43EO+TrjGeiwqzJxGxLVeK/2htfKUeOaFiHcTqYURIu0yLdHbLs5G9c7jNI2OgJSbFosKyZaf0HbGeBZtM6yolCFctUMdBEYpPoyze/VPHeVQC/6+pQ7rUw2JEFT4bCH4DFAdt5YQ4qoTGFG0obCtZ9eWhZjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782804; c=relaxed/simple; bh=zxac0YZ+UVGUyIsLRlzYrg6jB0A4yFDf8Ymaifq3hLU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aW9gV0m7zEBHexmbW0wNn+sanfkJGB0Ojvr0K5aZS0Lxkx9ucxiZ3THGMHbwg332A9xObv1LjJEm9i7wiE1+tU5jmKdMnFMBDBqz//8yzEf3/ofGDYHUDH2cjSYIqo0wwa24w18ar2qY+yCWQulJ2tugF+SH2Z/2yIQYxdE3DpQ= 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=faOe3ROc; arc=none smtp.client-ip=209.85.210.177 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="faOe3ROc" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-8487b7b3fc8so4363471b3a.3 for ; Mon, 03 Aug 2026 11:46:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782800; x=1786387600; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Yfk1wrUGljf1bo39RPlNvsXr+Q+XQylnHMnMfOANzM4=; b=faOe3ROc7KpPbqp6++9+I9YT4D834TCPYeXkF2qMJu7G0GNgk2reJ4xtMyYQ4YLD28 mR7x4g9mSp6YAxNcIZkd3jdjGyiPQQ2LXV1czD4y1dsINbD8NObkangPAQ5V4D2m5RnZ pgY4FWpWS6ltNtiGznl0ONEi9Ou9618Z1OdScMIdmauCJs5EoNGe66JR1rnNXRInr/g8 7xy5cTTy9jdwXs1dfy+473mA6vjmM0amjrckj1fzYK+0XcNFNNSaTOx3NUUl/2PR5A/S pbxUVauJCHQpTJXVNGpU8FhMi54QR4nwTUn7zAbtW7Ww3Jc6AurgyCswLEdgbImYfCKU 7x0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782800; x=1786387600; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Yfk1wrUGljf1bo39RPlNvsXr+Q+XQylnHMnMfOANzM4=; b=JmJyuvKa8ry2FwZGFLX+23pDuiJ8BPf216fT0ji7RYbEO4NBI1QuXn30vhCkScVKlD XK2HWRIN+x3oYEtoFBtUZ7p4I3jNfV2KsZ8wunNyqBZhkXoIGvCcJYM74Zwqk8MBUq/p bpkSZAVGk1iRBDjZYpApFKsQVkmmzs2vr9JpW2AnKTlGS8kXIdPB2q/mEMyaPaxfrBWN 8OHi2ma4VskVvsMfjymuZd2dEHch+UWufYF4S3rEXhfD1+kmXcycjsL5TJ9L02rMY9K6 8ClF1nYMCLcoovsuSkH1lCiDUyV5bV6LcEUrsdDWBrdT6ps4DV3orauaECM6GxEu/mUB h56g== X-Forwarded-Encrypted: i=1; AHgh+Ro2Hrryw6/epGWzmeqHxm6FKi/Iry9Eil7a4ImRkYC/4Cf7RGn9CJtdsjZyo4+mZi6StEZQ3RqrRkAUwck=@vger.kernel.org X-Gm-Message-State: AOJu0YxXNpSqbAhUOZlvYuODOTLc0HL58oPl3aLuYbkTnS2vDUt3COPf yzHAvZynx7gdTb+ye2ip/10qKwgk+afSo+XMVE+l4WTVE17Hp3sMeEGy X-Gm-Gg: AR+sD10vJdPgAb+YCmibnwCVTqqp1mLde9Ndgss+frre/gAQJA/fow4RGtWfASfczVO vUHYWbGkDHaPdyawMS2EN24lzgc/9jU4xvMFa1fyMsYvg0/luJhOVS1iWBAh63Sl2XWpvn3qr4U 51VrgHvfmeQui+EUwU++9TRIB1gF6oA+b52ffpqnS3k4TZYXm6SrsB6yCKo+76xZu07tbia54BX NqB0T+VE9n8sVxQmty1IXVBq70lHOaJlmkJ3l9GVR5pX/+usTaRw9r+0ruXFX/HFjP/kK/dUAa2 pso12ATK/B9AHX+Me+nR8EgRybYJNeBtArMvqdCM9SdapUWGg+bII2UPqsV8T7DYS7cq5EqzFl4 0MFU7dzArhmsIBLY/rxH2+Ic86JSmzYPwe7iqXaIMzNHV30atvTMaV43vtyYLV22a0ibCLwrCQm 3tVZGzbixXVHLfOY9X9g17sypxYYPZSway1dKYlIyKDmL/epgyrgw5DS94dHyjyM0a9fL8i3b5Q Lw0+rD7rzeo/yt6ZeAs/s5eW4pzNqeeteisXYVh0/5uOlFOD20B X-Received: by 2002:a05:6a21:7a82:b0:3c3:652c:664e with SMTP id adf61e73a8af0-3c92a98f2camr11892049637.69.1785782799808; Mon, 03 Aug 2026 11:46:39 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:39 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:29 -0700 Subject: [PATCH 04/21] HID: betop: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-4-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_hw_start() with HID_CONNECT_DEFAULT. This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-betopff.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/drivers/hid/hid-betopff.c b/drivers/hid/hid-betopff.c index 8a7fe895926c..f802046a688a 100644 --- a/drivers/hid/hid-betopff.c +++ b/drivers/hid/hid-betopff.c @@ -52,31 +52,24 @@ static int hid_betopff_play(struct input_dev *dev, void= *data, return 0; } =20 -static int betopff_init(struct hid_device *hid) +static int betop_input_configured(struct hid_device *hid, struct hid_input= *hidinput) { struct betopff_device *betopff; struct hid_report *report; - struct hid_input *hidinput; struct list_head *report_list =3D &hid->report_enum[HID_OUTPUT_REPORT].report_list; - struct input_dev *dev; + struct input_dev *dev =3D hidinput->input; int error; int i, j; =20 - if (list_empty(&hid->inputs)) { - hid_err(hid, "no inputs found\n"); - return -ENODEV; - } + if (!list_is_first(&hidinput->list, &hid->inputs)) + return 0; =20 - hidinput =3D list_first_entry(&hid->inputs, struct hid_input, list); - dev =3D hidinput->input; - - if (list_empty(report_list)) { + report =3D list_first_entry_or_null(report_list, struct hid_report, list); + if (!report) { hid_err(hid, "no output reports found\n"); return -ENODEV; } - - report =3D list_first_entry(report_list, struct hid_report, list); /* * Actually there are 4 fields for 4 Bytes as below: * ----------------------------------------- @@ -104,6 +97,7 @@ static int betopff_init(struct hid_device *hid) if (!betopff) return -ENOMEM; =20 + betopff->report =3D report; set_bit(FF_RUMBLE, dev->ffbit); =20 error =3D input_ff_create_memless(dev, betopff, hid_betopff_play); @@ -112,7 +106,6 @@ static int betopff_init(struct hid_device *hid) return error; } =20 - betopff->report =3D report; hid_hw_request(hid, betopff->report, HID_REQ_SET_REPORT); =20 hid_info(hid, "Force feedback for betop devices by huangbo \n"); @@ -130,20 +123,15 @@ static int betop_probe(struct hid_device *hdev, const= struct hid_device_id *id) ret =3D hid_parse(hdev); if (ret) { hid_err(hdev, "parse failed\n"); - goto err; + return ret; } =20 - ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); + ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT); if (ret) { hid_err(hdev, "hw start failed\n"); - goto err; + return ret; } - - betopff_init(hdev); - return 0; -err: - return ret; } =20 static const struct hid_device_id betop_devices[] =3D { @@ -159,6 +147,7 @@ static struct hid_driver betop_driver =3D { .name =3D "betop", .id_table =3D betop_devices, .probe =3D betop_probe, + .input_configured =3D betop_input_configured, }; module_hid_driver(betop_driver); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 9C2D043934B for ; Mon, 3 Aug 2026 18:46:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782806; cv=none; b=V9EJ6GxLnHNhPufgILdQKL9t31ChFlyYs8PcmB5ZGwDQa5uDAmtlFUFoI0OBbmevW1QjXP4JPFrgW1mNhJdMAK5v5N9abfu6ybGPMBsWJlAAxQ6qjmd1bIx0vx9gx3wk5dLydeqJMXvxssz3gQooIyJp5D8xKrL1RazUVWKFjIY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782806; c=relaxed/simple; bh=FLBZ6TUpfMBXlB7N0BVa7vU2Xr9/kJojTsuqYcBwngA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GTCjEI/s6njbgg1PqQVg5vMBHw5cGj4rc8fuJScFhK7oEY/evpNHHMA+WOf3m+8lxH74GYbsCeSj+lTtnzmUdl0n2zsdfaOePc2zjwH41qtXW74qCCSj+bgH7aD93X5u7IqnZPC8LR0ckWpRdhRAMkCO36iYVELI3K/mIT4UwU4= 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=F3S2ayFk; arc=none smtp.client-ip=209.85.216.42 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="F3S2ayFk" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-384930ca5e2so3158730a91.3 for ; Mon, 03 Aug 2026 11:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782801; x=1786387601; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=nlCI4/gle3R9IwS53kvCY4cjueCVDjt1k2gYqGOMeAY=; b=F3S2ayFkYSrOLutKodBQQBz/tdE97usQ4NB3iYYl4PQZYo5Y+nDiQ0+L+817rYK0nU wE3wR5/ZDSo5gGf9LejuS9Z9Trhj7tdGjy9R9bdk1C1+11VjLFG/gDMFxL8/APK7YY2J ILFyBm1yWJo6aFpJcWqBcsqIRa7Gp6Ib+QmmA/k0oprEnSnrMHLivcTjyMCA4lfxwxCq WALBLSc9N0Iu1vZiHwqm4pFLhOCiFKMFmhrA8TNkDZCpFvGO4nyRpuJG5uzHxrwOUGuC AL6QwdT37KpmHn3VAiumWLm23NhVn4/6b28paj7dnFfzEs2BsNKNW3SiOJQXbeXhrb6m Y7ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782801; x=1786387601; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=nlCI4/gle3R9IwS53kvCY4cjueCVDjt1k2gYqGOMeAY=; b=J77EDUUK/VAFpE7awlNaTfoJSUK9VV+qOeyyZ8tR37sCAjChBNk/Z1NQ5aGeo8ct0X fuc80t1/sWLFYirkqZvFaeaNnDMvo4k4hD8HzNRQLQNx3VbiY6eVmH/WtEbOoN7FCnXR XHnJY4NL/ev3NoWa6u1MIwYDopKYxEu8p16uXA+hN++jsewuj+VEb0Myq/d+99uKJPFy ZLgQPLVzzzT1MivjeAykuA4m7vFCebshl6TJeh+SKpVG1ZWFKK1SajLkb8cHMdfGjjdt bk/Sclas6tmMAZG3zKDQsp3KiIjVcZZHPBRMGZ/0hcQ7d7pFC929GPSwL3X+bptfDOcW trGg== X-Forwarded-Encrypted: i=1; AHgh+RprEOc+7oT4ul+gB70WQ6477foX56c5lmtXLYWU++24bICB75FmjpsfWgT/1fNC3UNdQqCrvlCwVciyAyg=@vger.kernel.org X-Gm-Message-State: AOJu0YwBt8X0TnvwQn+eYHlTbe05GwyLthbOdNzcyLwo0WtPsPW2AWhR twmKbIp1ye6z9MBO4sZarrVCOI5FtB8XbGgLphBxHlvxgwSDTEqHKSVB X-Gm-Gg: AR+sD11/V89GA83+/xw6o89qx6w6P9xV2Ll4PHCT3jeYd3XxGTQmAnlmMeP30mDzzXs gkBdX2KDGYhs9o/2Vd++/t1geglO0QSMgMckKj0XiMk/FYxk9UfHpC9P6j8SdcgaK6xpWYmvUth +SjqAXX+bD9XSnC4RfTgnhJaWV6Fm+qzd6M50FlPF1jiwTaPZPLo+BHNCzeIjhPGy6bliMvBctN 8KeZSxwxTnbDY6tMTCTVA9lxjQ9JQHkTrw00PVRwkK4CONZEQoJHGdjNdomOuwe2EG4txxWo9Z/ /NmRZ4AAgwt3eAcJ5AfAf6Nt79N1dLSgqX1hB3awRCpkUCwgLHIZnKkb+CG0BXODf9r/l0M0MlN kLGiNAb/7bcMu+1ogu3bko0FPZQUu/yPM6ag4g4GvDepXt/D7osMyACBZSB8w4oUXIjylmj1oi6 BXSTpCR25gpKE/st3TRHHgjyQPB/yClhZE3E3BU24NxWhIieYESPxSM5t24ndqVqNmoI7Bm5vHB Dwyok7kltrY853vRoPSh5cshqBjMnB6Y4da3ucC3weLR153vzQjmQq0PHOid0s= X-Received: by 2002:a17:90b:2649:b0:387:e0db:3d8d with SMTP id 98e67ed59e1d1-38fbc552923mr10107203a91.40.1785782801117; Mon, 03 Aug 2026 11:46:41 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:40 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:30 -0700 Subject: [PATCH 05/21] HID: bigben: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-5-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_hw_start() with HID_CONNECT_DEFAULT. This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-bigbenff.c | 89 ++++++++++++++++++++++--------------------= ---- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/drivers/hid/hid-bigbenff.c b/drivers/hid/hid-bigbenff.c index 9f05465358d9..3c87317ccc6b 100644 --- a/drivers/hid/hid-bigbenff.c +++ b/drivers/hid/hid-bigbenff.c @@ -366,58 +366,29 @@ static void bigben_remove(struct hid_device *hid) hid_hw_stop(hid); } =20 -static int bigben_probe(struct hid_device *hid, - const struct hid_device_id *id) +static int bigben_input_configured(struct hid_device *hid, struct hid_inpu= t *hidinput) { - struct bigben_device *bigben; - struct hid_input *hidinput; + struct bigben_device *bigben =3D hid_get_drvdata(hid); + struct input_dev *input_dev =3D hidinput->input; struct led_classdev *led; char *name; size_t name_sz; int n, error; =20 - bigben =3D devm_kzalloc(&hid->dev, sizeof(*bigben), GFP_KERNEL); - if (!bigben) - return -ENOMEM; - hid_set_drvdata(hid, bigben); - bigben->hid =3D hid; - bigben->removed =3D false; - - error =3D hid_parse(hid); - if (error) { - hid_err(hid, "parse failed\n"); - return error; - } - - error =3D hid_hw_start(hid, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); - if (error) { - hid_err(hid, "hw start failed\n"); - return error; - } + if (!list_is_first(&hidinput->list, &hid->inputs)) + return 0; =20 bigben->report =3D hid_validate_values(hid, HID_OUTPUT_REPORT, 0, 0, 8); if (!bigben->report) { hid_err(hid, "no output report found\n"); - error =3D -ENODEV; - goto error_hw_stop; - } - - if (list_empty(&hid->inputs)) { - hid_err(hid, "no inputs found\n"); - error =3D -ENODEV; - goto error_hw_stop; + return -ENODEV; } =20 - hidinput =3D list_first_entry(&hid->inputs, struct hid_input, list); - set_bit(FF_RUMBLE, hidinput->input->ffbit); - - INIT_WORK(&bigben->worker, bigben_worker); - spin_lock_init(&bigben->lock); + set_bit(FF_RUMBLE, input_dev->ffbit); =20 - error =3D input_ff_create_memless(hidinput->input, NULL, - hid_bigben_play_effect); + error =3D input_ff_create_memless(input_dev, NULL, hid_bigben_play_effect= ); if (error) - goto error_hw_stop; + return error; =20 name_sz =3D strlen(dev_name(&hid->dev)) + strlen(":red:bigben#") + 1; =20 @@ -427,10 +398,9 @@ static int bigben_probe(struct hid_device *hid, sizeof(struct led_classdev) + name_sz, GFP_KERNEL ); - if (!led) { - error =3D -ENOMEM; - goto error_hw_stop; - } + if (!led) + return -ENOMEM; + name =3D (void *)(&led[1]); snprintf(name, name_sz, "%s:red:bigben%d", @@ -444,7 +414,7 @@ static int bigben_probe(struct hid_device *hid, bigben->leds[n] =3D led; error =3D devm_led_classdev_register(&hid->dev, led); if (error) - goto error_hw_stop; + return error; } =20 /* initial state: LED1 is on, no rumble effect */ @@ -458,10 +428,36 @@ static int bigben_probe(struct hid_device *hid, hid_info(hid, "LED and force feedback support for BigBen gamepad\n"); =20 return 0; +} =20 -error_hw_stop: - hid_hw_stop(hid); - return error; +static int bigben_probe(struct hid_device *hid, const struct hid_device_id= *id) +{ + struct bigben_device *bigben; + int error; + + bigben =3D devm_kzalloc(&hid->dev, sizeof(*bigben), GFP_KERNEL); + if (!bigben) + return -ENOMEM; + + hid_set_drvdata(hid, bigben); + bigben->hid =3D hid; + bigben->removed =3D false; + INIT_WORK(&bigben->worker, bigben_worker); + spin_lock_init(&bigben->lock); + + error =3D hid_parse(hid); + if (error) { + hid_err(hid, "parse failed\n"); + return error; + } + + error =3D hid_hw_start(hid, HID_CONNECT_DEFAULT); + if (error) { + hid_err(hid, "hw start failed\n"); + return error; + } + + return 0; } =20 static const __u8 *bigben_report_fixup(struct hid_device *hid, __u8 *rdesc, @@ -487,6 +483,7 @@ static struct hid_driver bigben_driver =3D { .probe =3D bigben_probe, .report_fixup =3D bigben_report_fixup, .remove =3D bigben_remove, + .input_configured =3D bigben_input_configured, }; module_hid_driver(bigben_driver); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.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 27486435AA1 for ; Mon, 3 Aug 2026 18:46:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782809; cv=none; b=KPtizSIlLT/yby5rPsXv/M3xNgFQHvhfVIS4QDj32F88fLvjPH2c6Jh+KTR3GsWmDmYoiPibdPttMJwIS1JPHCxWMYQX2lgUHH1LB1N6tKm8bDOxzrJflZfsllRLQ36sWir7MV1HJfL7vXHxxJRt1h3wHclnuWWAvDozC9nCB00= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782809; c=relaxed/simple; bh=92PvuERNoxRSPO39JTqhB9ZUwSyTWzKMYKZ36bV17RM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AvgaUhZ40XeiUOkMpwbPzQAPTWxtcczyEbC2ivden8PX8gJMDRx48BjVpkAKVC7EybQTOmhZ799RPycbSN35E3jbh5CBWFHkBWvZWRQPvFG+7TDy0cKi83N3Vse4QQnwoFRGYY8dhC9Gu1l+0MdHjRiwNLXifTvh0RyH7pgGubM= 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=NPKUMAA/; arc=none smtp.client-ip=209.85.210.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="NPKUMAA/" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-848479c9bd5so3147535b3a.3 for ; Mon, 03 Aug 2026 11:46:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782803; x=1786387603; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=HOz5PiX1ZSB+vLRo+K76aRMaf9WXlDbNtHntTklC834=; b=NPKUMAA/t2xrKi+aTUBD2QU1v0VlE5jVyU7vt9T06YsF6xLBz8DGgXnd9QEMwGd4Gc +hvOzyOG4w9MjXvicGW08yfp4GNtgQv2HfZgg4lBgaVnW0PGoZ8QBaay1B18uEYMjgO5 C6UGmf3ZVNSDAW7ngmzim62HUhN1qXqxBDr7exnPiRPiH5EnqT2Q3zJryJE7oP0BJmPo lftWk1pPCM1l1e4zjwtsFhchyJlNkWN1DXQrcFVPwRaFFwaIsLKPRCajBfqltv1we2t6 HviYcAS1EgIYuLnjh4zSwiW4vIgqxpAtu37JQSYaCrP5LfnZAXqy+uv/lTdSW2AwIOF5 xCgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782803; x=1786387603; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=HOz5PiX1ZSB+vLRo+K76aRMaf9WXlDbNtHntTklC834=; b=hDM/edzNXCpbULt8hcmefRxRzn4dMlHGeuluW/0vM9zO4T5kvt8ZarPAYwC1s4OP2v 8bI5vTIfY5NPqP7YyYrDfQKdMsp6Xrq2c9DoFVLLLKigfJu6yY1zymsn/ONUXWjX/CwI K6B3fi7CdlnRBh70QUmk1RNoXvmNsl+vESBMZuICXbH5vjEoaAj/XwJQf01T61Em8e/Y D4Tk4Ku1fkNsLcOhDaWLF/LVdFOi5gvnc6h/ZV8h4LVxuKrzr8+8Ln9FoAuiTI+2/nbS +G9Bp2E0DyOnKrmabJC3Da1NOa1q4Vnu0zoBf2Jm846aYRXNQQKLeMCX3MkHwjMGBgeC 30Fw== X-Forwarded-Encrypted: i=1; AHgh+RpnuNJvrZzT82SOqWqHn3k5ohUqrSpVnA9Rnov6v+q6wEE/CXkii7ZJ4OYS2XslO+kYy7Lqyl6GspBBghw=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/Os1kIw8hTTPlSY3d6NMPqJgiey3hnMG8jZoi4fF7b00JsrX9 /9RxQyqoFgnt9upXcRZ+gOGsgT4Vg0u8R2Zv3YxaWhuUk5NaA1owiw9e X-Gm-Gg: AR+sD12D8A8xe/e+hQHg4rgDF94H/mOagTVCH2iCJmS4anwcx2+k0HpnxKrb9AC7/Av Fx1+eq2cDo60BQHyAHjXFoaclcE+r9FP0+mhUmCIUmK3J3k95vSW+IHvwtGGJbJhrhgogDKoKLx t8Hh8T06Ul8e65bk1FXjyz2CLTEOC19qaKLdVKPdmMMObHZYf6wzDyPWKApAUFhyh29xmNPADXH EkWIyGtxe44ZrnfZUHFhqorgf5D7oT516FZ4LfT4f4cjsjbzHmWojdpc6uEDeYSETotyQMYLre4 MfJRZUeKAUMpKMHntxSWIxiIanqZlDjAcMz6tSFX5n0nhRg48x6NrW57HqX0qtlc7JJbf3lqQl7 ZxkJBLrve/SMPxlUphs2hzEq/Xyd7mz9RQowgY/wLONyegkdBd4rM60e+EKyd9R6fiVYAelS31F Mc4GjSEGXRjKjAgxpq7FMUx21/7qU+L+kW8Uq4ckCWpY1vHg2PZkZbbxp+tI0CLitXakqxcD1A5 DVAbHc/Kmxpn6Wf1K7N5FWHB/tlsLWvWzioYP61mWJ25ZCFd7ZRHKDoCP8Qh/U= X-Received: by 2002:a05:6a21:648f:b0:3c9:e7d:b170 with SMTP id adf61e73a8af0-3c92a8f3f7dmr11102990637.58.1785782802450; Mon, 03 Aug 2026 11:46:42 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:41 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:31 -0700 Subject: [PATCH 06/21] HID: dragonrise: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-6-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_hw_start() with HID_CONNECT_DEFAULT. This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-dr.c | 66 ++++++++++++------------------------------------= ---- 1 file changed, 15 insertions(+), 51 deletions(-) diff --git a/drivers/hid/hid-dr.c b/drivers/hid/hid-dr.c index 8a8f68a7feb0..a1e10ee8df4d 100644 --- a/drivers/hid/hid-dr.c +++ b/drivers/hid/hid-dr.c @@ -71,29 +71,26 @@ static int drff_play(struct input_dev *dev, void *data, return 0; } =20 -static int drff_init(struct hid_device *hid) +static int dr_input_configured(struct hid_device *hid, struct hid_input *h= idinput) { struct drff_device *drff; struct hid_report *report; - struct hid_input *hidinput; struct list_head *report_list =3D &hid->report_enum[HID_OUTPUT_REPORT].report_list; - struct input_dev *dev; + struct input_dev *dev =3D hidinput->input; int error; =20 - if (list_empty(&hid->inputs)) { - hid_err(hid, "no inputs found\n"); - return -ENODEV; - } - hidinput =3D list_first_entry(&hid->inputs, struct hid_input, list); - dev =3D hidinput->input; + if (!list_is_first(&hidinput->list, &hid->inputs)) + return 0; + + if (hid->product !=3D 0x0006) + return 0; =20 - if (list_empty(report_list)) { + report =3D list_first_entry_or_null(report_list, struct hid_report, list); + if (!report) { hid_err(hid, "no output reports found\n"); return -ENODEV; } - - report =3D list_first_entry(report_list, struct hid_report, list); if (report->maxfield < 1) { hid_err(hid, "no fields in the report\n"); return -ENODEV; @@ -108,6 +105,7 @@ static int drff_init(struct hid_device *hid) if (!drff) return -ENOMEM; =20 + drff->report =3D report; set_bit(FF_RUMBLE, dev->ffbit); =20 error =3D input_ff_create_memless(dev, drff, drff_play); @@ -116,7 +114,6 @@ static int drff_init(struct hid_device *hid) return error; } =20 - drff->report =3D report; drff->report->field[0]->value[0] =3D 0xf3; drff->report->field[0]->value[1] =3D 0x00; drff->report->field[0]->value[2] =3D 0x00; @@ -132,7 +129,8 @@ static int drff_init(struct hid_device *hid) return 0; } #else -static inline int drff_init(struct hid_device *hid) +static inline int dr_input_configured(struct hid_device *hid, + struct hid_input *hidinput) { return 0; } @@ -266,43 +264,9 @@ static int dr_input_mapping(struct hid_device *hdev, s= truct hid_input *hi, return 0; } =20 -static int dr_probe(struct hid_device *hdev, const struct hid_device_id *i= d) -{ - int ret; - - dev_dbg(&hdev->dev, "DragonRise Inc. HID hardware probe..."); - - ret =3D hid_parse(hdev); - if (ret) { - hid_err(hdev, "parse failed\n"); - goto err; - } - - ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); - if (ret) { - hid_err(hdev, "hw start failed\n"); - goto err; - } - - switch (hdev->product) { - case 0x0006: - ret =3D drff_init(hdev); - if (ret) { - dev_err(&hdev->dev, "force feedback init failed\n"); - hid_hw_stop(hdev); - goto err; - } - break; - } - - return 0; -err: - return ret; -} - static const struct hid_device_id dr_devices[] =3D { - { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006), }, - { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011), }, + { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006), }, + { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011), }, { } }; MODULE_DEVICE_TABLE(hid, dr_devices); @@ -311,8 +275,8 @@ static struct hid_driver dr_driver =3D { .name =3D "dragonrise", .id_table =3D dr_devices, .report_fixup =3D dr_report_fixup, - .probe =3D dr_probe, .input_mapping =3D dr_input_mapping, + .input_configured =3D dr_input_configured, }; module_hid_driver(dr_driver); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 CEFB2439F94 for ; Mon, 3 Aug 2026 18:46:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782808; cv=none; b=HHDDoCAwt/9Z8sd7pK0ls1Fvsqb/aQw9cIkNptOQERcHK13GT/lhI4vOVlP08eoqfrOMzY+6UMAgtmqtx5GotUOKWTf2fo77uK9cPl1SXPQpMzRvWbJpGXIZW/otI57MscxpAYAggg4+OUF08Ka+jHY5f+YHNrR+Q2+NPLslC7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782808; c=relaxed/simple; bh=LHE5r9HcJGmgdAN0lDq2vDv6+I/AvjL339mlhS4SPzs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dTg0uOEoAbB+XJ6JelyhoHaBcRSRnU7ML1mNDQXP46u0dBBPQPi+0HEvNBOzUxWTw7e4UIfErbzoK/vO+qzxU8e19Jw6Q7gmKd+75sd9o6n8hc4twI5AX11uQPZZpANPCnNfjR70KEeGjDNw6G7j1BrsjNm/afmEx2RqCpx4E5s= 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=pYDbU4bm; arc=none smtp.client-ip=209.85.216.48 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="pYDbU4bm" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-383cb94f742so3755827a91.3 for ; Mon, 03 Aug 2026 11:46:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782804; x=1786387604; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Yy7DVKg39FEAhLMMdKRgyYcMZGvYjnaxEZ5h7r1ZLPQ=; b=pYDbU4bmVMsov+GZE9cys5voDKqpoMrqkEBN90nNUwT/ltBrOth1hjk0gAjDMM03RY bhj/TRfYw1mYQidAx6wyz8asXUZmp2MALCmD+qfO2+jCu+mIDn/EWM/uwuXmtY3GYD5R 5NlX9kjiTN4qEeBHu+AbKipZEa4ZymkJSDwEclmrU+Z6bZEFUScPu+5ZCyWj+yk2DO3H VHy9cYm5yVLQnvueHZbyG17cZFBMYvPx4FCAG9uKbB0o7AxvniwFRRXMF16XgIxtkGyN 3lEJS9c2P6SxcoDvlF7i6dTUY+oFteYyJqAkgwxq0BIC48wNoLH7w1j/76Ok7paPACkd hhmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782804; x=1786387604; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Yy7DVKg39FEAhLMMdKRgyYcMZGvYjnaxEZ5h7r1ZLPQ=; b=d30SztADfseCsmyo+CvXsJ6G3USES0x6sU0oGq4BmpnScH5F9ryhzpOqu942RomVXT qTG3jUyBdoV3SrI5scXPIML7idn4gy/8emeuTRMO27ZAw6LEVHMf28/x2D2RA0+/Gb05 nWgdcCZDvn3H6wttuTN9Ade4bpnCVjvZfmpN/491q577WkQaOvW4xHKCUZqvSAQJNtsV 04tf4dbGsXXOoVTpoeU4quYVy2G8dX9hLt1QS1ajcFakLT0NETg530bY7G8IlyhjCV7/ jGgA5E9iW0uEjHcLaw5pJei1X4kVAemmzfB65SYw58cWPorBK/ixvWXpmTNmZ5qe59SH aRfg== X-Forwarded-Encrypted: i=1; AHgh+Ror6ZQBOxoPlKGEpOMiEUblWyeoHXZOMvnDc8zDaZMJiOAGbDAN9vjBHfmynloBPvfSCeZLkVq0kXhceaw=@vger.kernel.org X-Gm-Message-State: AOJu0YyB6FVdimvs22omuF5XXY3UgyEG+JoVn/WsTA07RlM3GAb5wZuO O3GMeL0/M+Bl+lM75hDyBc9JhF8SzFPD2Q0p2EaFrUlmpk/8LVCE762v X-Gm-Gg: AR+sD10WTE0ryb0rBOzNovZSGhrc4hDdxQxuOMr3Oqb6/if8c7qncRDSkgV6B2ksEqC 99m2VPGU6a257KDWdS9XAhJ+6sKNfixx04WuKPr1vexABscnwrYnolKwNTmdvJb71WZETMoiG2/ QKYb2h9PIePQfkkBsBpU0FiA/3WARUzHfz5zHZ8ITsWjefGOg6P+0OJPn8arOKAkDjByop7O6kC J02/IM7iN7LYEgpiXq1FxZxZfscvv/KukiwwHinAtBIqd8Q67DY5rOFfJ4axgsf2PwWLhQS869i FXo0KpfKeZUW9C6HIYvs+xsLcSHuHUEv2bUGFvj9BMnQJ+Z4himUGV9FP8WBQH+pCRqvJPq9jZ8 8DXJgDkBXuvwmSJkektS59krm3c0V1cKjiDbmdWiH6iYsz1MG/pK/eHL+ajZOKCzjSOmfB2GveI +qJWrfCJiUsLOGBRDa39kn939b8wpzEYDN+q4Q1evwytEZeKRnmwGMaUf+Fhll8/P5AbPmvpfiW /MhLl5FuzcjL3fkWRYWlgmjde5JDNSTM5/0n3U+jIPSwAudrCHI X-Received: by 2002:a17:90b:590f:b0:38e:7a05:9c0a with SMTP id 98e67ed59e1d1-38fbc493f0bmr10257115a91.18.1785782803842; Mon, 03 Aug 2026 11:46:43 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:43 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:32 -0700 Subject: [PATCH 07/21] HID: emsff: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-7-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_hw_start() with HID_CONNECT_DEFAULT. This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-emsff.c | 50 ++++++++-------------------------------------= ---- 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/drivers/hid/hid-emsff.c b/drivers/hid/hid-emsff.c index 1b4ad18f6051..d8e559e0524f 100644 --- a/drivers/hid/hid-emsff.c +++ b/drivers/hid/hid-emsff.c @@ -43,29 +43,23 @@ static int emsff_play(struct input_dev *dev, void *data, return 0; } =20 -static int emsff_init(struct hid_device *hid) +static int ems_input_configured(struct hid_device *hid, struct hid_input *= hidinput) { struct emsff_device *emsff; struct hid_report *report; - struct hid_input *hidinput; struct list_head *report_list =3D &hid->report_enum[HID_OUTPUT_REPORT].report_list; - struct input_dev *dev; + struct input_dev *dev =3D hidinput->input; int error; =20 - if (list_empty(&hid->inputs)) { - hid_err(hid, "no inputs found\n"); - return -ENODEV; - } - hidinput =3D list_first_entry(&hid->inputs, struct hid_input, list); - dev =3D hidinput->input; + if (!list_is_first(&hidinput->list, &hid->inputs)) + return 0; =20 - if (list_empty(report_list)) { + report =3D list_first_entry_or_null(report_list, struct hid_report, list); + if (!report) { hid_err(hid, "no output reports found\n"); return -ENODEV; } - - report =3D list_first_entry(report_list, struct hid_report, list); if (report->maxfield < 1) { hid_err(hid, "no fields in the report\n"); return -ENODEV; @@ -80,6 +74,7 @@ static int emsff_init(struct hid_device *hid) if (!emsff) return -ENOMEM; =20 + emsff->report =3D report; set_bit(FF_RUMBLE, dev->ffbit); =20 error =3D input_ff_create_memless(dev, emsff, emsff_play); @@ -88,7 +83,6 @@ static int emsff_init(struct hid_device *hid) return error; } =20 - emsff->report =3D report; emsff->report->field[0]->value[0] =3D 0x01; emsff->report->field[0]->value[1] =3D 0x00; emsff->report->field[0]->value[2] =3D 0x00; @@ -103,34 +97,6 @@ static int emsff_init(struct hid_device *hid) return 0; } =20 -static int ems_probe(struct hid_device *hdev, const struct hid_device_id *= id) -{ - int ret; - - ret =3D hid_parse(hdev); - if (ret) { - hid_err(hdev, "parse failed\n"); - goto err; - } - - ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); - if (ret) { - hid_err(hdev, "hw start failed\n"); - goto err; - } - - ret =3D emsff_init(hdev); - if (ret) { - dev_err(&hdev->dev, "force feedback init failed\n"); - hid_hw_stop(hdev); - goto err; - } - - return 0; -err: - return ret; -} - static const struct hid_device_id ems_devices[] =3D { { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II= ) }, { } @@ -140,7 +106,7 @@ MODULE_DEVICE_TABLE(hid, ems_devices); static struct hid_driver ems_driver =3D { .name =3D "hkems", .id_table =3D ems_devices, - .probe =3D ems_probe, + .input_configured =3D ems_input_configured, }; module_hid_driver(ems_driver); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 87554439916 for ; Mon, 3 Aug 2026 18:46:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782810; cv=none; b=V/8vwSGWO1WuMHkdY2yxTMRMzYk68cvXynZKwf4QaRVpsB23/9jsznDCtgQ384h/EwrMbbgwSHH7u8flT4lkNCxNPQfGUfJoN4Dm0FEYT3BXXQJjEDbwz39HqRXJGI7LUy0iUJwERRYlcwa0qItkRWcTL877fBB1awESmO5Y9Cw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782810; c=relaxed/simple; bh=v7TqxLgBA7wkrh0lpbqWkH+WYHzABumUa7WM8oNwkxo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uaolURkqZrNknBxxAysdfRk9TW00Kgyk1Lhzw7c//h7rbxNp2PEHLnnQEEpNbmxBjSaQ9KUlqjvqHVJ/Lh9V4UX9PFf/jhIpHCIJAxahLJjCjO+guIkvBFxKVoMgMd4R1WO7KONvMwBthga8y0kRq613tmUDTKUY4Yb5H0WWVtQ= 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=McDDjGfk; arc=none smtp.client-ip=209.85.216.44 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="McDDjGfk" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-383cb94f742so3755855a91.3 for ; Mon, 03 Aug 2026 11:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782805; x=1786387605; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=XII8xKdk1EK6oOq1Wzl11N5mboBPK8ToSXyj9I3cUDA=; b=McDDjGfkx5cBd3TPb/t5SRDVxcVcW1mEqXLcs+Ae1zJf2IxBCT2K8A8lZAJ2JpJu2C M4dPyFc/BX96Hs8ewslaRUAQDj5LWIFCmvr8EKkLJCxtIsVsUkxCg3WAFihQh0JGKnIi 3D00JOUFiFRIPhRjadzjEVsOh3jJnDRQbE3SzO3ZkPCdec4G8BTmPLqVEvbWEWReI0oj /oEHgKQOQJ8a3ksX4GPn5URYP9dbaoEztLKbXowEcB5gWUG5n436s8Qxk/DEX93QamHT DwrJaWWqrQ0YoZtgYyrgpx/hv9kuyG5OiGQLrsRwMx2QZDE3sJNF1LrpG15WrJq9PBNl xSFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782805; x=1786387605; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=XII8xKdk1EK6oOq1Wzl11N5mboBPK8ToSXyj9I3cUDA=; b=XM9cYvNM6xYcWjhiM+Lm5mjYa3LLu2u8/chZI6VWiUCaSKcFgjDM8CnqFDhn4bwlyH xN5oB7c0A955BaORoygl1INaz+7MBVClKcpKDGDSlKiAiSkaOuPRRbsVv/38lfvPUdY6 s6MX4yXUHGkVvFJTp/A2+r7uI0jTHb88tPl/VOudaDWwpSyusEJFGpth/RnGRJ+UUoBD X9BLLc2sIAqS+hPik9W+asrD8e04HPHhEHA3K5+F56elaeO88GxeTxsbmmaChTXqh/Au N5735m16vINFVvJx0HF0rjYkHejbImXe8NrRC1c1GRUi2eNKX2u/qITthQjIVeCydGOH UiPw== X-Forwarded-Encrypted: i=1; AHgh+RqfpLjnhuOJpj1qAA4P/x8AzM2rqL8m5oBpfsbU2D2KM6J6J9bCmU5fiCQXOJ2qcHe1noOZjMnWoZJTwZA=@vger.kernel.org X-Gm-Message-State: AOJu0YxnsG2lror3sHVP54XStBHWzi9t+Acju9LY1GyvKGNHRbpVJnXD ksL70j9oOgsD9vHzEs7nggKL2HTMbbaqs8yOiVV5sZrnvwV02VFj2z8a X-Gm-Gg: AR+sD12Ul0DfERJhwrl6J7cT7/J4KWHTK2PUkiulerl3BJhtAvf8e+yBybM2KqUQKFV nya2iYUSEsbXBnKP/j9UZZ3PiTiTeZXmHR6SveeDlzpPOF98GqUnvdPgFKEQCC1nTAXROwFDnya 0FKCVAm/pSmYStpV8M3izfDyF34X6MwTEHwD50CVlS0iVLAA2PWljtoFxXqwouh3o/Y5U673O3v EPSjC1gPrKHkP6fdekIHUFoVho6ERg28qoF6TtAguQhGDaq4a7hF+AyX8PFjZXKTzo918J3pB6F NxaePM7ITjIs3QlBukdPhu99kASd7FLRI1pCNAn15XH51TKJX7dZBao/QWwYxlx7yz8HRD3VYDM b4a0lywOs48l9afVy/TvuPtQiUsdzwQ5bPTE747SilG0yPyCYyBcXY+V/CPwaINxqIZvqqVJrO3 AfDKSsQEINKExKOfhL4D4CsNg6qRfcNZQpYMqH+l3MAKBfXbPmEJ0XocUiDc3QG8ZTA6GCRXF5J 98U5Kh2d76rU72nGFXnu4qZ8QMNxiwsiYdi9y7C4sbVUVtvVzCV X-Received: by 2002:a17:90b:53c5:b0:38e:85fb:71b9 with SMTP id 98e67ed59e1d1-38fbc3f9aa9mr10534877a91.4.1785782805317; Mon, 03 Aug 2026 11:46:45 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:44 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:33 -0700 Subject: [PATCH 08/21] HID: gaff: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-8-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_hw_start() with HID_CONNECT_DEFAULT. This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-gaff.c | 53 ++++++++++------------------------------------= ---- 1 file changed, 10 insertions(+), 43 deletions(-) diff --git a/drivers/hid/hid-gaff.c b/drivers/hid/hid-gaff.c index 8b99686b63df..ec793a179b47 100644 --- a/drivers/hid/hid-gaff.c +++ b/drivers/hid/hid-gaff.c @@ -60,32 +60,23 @@ static int hid_gaff_play(struct input_dev *dev, void *d= ata, return 0; } =20 -static int gaff_init(struct hid_device *hid) +static int gaff_input_configured(struct hid_device *hid, struct hid_input = *hidinput) { struct gaff_device *gaff; struct hid_report *report; - struct hid_input *hidinput; struct list_head *report_list =3D &hid->report_enum[HID_OUTPUT_REPORT].report_list; - struct list_head *report_ptr =3D report_list; - struct input_dev *dev; + struct input_dev *dev =3D hidinput->input; int error; =20 - if (list_empty(&hid->inputs)) { - hid_err(hid, "no inputs found\n"); - return -ENODEV; - } - hidinput =3D list_entry(hid->inputs.next, struct hid_input, list); - dev =3D hidinput->input; + if (!list_is_first(&hidinput->list, &hid->inputs)) + return 0; =20 - if (list_empty(report_list)) { + report =3D list_first_entry_or_null(report_list, struct hid_report, list); + if (!report) { hid_err(hid, "no output reports found\n"); return -ENODEV; } - - report_ptr =3D report_ptr->next; - - report =3D list_entry(report_ptr, struct hid_report, list); if (report->maxfield < 1) { hid_err(hid, "no fields in the report\n"); return -ENODEV; @@ -100,6 +91,7 @@ static int gaff_init(struct hid_device *hid) if (!gaff) return -ENOMEM; =20 + gaff->report =3D report; set_bit(FF_RUMBLE, dev->ffbit); =20 error =3D input_ff_create_memless(dev, gaff, hid_gaff_play); @@ -108,7 +100,6 @@ static int gaff_init(struct hid_device *hid) return error; } =20 - gaff->report =3D report; gaff->report->field[0]->value[0] =3D 0x51; gaff->report->field[0]->value[1] =3D 0x00; gaff->report->field[0]->value[2] =3D 0x00; @@ -125,37 +116,13 @@ static int gaff_init(struct hid_device *hid) return 0; } #else -static inline int gaff_init(struct hid_device *hdev) +static inline int gaff_input_configured(struct hid_device *hdev, + struct hid_input *hidinput) { return 0; } #endif =20 -static int ga_probe(struct hid_device *hdev, const struct hid_device_id *i= d) -{ - int ret; - - dev_dbg(&hdev->dev, "Greenasia HID hardware probe..."); - - ret =3D hid_parse(hdev); - if (ret) { - hid_err(hdev, "parse failed\n"); - goto err; - } - - ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); - if (ret) { - hid_err(hdev, "hw start failed\n"); - goto err; - } - - gaff_init(hdev); - - return 0; -err: - return ret; -} - static const struct hid_device_id ga_devices[] =3D { { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012), }, { } @@ -165,7 +132,7 @@ MODULE_DEVICE_TABLE(hid, ga_devices); static struct hid_driver ga_driver =3D { .name =3D "greenasia", .id_table =3D ga_devices, - .probe =3D ga_probe, + .input_configured =3D gaff_input_configured, }; module_hid_driver(ga_driver); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.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 90C38439F82 for ; Mon, 3 Aug 2026 18:46:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782811; cv=none; b=tFUACPbue3E930waNMfdEcJcYKQ/G/zxxUco3PwVTBmKBOGPW/LwYrBMGizPWgoatNdD82IFfZYyQUhx8t+Du40lLl9MlOvF0PIU+QREEKOMpdtiO9g9I5lToF52HYDmKVd/kWMGSmEA6oad/JAB1/ZMgDEttJBPdP+20LrTWr0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782811; c=relaxed/simple; bh=qaDSk/5YmV6gZkAdMcHZslIzINZ+ip8Z1U6jUiEQCkI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=P1zMJnp7EG0fiholfg0r7PTC99RT2/R6GhUWH5OYG+1ZKmDpz/hv9x8Dvxv+74hdv8cBAdEA64v5rWCzQnxXKoxDxNiP//TUGVyTSVgmEwFkKOQP/eZJNJOiKXjQ4aVo9yxGu9VTOK6z7exY/xnZRpj7+PUIfvo2taCE+oFIhAE= 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=UojGgpTM; arc=none smtp.client-ip=209.85.210.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="UojGgpTM" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-84a2dcede83so5135467b3a.3 for ; Mon, 03 Aug 2026 11:46:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782807; x=1786387607; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=SV2MN5jqx3aqjs62FVvaU6OUodkPbSGwRNX49TcVWl8=; b=UojGgpTM/RbHpng8Ahk0hkgXYtt8tzAjgnARt/9zR+NwwlkckcQqZr75v83wYQE1Gp dAUDPpmrll1DayJ7j76N8Cy9s83PeXQxzQiDxsm5De2lQlYrmWcTubiNiUILL+0iWCHF vbbrnIl1XT0tRyBpsi9j2ZtSR5SHibg9CIGgkNv1+5Uf0fXq8FBS3P/YohmH1/oBFebG GikzNLZAgQZClMdDqqBuYijnGtoS3b6HkjnWcDTF1HZUmpHFQ5bB+mSe3t2DPSacWsRq Qnn9Q3HATVGejorrtRczdeOEhT4dBq4R4zVU2cVRYGzt5mFwexYInmt4E7/6PW0kzUa2 B4TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782807; x=1786387607; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=SV2MN5jqx3aqjs62FVvaU6OUodkPbSGwRNX49TcVWl8=; b=itil1ebGqslu9DLZvOmfA48JdHEep057TyXwMXC82zvDlwDw8eeyFBH4WXULfh651q kBootqBVyK/9o1gLG5g25e+8+p9H38S9gWYtinzgaH8rcEUPN5OCftEzMvfbZNiOiiAR JSNBmdUioxgBSwRY6wGIuk/nzkNypOVL9slj8x/4RWYj21wO1zVVEY6hEAjOjuFfS57F Z0WFR+/qYWPtbhMB+3n8dVqcj8bvLSEJm5bd/dY+UE8HfFlKsa574z65nLamPkh6Z2NI bfPkuSDCTK6SqtTvhnWRENcKUjBOh48BKdm1+ImJHiIRgN4t1u3BEmO9D01j2FKpmJQG RAvw== X-Forwarded-Encrypted: i=1; AHgh+RoDJzr0FGgIw0j0NrguZANIHaLj29zAZ3jMM/76qPk3arunqOQE84uLGHlDd/llFj+2UgS0j/tsznS1qFE=@vger.kernel.org X-Gm-Message-State: AOJu0YxyXA+b0p8l14/pgx9l1a7/Mb6A/hWD4EoohOX5fIxxAKuauz2K RFJTwMO/v/HxCXMs3zn28VfjQhmMItmrwN221jZA8Tf1SjUSkm9TRHoE X-Gm-Gg: AR+sD13mV/snk2ATuenpefM5r3sYCX0rdXY1ZMoQeC+xLzFBuySPTds3QQ3f2X5Uy7t SKlUjnH9nE+0FF/JnEIhK2tGbvI1ivpmuXLQG4p2UQa7eeJsA757ffbVYTS36zhwYWaFadI0QjH iNuba1/BtfFvU5tiWOJi966M8UlMBKZ9w9V6FGfAa5M8X+ajUl/bQd+E5Z2IQ0Z2OZeiO0nC49H aCi5xSLFBXbSSIrFdaxP0L4YfZ4rhSxkRSE79QunhIMkAUodStY+V12X0rGYGDUh/5+9GE9kQLc dl/3UeyJCicU2qQ+2JwopD/ltG9OnQB1RpwEsGaaAoguvXzjJoftDYri+gLJYFnGJhkcf1+VLro xFSyBqoZQWMoAXEKz4HozCTsR4BXYV+xqpuBY8QxpJ74CUIX0kjWp/aqMVBM2dZMbTG2WpvY+3q Py8YDr28R+7sWoP0NVxjcnIVacotbSTjKEnqnfUsmD2xxDY0d+MQ/BwwxxJ5dPADPft1PluyJ03 c+BfQl599A/dnW+9C2XW5T17O0To73F4Iuw9SAKlV/mccKODDJ0 X-Received: by 2002:a05:6a21:7002:b0:3c2:dcdd:a861 with SMTP id adf61e73a8af0-3c92a85c953mr11789820637.43.1785782806919; Mon, 03 Aug 2026 11:46:46 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:46 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:34 -0700 Subject: [PATCH 09/21] HID: stadia: use open/close to manage workqueue lifecycle Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-9-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f Override input device open() and close() callbacks to enable and disable the force-feedback workqueue item synchronously. When the input device is opened by userspace, call hid_hw_open() and enable_work(). When it is closed, disable_work_sync() ensures that any pending or running work item is cancelled/flushed and no further work items can be scheduled. In close(), zero out magnitudes and issue a final report to turn off the rumble motors on the physical controller before shutting down transport I/O. Pack strong and weak magnitudes into a single u32 integer using WRITE_ONCE() and READ_ONCE() for atomic, lockless updates. This allows eliminating the manual 'removed' boolean flag and spinlock completely. Assisted-by: Antigravity:gemini-3.6-flash Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-google-stadiaff.c | 71 +++++++++++++++++++++--------------= ---- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/drivers/hid/hid-google-stadiaff.c b/drivers/hid/hid-google-sta= diaff.c index 6b38d2421d3d..d6a73d210599 100644 --- a/drivers/hid/hid-google-stadiaff.c +++ b/drivers/hid/hid-google-stadiaff.c @@ -17,10 +17,7 @@ struct stadiaff_device { struct hid_device *hid; struct hid_report *report; - spinlock_t lock; - bool removed; - uint16_t strong_magnitude; - uint16_t weak_magnitude; + u32 magnitudes; struct work_struct work; }; =20 @@ -29,12 +26,10 @@ static void stadiaff_work(struct work_struct *work) struct stadiaff_device *stadiaff =3D container_of(work, struct stadiaff_device, work); struct hid_field *rumble_field =3D stadiaff->report->field[0]; - unsigned long flags; + u32 mags =3D READ_ONCE(stadiaff->magnitudes); =20 - spin_lock_irqsave(&stadiaff->lock, flags); - rumble_field->value[0] =3D stadiaff->strong_magnitude; - rumble_field->value[1] =3D stadiaff->weak_magnitude; - spin_unlock_irqrestore(&stadiaff->lock, flags); + rumble_field->value[0] =3D mags & 0xffff; + rumble_field->value[1] =3D (mags >> 16) & 0xffff; =20 hid_hw_request(stadiaff->hid, stadiaff->report, HID_REQ_SET_REPORT); } @@ -44,19 +39,41 @@ static int stadiaff_play(struct input_dev *dev, void *d= ata, { struct hid_device *hid =3D input_get_drvdata(dev); struct stadiaff_device *stadiaff =3D hid_get_drvdata(hid); - unsigned long flags; + u32 mags =3D (u32)effect->u.rumble.strong_magnitude | + ((u32)effect->u.rumble.weak_magnitude << 16); =20 - spin_lock_irqsave(&stadiaff->lock, flags); - if (!stadiaff->removed) { - stadiaff->strong_magnitude =3D effect->u.rumble.strong_magnitude; - stadiaff->weak_magnitude =3D effect->u.rumble.weak_magnitude; - schedule_work(&stadiaff->work); - } - spin_unlock_irqrestore(&stadiaff->lock, flags); + WRITE_ONCE(stadiaff->magnitudes, mags); + schedule_work(&stadiaff->work); =20 return 0; } =20 +static int stadia_input_open(struct input_dev *dev) +{ + struct hid_device *hid =3D input_get_drvdata(dev); + struct stadiaff_device *stadiaff =3D hid_get_drvdata(hid); + int error; + + error =3D hid_hw_open(hid); + if (error) + return error; + + enable_work(&stadiaff->work); + return 0; +} + +static void stadia_input_close(struct input_dev *dev) +{ + struct hid_device *hid =3D input_get_drvdata(dev); + struct stadiaff_device *stadiaff =3D hid_get_drvdata(hid); + + WRITE_ONCE(stadiaff->magnitudes, 0); + stadiaff_work(&stadiaff->work); + disable_work_sync(&stadiaff->work); + + hid_hw_close(hid); +} + static int stadiaff_init(struct hid_device *hid) { struct stadiaff_device *stadiaff; @@ -90,11 +107,13 @@ static int stadiaff_init(struct hid_device *hid) if (error) return error; =20 - stadiaff->removed =3D false; stadiaff->hid =3D hid; stadiaff->report =3D report; INIT_WORK(&stadiaff->work, stadiaff_work); - spin_lock_init(&stadiaff->lock); + disable_work_sync(&stadiaff->work); + + dev->open =3D stadia_input_open; + dev->close =3D stadia_input_close; =20 hid_info(hid, "Force Feedback for Google Stadia controller\n"); =20 @@ -127,19 +146,6 @@ static int stadia_probe(struct hid_device *hdev, const= struct hid_device_id *id) return 0; } =20 -static void stadia_remove(struct hid_device *hid) -{ - struct stadiaff_device *stadiaff =3D hid_get_drvdata(hid); - unsigned long flags; - - spin_lock_irqsave(&stadiaff->lock, flags); - stadiaff->removed =3D true; - spin_unlock_irqrestore(&stadiaff->lock, flags); - - cancel_work_sync(&stadiaff->work); - hid_hw_stop(hid); -} - static const struct hid_device_id stadia_devices[] =3D { { HID_USB_DEVICE(USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_STADIA) }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_STADIA)= }, @@ -151,7 +157,6 @@ static struct hid_driver stadia_driver =3D { .name =3D "stadia", .id_table =3D stadia_devices, .probe =3D stadia_probe, - .remove =3D stadia_remove, }; module_hid_driver(stadia_driver); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 92EA343552B for ; Mon, 3 Aug 2026 18:46:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782812; cv=none; b=fnsV4h6YBvcaUNluiwuXJIZNBqnTA3jjlSRm4FtzkOMcJTzhmKVAcJQ5NMyhWkX7Jt+DQ9OQFZ97NUgNGI3HJuYksj1cvFV6MFY3gKnSe4gnyuL4aClW0v9b0x0KyHs5hvACFpaB1LZfGgz8lIq1Zm8mF70uHf+QfrhfPSPHkbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782812; c=relaxed/simple; bh=Uf8he7nAsG/KRuBT/yGn3TrZ1ExEAQm9BaOvzIjqfp4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fZFn+/Uf+hhSEbT5ZIduW36gTSQqm/ZJ3vnhshYRcQIH2VOrs+zeb/htRVe/Pv/tzNRgfoNTjwMRCYx/SA5dABlIK4y0kjdmoyrYcxDlTHZEic7LXChXjpl/XeEW5DxeNTCUoaPUZl2vgq+ErVLI2twIEA297S4Nh6JKdtwdtD8= 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=V7/0T1m2; arc=none smtp.client-ip=209.85.210.171 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="V7/0T1m2" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-84a4d8fd6ecso4011799b3a.1 for ; Mon, 03 Aug 2026 11:46:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782808; x=1786387608; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=87bvLzjv5ZZpsa24dDBIH3Ak2KXTk9+GG+h8XVlqydU=; b=V7/0T1m2pKy5JIoxdxw587Ans8MZ52s3+7VT5Otak3wz43+yBND7QqRp1pTalwv/IP 5qvZlyrfUUYHLXh20nPCPWn8C9w6Fn9f2ocz2uf3rwmqAm14LDaZ3z2Xfe6pc11NlW/q jnG9akAG6xcDjkJg+uDc3+DF3+dffYXkURl+CpyfWOlFeykOE3iHuZVqIoRrGQk5xPTk s+B39781ZYOGFe8siOO0cal1RwjZZNTyDUj4SCVzk6SnIPkqH6iVze/9fkf/ERA4L/EP 7UNBLxowUXw5VpLmgNBurqAUk5DYbWc7lH+VEjZLTik75bh5ZIhse9v5L+p8K1qFHKxm 8/0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782808; x=1786387608; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=87bvLzjv5ZZpsa24dDBIH3Ak2KXTk9+GG+h8XVlqydU=; b=r7m3+tkcDxkkPVwBX9r/jQgEuEOC6Z6mCqXugUiI9/L/J8mcEIA5gBU4Zwk/wNdzYA p5fFCIxlSzqDamyuVvJ+dDoMugPNUgYBNkfSFTBiNFhVe0X3Pof7+SQ2Sjc5sPbbnyup 5vS1gAkCrUD09vSOxND/86PW1VmtLsXDKrGvbJDpusHt7LIkFQZ1xR2zQNsQ4A4SYu0f Y0AOt1DBXsR5eJVQ0CQIQjXVMYRxbubzSAcOsd3UwEi63H44rP9dX1ShmzuUYERU/W8A Ww0G3YfbdNjozGIwqPDzcBJheKchYfJsn6uUNbeHgNWUe+qllqp2YDgLzHMDVjB4N+LH MfoA== X-Forwarded-Encrypted: i=1; AHgh+RpsUYpg76A/2etbRIgvgS6r2yPsuYJuFTSukM5TjyHGISq3y8E0jgKUu5qRhlARi2vzO96HgNJ5f8/CUqQ=@vger.kernel.org X-Gm-Message-State: AOJu0Ywm15ACm9JTAWMoszjKqtOR27fKcQWw8WKwWSZI2+hjl8PY2hUG 9fClcSsZZeyidEIaJEQniH59CxxmQt9RYy4J3nLo0wRW26Ba0rDJWV7y X-Gm-Gg: AR+sD113LoruOlh4WWPnFTPjp8CwbGPlDzd8glLQ4iR7xFC68+/zvwKC+xgPTEmMn6j tlBlZS4YblvhhwRHR0f/E14r2cvxhh+ykV7wmpN/TWPx6eqbs/I6I3SkRqHwESOlhcCla1XJf3R 6not3nin7EaHw3QOC5zCxzC2cfykZm7Xbc0gz5gKQzCCDSJUEfiiwQNAEY4n4ibe9Njbsd2IXSQ aYbCzSm/SRfUT0ZyCkuldCFxNML+Fy6vNMNhNDJaisxwR0Bw0x8wivbK8yGFW9gWi0fAGyoWZEa +NsX6Z2KyJEHa5m1qGNbqTcdu6A6D9UzOZdLyif8iF1i6N++7jWBpkZdLRcuH0Q4BBmnvAQrd3E 1Gc4SXbqI6i+2VOB8+wgRoBnF2qN7K7drDP/c490ETimDmgmm8FaBf64R/7UBQfOJLkN1oFeXAz dpJ9Y6HJ+EBmqFFHbOP7kYiyJi5tUwh4oWg8PdoBYELIj/NEsR5d9OCcDo7rkxHLJj/OQSBafWr bXTuOmtvnRTpzb2DArgHR7SzS6q39NZ1PHeZ9PFTCJC8pKEW8in X-Received: by 2002:a05:6a21:1fc4:b0:3c3:c185:f334 with SMTP id adf61e73a8af0-3c92a95073cmr13139560637.66.1785782808357; Mon, 03 Aug 2026 11:46:48 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:47 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:35 -0700 Subject: [PATCH 10/21] HID: stadia: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-10-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_hw_start() with HID_CONNECT_DEFAULT. This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-google-stadiaff.c | 41 +++++------------------------------= ---- 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/drivers/hid/hid-google-stadiaff.c b/drivers/hid/hid-google-sta= diaff.c index d6a73d210599..0214aae6b0fa 100644 --- a/drivers/hid/hid-google-stadiaff.c +++ b/drivers/hid/hid-google-stadiaff.c @@ -74,20 +74,15 @@ static void stadia_input_close(struct input_dev *dev) hid_hw_close(hid); } =20 -static int stadiaff_init(struct hid_device *hid) +static int stadia_input_configured(struct hid_device *hid, struct hid_inpu= t *hidinput) { struct stadiaff_device *stadiaff; struct hid_report *report; - struct hid_input *hidinput; - struct input_dev *dev; + struct input_dev *dev =3D hidinput->input; int error; =20 - if (list_empty(&hid->inputs)) { - hid_err(hid, "no inputs found\n"); - return -ENODEV; - } - hidinput =3D list_entry(hid->inputs.next, struct hid_input, list); - dev =3D hidinput->input; + if (!list_is_first(&hidinput->list, &hid->inputs)) + return 0; =20 report =3D hid_validate_values(hid, HID_OUTPUT_REPORT, STADIA_FF_REPORT_ID, 0, 2); @@ -120,32 +115,6 @@ static int stadiaff_init(struct hid_device *hid) return 0; } =20 -static int stadia_probe(struct hid_device *hdev, const struct hid_device_i= d *id) -{ - int ret; - - ret =3D hid_parse(hdev); - if (ret) { - hid_err(hdev, "parse failed\n"); - return ret; - } - - ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); - if (ret) { - hid_err(hdev, "hw start failed\n"); - return ret; - } - - ret =3D stadiaff_init(hdev); - if (ret) { - hid_err(hdev, "force feedback init failed\n"); - hid_hw_stop(hdev); - return ret; - } - - return 0; -} - static const struct hid_device_id stadia_devices[] =3D { { HID_USB_DEVICE(USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_STADIA) }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_GOOGLE, USB_DEVICE_ID_GOOGLE_STADIA)= }, @@ -156,7 +125,7 @@ MODULE_DEVICE_TABLE(hid, stadia_devices); static struct hid_driver stadia_driver =3D { .name =3D "stadia", .id_table =3D stadia_devices, - .probe =3D stadia_probe, + .input_configured =3D stadia_input_configured, }; module_hid_driver(stadia_driver); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 F0ADE43C7A8 for ; Mon, 3 Aug 2026 18:46:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782813; cv=none; b=TiVqcSQqtjL3yxFFj0zqx7bZB52taYP+xsD0PbPavtANZikYn6wj04R+uBbeC5H7PmcITgEzSa1631nshKJvsYqY+imzohb6QMTXFyTTw6GmM3kEO0aZVCday+JzSSJW3u/Sn43auNAcJjmVesF7L4Fr2P/jFJqou5D+lojsSiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782813; c=relaxed/simple; bh=43vki49h06rq45+wi6hFCpgITlqMDHeBeV30GmHzBQU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VW1mlMMLs4XXLSuYC3H3HXWYNgDrDL7bWfdADOszELaE8+H/xAmuAXN9rXveE4XUyVKik6fOosGG02wLzJ8RYMwD5viLiFMCQHkmY7QQD5bdKclEMbiOZ0jE+ptkTqJgkCXjTFCBKH9dkgAMHzdAuKsrqahfDO29vD+j2NcIG30= 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=lXKMmOUc; arc=none smtp.client-ip=209.85.215.170 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="lXKMmOUc" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-ca97d139d8dso2051497a12.2 for ; Mon, 03 Aug 2026 11:46:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782810; x=1786387610; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ydH8f/RNEjiAE8vzC0rt7/9rgp0aug18seAQOKz0/VY=; b=lXKMmOUcfzkhR4P9DHpcm73LPrdw9Ul9LGtJQoMc7rITpSjEkbPvK60QBSyAU/TKfG 4F1Bn3K4K5LDklMUuMpSjCtrgNjPmoMe9tVevcdjyGyxS5YIaUV1sD7FgCEXX6MsITvI LWYxpo2RGGjqoDGwrhgbYCfr8bW0MMlKpsfnEDUyu8VvjEdApsTQWLnN+ZkeuNfevhDc Eq4BsGIKUu8q1EhsjtFcJuWRa2nOrqaQlQhuYiyq9+26RK2SzYdI5r0vONO02VKaVxp9 U+7uYFHyw6+aqvzcEk5PbmN5xw+yIgMntbPXgkjHHFWMfUkSUvMIhUL6c08csDvHzWbz sdtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782810; x=1786387610; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ydH8f/RNEjiAE8vzC0rt7/9rgp0aug18seAQOKz0/VY=; b=TFAwBWPo2+xzkEo0mek1JM6LSgBurrpQFMZntXxnVgKIXApK3UJ5TxxiTiBplLKeac 1Ffem7HV3n7O38byDQcjW9uQsWcvYHFjYXuezs37mxFjJAcSiyakDljo5Z74HLnUxyXM KmaagTj7xFvoS2s0+CQ1dYfQoO2OPmqI+i0UjqFSMLvcGKVtWaWkcxChVrQ6VM6ncXqH hlcHd9yPaFGon+AzcLGJbywSGflQP0rqmWz8eIJI9mUzjjwZIlsuA5Gf6uKxGM/di/9h DWnNUiCHD96FzeKYpA+NjKJ/CAkseDT0YOG7WWyBv+7E7dh/1z0Rjb3FnlTyIcH1y209 4hCQ== X-Forwarded-Encrypted: i=1; AHgh+Rp8AcdY0be7uTqVsbumxs9Z80phVKv3UP0IJsnXfxFyo1n0K+f95vZvobeGaozKAoBK1omnrIY9iKTR47o=@vger.kernel.org X-Gm-Message-State: AOJu0Yzlgq7q53R5lHdef9WcytiHZriqgKOMrBt4d6wjaniVSmJMhzD3 2LKkHk2usVQX9KzONoX0b+Y9wPfqbFF5AxnecmE1EHE3oiLUS4rnHe16 X-Gm-Gg: AR+sD13WnlSLwxoOG2EEgRsp5loJ1HlE9PkIxnYJAhAaFaSwuWNDkmnbmmlNYd725Bk dxt23hEzIlz7I7Gf/fN+Scwr/qx2eEydmyPPF11h98lG+KdircySGApvkgi4HdjtQKKWLJMwI7q tWb973qdBgDeDuh2wdcttVNeted87eENRilVjGRC12ECw3M32EpDiszdm7Tr6Tf/JbrUykQMerA B1YT8JKi2buOly9uz8e15HESiEz335NaDYEqFvHCv0mw78EX6luKL4D0YN2cTn+ETXJxYiXDAd2 Sccf/XAqwlJ0VOMgCkjdWjK0fUsCtkA7xRIAoZFwZUV45fL1uZmzeiklOuy+JuvB57TMIPhxqcX uLYY5pzjX09Sogb9yF8Y3ulk+ehYsJPWklS86r0S/XP5pQcl/uUaVX6deTQNVTBYsyBbq8xOZ85 ojckFuuH0fWbxUU3JyAFDXnH4BDYpn0g+7ezXENy7QKwdojSTjx85+PO4WHhNePjU7OnLfbtbml vTm24JigQmYVfF88agtbYr+w1fNhHk4I9pbjpzkK9gnw2dgAgCy X-Received: by 2002:a05:6a21:7009:b0:3c3:76a8:c0f with SMTP id adf61e73a8af0-3c92a598292mr11186788637.4.1785782809771; Mon, 03 Aug 2026 11:46:49 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:49 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:36 -0700 Subject: [PATCH 11/21] HID: holtek: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-11-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_hw_start() with HID_CONNECT_DEFAULT. This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-holtekff.c | 46 +++++++++---------------------------------= ---- 1 file changed, 9 insertions(+), 37 deletions(-) diff --git a/drivers/hid/hid-holtekff.c b/drivers/hid/hid-holtekff.c index 32d08f7a660d..4834d42b2fa6 100644 --- a/drivers/hid/hid-holtekff.c +++ b/drivers/hid/hid-holtekff.c @@ -120,30 +120,24 @@ static int holtekff_play(struct input_dev *dev, void = *data, return 0; } =20 -static int holtekff_init(struct hid_device *hid) +static int holtek_input_configured(struct hid_device *hid, struct hid_inpu= t *hidinput) { struct holtekff_device *holtekff; struct hid_report *report; - struct hid_input *hidinput; struct list_head *report_list =3D &hid->report_enum[HID_OUTPUT_REPORT].report_list; - struct input_dev *dev; + struct input_dev *dev =3D hidinput->input; int error; =20 - if (list_empty(&hid->inputs)) { - hid_err(hid, "no inputs found\n"); - return -ENODEV; - } - hidinput =3D list_entry(hid->inputs.next, struct hid_input, list); - dev =3D hidinput->input; + if (!list_is_first(&hidinput->list, &hid->inputs)) + return 0; =20 - if (list_empty(report_list)) { + report =3D list_first_entry_or_null(report_list, struct hid_report, list); + if (!report) { hid_err(hid, "no output report found\n"); return -ENODEV; } =20 - report =3D list_entry(report_list->next, struct hid_report, list); - if (report->maxfield < 1 || report->field[0]->report_count !=3D 7) { hid_err(hid, "unexpected output report layout\n"); return -ENODEV; @@ -172,35 +166,13 @@ static int holtekff_init(struct hid_device *hid) return 0; } #else -static inline int holtekff_init(struct hid_device *hid) +static inline int holtek_input_configured(struct hid_device *hid, + struct hid_input *hidinput) { return 0; } #endif =20 -static int holtek_probe(struct hid_device *hdev, const struct hid_device_i= d *id) -{ - int ret; - - ret =3D hid_parse(hdev); - if (ret) { - hid_err(hdev, "parse failed\n"); - goto err; - } - - ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); - if (ret) { - hid_err(hdev, "hw start failed\n"); - goto err; - } - - holtekff_init(hdev); - - return 0; -err: - return ret; -} - static const struct hid_device_id holtek_devices[] =3D { { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP)= }, { } @@ -210,7 +182,7 @@ MODULE_DEVICE_TABLE(hid, holtek_devices); static struct hid_driver holtek_driver =3D { .name =3D "holtek", .id_table =3D holtek_devices, - .probe =3D holtek_probe, + .input_configured =3D holtek_input_configured, }; module_hid_driver(holtek_driver); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 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 88409435EF0 for ; Mon, 3 Aug 2026 18:46:52 +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=1785782817; cv=none; b=PVpELrAyiYBeC8tYhqWQCHa2B0HFTluP/6jjtLTCezfLKPDXQXyj5h1RHqa7FWGOLKgudMHGHW/MVfPjWD4NPYtPgrPahvO5v1CjN4jfqpuvymwLhCmWap6znmcGRTeTSVNXxOF8VYb597PztXuzXFFDcRo7cmVwnDR+L6vMp1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782817; c=relaxed/simple; bh=PisLEpAU851Mg7Pg4lhKpGxGkR/wS0p10CRwuDaFrww=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=K7N7NmrKpwAFRZ/S6dx6vmVOIAiWHvM7LDg6q11Uut0kzhA8zBqEjvYM6PTRWP22PBGl9uJUfb2Pij6aqMChkrVU3XDZffSEEsxV6fFHm4LsLVw/ZEcliuEoAxvGdkKDiuRUjoUmYJs9qBeV2NG4Fp3WKTGGXXI5ucZuMTZnErI= 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=gBuYwrgN; 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="gBuYwrgN" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-c9cf07d2df6so2820601a12.2 for ; Mon, 03 Aug 2026 11:46:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782811; x=1786387611; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=w0IDthsjYtA6pK63nJE/aU6irDSAEPiJfPVdmQsfY5g=; b=gBuYwrgN/EuB1cyNYRUCJQJ9PJ+8H+07p7KTmI/v75T0poKS9DB50/s+aih/WpTcg5 SCMRyyI1BgWKUmThW8Frwvo0RUfyHchefsSSxOW83IHbbChAsvmrLbZhgsYUaEH74dAq FBBbGLl0lSU+zzj0IsVNRge+pKm45ZsV6CxFQAbXJS+RYhyNVMNGw1ISUg1+/71zdXH3 hfaIfWMCeUNYLlR26keESeBBgVzt4ZsaNtKCKmBiIW4LegbxRvj5lpuKwCqyxxSk/noE ibMGWoct7ezjPOE6rIitB2uTA9xxqkOb50mHWJrUNhmmpDtjUViBsnunyKbPJQ3c1xpO 3kPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782811; x=1786387611; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=w0IDthsjYtA6pK63nJE/aU6irDSAEPiJfPVdmQsfY5g=; b=KyuxeZnJnsfVxVv20JpzW/h+H9PgyOZJ0hyt3RCvEhbdRFJyHmctEzjhKDMGY36dYj QvgQHPotBQMgDXIjn9k/j1/Pi/5KtopGu4STUVQbQrKO6gxJFM4hjXEu5MsBd7YxLw5o JJ6GeMoUQvz2wJmDAH2eSAYUNqmujvRgIS5Mh62kX73NK3Txuwwkp02IIGCnf1YjFsDT KZvPWezKXdXsW/WjfKh/RH6/z1cCTb5p9S9E+rDnG3uBVznI278jmfyRL6j02g2obkz1 JVNZLhA6zAWYWOardR6l6jHvL3r2oafb4G8wHwLW1t2A71Ul/FAdIRzinnf3k+nr5KNs Y3nw== X-Forwarded-Encrypted: i=1; AHgh+Rpc3wuIKhk1ECWQ6Fh/Cc18TVQVWy7epYC0OtDy3e5xPaJ9VbOolclPcRspOm1rjOF6JoP6EdEZklmxNso=@vger.kernel.org X-Gm-Message-State: AOJu0Yyl+YXL61/GLAwl4VhOpFmSV11DoqBvGG18PGGF0zmQhm/4fPGs eL4wjxzON/6Q3LI/kbnOqqJC/1IELegNeYoq82jnB+0qqRFNoho+vgKX X-Gm-Gg: AR+sD10K6WRRWZzHN9wB7kmIsi5+L87bveU6eEw9YO3wk6bUe494UZfuU7oFR/k0gk1 oMTtCFGzM0BLJZ7OcDjHHsLzgqJCV0mvL+6glPsjMyoMvBuQfzDE9QqvxgbuujWLy5DJUb0SJGd rDIdRu14+Q4yyfnZS6RRlQ1ooJp/K6SK7mLPeyPH8lZfOEBm7ENb8kBDKkqerSX1msn23knsRyZ ptxJgizeYGLlKfKGUjVra9YT8tIV+HeqjCAnUC6/ZsIjtmQjHaGR2h7hKlofCy0H+aMSNzGGNhX foDXPB931nXewwzQtb7FraijLNm/AW0ZZu5vb9h11kOs8dd9M0AL2AtgBbMz2gDrM7odGDk/ilf Yl8XS1pTwblQWcXv3LqI4mba2utlR/DlIbbBwBXAjK2+sRq7w2xZe3Njo7MLLobYvYKLjaVpGLE HtgUriHYVsnJLfIl3+wDNXGOpFFyIMDuDvmE3OY04K1T+EW2ZBXpVWKouskeuvI3iQ6t1+3ZskZ G94uTrks8EZs4+Kegdn9Vw/kc44nHwK3Lap5gJb8SktDxc0eP+K X-Received: by 2002:a05:6a21:7a46:b0:3bf:6011:53b with SMTP id adf61e73a8af0-3c92a8139c6mr11132293637.38.1785782811369; Mon, 03 Aug 2026 11:46:51 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:50 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:37 -0700 Subject: [PATCH 12/21] HID: move generic FF initialization into hidinput_connect() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-12-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f Generic force-feedback initialization (pidff) currently happens in hid_connect() after hidinput_connect() has already registered the input devices. This is racy as the device is live and visible to userspace before FF support is fully set up. Move the call to hdev->ff_init() into hidinput_connect(), ensuring it runs before input_register_device() is called. This closes the race window for standard PID-capable devices. The initialization now also checks (connect_mask & HID_CONNECT_FF) and !hid_has_ff_input() to avoid conflicts with custom FF implementations and respect driver opt-outs. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-core.c | 21 ++------------------- drivers/hid/hid-input.c | 21 +++++++++++++++++++-- include/linux/hid.h | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 2767a171eae9..d8cba852d2b5 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -2287,18 +2287,6 @@ static const BIN_ATTR_RO(report_descriptor, HID_MAX_= DESCRIPTOR_SIZE); =20 static const DEVICE_ATTR_RO(country); =20 -static bool hid_has_ff_input(struct hid_device *hdev) -{ - struct hid_input *hidinput; - - list_for_each_entry(hidinput, &hdev->inputs, list) { - if (test_bit(EV_FF, hidinput->input->evbit)) - return true; - } - - return false; -} - int hid_connect(struct hid_device *hdev, unsigned int connect_mask) { static const char *types[] =3D { "Device", "Pointer", "Mouse", "Device", @@ -2324,8 +2312,8 @@ int hid_connect(struct hid_device *hdev, unsigned int= connect_mask) if (hid_hiddev(hdev)) connect_mask |=3D HID_CONNECT_HIDDEV_FORCE; =20 - if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev, - connect_mask & HID_CONNECT_HIDINPUT_FORCE)) + if ((connect_mask & HID_CONNECT_HIDINPUT) && + !hidinput_connect(hdev, connect_mask)) hdev->claimed |=3D HID_CLAIMED_INPUT; =20 if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect && @@ -2347,11 +2335,6 @@ int hid_connect(struct hid_device *hdev, unsigned in= t connect_mask) =20 hid_process_ordering(hdev); =20 - if ((hdev->claimed & HID_CLAIMED_INPUT) && - (connect_mask & HID_CONNECT_FF) && hdev->ff_init && - !hid_has_ff_input(hdev)) - hdev->ff_init(hdev); - len =3D 0; if (hdev->claimed & HID_CLAIMED_INPUT) len +=3D sprintf(buf + len, "input"); diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 3487600cadb4..70ec1b7e7d38 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -2317,7 +2317,19 @@ static inline void hidinput_configure_usages(struct = hid_input *hidinput, * Read all reports and initialize the absolute field values. */ =20 -int hidinput_connect(struct hid_device *hid, unsigned int force) +static bool hid_has_ff_input(struct hid_device *hdev) +{ + struct hid_input *hidinput; + + list_for_each_entry(hidinput, &hdev->inputs, list) { + if (test_bit(EV_FF, hidinput->input->evbit)) + return true; + } + + return false; +} + +int hidinput_connect(struct hid_device *hid, unsigned int connect_mask) { struct hid_driver *drv =3D hid->driver; struct hid_report *report; @@ -2330,7 +2342,7 @@ int hidinput_connect(struct hid_device *hid, unsigned= int force) =20 hid->status &=3D ~HID_STAT_DUP_DETECTED; =20 - if (!force) { + if (!(connect_mask & HID_CONNECT_HIDINPUT_FORCE)) { for (i =3D 0; i < hid->maxcollection; i++) { struct hid_collection *col =3D &hid->collection[i]; if (col->type =3D=3D HID_COLLECTION_APPLICATION || @@ -2396,6 +2408,11 @@ int hidinput_connect(struct hid_device *hid, unsigne= d int force) continue; } =20 + if (list_is_first(&hidinput->list, &hid->inputs) && + (connect_mask & HID_CONNECT_FF) && hid->ff_init && + !hid_has_ff_input(hid)) + hid->ff_init(hid); + if (input_register_device(hidinput->input)) goto out_unwind; hidinput->registered =3D true; diff --git a/include/linux/hid.h b/include/linux/hid.h index b240baa95ab5..451c3e05d167 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -1021,7 +1021,7 @@ extern void hid_unregister_driver(struct hid_driver *= ); =20 extern void hidinput_hid_event(struct hid_device *, struct hid_field *, st= ruct hid_usage *, __s32); extern void hidinput_report_event(struct hid_device *hid, struct hid_repor= t *report); -extern int hidinput_connect(struct hid_device *hid, unsigned int force); +extern int hidinput_connect(struct hid_device *hid, unsigned int connect_m= ask); extern void hidinput_disconnect(struct hid_device *); void hidinput_reset_resume(struct hid_device *hid); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.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 265424322E7 for ; Mon, 3 Aug 2026 18:46:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782818; cv=none; b=bx1Eak/qKoLyYPypzfrEBIRO/zZpaizD/mf44BMcAPAA2M4rTcYrxmB0svB3M5bnoYHe9ziDyMVJ9wVT7v3oUJtnRcajXh1HLLsKcHdgtlo7g4JbZsdjy/DWYTkWnwaGGeF3elCF8T5grPC5TBMLMEVAHNIwd6mbSp/vi+2R3n0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782818; c=relaxed/simple; bh=65jOuI6e62BcdMsXySY+z4DsuyFq45DZBtqvCjGRPWI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZoMYBtocwQIcRK9uOTP+5mJuokNXith9OxQVVrVjAjtIvpF/aF8T3VaZPM09pvbjDC4KUG95hA4bR1TWKIK0x7WzCT8tDj7WcrmYVAh1GdpvRYL3eKVs6rUOsdqcJQ8zwVZHobG6s2cFbn2WFfMhYrs6Hqo1HUdb8mvnbPAwYRA= 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=IIJlvWKi; arc=none smtp.client-ip=209.85.214.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="IIJlvWKi" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2cee9b74ee1so29454655ad.3 for ; Mon, 03 Aug 2026 11:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782813; x=1786387613; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=NXKKFDhD/yFBZfYuq7/G58wNu/C7P3oEAv/AO5ZEFrk=; b=IIJlvWKiCj4bOwpeionY4joiDi8A20b6omQAhV61Byj3xw/h8kDbj9JBdzm+TeJIGd q7YoNOTXQ+nl9w9xv1dgBtMF87KXv00g8rCaN+MeO9hwidDD+Dx1wPXUVq+/GB/Wpkx/ GcHkynaqovDbzdiufju3FbGmv0CircAyjICIIJIZ8Su1qdIkMU/B1oQ50qk6+sftI7UW 3Ynejh+uLwtFleLfR2SSd0156m4Ej8xhC/VUFDgq9cuR/RJCyRQzSg0SJzqlEPlI/AGM f0eVv7eGSGZ34Fp67B9IOhCAIzEUrYRERmBeDl+VFi2zdOLofeOmmMsabdXzZyiF6Fh+ Lrkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782813; x=1786387613; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=NXKKFDhD/yFBZfYuq7/G58wNu/C7P3oEAv/AO5ZEFrk=; b=pA7GQPyt4KGf3f4dyYfbOOqkQbo6ijcO+MBijWD78TqMsUuzDEZR2/6mYisbRVmJ0D 8InF3EusaXAtBwF2vOLy7ODUUbNcKlpE3Igum7pVkMok6sIyZFOGk6IysGeU5oDIHEZd IHqLQ1zjeSkxcpCJ/bgfSUSmI4ik6bBjtCkBrhLulvrgooWh3n1OLpiYvbfuSIuezcGm 8/m2sDPvG/rbIvi3V1khDDTwQivbpVkAJ22yeDd88A7shSI+eVHxWFztlks4lCmKeRbC sr2u+Af7YH1nE9DtgH2KWAu3YdP9sQ6R6XkEg603RjdzHoPG5MEfXDcQ0Ym8YYFzOvoP kwQg== X-Forwarded-Encrypted: i=1; AHgh+RrOYnqJb/Rj55WvfRPoO3L3wDXfbHG/4MzG+1iY9IoHynctmGixojPs/Gn9bnhTHDIlnKEihDGNQJA2gOs=@vger.kernel.org X-Gm-Message-State: AOJu0YwWkkxN7DGC0Kbb59A2idApL7w6sZV3P+2r/JkGM6zaK3DvozPK lK671gESyDuLff2nmQrWfSrL0MS8WUml3SmtWF1cAe+x2D28VE/w9tve X-Gm-Gg: AR+sD12Hlc+onCyyQDhFom0reEFXVT24UwYjiMg1xDhbPV3Mo+BM5SJyjnD2XY31jZI tqBP4E/o1/8UMGihpKD88fIRNmLJLWlNhiDpzgA30WtnFToR7eFCJGbFH5TvA/yqU3MM5b1ebIZ iUCUkiyKJDva7q1Y7eLi31v8AdEbjrAY9XzG9EHt9RQGpmqBAeXcfQQ1XiD/JmFQbqypey+s8cV 00jRLToYmPHZVA2dnnVwEgM8cfof+87cpcBwV2QU+m8cl/0GC+6gN5YTZTdL7mH9POyJkRDF8JV XIMeFz6zSvlCqqy53fyOD6Klmfk34nivUze/euOcTIwZaCR9PXyGwhnLWtvLV9bqqufQHSarICY DvIgLqdsTSNt99pfu4SPCKcefCiU+KXEmMDpoufOEJ5GcDyIXk2DWVP1RvUJiD1GcoNigr9TUep QTFvfiwjFUtsv0PHcsRDRZRy15ALu647bGCxjvbU8Mejaijv167Rl172n60m9VNDJKpCHTbpOhm wjgb3XwQcdUUJ9nVKHrEvHWmx0P9moLtDBeE0oL4rNi3JWRDHlg X-Received: by 2002:a17:90b:53c3:b0:36a:5d1f:7b6 with SMTP id 98e67ed59e1d1-38fbc40e148mr10108506a91.2.1785782812925; Mon, 03 Aug 2026 11:46:52 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:52 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:38 -0700 Subject: [PATCH 13/21] HID: microsoft: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-13-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_hw_start(). This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-microsoft.c | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c index 18ac21c0bcb2..a7d3493a6141 100644 --- a/drivers/hid/hid-microsoft.c +++ b/drivers/hid/hid-microsoft.c @@ -323,22 +323,17 @@ static int ms_play_effect(struct input_dev *dev, void= *data, return 0; } =20 -static int ms_init_ff(struct hid_device *hdev) +static int ms_input_configured(struct hid_device *hdev, struct hid_input *= hidinput) { - struct hid_input *hidinput; - struct input_dev *input_dev; struct ms_data *ms =3D hid_get_drvdata(hdev); - - if (list_empty(&hdev->inputs)) { - hid_err(hdev, "no inputs found\n"); - return -ENODEV; - } - hidinput =3D list_entry(hdev->inputs.next, struct hid_input, list); - input_dev =3D hidinput->input; + struct input_dev *input_dev =3D hidinput->input; =20 if (!(ms->quirks & MS_QUIRK_FF)) return 0; =20 + if (!list_is_first(&hidinput->list, &hdev->inputs)) + return 0; + ms->hdev =3D hdev; INIT_WORK(&ms->ff_worker, ms_ff_worker); =20 @@ -352,16 +347,6 @@ static int ms_init_ff(struct hid_device *hdev) return input_ff_create_memless(input_dev, NULL, ms_play_effect); } =20 -static void ms_remove_ff(struct hid_device *hdev) -{ - struct ms_data *ms =3D hid_get_drvdata(hdev); - - if (!(ms->quirks & MS_QUIRK_FF)) - return; - - cancel_work_sync(&ms->ff_worker); -} - static int ms_probe(struct hid_device *hdev, const struct hid_device_id *i= d) { unsigned long quirks =3D id->driver_data; @@ -385,29 +370,21 @@ static int ms_probe(struct hid_device *hdev, const st= ruct hid_device_id *id) ret =3D hid_parse(hdev); if (ret) { hid_err(hdev, "parse failed\n"); - goto err_free; + return ret; } =20 ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT | ((quirks & MS_HIDINPUT) ? HID_CONNECT_HIDINPUT_FORCE : 0)); if (ret) { hid_err(hdev, "hw start failed\n"); - goto err_free; + return ret; } =20 - ret =3D ms_init_ff(hdev); - if (ret) - hid_err(hdev, "could not initialize ff, continuing anyway"); - return 0; -err_free: - return ret; } - static void ms_remove(struct hid_device *hdev) { hid_hw_stop(hdev); - ms_remove_ff(hdev); } =20 static const struct hid_device_id ms_devices[] =3D { @@ -469,6 +446,7 @@ static struct hid_driver ms_driver =3D { .report_fixup =3D ms_report_fixup, .input_mapping =3D ms_input_mapping, .input_mapped =3D ms_input_mapped, + .input_configured =3D ms_input_configured, .event =3D ms_event, .probe =3D ms_probe, .remove =3D ms_remove, --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 AA10043F4AD for ; Mon, 3 Aug 2026 18:46:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782819; cv=none; b=B4QUUQyzVqMrM+vOxZxsWk5oPlIOR/nrsvIDBoS3IeB3jF8b9WDZkUB0gyr5EmYM3iCKWldNcMz2GVaXJfODZDdC1hPTqT3ppeImFWH/Jaz26QCxKNeppaRSUL+nZToZ95QFMdNmK7mK4olCEfPB6b++wBnVOcaH8uVb1TADQpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782819; c=relaxed/simple; bh=Hj2pUN9eZtk3cHH/+XZnpDlO6cmq6IWDj87s14TH9kc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bcqMZuhczHRWMWPgdRrLWICvEGbrefEllLlTFJ77+13dJQKU5RmRQ00GHxvijwMV8I/0IbD311DF8fOCo4onNrD5gDVFCzYsLYoi4lDHKYL6NIrqIhLHKFX4hIZsPPcGR65jKiMnHa6AJ2g9EXEk1fBgvyJbSGRE4W9w3iyb9Jc= 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=h/NiIsoB; arc=none smtp.client-ip=209.85.216.53 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="h/NiIsoB" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-38e88b60121so2847910a91.3 for ; Mon, 03 Aug 2026 11:46:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782814; x=1786387614; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=4g0QiXRRj0YBm7OorcxDBjlq8/39kTdHz/r69LBWkhc=; b=h/NiIsoBL2lfeln2obAv4ESo8lg7BKnjVTsdBVo/x0S4hN8hRiFZxGfhQ+pdgrx5To JCIGpBjPWx8hLnHp22D4tAre0HYY3cgTGUOMVVc3rnf1kd2WXKgc3cw8CHwgwmA2E4Og Gfq5CfBrm3zgwkUmMxYnv6HgOOmLzGy4UaBuSHiBSPLbcMe+p8bMx0lMoBqPbwX7CRJ0 rVzSkAcBhycBrZNPjNk1h6LMWm6sPXS5VDTUg1GCVAUC8Gs0w/ApbQe4UEvtK1MuhMmo uVZ84r7mc2vjKzfM5Hm3VLGTIxyldDK7NHLbAYy/mqrSDCJyE4wMndBDQvid46DWIM4N mwpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782814; x=1786387614; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=4g0QiXRRj0YBm7OorcxDBjlq8/39kTdHz/r69LBWkhc=; b=riTN+jQ0rH99XRjs9dsTnACVUVMQnQbTP9YKT7PvwQFyFdrj1TOUej2LcINYVVTZ0k 36MPvBSibpmuutvFrVH+7TA18YWa31cs913cggywTvXZhmXJaD0ZjmmQG4mIA/XQW6r6 3cesirac7jPP4fDKcBvuNPfR5IFtLQrBI647gKcvISa1v69tZ6TR7nxr4uerBAvhUbtE PTVYWFdDyaVfpv1tynrf9udiOzFeo25Ez4JKYbtdP7xMZBHYT+NftqP8HLdexEjBpdMJ TLPeNIDQk0FcjzZENcv1Gh2hmDbyveI19jrfuLIyDZb+ObOa87Fzab/O8n0yZWly24IZ M0rA== X-Forwarded-Encrypted: i=1; AHgh+RqMheW1Wgk3cX8gfDiZYgflMYj7nCUmMULHs8JAJRpO3N30LGf7Z1S8xtJaUOtZsbrBWYv6Bgrsef5lync=@vger.kernel.org X-Gm-Message-State: AOJu0YwYgjalfMIMCn494NR8pR56NpXy3yXTcsgERqFW0qJOigPfJAWp LWaJEfwzBZQ91gYZ9DNYfiLePoVhodZQp49C0ffTUilf3NgcHPcOUme6 X-Gm-Gg: AR+sD13gE3h7eOjC/EsSulo5HWxkbQI+Uoxuq7w2Y6YscetWL0VgQqMQPH/KXSLQdEo YXpU3aUvCR+Js2ANzLgNRgR+CDAu6oFzPYXyBS7mSSliAGJxtxUzde5qv6SZiukFZByw/IPdhVE fQ+iwSeGiRBBl1TEyoCp5GLr5DsGHJ/Dprr9Rv4tci5wT6mVEc5vVhkfsGww0oZssYTFvtlkTy5 i2mZX3FHfECJ5HpwiOBUcGW3F43J5y1hYsCK0GXZiwb0A8XTK9bZ6ZsIUnW6DLsAQa3sOVDGueO eWlOFu0OwLqJN/gIdfHAJLkyTlI1PJ7qqWJrmfp8rBKRJcWjWjL0DwFROKdcz9i+nLA/cRliOz5 vPLCetVQodM1hn00yJcR0YnE+G0aK5HrkrgSMJYaikPp2WXaGOkk3RY/nqdnwr0B8We2m5V65h5 PE2zmVVgQLFq9r5vA2aWBhsXy/tPRJOToPivnwCjxy8CMw3oYwltNB/YUCaDIpihvGYJhte9XpT EAOq35N5k2jjCda/9eBJ2CYb5IaQuoEt8cRqdvKmIHjiriOmIvT X-Received: by 2002:a17:90b:3b46:b0:38f:57f3:4dc6 with SMTP id 98e67ed59e1d1-38fbc4fe7aamr9686977a91.21.1785782814271; Mon, 03 Aug 2026 11:46:54 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:53 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:39 -0700 Subject: [PATCH 14/21] HID: pantherlord: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-14-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_hw_start(). This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-pl.c | 150 ++++++++++++++++++++++-------------------------= ---- 1 file changed, 65 insertions(+), 85 deletions(-) diff --git a/drivers/hid/hid-pl.c b/drivers/hid/hid-pl.c index 8bba29ef6c7a..cae56a6c941b 100644 --- a/drivers/hid/hid-pl.c +++ b/drivers/hid/hid-pl.c @@ -62,15 +62,13 @@ static int hid_plff_play(struct input_dev *dev, void *d= ata, return 0; } =20 -static int plff_init(struct hid_device *hid) +static int pl_input_configured(struct hid_device *hid, struct hid_input *h= idinput) { struct plff_device *plff; struct hid_report *report; - struct hid_input *hidinput; struct list_head *report_list =3D &hid->report_enum[HID_OUTPUT_REPORT].report_list; - struct list_head *report_ptr =3D report_list; - struct input_dev *dev; + struct input_dev *dev =3D hidinput->input; int error; s32 maxval; s32 *strong; @@ -83,89 +81,80 @@ static int plff_init(struct hid_device *hid) The input reports also contain a field which contains 8 ff00.0001 usages and 8 boolean values. Their meaning is currently unknown. - =20 + A version of the 0e8f:0003 exists that has all the values in separate fields and misses the extra input field, thus resembling Zeroplus (hid-zpff) devices. */ =20 - if (list_empty(report_list)) { + if (!list_is_first(&hidinput->list, &hid->inputs)) + return 0; + + report =3D list_first_entry_or_null(report_list, struct hid_report, list); + if (!report) { hid_err(hid, "no output reports found\n"); return -ENODEV; } + if (report->maxfield < 1) { + hid_err(hid, "no fields in the report\n"); + return -ENODEV; + } =20 - list_for_each_entry(hidinput, &hid->inputs, list) { - - report_ptr =3D report_ptr->next; - - if (report_ptr =3D=3D report_list) { - hid_err(hid, "required output report is missing\n"); - return -ENODEV; - } - - report =3D list_entry(report_ptr, struct hid_report, list); - if (report->maxfield < 1) { - hid_err(hid, "no fields in the report\n"); - return -ENODEV; - } - - maxval =3D 0x7f; - if (report->field[0]->report_count >=3D 4) { - report->field[0]->value[0] =3D 0x00; - report->field[0]->value[1] =3D 0x00; - strong =3D &report->field[0]->value[2]; - weak =3D &report->field[0]->value[3]; - hid_dbg(hid, "detected single-field device"); - } else if (report->field[0]->maxusage =3D=3D 1 && - report->field[0]->usage[0].hid =3D=3D - (HID_UP_LED | 0x43) && - report->maxfield >=3D 4 && - report->field[0]->report_count >=3D 1 && - report->field[1]->report_count >=3D 1 && - report->field[2]->report_count >=3D 1 && - report->field[3]->report_count >=3D 1) { - report->field[0]->value[0] =3D 0x00; - report->field[1]->value[0] =3D 0x00; - strong =3D &report->field[2]->value[0]; - weak =3D &report->field[3]->value[0]; - if (hid->vendor =3D=3D USB_VENDOR_ID_JESS2) - maxval =3D 0xff; - hid_dbg(hid, "detected 4-field device"); - } else { - hid_err(hid, "not enough fields or values\n"); - return -ENODEV; - } - - plff =3D kzalloc_obj(struct plff_device); - if (!plff) - return -ENOMEM; - - dev =3D hidinput->input; - - set_bit(FF_RUMBLE, dev->ffbit); - - error =3D input_ff_create_memless(dev, plff, hid_plff_play); - if (error) { - kfree(plff); - return error; - } - - plff->report =3D report; - plff->strong =3D strong; - plff->weak =3D weak; - plff->maxval =3D maxval; - - *strong =3D 0x00; - *weak =3D 0x00; - hid_hw_request(hid, plff->report, HID_REQ_SET_REPORT); + maxval =3D 0x7f; + if (report->field[0]->report_count >=3D 4) { + report->field[0]->value[0] =3D 0x00; + report->field[0]->value[1] =3D 0x00; + strong =3D &report->field[0]->value[2]; + weak =3D &report->field[0]->value[3]; + hid_dbg(hid, "detected single-field device"); + } else if (report->field[0]->maxusage =3D=3D 1 && + report->field[0]->usage[0].hid =3D=3D + (HID_UP_LED | 0x43) && + report->maxfield >=3D 4 && + report->field[0]->report_count >=3D 1 && + report->field[1]->report_count >=3D 1 && + report->field[2]->report_count >=3D 1 && + report->field[3]->report_count >=3D 1) { + report->field[0]->value[0] =3D 0x00; + report->field[1]->value[0] =3D 0x00; + strong =3D &report->field[2]->value[0]; + weak =3D &report->field[3]->value[0]; + if (hid->vendor =3D=3D USB_VENDOR_ID_JESS2) + maxval =3D 0xff; + hid_dbg(hid, "detected 4-field device"); + } else { + hid_err(hid, "not enough fields or values\n"); + return -ENODEV; } =20 - hid_info(hid, "Force feedback for PantherLord/GreenAsia devices by Anssi = Hannula \n"); + plff =3D kzalloc_obj(struct plff_device); + if (!plff) + return -ENOMEM; + + dev =3D hidinput->input; + + set_bit(FF_RUMBLE, dev->ffbit); + + error =3D input_ff_create_memless(dev, plff, hid_plff_play); + if (error) { + kfree(plff); + return error; + } + + plff->report =3D report; + plff->strong =3D strong; + plff->weak =3D weak; + plff->maxval =3D maxval; + + *strong =3D 0x00; + *weak =3D 0x00; + hid_hw_request(hid, plff->report, HID_REQ_SET_REPORT); =20 return 0; } #else -static inline int plff_init(struct hid_device *hid) +static inline int pl_input_configured(struct hid_device *hid, + struct hid_input *hidinput) { return 0; } @@ -181,27 +170,17 @@ static int pl_probe(struct hid_device *hdev, const st= ruct hid_device_id *id) ret =3D hid_parse(hdev); if (ret) { hid_err(hdev, "parse failed\n"); - goto err; + return ret; } =20 - ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); + ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT); if (ret) { hid_err(hdev, "hw start failed\n"); - goto err; + return ret; } =20 - ret =3D plff_init(hdev); - if (ret) - goto stop; - return 0; - -stop: - hid_hw_stop(hdev); -err: - return ret; } - static const struct hid_device_id pl_devices[] =3D { { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_AD= APTOR), .driver_data =3D 1 }, /* Twin USB Joystick */ @@ -217,6 +196,7 @@ static struct hid_driver pl_driver =3D { .name =3D "pantherlord", .id_table =3D pl_devices, .probe =3D pl_probe, + .input_configured =3D pl_input_configured, }; module_hid_driver(pl_driver); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 26BBA436BFE for ; Mon, 3 Aug 2026 18:46:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782820; cv=none; b=LgfqYD4dN/7HrhUr5BdFi3te3/tPnAGKQYoYGJU6E3RatdchXJjbZLPolWOhziRtzs+p8GHOjFY/C1BjnD6a6tACRqf4EIA0HFiDyj+YqNWLvtO2PTxx/zg9h4lCv+jCeR1o8IVa02x3umUsEa+KZhhCDGm3QUhYjOFGfqd5jZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782820; c=relaxed/simple; bh=bkkjuJ7kHovlBy2GQl50Xio+Ck7Q4NkLDSybgRgkKTQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XKs5H+frkWkYpZXBses4QsAS+hTslCv5+ydHyRS0XmqqUILHhyyHCRdzGFtj5E+HaqWQcjWQOwD8hT5cOdkbqEaeX45anktoiVpZQ8bYmz6z6p3QzGZSTn+VLa49A+36G4iFHoufblde6OilUrVZKrqC1XO6iLi7vWcx6jNpPhE= 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=SDn9GZH8; arc=none smtp.client-ip=209.85.214.178 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="SDn9GZH8" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2cace91f112so41622395ad.0 for ; Mon, 03 Aug 2026 11:46:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782815; x=1786387615; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=mMeooT+Pd2wEyftNL9TbUExuIFr34iBpC5GZzR8qYww=; b=SDn9GZH8AF7tWgGkUBLPSHgFgyD7EBkNNjHYiDdgT6pDLHMfHEbneYcHCPz6k4dlQi fOrgQtcb9AQwMmYHPIv5auX+7pJCg6wniuJxXEf1ho1DBnCq2cKqyIW8DAlcSA+sODt5 8/Lkp0GlG8+w/ggt6QhYML/LDmkT9eKDXZUx+i4lSPmnSy8pc/zzh2H0h618pOxGutda xD6eBWZxF2gbISWE13ANQiWY42Mas8WOiGbBqKVxRsbA3YnSZOM/1r77L3+K36Ho9inr lE3LcfWhcRh2EKc2gwPCK/uwYVO6B6Do4lTgHhzSnbWYfq6ksradlqlMkyCIf2di5Jof P7iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782815; x=1786387615; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=mMeooT+Pd2wEyftNL9TbUExuIFr34iBpC5GZzR8qYww=; b=YJoNXZRnqt7HSAQxLcHvPBhe7tMZk3KxN/5AA8tMChRLi1bnqaP+p00RpWEKAViaeF mmDcqUh5s1ecKX11nwvU/ykhKqvqZWquVHo1Hs+W6ZlFSH1qaU50UMtZnzI7tiE853fY lS6egZDpp6aoBKZP94XLZ7dgb2q2JrYF4hPjR+BYxyX0LI83n05LRZUWct2kCppWGqCt IV2skwrCiRj585Xe8u2CxBJvG0PkqZgxAyrqwPWbd63lvdh+o9YS6zSguVOcF76XoLof dtt0TbWdPscpcMvhimnS7gD1PtRLjVCc6hvicFvIB0AGE/fHtbsCbCy5pTwbHJnhoy2m mNQA== X-Forwarded-Encrypted: i=1; AHgh+RpFSxcpSLxRWrCZC4B+wjTB2quWGxKo31IgHIhxdeqXkQWNNPPvUKutiyJL+RlDaACh5psKBsQL2vp4du0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9sTV1jrdPNIAqQNzck8BJC2PNGOQDvridVPhMGX3cXvXxLtmP BNdql2sP+6YlfVteYM1Xk6gxah3XONVhLOhCmNDH0OxacpUC5oEw51tr X-Gm-Gg: AR+sD10GzBWMbBVmFeM44MkVedlIFa4jzUufmvDxonaFs1DzuG/3qIUTvBKQ4aJfT85 otG7VWEcBsdhyhBCPKDQdQxlppHSAxdtpDYbkocA5GlLtgavKc+BcFmZZ4Be9Asjd9UcsO08BS0 8WmWyBu9rrD7yHU9f5s6iFpz7ZCQ6l1IIElZUPofUjgh7EJCFTUuxKRP9Hf6KxNbvC+JDcb/1Rn TPjYlcCMsSDKXJbZuvamgYZ3Zrly2hDXCHznQviYpEp8kA5xagHzX8VJypEQtPqN4DxYql5K/hF qLT2MZ59Be8hA61b01jW+HOHPeQnhyV8FxV5+G9et5a/67o8M7aAZePW4k/o3NTy86cp2XTkLKW S1p1hrlZAw93Wr1EULjuUNuc+fut+SxznQpcO8RID4So0W1YL6gnczVcp1ZifpkKe4ok5GcwBpB a6/fDwZwZNmANg6Vl20mOQtKYqrBQlykqW8UB+bXtzOYfkkZq0VgiXioEhGvVm2zZaewsYm6bUb 8XWcm60IL06QHq4MlDv73VHLtIUIyu55vw+BO8uSANVdNKIQSjJXFYKpCnCs346 X-Received: by 2002:a05:6a20:a114:b0:3c0:9c19:65a3 with SMTP id adf61e73a8af0-3c92a98cd35mr11005065637.75.1785782815610; Mon, 03 Aug 2026 11:46:55 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:55 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:40 -0700 Subject: [PATCH 15/21] HID: thrustmaster: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-15-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_hw_start(). This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-tmff.c | 47 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/drivers/hid/hid-tmff.c b/drivers/hid/hid-tmff.c index 423f395d01ac..0ed152e0dba9 100644 --- a/drivers/hid/hid-tmff.c +++ b/drivers/hid/hid-tmff.c @@ -115,22 +115,25 @@ static int tmff_play(struct input_dev *dev, void *dat= a, return 0; } =20 -static int tmff_init(struct hid_device *hid, const signed short *ff_bits) +static int tm_input_configured(struct hid_device *hid, struct hid_input *h= idinput) { struct tmff_device *tmff; struct hid_report *report; struct list_head *report_list; - struct hid_input *hidinput; - struct input_dev *input_dev; + struct input_dev *input_dev =3D hidinput->input; + const struct hid_device_id *id; + const signed short *ff_bits; int error; int i; =20 - if (list_empty(&hid->inputs)) { - hid_err(hid, "no inputs found\n"); + if (!list_is_first(&hidinput->list, &hid->inputs)) + return 0; + + id =3D hid_match_device(hid, hid->driver); + if (!id) return -ENODEV; - } - hidinput =3D list_entry(hid->inputs.next, struct hid_input, list); - input_dev =3D hidinput->input; + + ff_bits =3D (void *)id->driver_data; =20 tmff =3D kzalloc_obj(struct tmff_device); if (!tmff) @@ -204,35 +207,13 @@ static int tmff_init(struct hid_device *hid, const si= gned short *ff_bits) return error; } #else -static inline int tmff_init(struct hid_device *hid, const signed short *ff= _bits) +static inline int tm_input_configured(struct hid_device *hid, + struct hid_input *hidinput) { return 0; } #endif =20 -static int tm_probe(struct hid_device *hdev, const struct hid_device_id *i= d) -{ - int ret; - - ret =3D hid_parse(hdev); - if (ret) { - hid_err(hdev, "parse failed\n"); - goto err; - } - - ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); - if (ret) { - hid_err(hdev, "hw start failed\n"); - goto err; - } - - tmff_init(hdev, (void *)id->driver_data); - - return 0; -err: - return ret; -} - static const struct hid_device_id tm_devices[] =3D { { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300), .driver_data =3D (unsigned long)ff_rumble }, @@ -261,7 +242,7 @@ MODULE_DEVICE_TABLE(hid, tm_devices); static struct hid_driver tm_driver =3D { .name =3D "thrustmaster", .id_table =3D tm_devices, - .probe =3D tm_probe, + .input_configured =3D tm_input_configured, }; module_hid_driver(tm_driver); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (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 5DD28441041 for ; Mon, 3 Aug 2026 18:46:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782823; cv=none; b=HsecLVbkczeTjFCN0glR4j12UAQ3IZf4mU99fwIC9DpoqoIOI3l/jaIe8Rj/0QWjjKyNHgehFpDAUjlzYPqyRyGuB7RMdKBlejp0fCi/4VtU/RFgT5El4p9yz5OqXkqGkGstFN0fykXsQa5Be0oeRz23gSXNL8YtIwQk+V0uw7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782823; c=relaxed/simple; bh=9RXXUuoTfoL6J5em10rnlXUTmB4DkBiDhCtVINGOk9A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SAYZZQm+FqWQWOsM6wyc4NpKq8lhyFtzXE4VvReZI0fnWVKiL4842s3+aOe3Ndc1blW7PA+rXeqgwqBhU32uYOXZ+TQpx1KArofX+1uE2HDy+A+7QvjPhtUXHsJZWLI+ZSWA6L+P66haNjGtgB3RhKRGwwMK2qw4CQWrGCWkpMQ= 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=UlZXoGnt; arc=none smtp.client-ip=209.85.216.45 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="UlZXoGnt" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-38d489b6b71so3309461a91.0 for ; Mon, 03 Aug 2026 11:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782817; x=1786387617; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=R6FvS+GVirUFZzmRqDLJtbKL/PG96hr59JxKd1SuplY=; b=UlZXoGntD325wdxjz3gEDrGJcIf3G8EwUmjB/pabb5S8aYHPeOEEuJdS+PToczmwzs moPeHa0a76vYNPQ+hXJibjRr1roQEw4DmMdTxRq6/KmXGK6C5e8lL26Uf1lnl5NUi8Qp 34/0Vb/Z34R+lQ860stkxRJvhC5YP6vTFzS4JXHpcrrUsXpl71oxzOtmD2oX73ctK8+U hSAnrmQl9UEarJyXNdvMKJtnRHemx0OKTZr5WG0GmrDXqixDsNfvfpA1NtDWP6eOhOji 98SZSJbBcd5RZ0B4/ZEyJM1gZk5SoLkhpNiNZznmHNUF2EQi5JTkFo8qss9Gz7GiSVmV Yv+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782817; x=1786387617; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=R6FvS+GVirUFZzmRqDLJtbKL/PG96hr59JxKd1SuplY=; b=knSLRHtYQCRVVNJmXTNL1VsKAzO+CLivSrE3oYZiRcDk7VvUdXV0nHSq6tmL4ZTtZo bM8rmRyIt0d3puRumD4rEtn0RAjogLP7ogSZ08AMStwzVm6LlPCc57fUKsw7HEPvRbOX ni+roUa6v8M3gAEO3vlrOjppGjAFlBTjZPA0aSWpOwxdrBQH8Nlu+oYP0CF2Q3BRwcuL xBffX7PtIAZCouDE+e0yEj5wE/R5L/XEdmryywQULO+qIqIbOad3i9292GhdjudVp3Yf wBDYZF4b6vbTXk1R3lPUeBauCapvvDJD6yggEzJICk+8PSf7sMRPTCz25I/e1C3t/urN EOBQ== X-Forwarded-Encrypted: i=1; AHgh+RrU0PqgWttzlEjjs8fijoUTAgz8dUUOgzV3Hj0+CqIRrvyPfyCUq5pA93vhE0Il6+5o0LvMulROfIfSzEY=@vger.kernel.org X-Gm-Message-State: AOJu0Yzu4JL3dsN1oFtekmw4EC27spejg7r3lHxEJa+b4bkRKNCoqoQw 9MJClfMA23oplu1OfsRW1bW+Z3UvlKeD6hu/Vi+Ek178NMaM1CroRTTs X-Gm-Gg: AR+sD11jRXXIWCy33OPhfmFyffJuzAusrVCuB3DMnURejACk4FfIlTYpkmhZGFDrnVi AgB/r70+7SWF2eCFliJYe1JXmy4PsmFCLkq35RkKE1AKZmxjkfKG2sneHM9V9XSx3/DhpMJqs/v kEWEC3llQaMX820Qtji/rKUhcHwZTkeAWCLbDFjL1EdUYCgT8t3ucxQT/gMl9BsuAJJ8SXy8jti CR4vMsSL06f8yG58w49T2NzxC2UyOdH62GMqtJte02d+FPES6BV9hKVOufHu26xjkDTkshNSOAz 8Owk9mpWiuPZHFm8Xdpg6zsZY7d2gFL8PJ99bL8wrxwU5Mz2S6+69XerbStkxzhtp4wqd7XcYhz S9izKkwYFnyYsgXRfNY/m0tJvWPapzPcxO85NMjAWh9nRuX1Kp0+y1ze6kQ4uVZCJFs/bMi6iE2 vG/Fi43ZTtp2g996c5iRj6KH9yBby1GJVuMpDxJdrz/cSW1WJsCkthSrxkL2x0WavHWKkyqCR3B 6YKpKTgU7r+mjPMDYNulqIqudbKGlEsQhEnrphMnp71FdHJK++02g253Q70VoE= X-Received: by 2002:a17:90b:57ec:b0:380:83fc:4315 with SMTP id 98e67ed59e1d1-38fbc4ae59bmr11034812a91.21.1785782817176; Mon, 03 Aug 2026 11:46:57 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:56 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:41 -0700 Subject: [PATCH 16/21] HID: zeroplus: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-16-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_hw_start(). This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-zpff.c | 43 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/drivers/hid/hid-zpff.c b/drivers/hid/hid-zpff.c index d8e023c8aa84..b565c59d3dfe 100644 --- a/drivers/hid/hid-zpff.c +++ b/drivers/hid/hid-zpff.c @@ -50,20 +50,15 @@ static int zpff_play(struct input_dev *dev, void *data, return 0; } =20 -static int zpff_init(struct hid_device *hid) +static int zp_input_configured(struct hid_device *hid, struct hid_input *h= idinput) { struct zpff_device *zpff; struct hid_report *report; - struct hid_input *hidinput; - struct input_dev *dev; + struct input_dev *dev =3D hidinput->input; int i, error; =20 - if (list_empty(&hid->inputs)) { - hid_err(hid, "no inputs found\n"); - return -ENODEV; - } - hidinput =3D list_entry(hid->inputs.next, struct hid_input, list); - dev =3D hidinput->input; + if (!list_is_first(&hidinput->list, &hid->inputs)) + return 0; =20 for (i =3D 0; i < 4; i++) { report =3D hid_validate_values(hid, HID_OUTPUT_REPORT, 0, i, 1); @@ -75,6 +70,7 @@ static int zpff_init(struct hid_device *hid) if (!zpff) return -ENOMEM; =20 + zpff->report =3D report; set_bit(FF_RUMBLE, dev->ffbit); =20 error =3D input_ff_create_memless(dev, zpff, zpff_play); @@ -83,7 +79,6 @@ static int zpff_init(struct hid_device *hid) return error; } =20 - zpff->report =3D report; zpff->report->field[0]->value[0] =3D 0x00; zpff->report->field[1]->value[0] =3D 0x02; zpff->report->field[2]->value[0] =3D 0x00; @@ -95,35 +90,13 @@ static int zpff_init(struct hid_device *hid) return 0; } #else -static inline int zpff_init(struct hid_device *hid) +static inline int zp_input_configured(struct hid_device *hid, + struct hid_input *hidinput) { return 0; } #endif =20 -static int zp_probe(struct hid_device *hdev, const struct hid_device_id *i= d) -{ - int ret; - - ret =3D hid_parse(hdev); - if (ret) { - hid_err(hdev, "parse failed\n"); - goto err; - } - - ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); - if (ret) { - hid_err(hdev, "hw start failed\n"); - goto err; - } - - zpff_init(hdev); - - return 0; -err: - return ret; -} - static const struct hid_device_id zp_devices[] =3D { { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) }, { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) }, @@ -134,7 +107,7 @@ MODULE_DEVICE_TABLE(hid, zp_devices); static struct hid_driver zp_driver =3D { .name =3D "zeroplus", .id_table =3D zp_devices, - .probe =3D zp_probe, + .input_configured =3D zp_input_configured, }; module_hid_driver(zp_driver); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 7E009437118 for ; Mon, 3 Aug 2026 18:46:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782822; cv=none; b=UluPANBza+qG/UaWeria/rL8C1ib4UAF4bHTu33T9pjNkpIP8RMxPaQMJ3uKaS6HAfR7rs5KkNAOOKeKKl7b3weP5OApB5ycBIAJpsKqdwe3HqGO/YerY2YvRtudhHcDTRvV2CtNQVHSXfkcrK+yBS/anz5Iw3yMybnyUG8i95U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782822; c=relaxed/simple; bh=zg2vHl0mCSduGubZyTdWB58tFEF8l8Mkk6Gef8XuXWM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CjQs2BSoloiZzxoaXQsonFDeI4/eZ2JaS8LSAjXed1RK9q0qHeGz7YbCMsozCM/LgulLLFHbKEFmRzQqLnvBjH5l1x1y4e3jGsImys1E0q9/HdkTvjXNmzMODkGhHnqDfIltEGae951ob8fx/b7qa5LOKW5SnFqQIVgUnYwKm14= 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=DP5YVbhe; arc=none smtp.client-ip=209.85.216.43 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="DP5YVbhe" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-382ef647e20so3955000a91.1 for ; Mon, 03 Aug 2026 11:46:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782819; x=1786387619; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=hJwE+xsjxuKlh9v3sgz7HiVvQbwBghbMJJRyGqgWcGE=; b=DP5YVbhepRNxaYbq5cJPp2+a0SQQ5GmhmgZ0hn8/+bUe8grrKNh1dq0fNaxlqfP7/f waZ81KBZcfVBYNBLAKfj5KoSjl1NbUswCjlPfWgtqN0SetOQevbv5zsUPFL8nlhR5/QE NuUGZZL2eNM08VW8pzNtjUBmBiPw4ezQiH+kqu3gytdXaHUX1RJLO2gGEvna07NNTFOd vOGDmLjUl8DicY5KvYEi1bRtz3VS0ZaYF9pexXTVxDLqK/6WSG0uAom+X/TCAm+Ix+kw 0YfW0lJ4rqghiafCrO4zYZ/EQzK1kkM29JgvkQnQo0nULhZQkC48FRUEGg2I08ZWfgbn ggTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782819; x=1786387619; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=hJwE+xsjxuKlh9v3sgz7HiVvQbwBghbMJJRyGqgWcGE=; b=m1pEz7ochVLAIt4H+h+NrFJg8o1O/R8qSMRpf2tr4X1xLdPvnT8BkpG+sKCwmPuFFK MTk/o+Ko52KhqL0xgEbCT5Jl/IRECiU7idQAbWKBALPxzAvbQsiX3OsVqK4SDJK5eWCg Ws+M8h9iF6ZmQNPDH4tOPm0ilrw9ioXUhVrm/KgpqTYTcUdCFTstVAqu9DeqygK3kxBp H7YM9e2D6sPPbPDXRkoI2iLNmPB5jMqt1VzfAufDSv9HhxFXjNrFgzv3banIOC/nMl87 P8+nKvnXsT2m5U10TPyTM93roJsfYJxgvJvUMl/8YV1ZAD8sBeHNeOrOPNm6ONGI0a0k R/4Q== X-Forwarded-Encrypted: i=1; AHgh+Ro8YWsL7pgP9f3TYsiuYL55NTIbCpUOl4UspuqV77RR3bAz+7FmT/F5ebn1p9B9GxmihygDW2vN3X+z/wE=@vger.kernel.org X-Gm-Message-State: AOJu0Yx69KH/qwTROGuS96FIbT/w3oyrjpawS61Q1yIiBou+AxPRx2vo Bgi1FRjGb1+p17l7WHE9TSqIn6mw/w8oQXue5LtQCuI9NlYtlCVmkO1bLbgKwg== X-Gm-Gg: AR+sD10U5/ZJZZUBRbbblEe3kAzgDargS5yD+FWDLYu/iT/AxcyXGwOVNfzmKaulwaB TjvR9w0Hw1NpkAGjaOYj8FO5mVcT4GfVF7ETpppX2rMn0Ltu1vQ9OKGirJFaT+mc8KtKwFq9Cev AHhg3HhfI99tU7L2YI3FDkMnE4+Pnt1KX11Qha92CgdSOU8vwNmtVg3SZ3AD6LUL6QjvVRicGgi 5TdwTSwK0fbFh42e+C/5zFbyHabrai7/RefRlNdhgE8YNMdZW+W1svjCIGAS8NeFqQYSqJhsv2h dl+PUlXw9t4aGDD+jlHgesPyVhlyvrM2QIb/GMe2IRfoHHeHjbxzDVxqay7hwY0lhb+O3zf8kmi sEzgtz/tmYNwx1blFg6kvwCRyWQhuKStuvjWkBV45hat84vHVD55/q01xcDDE0+7+hL7ASbx4Pl CarudpA//Nr1aGRoyti6hKekipzI1evItzQ6aT9v3fXTRmEhK1U+Tvz/RGcpLUGjTCyNiZZ4FOW XrGbNZ3ySSakqo2GHawWooK2fv242PrcAEuS5wO80ypmOF5kIwvPCK63i/ywBo= X-Received: by 2002:a17:90b:5605:b0:38e:9e9e:ec57 with SMTP id 98e67ed59e1d1-38fbc561025mr10384614a91.43.1785782818660; Mon, 03 Aug 2026 11:46:58 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:58 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:42 -0700 Subject: [PATCH 17/21] HID: mayflash: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-17-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_hw_start(). This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-mf.c | 77 ++++++++++++++++++------------------------------= ---- 1 file changed, 27 insertions(+), 50 deletions(-) diff --git a/drivers/hid/hid-mf.c b/drivers/hid/hid-mf.c index 6ff54a1ec697..136e8b41d5f4 100644 --- a/drivers/hid/hid-mf.c +++ b/drivers/hid/hid-mf.c @@ -54,61 +54,45 @@ static int mf_play(struct input_dev *dev, void *data, s= truct ff_effect *effect) return 0; } =20 -static int mf_init(struct hid_device *hid) +static int mf_input_configured(struct hid_device *hid, struct hid_input *h= idinput) { struct mf_device *mf; - struct list_head *report_list =3D &hid->report_enum[HID_OUTPUT_REPORT].report_list; - - struct list_head *report_ptr; struct hid_report *report; - - struct list_head *input_ptr =3D &hid->inputs; - struct hid_input *input; - - struct input_dev *dev; - + struct input_dev *dev =3D hidinput->input; int error; =20 - /* Setup each of the four inputs */ - list_for_each(report_ptr, report_list) { - report =3D list_entry(report_ptr, struct hid_report, list); + if (!list_is_first(&hidinput->list, &hid->inputs)) + return 0; =20 - if (report->maxfield < 1 || report->field[0]->report_count < 2) { - hid_err(hid, "Invalid report, this should never happen!\n"); - return -ENODEV; - } - - if (list_is_last(input_ptr, &hid->inputs)) { - hid_err(hid, "Missing input, this should never happen!\n"); - return -ENODEV; - } - - input_ptr =3D input_ptr->next; - input =3D list_entry(input_ptr, struct hid_input, list); + report =3D list_first_entry_or_null(report_list, struct hid_report, list); + if (!report) { + hid_err(hid, "no output reports found\n"); + return -ENODEV; + } =20 - mf =3D kzalloc_obj(struct mf_device); - if (!mf) - return -ENOMEM; + if (report->maxfield < 1 || report->field[0]->report_count < 2) { + hid_err(hid, "Invalid report, this should never happen!\n"); + return -ENODEV; + } =20 - dev =3D input->input; - set_bit(FF_RUMBLE, dev->ffbit); + mf =3D kzalloc_obj(struct mf_device); + if (!mf) + return -ENOMEM; =20 - error =3D input_ff_create_memless(dev, mf, mf_play); - if (error) { - kfree(mf); - return error; - } + mf->report =3D report; + set_bit(FF_RUMBLE, dev->ffbit); =20 - mf->report =3D report; - mf->report->field[0]->value[0] =3D 0x00; - mf->report->field[0]->value[1] =3D 0x00; - hid_hw_request(hid, mf->report, HID_REQ_SET_REPORT); + error =3D input_ff_create_memless(dev, mf, mf_play); + if (error) { + kfree(mf); + return error; } =20 - hid_info(hid, "Force feedback for HJZ Mayflash game controller " - "adapters by Marcel Hasler \n"); + mf->report->field[0]->value[0] =3D 0x00; + mf->report->field[0]->value[1] =3D 0x00; + hid_hw_request(hid, mf->report, HID_REQ_SET_REPORT); =20 return 0; } @@ -128,22 +112,14 @@ static int mf_probe(struct hid_device *hid, const str= uct hid_device_id *id) return error; } =20 - error =3D hid_hw_start(hid, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); + error =3D hid_hw_start(hid, HID_CONNECT_DEFAULT); if (error) { hid_err(hid, "HID hw start failed\n"); return error; } =20 - error =3D mf_init(hid); - if (error) { - hid_err(hid, "Force feedback init failed.\n"); - hid_hw_stop(hid); - return error; - } - return 0; } - static const struct hid_device_id mf_devices[] =3D { { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, USB_DEVICE_ID_DRAGONRISE_PS3), .driver_data =3D HID_QUIRK_MULTI_INPUT }, @@ -163,6 +139,7 @@ static struct hid_driver mf_driver =3D { .name =3D "hid_mf", .id_table =3D mf_devices, .probe =3D mf_probe, + .input_configured =3D mf_input_configured, }; module_hid_driver(mf_driver); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 32FF1443AA2 for ; Mon, 3 Aug 2026 18:47:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782824; cv=none; b=MRgzia6OSpSWhCU/lXDpo6FT609bS/4bu4vPLO1DP4PHQnMb2Hik/PGFPP4hZ3OGio6+G9TToW7tPo0TrrBVfiqDlthCX38kHkRNkgpGaFnwHT/ke6NwiSOhjfsnIUM/ae8mG9ZD2x4hDLiIP9MCIcZlfvd23scuH8yP4if0n+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782824; c=relaxed/simple; bh=sX1u2I9KlZuUAyIWLr1DKTH/D+67bak6JQXKiLEKJ0g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B08Hu6E8PBzwXiSzz5xOfX76DWXNXwg/0h2ZSVCqEqHA04o0UQvVIlxSsyMs7lg3KiItTKPFntc8pplGUzaVYE+obJ5RjchA7hty04p1s9+2lgfcSSebDj+1y+qbGmLEtcGfzXzUxTer+xa+AA6DH3g4lL05P9atlfzdQjPExis= 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=rnZMnVqa; arc=none smtp.client-ip=209.85.216.42 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="rnZMnVqa" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-384930ca5e2so3158972a91.3 for ; Mon, 03 Aug 2026 11:47:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782821; x=1786387621; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=MbT2WXShN1lekSN2/J4SPsyEo8OMF/+Z/0XrCjyCo/Q=; b=rnZMnVqaMPd+QWWs0GR0M62yJYxeAzwRxpZuaoIRHYGVqFKLQBbGyz2vkdmF25m3g8 V7JSpL9eX8jsLLVydLZ1+v5dKa+KOMJnNmm/0vHaQcyHtQs8EtkezaPPyDUNK1BNw3gN c2hrM9Iabeu0J/6Is56LjRXOfrL4o09kZKoK/PkuF6OUkycL3dfFO2oTfPxuFhmA0wSK BNmPPdzoptlVm5j8fuxXVarzqpwZLZ3dOiQpzGI1L1xjUJXcUixATT9Iyx/Ic5I6eodq h/ZRVrDAsPeKrRaJcCSTeqrAv6ZhhRRSl2stK2kV5vU59Nqg7A/iJ0IOde6H3Sg7DhII n9yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782821; x=1786387621; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=MbT2WXShN1lekSN2/J4SPsyEo8OMF/+Z/0XrCjyCo/Q=; b=JkPgQtphuIrS4pPcYV99wnGCMyhGWcgiNarRo+jR+3/tFU+jBamUL8h1LiePqm6OZN 0thr16G1BTp2alN7PB+Agym1r2IyEyCHneoYg9h0fdXlk9O6WBVF5Qg3Ov2776rWSkNy 3hRNK5cSLXGbU+WeP4irbYiZ5JWmlEhVYxEI41cIxLVxqKmYT9mbrYZGKmbpeC/ALtW3 wuTDAvfBeE0f+LmPMoY3mVvCHwk8nvN6hBVmg1Ge5PDSFUnW0Rg/zVEPx1MhnQ1i4se2 EbJAWgu1orb6uUUibTgg2snINZLY1FWfTfJSN1rgggH1hzfPUI/ph5ZReMs2zgODeEwO sUQw== X-Forwarded-Encrypted: i=1; AHgh+RqCyw8c/akcGqrU1SJqtsoNVwHeG66dirUcNwfT1tFABfIAz1K3X5k6TEsmoAH2bH5FKWEt3Sm/YTQfwc4=@vger.kernel.org X-Gm-Message-State: AOJu0YzbOhDrLRiTc0/qSsCOmwH3gzz+K2GukS/ufgnxV1Rcx4g+uzSY sx6LCMvyVkGie/U5ku8N6UVSnyv0Ah3aTtQwoknbWSsbX5IJvPACIjn6 X-Gm-Gg: AR+sD10hvO7vjGkGLpQgzbJ93fRnWh1eQt1UnHFEvKaJjgHA+jKBFlEP5lnZX14c2Ht oTe9EEgZ0m105FbvvJNqYZA0ry6l7d/sN3oRREmlDkWSGJUlm+tij39bo0i3rlsbTNJ1cdmrul+ t8CWLK1fW+2qHCjR2JTsevBFaxzR4EX3rZH03s5UN/T4+X67QmwwdIjK8eJL0Sa1VFf/Lak5dik Y0D7BBNb35F3kjt8fW8aHb3Yex+IBu3zx1/fPMkCokitBNeTGDb7ZJ4o+bYN2UqYOHBAMJkezC+ A7cgGBCxPvK7KXikQEVpWkFdgp9RteUUT0kei8PJpjp5o0VvlWnpK8sVOmDWYQeMJLCD1q66QFG 8xRlv1qsN8s7kB2Sq73hNn8hrqvfWP/HdSXo3p8wtXl9LOx7WD5uZfqZh7OEPo8bow4O+9zJC85 mDeU8SMa0MVbvnXCrOIt9hSBdRMMBBUVjLWiOH/RIkdBVY/awi1x9fU3kKsf5JlwiQMpEeknS96 aY6VAn+bJeo8zhB5L92aXUPW9aQMzjb/H/qC7ZTjh5Aq1+CRfa+ X-Received: by 2002:a17:90a:dfc4:b0:38e:7268:220d with SMTP id 98e67ed59e1d1-38fbc4cb98amr10426103a91.20.1785782821239; Mon, 03 Aug 2026 11:47:01 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.46.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:46:59 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:43 -0700 Subject: [PATCH 18/21] HID: smartjoyplus: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-18-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_hw_start(). This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-sjoy.c | 83 +++++++++++++++++++++-------------------------= ---- 1 file changed, 34 insertions(+), 49 deletions(-) diff --git a/drivers/hid/hid-sjoy.c b/drivers/hid/hid-sjoy.c index 963c45113204..193ab2a6146e 100644 --- a/drivers/hid/hid-sjoy.c +++ b/drivers/hid/hid-sjoy.c @@ -48,68 +48,56 @@ static int hid_sjoyff_play(struct input_dev *dev, void = *data, return 0; } =20 -static int sjoyff_init(struct hid_device *hid) +static int sjoy_input_configured(struct hid_device *hid, struct hid_input = *hidinput) { struct sjoyff_device *sjoyff; struct hid_report *report; - struct hid_input *hidinput; struct list_head *report_list =3D &hid->report_enum[HID_OUTPUT_REPORT].report_list; - struct list_head *report_ptr =3D report_list; - struct input_dev *dev; + struct input_dev *dev =3D hidinput->input; int error; =20 - if (list_empty(report_list)) { + if (!list_is_first(&hidinput->list, &hid->inputs)) + return 0; + + report =3D list_first_entry_or_null(report_list, struct hid_report, list); + if (!report) { hid_err(hid, "no output reports found\n"); return -ENODEV; } + if (report->maxfield < 1) { + hid_err(hid, "no fields in the report\n"); + return -ENODEV; + } =20 - list_for_each_entry(hidinput, &hid->inputs, list) { - report_ptr =3D report_ptr->next; - - if (report_ptr =3D=3D report_list) { - hid_err(hid, "required output report is missing\n"); - return -ENODEV; - } - - report =3D list_entry(report_ptr, struct hid_report, list); - if (report->maxfield < 1) { - hid_err(hid, "no fields in the report\n"); - return -ENODEV; - } - - if (report->field[0]->report_count < 3) { - hid_err(hid, "not enough values in the field\n"); - return -ENODEV; - } - - sjoyff =3D kzalloc_obj(struct sjoyff_device); - if (!sjoyff) - return -ENOMEM; + if (report->field[0]->report_count < 3) { + hid_err(hid, "not enough values in the field\n"); + return -ENODEV; + } =20 - dev =3D hidinput->input; + sjoyff =3D kzalloc_obj(struct sjoyff_device); + if (!sjoyff) + return -ENOMEM; =20 - set_bit(FF_RUMBLE, dev->ffbit); + set_bit(FF_RUMBLE, dev->ffbit); =20 - sjoyff->report =3D report; - sjoyff->report->field[0]->value[0] =3D 0x01; - sjoyff->report->field[0]->value[1] =3D 0x00; - sjoyff->report->field[0]->value[2] =3D 0x00; - hid_hw_request(hid, sjoyff->report, HID_REQ_SET_REPORT); + sjoyff->report =3D report; + sjoyff->report->field[0]->value[0] =3D 0x01; + sjoyff->report->field[0]->value[1] =3D 0x00; + sjoyff->report->field[0]->value[2] =3D 0x00; + hid_hw_request(hid, sjoyff->report, HID_REQ_SET_REPORT); =20 - error =3D input_ff_create_memless(dev, sjoyff, hid_sjoyff_play); - if (error) { - kfree(sjoyff); - return error; - } + error =3D input_ff_create_memless(dev, sjoyff, hid_sjoyff_play); + if (error) { + kfree(sjoyff); + return error; } =20 - hid_info(hid, "Force feedback for SmartJoy PLUS PS2/USB adapter\n"); - return 0; } #else -static inline int sjoyff_init(struct hid_device *hid) +static inline int sjoy_input_configured(struct hid_device *hid, + struct hid_input *hidinput) { return 0; } @@ -124,20 +112,16 @@ static int sjoy_probe(struct hid_device *hdev, const = struct hid_device_id *id) ret =3D hid_parse(hdev); if (ret) { hid_err(hdev, "parse failed\n"); - goto err; + return ret; } =20 - ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); + ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT); if (ret) { hid_err(hdev, "hw start failed\n"); - goto err; + return ret; } =20 - sjoyff_init(hdev); - return 0; -err: - return ret; } =20 static const struct hid_device_id sjoy_devices[] =3D { @@ -165,6 +149,7 @@ static struct hid_driver sjoy_driver =3D { .name =3D "smartjoyplus", .id_table =3D sjoy_devices, .probe =3D sjoy_probe, + .input_configured =3D sjoy_input_configured, }; module_hid_driver(sjoy_driver); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 56185444717 for ; Mon, 3 Aug 2026 18:47:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782825; cv=none; b=oEWhLFPmrAnim03it93tffzfJGUSwNwqHEhs+djAOL71jGQAJG7BFwLn261YsfQw2tWLBgA3Qn6PcTW1qFosZctqHk5uLd9xBhy0IfDwq/8ESc7sfJJQMlOAGoNKsnVsJ3xnFLA3JG28EeIEZ+lELQ2XZmJnhF1V3ssq+PWgvp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782825; c=relaxed/simple; bh=jpAOqaBdI7XZv/2UrjAfgGxJNhTK/u5+yBOK2+bVK64=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iHRzIpkbsfg95//fXUJ1z+aA3lkYTjGqscE/e6gIwkbZYsh8gvQawOtVC9Ibq0o6MZ5EF3OS4dfqwekf2MjDH08SDnQSUvF5YhDzeVqbT7xic0n81BsuDqXaHuQ8KvtDUlSAOuosoWbeEOei+23NnfnNB7DaadXLceT5wUeVKlo= 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=mw9gI9k9; arc=none smtp.client-ip=209.85.216.52 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="mw9gI9k9" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-38dfe910e9dso3549940a91.3 for ; Mon, 03 Aug 2026 11:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782822; x=1786387622; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=BkuSCqc+yAADDamWfiyKN/ep68Wue9ZrU0Qqd8Kmzk8=; b=mw9gI9k9psH2ucd/5v+hM7lpApumvm1YDsiCptAJtPp0syc2YadfzB8db2XcsXHRCA yXgWnMvR2wr20udYKK3CUfISVdV2vPrQWUz4IbvS7D7zgI7MPBr6JU7If5ZTu7pIRnFG 5pnm6SjA5lWp1GV3K/+CO51N3aHYAw0+1dR2zeDodtdg7eMB78wHA/qxIvQkrfywCoaQ c5CCm96cCWMJXFUdoHT+jZbKPljT3ny5WwwyQbEJNJbzjcp/C9h3hVUhroQk6E0e3a91 meEO9QctT4ETOCXGsOIZrAr/R5MTPaLGH+sk49Ss5a9Uj23Tw6fsey30BzvOfMcW8e7P JxjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782822; x=1786387622; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=BkuSCqc+yAADDamWfiyKN/ep68Wue9ZrU0Qqd8Kmzk8=; b=gDyjFHtTgAKpfMIihwnInws+GQleY+8eoE/xwpMwoEFKEi3OIahzhcL2dGLqr0Beye sSGtEdFLhifV5wxtIhcGPX5DNF7FSRN1mV69RMCipfen7HJRSbXacJppDm2wgqq+8Krm aGzN/LmzJJqXbll0QdDYP0U1afp2Vj0QsvJI+XN4RyNsJMSkOYe5n043xLPpvoNjKeq6 Aw/fvATJqszBnCMIUIue1qZ0izg0NhySJoy0NV/a0QuOaPe2RtjmnTbJARnN4Do26Zs1 h1w6VkxBYsE4awwXczt+awItpVAJWy1z/mi7qYM2SNiCpKV2119ImisPqSMBVUXogr4+ vFOw== X-Forwarded-Encrypted: i=1; AHgh+RooAW9t5MFMenKMEK5DWMtyTExKg5KXL2nFMAICMMU5RRZzWOGiYq+SMVVbfc6Td7a7v3ETH09hXzgWFzc=@vger.kernel.org X-Gm-Message-State: AOJu0YyuVrvG4qQJweRjrsnngAhklOhlXDckevzRzLL4+w+XdgJ5JYL8 k9jV+k8VoJ1F9Rise8eJoZUZJHVTr6VrE6DrOZ52g8oD//00IOV8y+q2 X-Gm-Gg: AR+sD1284FS8mI+//3Xx4Z0zhtp2NA5sEw7VF0bFR5Djt8sQUFXHfwWhSY5Ws/9GoCv hzAbdZMi/FkmVl9ez4jpXUbygdEEn20xQLv4/2q2OziA8kFwrUjKiHcQVE0Q9IGFliBt8aF5wZF BGRsPIWK+YJhWwonbXMgdxDMP79lK6xPhVuJwB2+VNB1p7Wcb37IFgU4UCEuRvp53iIrcbvKrF8 Poho6AhM6QOd4ht1vWYGArjnV97r0RhZcd8M/SiiWp0SSUcEe6mFUvt2PHqmMHgFw1PqUr3sjsQ q9MESh7CPwcLXSLhqWnZgvnY0XfEB/Pe/XZVd3ZvBKXqfdMYq0nknMIV36tSL4K1BzVXusDfqat 65PetSyLVVJD/Cd1N50Z1AQS3p07Qk+W1Rru9+gz5HxOd69lOzfbgRvzNDTmGWwyi8rJa2mxsTR /cMd9q8l0awgX3qpR9jBsg4o7odz4AQgPxs1nDq/zF0uEitprwrnnUjLbk/GA07H0i/0LU00Czv sV+SZMvX0mdkrkh/iCGoyGlY7QOghnGKiKhzii3kc5q39vzcYCO X-Received: by 2002:a17:90b:3c86:b0:381:f7a:2e0d with SMTP id 98e67ed59e1d1-38fbc51f884mr10395038a91.33.1785782822529; Mon, 03 Aug 2026 11:47:02 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.47.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:47:02 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:44 -0700 Subject: [PATCH 19/21] HID: megaworld: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-19-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_hw_start(). This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-megaworld.c | 51 ++++++++++-------------------------------= ---- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/drivers/hid/hid-megaworld.c b/drivers/hid/hid-megaworld.c index 81acdbc3a00f..d5c868974275 100644 --- a/drivers/hid/hid-megaworld.c +++ b/drivers/hid/hid-megaworld.c @@ -35,21 +35,16 @@ static int mwctrl_play(struct input_dev *dev, void *dat= a, return 0; } =20 -static int mwctrl_init(struct hid_device *hid) +static int mwctrl_input_configured(struct hid_device *hid, struct hid_inpu= t *hidinput) { struct mwctrl_device *mwctrl; struct hid_report *report; - struct hid_input *hidinput; - struct input_dev *dev; + struct input_dev *dev =3D hidinput->input; int error; int i; =20 - if (list_empty(&hid->inputs)) { - hid_err(hid, "no inputs found\n"); - return -ENODEV; - } - hidinput =3D list_entry(hid->inputs.next, struct hid_input, list); - dev =3D hidinput->input; + if (!list_is_first(&hidinput->list, &hid->inputs)) + return 0; =20 for (i =3D 0; i < 4; i++) { report =3D hid_validate_values(hid, HID_OUTPUT_REPORT, 0, i, 1); @@ -61,16 +56,7 @@ static int mwctrl_init(struct hid_device *hid) if (!mwctrl) return -ENOMEM; =20 - set_bit(FF_RUMBLE, dev->ffbit); - - error =3D input_ff_create_memless(dev, mwctrl, mwctrl_play); - if (error) { - kfree(mwctrl); - return error; - } - mwctrl->report =3D report; - /* Field 0 is always 2, and field 1 is always 0. The original * windows driver has a 5 bytes command, where the 5th byte is * a repeat of the 3rd byte, however the device has only 4 @@ -82,30 +68,15 @@ static int mwctrl_init(struct hid_device *hid) mwctrl->strong =3D &report->field[2]->value[0]; mwctrl->weak =3D &report->field[3]->value[0]; =20 - return 0; -} - -static int mwctrl_probe(struct hid_device *hdev, const struct hid_device_i= d *id) -{ - int ret; - - ret =3D hid_parse(hdev); - if (ret) { - hid_err(hdev, "parse failed\n"); - return ret; - } + set_bit(FF_RUMBLE, dev->ffbit); =20 - ret =3D hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); - if (ret) { - hid_err(hdev, "hw start failed\n"); - return ret; + error =3D input_ff_create_memless(dev, mwctrl, mwctrl_play); + if (error) { + kfree(mwctrl); + return error; } =20 - ret =3D mwctrl_init(hdev); - if (ret) - hid_hw_stop(hdev); - - return ret; + return 0; } =20 static const struct hid_device_id mwctrl_devices[] =3D { @@ -118,7 +89,7 @@ MODULE_DEVICE_TABLE(hid, mwctrl_devices); static struct hid_driver mwctrl_driver =3D { .name =3D "megaworld", .id_table =3D mwctrl_devices, - .probe =3D mwctrl_probe, + .input_configured =3D mwctrl_input_configured, }; module_hid_driver(mwctrl_driver); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 BFAD8445AD2 for ; Mon, 3 Aug 2026 18:47:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782827; cv=none; b=lZpTsjbfI84nb5pEKn0Try8OgmE4Zy6er4bTqInqq0UMpNptoE5MzRApE/x1gcoC/BKF8DNLBk3Huvs6bzjKrKlViLbWSi19RQIvX790hycPtmMh3TxcITs1wHOw5NTIwas/yKdhozEGDGeiDUgfZa46fiZwCHQ/7giEP5vN/mo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782827; c=relaxed/simple; bh=vP4IwtvXrpZhfmJWbeISKZ2NnXGuGtLCc+RIUUejyWA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qOBds56ecUAyQbaO/gZlsaEzEBoY+l7LJlpi22qB79XO9NwrSlH5raRpADiCfQ11ECkQ/hsEE11mF9f7OMBKa0F4hH2XRjdOZthugDMZipmDxqEpOJP7K+ziKAaPp7IM0mBBK1mU6HWhmRgJ8ZLqb9pZLzLgk8S6v3be+7owdO4= 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=qI/V1ImP; arc=none smtp.client-ip=209.85.214.178 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="qI/V1ImP" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2ced3386430so37358435ad.1 for ; Mon, 03 Aug 2026 11:47:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782824; x=1786387624; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=tHw3HXNYpWvYMonYbPqZXuVoBB2JcVG5n1iAzr9iHHw=; b=qI/V1ImPScdX+9joozEqP1fBIRb5BOQQJAp92RHw/S82xm9ERqP0wo1JZv5H0XsZ94 jT6rsx6DGYE8FRiw3uJxPnbtbUK5L8dng3q4gnK/gyT0uQFpzEF3ob7bJE0ZYfimDPw6 Zp/FtJsZIRlfTh3EGSbQ0qT9Y3tZaRSvchMQkNXxY8cMH34UlG4VojFehcERz9xs7A/Z f948C09t4cBX5Zw306q4c23yrieIfnTgiZK7NkroRgYUdZqkwKo1hpj92sa37wNIbjSJ 1RB3OliCkPddYV61uimAZzIHP++GYCK2PBtTrvXQfMeKfSd5rlSzo+Jan3BY40DlfJHl VwBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782824; x=1786387624; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=tHw3HXNYpWvYMonYbPqZXuVoBB2JcVG5n1iAzr9iHHw=; b=BC4LBq5kWL8VSiLphdn0fyKhH/FmZgr6sLQAl+f3n173SRy8o9aRXAAb0tKUCWYwBr nzitl6/GolCbeN4YLqy/fawbYxPqRpNbrMJGsRh0PfF8J8NM98Bj0wjA65VdAHLzG9oJ zDv9DhMhskbbxf5OU2a043kCbM9tNczlHL7r1zg3Aaz/iwklBHhHOYiW/UO1AuyFNF3u swbt56t0T7LP3gHjjBxN8RO3VL92p4iDfsoFFqxckqXZwstOzhiCJD2jRsjzWeKTXxso zdlai/9sD+Oi9OHn+HcvnknYPEitU63uehVbK0bYEhj0yOIaBe2BbeAdcrYB2Dym2m05 eJvw== X-Forwarded-Encrypted: i=1; AHgh+RrbU+5bb8bbl9QUIaPmX/9C7FVA6RlZYuNs62mQHdIN2strurvZI1tlGjmRtJbcX9iZxmsdLUzpxoZNb6s=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/BFx0OBTNLoKkDoVGU6GyRy4VjKQPSjvPYzwAVMzzbjScRzM5 1mGU7kFPxCl4RE52336wJNi6Ock66R+YB/HSsLwmyDA27cdrEFdtok03 X-Gm-Gg: AR+sD11T9fLC4JNe93LauMo5FGkGm97I7+KoDh9vbV0wFm3GyLc0pkV0ssPEsXh230N oBmoeWUPuoJITx6NQezNocXLsGPoVUANv15r+pI8T/tIoUItcowNp4DjM4j/ASwp8xLvsCZZ45E spn1x3r/RuStkTVafcJPa78BEbaW7aAzrFc/KfciWO08XtG/ky6uU7AZsPofrqX1CpF86AuwM8o e8mC/WClCnsv/9BNEmKKZerj7XQ5//VeRwv/RHSo5pruHBSxhCB8gwydluzxqjAxOihj//9lU88 q50cxZrRhTcFW2tNlPF+JhDLVgbJ+kuJ5EwSjniOGoUw2zz3W5XjwJHtalhZ2SPA/A22HMf2Tet fSOJdpuyuSrklJASc4/77fRqbdeoblxehb4Lh7YZbxVXknUNOAGWMOIvNuFmVRFbaF9lOzRhTq5 EXOOzr6ODxf3Wvfbyh++BM5+9oqFVL4Loa+p/pSz125+wQa6GKka0NV487fIlPiFMFsvfZmv+5J qoKEU170q2sNUAp8gTgu1YsQwNWnG6omLYf6zNQuwwkitKqEMVL X-Received: by 2002:a05:6a20:4e92:b0:3c3:bb13:438 with SMTP id adf61e73a8af0-3c92a74cf9emr11650080637.32.1785782824005; Mon, 03 Aug 2026 11:47:04 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.47.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:47:03 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:45 -0700 Subject: [PATCH 20/21] HID: logitech-hidpp: move FF initialization to .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-20-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f The driver currently initializes force-feedback in its probe() function after calling hid_connect(). This is racy as the input device is already registered and visible to userspace at that point. Move the FF initialization to the .input_configured() callback to ensure the device is fully prepared before registration. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-logitech-hidpp.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hi= dpp.c index 90b0184df777..db53b45b0752 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -3861,15 +3861,32 @@ static void hidpp_populate_input(struct hidpp_devic= e *hidpp, hidpp10_extra_mouse_buttons_populate_input(hidpp, input); } =20 -static int hidpp_input_configured(struct hid_device *hdev, - struct hid_input *hidinput) +static int hidpp_input_configured(struct hid_device *hdev, struct hid_inpu= t *hidinput) { struct hidpp_device *hidpp =3D hid_get_drvdata(hdev); struct input_dev *input =3D hidinput->input; + int ret; =20 if (!hidpp) return 0; =20 + if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { + struct hidpp_ff_private_data data; + + if (!list_is_first(&hidinput->list, &hdev->inputs)) + return 0; + + ret =3D g920_get_config(hidpp, &data); + if (!ret) + ret =3D hidpp_ff_init(hidpp, &data); + + if (ret) { + hid_warn(hidpp->hid_dev, + "Unable to initialize force feedback support, errno %d\n", + ret); + } + } + hidpp_populate_input(hidpp, input); =20 return 0; @@ -4530,21 +4547,6 @@ static int hidpp_probe(struct hid_device *hdev, cons= t struct hid_device_id *id) schedule_work(&hidpp->work); flush_work(&hidpp->work); =20 - if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { - struct hidpp_ff_private_data data; - - ret =3D g920_get_config(hidpp, &data); - if (!ret) - ret =3D hidpp_ff_init(hidpp, &data); - - if (ret) { - hid_warn(hidpp->hid_dev, - "Unable to initialize force feedback support, errno %d\n", - ret); - ret =3D 0; - } - } - /* * This relies on logi_dj_ll_close() being a no-op so that DJ connection * events will still be received. --=20 2.55.0.629.g250fe7f194-goog From nobody Fri Oct 2 07:45:35 2026 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.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 BB75744838B for ; Mon, 3 Aug 2026 18:47:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782830; cv=none; b=tCFFr0AjfJPrulIixNmlWUgNMoguUCSfRpUoFCkWii++dnxJ/jEtXPBHiRTS2uTh7lwM9DhCRqz+FnhMlaS+rly5uOCfloP2MNLLRGyniuBbSFTm3W3pjQDs7xOaENrxWLQZ8ymnVf+p7xvcIzfMPfWm3Gkj61nfkCmfDbk3BgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782830; c=relaxed/simple; bh=Yoi3lubzRKWVWpcvd3Ifx+IIKQYam/xYCacTplW9mOc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=I5sn27eo6Epf7XDRhWO35kHKAl7/NoB0XyAXpDJf1uluQuvRHcakRB0pJ47EWBLioaZPcQJk2iOUKUQ+/7GbU/q3YWlwch3CUmosaoi6EDOjDHqrwt2vTRFuNnJdHcswvuHT8t1VQzjIiQeYWmbOAGsjFpEtbSYKrg4Yqtydfw0= 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=Wbny/eZZ; arc=none smtp.client-ip=209.85.215.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="Wbny/eZZ" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-cbe3fed2f58so2018699a12.3 for ; Mon, 03 Aug 2026 11:47:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785782825; x=1786387625; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=HhNt75xrdH23XiQfHURUjEm4mC5u0bmXUDGMCww7WdI=; b=Wbny/eZZnYcxHGcyDYuqUE5R5b8+1HuCkouS6P99ImtVDUfIY6wge9Uerdtwr94PS2 ouaeTKPyKpess511lqIqgJvPqAX7tP5zMT59A2Zn0TPcdmckpKgFewOWp9SQB9654y74 MN5YFZd0bY0KZIkkT9t7Q6XxyAvOC/oLWVCrjNsqR+ScuvNjvQvVaWyRxd4fRqWYTSk7 B/zNxqhyz02yZxu+s5kaJZflI1Y8tuNAUfsNbLqXr2hlgWKCymX99XaBzbQENBwttgk1 n2VqhFThaKl8EUI32VJs6WEWJ/ITPgka6fDkMlgGIFwqc/LCkZ/9mYPjMesG1e44FkPz Fqcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785782825; x=1786387625; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=HhNt75xrdH23XiQfHURUjEm4mC5u0bmXUDGMCww7WdI=; b=N+QxVI7XfJmJdv/12JMvn4/XfrpjNKWlVAuRHwHazUxvGeQX71yoRg98AHV2xIaa/6 4FcLk/sPaN2krV00F6Gm85EVGS1EJ1aD3WVmksIVoWV/QsprxqNdifFvcz5hbPvIVYOk CA5d+zLinHFLcBIo8LM1JZ0dIdig4km7jhLeXpvubtrBafQ61eYwxLzPKRZAloQHns7t U+RSgvcjA1K7ckjLYNFwjDJ3X5EA/ugrgn3hW8b2AQvU3ri48MM4SoA44ZjdyXBV+XDJ oUhTLkkKg+PwrcHsSYYKjym2gThhh9oKGGdfpyUkiMQMjYsjiLEPF5jwCp4mX4xCWrNC CChA== X-Forwarded-Encrypted: i=1; AHgh+RofpESDexDEkJeV3wIAVgyJ4dhZS9FKd1jHx953G4KEl2z6Z802KTUMUGAUzx4S3KxOgUgFAWLi3fU/IZc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1IpshwEpvA/oxP85DzouTDMYbl8U54tsO4UHTSZ46fVbGdOet /9eaxwBWK3EvOR32+J6nvT9VnHsgqlhrCSx84WfcPYMjRwWvpnTkOIxa X-Gm-Gg: AR+sD136AR2SOAkupTVfwFzWIKTLN6fqL8sOUFxcNvpTuGJp0Ak6RbJw7doH33s09fy cUVziTV64NKErPCZqpXb8IG95pE785QVb2EJ67RplKw/mYKHo6GWCCDgP+ajyIqTlJ6bmS1/KHB Nx5T8DaXP4aOcgfQsqmEz2UcmjWL7CJJfN679Fdjpm6l4xO+LMWsNSrC3BneW4kH8oKqeUGS1h1 uMqvG3rspubpQELQ0xd6bwsSQu/w/7E/5kSgamJKSi0xlzMjYAierEMCnQwAr8ZvIvpgxeJVrJx 8i+XztUz9qOFKxD4imekbbyvFn3nHT7cjQJD4NhoFe9euFvGHZ8oZeWpQjPXPT7vMC14kN2GWTb 8fIcUPNRreXLaU7KF4GxW2ChC1Ucjg9qMJyLskrmKtQlQgs5s+Qieor48Ws1ypPqt/yx4LyfXGR ZJpvDDS+YV7bmFZ3uhxu8XbNOYVKfSfPXhLsU7f5aL+Xg0SoSE5xV1TJtbDZQ+8ke4vA1KBg0oH j/TJp9v5rt28UB71r8tvOpQ0TxXoD2icrXqSXIpgzG2wYl/WVKl X-Received: by 2002:a05:6a20:93a0:b0:3c3:bbe6:95b1 with SMTP id adf61e73a8af0-3c92a5d6d57mr11389147637.24.1785782825402; Mon, 03 Aug 2026 11:47:05 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab24ec10sm33935472c88.6.2026.08.03.11.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 11:47:04 -0700 (PDT) From: Dmitry Torokhov Date: Mon, 03 Aug 2026 11:46:46 -0700 Subject: [PATCH 21/21] HID: haptic: move FF initialization into .input_configured() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260803-hid-ff-input-configured-v1-21-1dc9bbacd88c@gmail.com> References: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> In-Reply-To: <20260803-hid-ff-input-configured-v1-0-1dc9bbacd88c@gmail.com> To: Jiri Kosina , Benjamin Tissoires , Jonathan Corbet , Shuah Khan , Julia Lawall , Nicolas Palix , =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, cocci@inria.fr X-Mailer: b4 0.16-dev-b242f Refactor hid_haptic_init() to take a direct pointer to input_dev and integrate its invocation into hid_haptic_input_configured(). Update hid-multitouch to rely on the refactored callback to perform the force-feedback initialization during the registration loop. This ensures that force-feedback capabilities are set up before the input device is registered and exposed to userspace, closing the registration race. Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Dmitry Torokhov --- drivers/hid/hid-haptic.c | 45 +++++++++++++++++-----------------------= ---- drivers/hid/hid-haptic.h | 6 ++++-- drivers/hid/hid-multitouch.c | 10 +--------- 3 files changed, 22 insertions(+), 39 deletions(-) diff --git a/drivers/hid/hid-haptic.c b/drivers/hid/hid-haptic.c index deadab28cdbe..5d365a9767dd 100644 --- a/drivers/hid/hid-haptic.c +++ b/drivers/hid/hid-haptic.c @@ -82,16 +82,24 @@ int hid_haptic_input_configured(struct hid_device *hdev, struct hid_haptic_device *haptic, struct hid_input *hi) { + int error; =20 - if (hi->application =3D=3D HID_DG_TOUCHPAD) { - if (haptic->auto_trigger_report && - haptic->manual_trigger_report) { - __set_bit(INPUT_PROP_PRESSUREPAD, hi->input->propbit); - return 1; - } + if (hi->application !=3D HID_DG_TOUCHPAD) + return -1; + + if (!haptic->auto_trigger_report || !haptic->manual_trigger_report) + return 0; + + __set_bit(INPUT_PROP_PRESSUREPAD, hi->input->propbit); + + error =3D hid_haptic_init(hdev, haptic, hi->input); + if (error) { + dev_warn(&hdev->dev, "Cannot allocate haptic for %s\n", + hdev->name); return 0; } - return -1; + + return 1; } EXPORT_SYMBOL_GPL(hid_haptic_input_configured); =20 @@ -401,11 +409,9 @@ static void hid_haptic_destroy(struct ff_device *ff) } =20 int hid_haptic_init(struct hid_device *hdev, - struct hid_haptic_device **haptic_ptr) + struct hid_haptic_device *haptic, + struct input_dev *dev) { - struct hid_haptic_device *haptic =3D *haptic_ptr; - struct input_dev *dev =3D NULL; - struct hid_input *hidinput; struct ff_device *ff; int ret =3D 0, r; struct ff_haptic_effect stop_effect =3D { @@ -447,19 +453,6 @@ int hid_haptic_init(struct hid_device *hdev, for (r =3D 0; r < haptic->auto_trigger_report->maxfield; r++) parse_auto_trigger_field(haptic, haptic->auto_trigger_report->field[r]); =20 - list_for_each_entry(hidinput, &hdev->inputs, list) { - if (hidinput->application =3D=3D HID_DG_TOUCHPAD) { - dev =3D hidinput->input; - break; - } - } - - if (!dev) { - dev_err(&hdev->dev, "Failed to find the input device\n"); - ret =3D -ENODEV; - goto duration_map; - } - haptic->input_dev =3D dev; haptic->manual_trigger_report_len =3D hid_report_len(haptic->manual_trigger_report); @@ -535,10 +528,6 @@ int hid_haptic_init(struct hid_device *hdev, =20 input_free: input_ff_destroy(dev); - /* Do not let double free happen, input_ff_destroy will call - * hid_haptic_destroy. - */ - *haptic_ptr =3D NULL; /* Restore dev flush and event */ dev->flush =3D flush; dev->event =3D event; diff --git a/drivers/hid/hid-haptic.h b/drivers/hid/hid-haptic.h index c6539ac04c1d..6332991a7844 100644 --- a/drivers/hid/hid-haptic.h +++ b/drivers/hid/hid-haptic.h @@ -69,7 +69,8 @@ int hid_haptic_input_mapping(struct hid_device *hdev, int hid_haptic_input_configured(struct hid_device *hdev, struct hid_haptic_device *haptic, struct hid_input *hi); -int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device **ha= ptic_ptr); +int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *hap= tic, + struct input_dev *dev); void hid_haptic_handle_press_release(struct hid_haptic_device *haptic); void hid_haptic_pressure_reset(struct hid_haptic_device *haptic); void hid_haptic_pressure_increase(struct hid_haptic_device *haptic, @@ -107,7 +108,8 @@ static inline void hid_haptic_reset(struct hid_device *hdev, struct hid_haptic_device *h= aptic) {} static inline -int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device **ha= ptic_ptr) +int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *hap= tic, + struct input_dev *dev) { return 0; } diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index edb37b4c867e..15218e92aaa4 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -2189,16 +2189,8 @@ static int mt_probe(struct hid_device *hdev, const s= truct hid_device_id *id) =20 mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL); =20 - if (td->is_haptic_touchpad) { - if (hid_haptic_init(hdev, &td->haptic)) { - dev_warn(&hdev->dev, "Cannot allocate haptic for %s\n", - hdev->name); - td->is_haptic_touchpad =3D false; - devm_kfree(&hdev->dev, td->haptic); - } - } else { + if (!td->is_haptic_touchpad) devm_kfree(&hdev->dev, td->haptic); - } =20 return 0; } --=20 2.55.0.629.g250fe7f194-goog