From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BCAF3FF1B4; Tue, 13 Oct 2026 09:12:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791882776; cv=none; b=XzijYMn7y4Abc/ahRJwOqf0QKr5cn5c4K97lF7G0NMyvtvCFHSWbalxZiVaGDJ8B8dKuG6IIBBw/++G9Xyy36S4TisIDjcp5mGWKJsNbHLVHgrMghz6nYpbcutyLmgsA4TipMEaU4L24LaBoC3qDdmwQKIF/iGUMF3nAAjGdG+U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791882776; c=relaxed/simple; bh=1SofSJHDkmVGcMDJ5Xa/cP7Osut8S4n5Ff6WylW6E4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Km9B4uPIR1jRl4IgRK7tedlmFdMIg8UPvuiiD5KfHPYfqQJDUbi0sg7QB0nTqoSNf5FR/yohrQlbVHURUdNmJY506m36XZplUc4cMsSwS9ilJRj2YFeiWzSgAMRDwtTqMonFiMk8RpIk37AfZWAJuORzUJX3L+c4zEKb1e1PdvU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QuaZxomZ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QuaZxomZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A858E1F008A2; Tue, 13 Oct 2026 09:12:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1791882774; bh=fwPPwvuvYiLSXcOi4+s3q3exvamLfRyPh6VSPHNi9wY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QuaZxomZLWnuN6UPkGWmpadTP/p4MQZALynwXnnXm1NmASkPheRXaoyowa+e3jc8P d8c812hdf1pOXb8ONdar7VpS2g5flg0AWHPF+uLHrCBNhcwp+WnD+i15jVGaNPmNOZ Qx2UkbZf3KWu1+3ioa5wTG6HWrBxrDSG5JQqcR3xF17WW9HdQKN925W1dffqc6idCV KTy5uV1/MLtSUbu+Xy2eC9X+MSJm6cTt97A117O91lz1LWRPwkw4ZpSp1lNKnf9+D0 phoQEygH4i0ZyaRV3irCKbpGRX7xEDIJnaoxuOUhDsSC/uf649plzw7z14jkd3Q/z+ TZ7nBx6+lthIw== From: Lee Jones To: lee@kernel.org, Jiri Kosina , Benjamin Tissoires , Vicki Pfau , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org, Jiri Kosina Subject: [STABLE v6.1 3/6] HID: steam: Fully unregister controller when hidraw is opened Date: Tue, 13 Oct 2026 09:11:59 +0000 Message-ID: <20261013091204.529049-3-lee@kernel.org> X-Mailer: git-send-email 2.56.0.385.gd3acb90ef8-goog In-Reply-To: <20261013091204.529049-1-lee@kernel.org> References: <20261013091204.529049-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Vicki Pfau [ Upstream commit cd33a91d37eb4d7c6ce56aa7f4688066309808eb ] To avoid conflicts between anything touching the hidraw and the driver we had previously detached the evdev nodes when the hidraw is opened. However, this isn't sufficient to avoid FEATURE reports from conflicting, so we change to fully unregistering the controller internally, leaving only the hidraw active until it's closed. This also unifies the unregister and connect callbacks, as now the logic between these two callbacks is identical. Signed-off-by: Vicki Pfau Signed-off-by: Jiri Kosina [Lee: Convert steam_client_ll_open() and steam_client_ll_close() to schedule work_connect directly and omit sensors, rumble_work, mode_switch and unregister_work changes as e133dc99fc07, e1147961b214 and 1d4549fd1115 are not present] Signed-off-by: Lee Jones --- drivers/hid/hid-steam.c | 78 ++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c index 4a0a13b0ae62..e8f28c59a303 100644 --- a/drivers/hid/hid-steam.c +++ b/drivers/hid/hid-steam.c @@ -380,6 +380,7 @@ static int steam_battery_register(struct steam_device *steam) &steam->battery_desc, &battery_cfg); if (IS_ERR(battery)) { ret = PTR_ERR(battery); + devm_kfree(&steam->hdev->dev, steam->battery_desc.name); hid_err(steam->hdev, "%s:power_supply_register failed with error %d\n", __func__, ret); @@ -504,12 +505,15 @@ static void steam_battery_unregister(struct steam_device *steam) RCU_INIT_POINTER(steam->battery, NULL); synchronize_rcu(); power_supply_unregister(battery); + devm_kfree(&steam->hdev->dev, steam->battery_desc.name); } static int steam_register(struct steam_device *steam) { int ret; unsigned long client_opened; + unsigned long flags; + bool do_add; /* * This function can be called several times in a row with the @@ -535,38 +539,47 @@ static int steam_register(struct steam_device *steam) if (steam->quirks & STEAM_QUIRK_WIRELESS) steam_battery_register(steam); - mutex_lock(&steam_devices_lock); - if (list_empty(&steam->list)) - list_add(&steam->list, &steam_devices); - mutex_unlock(&steam_devices_lock); + do_add = true; } - mutex_lock(&steam->mutex); + spin_lock_irqsave(&steam->lock, flags); client_opened = steam->client_opened; - if (!client_opened) - steam_set_lizard_mode(steam, lizard_mode); - mutex_unlock(&steam->mutex); + spin_unlock_irqrestore(&steam->lock, flags); - if (!client_opened) + if (!client_opened) { + mutex_lock(&steam->mutex); + steam_set_lizard_mode(steam, lizard_mode); + mutex_unlock(&steam->mutex); ret = steam_input_register(steam); - else - ret = 0; + if (ret != 0) + goto steam_register_input_fail; + } + if (do_add) { + mutex_lock(&steam_devices_lock); + if (list_empty(&steam->list)) + list_add(&steam->list, &steam_devices); + mutex_unlock(&steam_devices_lock); + } + return 0; + +steam_register_input_fail: return ret; } static void steam_unregister(struct steam_device *steam) { + if (!steam->serial_no[0]) + return; + + hid_info(steam->hdev, "Steam Controller '%s' disconnected", + steam->serial_no); steam_battery_unregister(steam); steam_input_unregister(steam); - if (steam->serial_no[0]) { - hid_info(steam->hdev, "Steam Controller '%s' disconnected", - steam->serial_no); - mutex_lock(&steam_devices_lock); - list_del_init(&steam->list); - mutex_unlock(&steam_devices_lock); - steam->serial_no[0] = 0; - } + mutex_lock(&steam_devices_lock); + list_del_init(&steam->list); + mutex_unlock(&steam_devices_lock); + steam->serial_no[0] = 0; } static void steam_work_connect_cb(struct work_struct *work) @@ -575,19 +588,20 @@ static void steam_work_connect_cb(struct work_struct *work) work_connect); unsigned long flags; bool connected; + bool opened; int ret; spin_lock_irqsave(&steam->lock, flags); + opened = steam->client_opened; connected = steam->connected; spin_unlock_irqrestore(&steam->lock, flags); - if (connected) { + if (connected && !opened) { ret = steam_register(steam); - if (ret) { + if (ret) hid_err(steam->hdev, "%s:steam_register failed with error %d\n", __func__, ret); - } } else { steam_unregister(steam); } @@ -632,12 +646,13 @@ static void steam_client_ll_stop(struct hid_device *hdev) static int steam_client_ll_open(struct hid_device *hdev) { struct steam_device *steam = hdev->driver_data; + unsigned long flags; - mutex_lock(&steam->mutex); + spin_lock_irqsave(&steam->lock, flags); steam->client_opened++; - mutex_unlock(&steam->mutex); + spin_unlock_irqrestore(&steam->lock, flags); - steam_input_unregister(steam); + schedule_work(&steam->work_connect); return 0; } @@ -645,22 +660,13 @@ static int steam_client_ll_open(struct hid_device *hdev) static void steam_client_ll_close(struct hid_device *hdev) { struct steam_device *steam = hdev->driver_data; - unsigned long flags; - bool connected; spin_lock_irqsave(&steam->lock, flags); - connected = steam->connected; - spin_unlock_irqrestore(&steam->lock, flags); - - mutex_lock(&steam->mutex); steam->client_opened--; - if (connected && !steam->client_opened) - steam_set_lizard_mode(steam, lizard_mode); - mutex_unlock(&steam->mutex); + spin_unlock_irqrestore(&steam->lock, flags); - if (connected && !steam->client_opened) - steam_input_register(steam); + schedule_work(&steam->work_connect); } static int steam_client_ll_raw_request(struct hid_device *hdev, -- 2.56.0.385.gd3acb90ef8-goog