[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230727101636.v4.8.Ic3ecad4a825905f4e4ce2a772b17f3c9cb2d60a2@changeid>
Date: Thu, 27 Jul 2023 10:16:35 -0700
From: Douglas Anderson <dianders@...omium.org>
To: Jiri Kosina <jikos@...nel.org>,
Benjamin Tissoires <benjamin.tissoires@...hat.com>,
Bjorn Andersson <andersson@...nel.org>,
Konrad Dybcio <konrad.dybcio@...aro.org>,
Rob Herring <robh+dt@...nel.org>,
Frank Rowand <frowand.list@...il.com>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
Conor Dooley <conor+dt@...nel.org>,
Neil Armstrong <neil.armstrong@...aro.org>,
Sam Ravnborg <sam@...nborg.org>,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Maxime Ripard <mripard@...nel.org>,
Thomas Zimmermann <tzimmermann@...e.de>
Cc: linux-arm-msm@...r.kernel.org,
yangcong5@...qin.corp-partner.google.com,
devicetree@...r.kernel.org, Daniel Vetter <daniel@...ll.ch>,
hsinyi@...gle.com, Chris Morgan <macroalpha82@...il.com>,
linux-input@...r.kernel.org, cros-qcom-dts-watchers@...omium.org,
Dmitry Torokhov <dmitry.torokhov@...il.com>,
linux-kernel@...r.kernel.org, dri-devel@...ts.freedesktop.org,
Douglas Anderson <dianders@...omium.org>
Subject: [PATCH v4 08/11] HID: i2c-hid: Suspend i2c-hid devices in remove
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 <dianders@...omium.org>
---
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
Powered by blists - more mailing lists