From mboxrd@z Thu Jan 1 00:00:00 1970 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: 7bit 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); static const DEVICE_ATTR_RO(country); -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[] = { "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 |= HID_CONNECT_HIDDEV_FORCE; - 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 |= HID_CLAIMED_INPUT; if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect && @@ -2347,11 +2335,6 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask) hid_process_ordering(hdev); - if ((hdev->claimed & HID_CLAIMED_INPUT) && - (connect_mask & HID_CONNECT_FF) && hdev->ff_init && - !hid_has_ff_input(hdev)) - hdev->ff_init(hdev); - len = 0; if (hdev->claimed & HID_CLAIMED_INPUT) len += 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. */ -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 = hid->driver; struct hid_report *report; @@ -2330,7 +2342,7 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) hid->status &= ~HID_STAT_DUP_DETECTED; - if (!force) { + if (!(connect_mask & HID_CONNECT_HIDINPUT_FORCE)) { for (i = 0; i < hid->maxcollection; i++) { struct hid_collection *col = &hid->collection[i]; if (col->type == HID_COLLECTION_APPLICATION || @@ -2396,6 +2408,11 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) continue; } + 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 = 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 *); extern void hidinput_hid_event(struct hid_device *, struct hid_field *, struct hid_usage *, __s32); extern void hidinput_report_event(struct hid_device *hid, struct hid_report *report); -extern int hidinput_connect(struct hid_device *hid, unsigned int force); +extern int hidinput_connect(struct hid_device *hid, unsigned int connect_mask); extern void hidinput_disconnect(struct hid_device *); void hidinput_reset_resume(struct hid_device *hid); -- 2.55.0.629.g250fe7f194-goog