Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp151794rwb; Thu, 27 Jul 2023 10:37:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlFbPHLBQiybasg0Y6Ia9FKiwlgAcnrglAFIkRLW3fDfwDli8E0cx9efI4M2OY90VT6c0/Dv X-Received: by 2002:a17:902:f54a:b0:1b9:e972:134d with SMTP id h10-20020a170902f54a00b001b9e972134dmr25748plf.3.1690479426506; Thu, 27 Jul 2023 10:37:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690479426; cv=none; d=google.com; s=arc-20160816; b=QGLfOFqAtdrqkdSdJ8Z52+NnpMoxgbR+gRSUe5eWA1rlHW2r91j8xf0nDfTkIdHOhF 2XgBZMsOmhIh/FN6agiFimH83bHpXfpzBvJoaSOFTF8mq0oQ4+l02gAmtFtBRCN3WStH KUw9H2qdsb3TqovY+SZJB2Nov5DRKGuwENh0wEImetIqpOXt5pWfICpKcD2DZgWeFGb6 WVrtXj5uXeud0qK+Xj5X2c/T3E89vMeHIG4+GcgFTF4/N/JQMvvrvLl6b5O1h4EHRhY4 AQmxxmhTjpwK7tCVLfBCsBgZMIbgcwS6a1f/t6k8FzkBmVHPnY/A4sFGlO7Bct+h19A+ I4xw== 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=JE0/UXh96ihgYVclX63uFx20OU8KLkSmKPmtU0UMZZk=; fh=Pks6uESMALkm+FM9kM/YKp1n4hyLQKFUl8+AB2zSeNY=; b=RimxwYV5spqDaCobZcll0cAe7ERfc+uTkYDzx/3Ig9cLzjpru0iVg4kU7qDPIYNvri FWOcv072W4dN5iayAhwlDVuhlNJveaCes3Wu1wYRZKSI2dtNDmX5lI3X+TPI76SCSHgm zq3WHIJzluQ+VvvG1IeIbRiMO+OeqvqbvLW8pDcEUCfi2x5mO+jgPC3QKWi8djT4Cbui ODWlTsmM/bnZ5Bqt2up5rT4ygGGBCGbKYtxrFY5iETMlEa2oqwKBuc2kCMPXG7gRyGe4 /Lh1O6wCYpRc5jmRv8EBd5ei7txDxVBJRjmJKP26y1X5DtFsj5MJnJaSSFKJ1CQ23jcn fvSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jFm7Y3pV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u5-20020a17090282c500b001bb3499d8besi1525989plz.478.2023.07.27.10.36.54; Thu, 27 Jul 2023 10:37:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jFm7Y3pV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233344AbjG0RTe (ORCPT + 99 others); Thu, 27 Jul 2023 13:19:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232433AbjG0RTS (ORCPT ); Thu, 27 Jul 2023 13:19:18 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B6A33AA3 for ; Thu, 27 Jul 2023 10:18:49 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-686d8c8fc65so962360b3a.0 for ; Thu, 27 Jul 2023 10:18:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1690478329; x=1691083129; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JE0/UXh96ihgYVclX63uFx20OU8KLkSmKPmtU0UMZZk=; b=jFm7Y3pVztqxRpdquGXn2GCDPzKNRJczGTzTOaX187e/SfwDrJBxSzzonbM4Bjz+P9 uEOhwdf/+JdRdT+MJHMzWK1WoaFhvxbd3DqXDhNFE9w32cSkuiw7MFJ6oFNQT3Vcy2p+ zzRxkIHv7qezN3fHVjV8gV3aAnNQYniV7Lb+8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690478329; x=1691083129; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JE0/UXh96ihgYVclX63uFx20OU8KLkSmKPmtU0UMZZk=; b=gQJ4C8UUAjT8WPA416GwVfFFLLJFZbVcwk5OX31umCILGGTPtZYZhtWmbJbcl42+Xh odVnBUpvIF2yv5fP8fozFS6P8M8zmKoxy/dRfaHOzL+AdxsYJwcaLLO1L+1NTurFucBD /wwKPuVHd738yx90kLPwgWnHHgb2gp984PGsoNrWEDl+9lsKejvkQ0CnyfRXNMn2TmmX pMPy1Qa7XGtklNxz/u1rc/fAfk+N+uU9Y58Ad3ofmU+rLMkFdYf365IM9vArg0fmlphl wzTr3nHvw//+kF8QdcSCpEXDqCLLOLGHC3msc8iC6NnUtbSIjWutJ5QLVGh44G2VNPh8 6v5g== X-Gm-Message-State: ABy/qLZu9IcpwihIHPPa6OWyIxOUnsIdfLGKCt4R9aJvGRB20hnJ/3wV wY/f8iPOACH+Q9tyV3idPdcUrw== X-Received: by 2002:a05:6a00:15cb:b0:686:be77:4311 with SMTP id o11-20020a056a0015cb00b00686be774311mr5711310pfu.4.1690478329127; Thu, 27 Jul 2023 10:18:49 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:2339:954b:b98f:611a]) by smtp.gmail.com with ESMTPSA id 17-20020aa79111000000b0064f76992905sm1702524pfh.202.2023.07.27.10.18.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 10:18:48 -0700 (PDT) From: Douglas Anderson To: Jiri Kosina , Benjamin Tissoires , Bjorn Andersson , Konrad Dybcio , Rob Herring , Frank Rowand , Krzysztof Kozlowski , Conor Dooley , Neil Armstrong , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann Cc: linux-arm-msm@vger.kernel.org, yangcong5@huaqin.corp-partner.google.com, devicetree@vger.kernel.org, Daniel Vetter , hsinyi@google.com, Chris Morgan , linux-input@vger.kernel.org, cros-qcom-dts-watchers@chromium.org, Dmitry Torokhov , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Douglas Anderson Subject: [PATCH v4 08/11] HID: i2c-hid: Suspend i2c-hid devices in remove Date: Thu, 27 Jul 2023 10:16:35 -0700 Message-ID: <20230727101636.v4.8.Ic3ecad4a825905f4e4ce2a772b17f3c9cb2d60a2@changeid> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230727171750.633410-1-dianders@chromium.org> References: <20230727171750.633410-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 In the i2c-hid remove() function we currently try to power off, depopulate our child device, and free our resources. That's OK, but... * If the i2c-hid device is on a power rail that can't turn off (either an always-on or a shared power rail) we won't try to put the device in a low power state during remove(). This probably doesn't matter for very many devices but it could be nice in some instances. * If the i2c-hid device somehow manages to generate an interrupt after we tried to power off it is conceivable that the interrupt could arrive during or after the call to hid_destroy_device() but before the call to free_irq(). That could cause a crash since our IRQ handler isn't expecting it. One could imagine this happening in the case where we couldn't turn off (see the previous bullet) or, possibly, if the interrupt line could glitch shortly after the device powered off. Let's call the suspend code during remove to avoid these issues. That will put the device into a low power state and also disable interrupts. Technically, one could consider this a "fix" of commit 4a200c3b9a40 ("HID: i2c-hid: introduce HID over i2c specification implementation"). However, since the above bullet points are more theoretical than problems seen on real systems and since the remove() of an i2c-hid touchscreen isn't terribly likely to be called in production, it's probably not worth the bother of trying to backport it. Signed-off-by: Douglas Anderson --- Changes in v4: - ("Suspend i2c-hid devices in remove") new for v4. drivers/hid/i2c-hid/i2c-hid-core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c index fa8a1ca43d7f..46658ed6380f 100644 --- a/drivers/hid/i2c-hid/i2c-hid-core.c +++ b/drivers/hid/i2c-hid/i2c-hid-core.c @@ -941,7 +941,7 @@ static void i2c_hid_core_shutdown_tail(struct i2c_hid *ihid) ihid->ops->shutdown_tail(ihid->ops); } -static int i2c_hid_core_suspend(struct i2c_hid *ihid) +static int i2c_hid_core_suspend(struct i2c_hid *ihid, bool force_poweroff) { struct i2c_client *client = ihid->client; struct hid_device *hid = ihid->hid; @@ -956,7 +956,7 @@ static int i2c_hid_core_suspend(struct i2c_hid *ihid) disable_irq(client->irq); - if (!device_may_wakeup(&client->dev)) + if (force_poweroff || !device_may_wakeup(&client->dev)) i2c_hid_core_power_down(ihid); return 0; @@ -1143,7 +1143,7 @@ void i2c_hid_core_remove(struct i2c_client *client) struct i2c_hid *ihid = i2c_get_clientdata(client); struct hid_device *hid; - i2c_hid_core_power_down(ihid); + i2c_hid_core_suspend(ihid, true); hid = ihid->hid; hid_destroy_device(hid); @@ -1171,7 +1171,7 @@ static int i2c_hid_core_pm_suspend(struct device *dev) struct i2c_client *client = to_i2c_client(dev); struct i2c_hid *ihid = i2c_get_clientdata(client); - return i2c_hid_core_suspend(ihid); + return i2c_hid_core_suspend(ihid, false); } static int i2c_hid_core_pm_resume(struct device *dev) -- 2.41.0.487.g6d72f3e995-goog