Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2019-05-17 06:38:43 +0200
committerJiri Slaby <jslaby@suse.cz>2019-05-17 06:38:46 +0200
commit34feaf77101616d17459d56af9e5dd52faeb2be2 (patch)
tree0893c08db75ae4f6af22bf8bf4425d91156e871c
parentb83db21c221a6bf8b7fbcb648c0e003f6d53fbf4 (diff)
i2c: core: ratelimit 'transfer when suspended' errors
-rw-r--r--patches.kernel.org/5.1.3-007-i2c-core-ratelimit-transfer-when-suspended-erro.patch64
-rw-r--r--series.conf1
2 files changed, 65 insertions, 0 deletions
diff --git a/patches.kernel.org/5.1.3-007-i2c-core-ratelimit-transfer-when-suspended-erro.patch b/patches.kernel.org/5.1.3-007-i2c-core-ratelimit-transfer-when-suspended-erro.patch
new file mode 100644
index 0000000000..927bbbebc9
--- /dev/null
+++ b/patches.kernel.org/5.1.3-007-i2c-core-ratelimit-transfer-when-suspended-erro.patch
@@ -0,0 +1,64 @@
+From: Wolfram Sang <wsa+renesas@sang-engineering.com>
+Date: Thu, 25 Apr 2019 16:19:47 +0200
+Subject: [PATCH] i2c: core: ratelimit 'transfer when suspended' errors
+References: bnc#1012628
+Patch-mainline: 5.1.3
+Git-commit: 4db61c2a16fce2ef85d82751de4ba43a39347cfb
+
+commit 4db61c2a16fce2ef85d82751de4ba43a39347cfb upstream.
+
+There are two problems with WARN_ON() here. One: It is not ratelimited.
+Two: We don't see which adapter was used when trying to transfer
+something when already suspended. Implement a custom ratelimit once per
+adapter and use dev_WARN there. This fixes both issues. Drawback is that
+we don't see if multiple drivers are trying to transfer with the same
+adapter while suspended. They need to be discovered one after the other
+now. This is better than a high CPU load because a really broken driver
+might try to resend endlessly.
+
+Fixes: 9ac6cb5fbb17 ("i2c: add suspended flag and accessors for i2c adapters")
+Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
+Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
+Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
+Cc: stable@vger.kernel.org # v5.1+
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Signed-off-by: Jiri Slaby <jslaby@suse.cz>
+---
+ drivers/i2c/i2c-core-base.c | 5 ++++-
+ include/linux/i2c.h | 3 ++-
+ 2 files changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
+index 688aa3b5f3ac..2f0f88b79c4b 100644
+--- a/drivers/i2c/i2c-core-base.c
++++ b/drivers/i2c/i2c-core-base.c
+@@ -1871,8 +1871,11 @@ int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
+
+ if (WARN_ON(!msgs || num < 1))
+ return -EINVAL;
+- if (WARN_ON(test_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags)))
++ if (test_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags)) {
++ if (!test_and_set_bit(I2C_ALF_SUSPEND_REPORTED, &adap->locked_flags))
++ dev_WARN(&adap->dev, "Transfer while suspended\n");
+ return -ESHUTDOWN;
++ }
+
+ if (adap->quirks && i2c_check_for_quirks(adap, msgs, num))
+ return -EOPNOTSUPP;
+diff --git a/include/linux/i2c.h b/include/linux/i2c.h
+index 383510b4f083..646dd962d6a1 100644
+--- a/include/linux/i2c.h
++++ b/include/linux/i2c.h
+@@ -682,7 +682,8 @@ struct i2c_adapter {
+ int retries;
+ struct device dev; /* the adapter device */
+ unsigned long locked_flags; /* owned by the I2C core */
+-#define I2C_ALF_IS_SUSPENDED 0
++#define I2C_ALF_IS_SUSPENDED 0
++#define I2C_ALF_SUSPEND_REPORTED 1
+
+ int nr;
+ char name[48];
+--
+2.21.0
+
diff --git a/series.conf b/series.conf
index 3ba5acfc13..ff6e1dd39f 100644
--- a/series.conf
+++ b/series.conf
@@ -92,6 +92,7 @@
patches.kernel.org/5.1.3-004-hwmon-pwm-fan-Disable-PWM-if-fetching-cooling-d.patch
patches.kernel.org/5.1.3-005-hwmon-occ-Fix-extended-status-bits.patch
patches.kernel.org/5.1.3-006-selftests-seccomp-Handle-namespace-failures-gra.patch
+ patches.kernel.org/5.1.3-007-i2c-core-ratelimit-transfer-when-suspended-erro.patch
########################################################
# Build fixes that apply to the vanilla kernel too.