From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org,
Troy Kisky <troy.kisky@boundarydevices.com>,
Alexandre Belloni <alexandre.belloni@free-electrons.com>,
Christoph Fritz <chf.fritz@googlemail.com>
Subject: [PATCH 4.14 12/14] rtc: m41t80: avoid i2c read in m41t80_sqw_recalc_rate
Date: Thu, 4 Jan 2018 13:09:29 +0100 [thread overview]
Message-ID: <20180104120918.648354012@linuxfoundation.org> (raw)
In-Reply-To: <20180104120917.043667757@linuxfoundation.org>
4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Troy Kisky <troy.kisky@boundarydevices.com>
commit 2cb90ed3de1e279dbaf23df141f54eb9fb1861e6 upstream.
This is a little more efficient, and avoids the warning
WARNING: possible circular locking dependency detected
4.14.0-rc7-00007 #14 Not tainted
------------------------------------------------------
alsactl/330 is trying to acquire lock:
(prepare_lock){+.+.}, at: [<c049300c>] clk_prepare_lock+0x80/0xf4
but task is already holding lock:
(i2c_register_adapter){+.+.}, at: [<c0690ae0>]
i2c_adapter_lock_bus+0x14/0x18
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (i2c_register_adapter){+.+.}:
rt_mutex_lock+0x44/0x5c
i2c_adapter_lock_bus+0x14/0x18
i2c_transfer+0xa8/0xbc
i2c_smbus_xfer+0x20c/0x5d8
i2c_smbus_read_byte_data+0x38/0x48
m41t80_sqw_recalc_rate+0x24/0x58
Signed-off-by: Troy Kisky <troy.kisky@boundarydevices.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: Christoph Fritz <chf.fritz@googlemail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/rtc/rtc-m41t80.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -154,6 +154,7 @@ struct m41t80_data {
struct rtc_device *rtc;
#ifdef CONFIG_COMMON_CLK
struct clk_hw sqw;
+ unsigned long freq;
#endif
};
@@ -443,26 +444,28 @@ static SIMPLE_DEV_PM_OPS(m41t80_pm, m41t
#ifdef CONFIG_COMMON_CLK
#define sqw_to_m41t80_data(_hw) container_of(_hw, struct m41t80_data, sqw)
-static unsigned long m41t80_sqw_recalc_rate(struct clk_hw *hw,
- unsigned long parent_rate)
+static unsigned long m41t80_decode_freq(int setting)
+{
+ return (setting == 0) ? 0 : (setting == 1) ? M41T80_SQW_MAX_FREQ :
+ M41T80_SQW_MAX_FREQ >> setting;
+}
+
+static unsigned long m41t80_get_freq(struct m41t80_data *m41t80)
{
- struct m41t80_data *m41t80 = sqw_to_m41t80_data(hw);
struct i2c_client *client = m41t80->client;
int reg_sqw = (m41t80->features & M41T80_FEATURE_SQ_ALT) ?
M41T80_REG_WDAY : M41T80_REG_SQW;
int ret = i2c_smbus_read_byte_data(client, reg_sqw);
- unsigned long val = M41T80_SQW_MAX_FREQ;
if (ret < 0)
return 0;
+ return m41t80_decode_freq(ret >> 4);
+}
- ret >>= 4;
- if (ret == 0)
- val = 0;
- else if (ret > 1)
- val = val / (1 << ret);
-
- return val;
+static unsigned long m41t80_sqw_recalc_rate(struct clk_hw *hw,
+ unsigned long parent_rate)
+{
+ return sqw_to_m41t80_data(hw)->freq;
}
static long m41t80_sqw_round_rate(struct clk_hw *hw, unsigned long rate,
@@ -505,6 +508,8 @@ static int m41t80_sqw_set_rate(struct cl
reg = (reg & 0x0f) | (val << 4);
ret = i2c_smbus_write_byte_data(client, reg_sqw, reg);
+ if (!ret)
+ m41t80->freq = m41t80_decode_freq(val);
return ret;
}
@@ -579,6 +584,7 @@ static struct clk *m41t80_sqw_register_c
init.parent_names = NULL;
init.num_parents = 0;
m41t80->sqw.init = &init;
+ m41t80->freq = m41t80_get_freq(m41t80);
/* optional override of the clockname */
of_property_read_string(node, "clock-output-names", &init.name);
next prev parent reply other threads:[~2018-01-04 12:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-04 12:09 [PATCH 4.14 00/14] 4.14.12-stable review Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 01/14] exec: Weaken dumpability for secureexec Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 02/14] capabilities: fix buffer overread on very short xattr Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 03/14] x86/cpu, x86/pti: Do not enable PTI on AMD processors Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 04/14] x86/pti: Make sure the user/kernel PTEs match Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 07/14] x86/pti: Switch to kernel CR3 at early in entry_SYSCALL_compat() Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 08/14] x86/process: Define cpu_tss_rw in same section as declaration Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 09/14] Revert "xfrm: Fix stack-out-of-bounds read in xfrm_state_find." Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 10/14] rtc: m41t80: m41t80_sqw_set_rate should return 0 on success Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 11/14] rtc: m41t80: fix m41t80_sqw_round_rate return value Greg Kroah-Hartman
2018-01-04 12:09 ` Greg Kroah-Hartman [this message]
2018-01-04 12:09 ` [PATCH 4.14 13/14] rtc: m41t80: avoid i2c read in m41t80_sqw_is_prepared Greg Kroah-Hartman
2018-01-04 12:09 ` [PATCH 4.14 14/14] rtc: m41t80: remove unneeded checks from m41t80_sqw_set_rate Greg Kroah-Hartman
2018-01-04 18:52 ` [PATCH 4.14 00/14] 4.14.12-stable review Guenter Roeck
2018-01-05 12:13 ` Greg Kroah-Hartman
2018-01-04 19:46 ` Dan Rue
2018-01-05 8:04 ` Greg Kroah-Hartman
2018-01-04 22:03 ` Shuah Khan
[not found] ` <5a4e68a8.e4a0df0a.b9e2d.7b39@mx.google.com>
[not found] ` <7h4lo12mfk.fsf@baylibre.com>
2018-01-05 7:55 ` Greg Kroah-Hartman
2018-01-08 14:58 ` Guillaume Tucker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180104120918.648354012@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=alexandre.belloni@free-electrons.com \
--cc=chf.fritz@googlemail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=troy.kisky@boundarydevices.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).