Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3281715lfo; Mon, 23 May 2022 00:37:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymr3BnBGu1vlkMgLVN4GHWs+eZ5yckD/qQ15DK18BbCebb8J34st+tqn1i4LJeQpMws2bA X-Received: by 2002:a17:902:b402:b0:162:29a3:9331 with SMTP id x2-20020a170902b40200b0016229a39331mr2809628plr.59.1653291424136; Mon, 23 May 2022 00:37:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653291424; cv=none; d=google.com; s=arc-20160816; b=BiaKD9CvU4o3306pgrFvRV0DtTVywlGyYrPUnXNRrH+mqnhG9T7kNLz90ZBgcXugcY yZHEacve7EZYFGVChrSgLGjNoM/O+e0EfXzqWQ8m8fCZS0m/RjJcaI7d8b2ITEoovO2w hFFjcTJYFmj1nY5yF6fmaC7H6YoB7k5Mvt1PSgQOhgMdHQ5/LrK7YzZDUmsXBgfDDpCv ZYx6q4yEnG2yIpLPgs2tVHSfLe9wxgZx+quVK2z3FFZim9HfO+s0esAwZX09gDnGoWkp GZspFKYoguJNSOGL1xyA0lBw0bFQDHyNHqGNTPgVB3F4Y9pAeDpZXt8aBPPpNWMVY9Wj KvAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qUjvuoWXG9UUtB5iaUNqYFk22P1RS1LUvWgzlAZCFx8=; b=eekQmstudltFTyiGNxSZ3prbNXVJhkDHRWS9M864OVpY8ZnICGV2e5/xCiSacVqhYo +CKgkOeBfnIZHJI4YqTAqNFep9irchMx7G+takVpD/zaAS+HsApiiCApVujaoDaLeCXR I5rgxy0stricPC6vLb5RHqWQ/HzLRZdt8aDgBnkGwh0WXzlZz83Jze2/JeB/Ujw2d5A+ 4fmJ72mbuPbv5VOU7y0GJeu4ygCjTsiN2HmtrHMUfgZ7Z48LZBT0GpBS0AYdo3mYvlha /BnarnBOuVXPEVZO871/ItpF/kM3zw+B1w9lEnHODqTw5t11hAtSJVY37L8imc5pLU9m zU4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cxNMpTAF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w2-20020a170902a70200b0016157654cf4si8858594plq.227.2022.05.23.00.37.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 00:37:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cxNMpTAF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B69FB1C94C3; Sun, 22 May 2022 23:47:05 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352842AbiETSfh (ORCPT + 99 others); Fri, 20 May 2022 14:35:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352752AbiETSet (ORCPT ); Fri, 20 May 2022 14:34:49 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E286166697; Fri, 20 May 2022 11:34:48 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id u3so12626555wrg.3; Fri, 20 May 2022 11:34:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qUjvuoWXG9UUtB5iaUNqYFk22P1RS1LUvWgzlAZCFx8=; b=cxNMpTAFuWKDIhN2tjtgTzcHUBXt6OLUdjX8CkMUG4ILZdFepZBnJGh78f/U+ubgbK QEXqE2+NWORsqQ/LDWmesBeli9Yri9oXsfVwkU9T/BCYB/VdAXwXs1uO9X5YO+W4ozxT +cWJGLN+TCd0UrT4fKmiLNIu0+HrHlPgrjt2Jm124P7EWb1UMnWaUVsnEqObXTq3kEUz poL6P8AgOZIf40734QR64IOAuL1uN5lcIsH1uLLRDBuvYIPgN5o/8vrgHjW1y0rn71Ja rJKbeZC7cG626vR96Sdje2lKqBMm9M31UngT8JLc1Pasb7kRiIpsr/GB3tNh998kIU9v 2YQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qUjvuoWXG9UUtB5iaUNqYFk22P1RS1LUvWgzlAZCFx8=; b=rn9Z/jsAUCZvAcTdkOMtFWjBnAMbiDnaHiUN3ASQvsBAAXNYBpmftt228nPtj+E9cN rfsuvuA2cJpFITxWg0Jlz2O+7R3X1Lmpl5s8DQka61a+diOIHqTUqNBF4E3vFDoW0RKg 70YZk4J8m7KKRx8Fn3YTDgXKdBo6U9vNJolXgsuje5UnWVadkijBsbPawQkgaJ8gEvOs y3cxZdQjsmPRVS6XTZfe6FY6fXYvdGPBOF+HrD0ySs8SQ9BZPDPPw1mXRrpizki94x69 i7g5jcvetfPoleDNp+Uaas/Wefm9jR6Sh0x5V8aE/Y6R1t8T1ggJOUQhX8X7P/Pt6Muw fR4g== X-Gm-Message-State: AOAM53261GUTIWzYQWLZwH5Wr7CD6e7PgChjXTdQzyUdzMGLUocyGUtb /Lzpy8oLqOo9CH5OHfDlz9k= X-Received: by 2002:adf:ebce:0:b0:20d:7859:494d with SMTP id v14-20020adfebce000000b0020d7859494dmr9301298wrn.590.1653071687104; Fri, 20 May 2022 11:34:47 -0700 (PDT) Received: from xws.localdomain (pd9e5a9fe.dip0.t-ipconnect.de. [217.229.169.254]) by smtp.gmail.com with ESMTPSA id r9-20020adfa149000000b0020e62feca05sm3252081wrr.32.2022.05.20.11.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 11:34:46 -0700 (PDT) From: Maximilian Luz To: Hans de Goede , Jiri Kosina Cc: Maximilian Luz , Mark Gross , Benjamin Tissoires , platform-driver-x86@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/10] HID: surface-hid: Add support for hot-removal Date: Fri, 20 May 2022 20:34:18 +0200 Message-Id: <20220520183422.7185-7-luzmaximilian@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220520183422.7185-1-luzmaximilian@gmail.com> References: <20220520183422.7185-1-luzmaximilian@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for hot-removal of SSAM HID client devices. Once a device has been hot-removed, further communication with it should be avoided as it may fail and time out. While the device will be removed as soon as we detect hot-removal, communication may still occur during teardown, especially when unregistering notifiers. While hot-removal is a surprise event that can happen at any time, try to avoid communication as much as possible once it has been detected to prevent timeouts that can slow down device removal and cause issues, e.g. when quickly re-attaching the device. Signed-off-by: Maximilian Luz --- drivers/hid/surface-hid/surface_hid_core.c | 38 +++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/hid/surface-hid/surface_hid_core.c b/drivers/hid/surface-hid/surface_hid_core.c index e46330b2e561..87637f813de2 100644 --- a/drivers/hid/surface-hid/surface_hid_core.c +++ b/drivers/hid/surface-hid/surface_hid_core.c @@ -19,12 +19,30 @@ #include "surface_hid_core.h" +/* -- Utility functions. ---------------------------------------------------- */ + +static bool surface_hid_is_hot_removed(struct surface_hid_device *shid) +{ + /* + * Non-ssam client devices, i.e. platform client devices, cannot be + * hot-removed. + */ + if (!is_ssam_device(shid->dev)) + return false; + + return ssam_device_is_hot_removed(to_ssam_device(shid->dev)); +} + + /* -- Device descriptor access. --------------------------------------------- */ static int surface_hid_load_hid_descriptor(struct surface_hid_device *shid) { int status; + if (surface_hid_is_hot_removed(shid)) + return -ENODEV; + status = shid->ops.get_descriptor(shid, SURFACE_HID_DESC_HID, (u8 *)&shid->hid_desc, sizeof(shid->hid_desc)); if (status) @@ -61,6 +79,9 @@ static int surface_hid_load_device_attributes(struct surface_hid_device *shid) { int status; + if (surface_hid_is_hot_removed(shid)) + return -ENODEV; + status = shid->ops.get_descriptor(shid, SURFACE_HID_DESC_ATTRS, (u8 *)&shid->attrs, sizeof(shid->attrs)); if (status) @@ -88,9 +109,18 @@ static int surface_hid_start(struct hid_device *hid) static void surface_hid_stop(struct hid_device *hid) { struct surface_hid_device *shid = hid->driver_data; + bool hot_removed; + + /* + * Communication may fail for devices that have been hot-removed. This + * also includes unregistration of HID events, so we need to check this + * here. Only if the device has not been marked as hot-removed, we can + * safely disable events. + */ + hot_removed = surface_hid_is_hot_removed(shid); /* Note: This call will log errors for us, so ignore them here. */ - ssam_notifier_unregister(shid->ctrl, &shid->notif); + __ssam_notifier_unregister(shid->ctrl, &shid->notif, !hot_removed); } static int surface_hid_open(struct hid_device *hid) @@ -109,6 +139,9 @@ static int surface_hid_parse(struct hid_device *hid) u8 *buf; int status; + if (surface_hid_is_hot_removed(shid)) + return -ENODEV; + buf = kzalloc(len, GFP_KERNEL); if (!buf) return -ENOMEM; @@ -126,6 +159,9 @@ static int surface_hid_raw_request(struct hid_device *hid, unsigned char reportn { struct surface_hid_device *shid = hid->driver_data; + if (surface_hid_is_hot_removed(shid)) + return -ENODEV; + if (rtype == HID_OUTPUT_REPORT && reqtype == HID_REQ_SET_REPORT) return shid->ops.output_report(shid, reportnum, buf, len); -- 2.36.1