From: alexandre.belloni@bootlin.com
To: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 19/19] rtc: abx80x: simplify locking
Date: Mon, 19 Oct 2026 23:18:20 +0200 [thread overview]
Message-ID: <20261019211827.126262-19-alexandre.belloni@bootlin.com> (raw)
In-Reply-To: <20261019211827.126262-1-alexandre.belloni@bootlin.com>
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
Use the ops_lock that is used by the core to lock operations. This ensures
we will never get any ABBA deadlock.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
drivers/rtc/rtc-abx80x.c | 27 +++++++--------------------
1 file changed, 7 insertions(+), 20 deletions(-)
diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
index 718e6b8555f5..1c69d0e2f940 100644
--- a/drivers/rtc/rtc-abx80x.c
+++ b/drivers/rtc/rtc-abx80x.c
@@ -15,7 +15,6 @@
#include <linux/i2c.h>
#include <linux/kstrtox.h>
#include <linux/module.h>
-#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/regmap.h>
#include <linux/rtc.h>
@@ -138,7 +137,6 @@ struct abx80x_priv {
struct rtc_device *rtc;
struct regmap *regmap;
struct watchdog_device wdog;
- struct mutex lock;
int irq;
};
@@ -249,8 +247,6 @@ static int abx80x_rtc_set_time(struct device *dev, struct rtc_time *tm)
buf[ABX8XX_REG_YR] = bin2bcd(tm->tm_year - 100);
buf[ABX8XX_REG_WD] = tm->tm_wday;
- guard(mutex)(&priv->lock);
-
err = regmap_bulk_write(priv->regmap, ABX8XX_REG_HTH, buf,
sizeof(buf));
if (err < 0) {
@@ -274,7 +270,7 @@ static irqreturn_t abx80x_handle_irq(int irq, void *dev_id)
unsigned int status, status_flags_clear;
int err;
- guard(mutex)(&priv->lock);
+ guard(rtc_ops)(rtc);
err = regmap_read(priv->regmap, ABX8XX_REG_STATUS, &status);
if (err < 0)
@@ -349,8 +345,6 @@ static int abx80x_set_alarm(struct device *dev, struct rtc_wkalrm *t)
alarm[4] = bin2bcd(t->time.tm_mday);
alarm[5] = bin2bcd(t->time.tm_mon + 1);
- guard(mutex)(&priv->lock);
-
err = regmap_bulk_write(priv->regmap, ABX8XX_REG_AHTH,
alarm, sizeof(alarm));
if (err < 0) {
@@ -391,7 +385,7 @@ static int abx80x_rtc_set_autocalibration(struct device *dev,
flags |= (ABX8XX_OSC_ACAL_1024 | ABX8XX_OSC_ACAL_512);
}
- guard(mutex)(&priv->lock);
+ guard(rtc_ops)(priv->rtc);
/* Unlock write access to Oscillator Control Register */
if (abx80x_write_config_key(dev, ABX8XX_CFG_KEY_OSC) < 0)
@@ -473,7 +467,7 @@ static ssize_t oscillator_store(struct device *dev,
return -EINVAL;
}
- guard(mutex)(&priv->lock);
+ guard(rtc_ops)(priv->rtc);
/* Unlock write access on Oscillator Control register */
if (abx80x_write_config_key(dev->parent, ABX8XX_CFG_KEY_OSC) < 0)
@@ -523,8 +517,6 @@ static int abx80x_alarm_irq_enable(struct device *dev, unsigned int enabled)
struct abx80x_priv *priv = dev_get_drvdata(dev);
int err;
- guard(mutex)(&priv->lock);
-
if (enabled)
err = regmap_write(priv->regmap, ABX8XX_REG_IRQ,
ABX8XX_IRQ_IM_1_4 | ABX8XX_IRQ_AIE);
@@ -551,10 +543,8 @@ static int abx80x_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
return put_user(tmp, (unsigned int __user *)arg);
case RTC_VL_CLR:
- scoped_guard(mutex, &priv->lock) {
- err = regmap_update_bits(priv->regmap, ABX8XX_REG_STATUS,
- ABX8XX_STATUS_BLF, 0);
- }
+ err = regmap_update_bits(priv->regmap, ABX8XX_REG_STATUS,
+ ABX8XX_STATUS_BLF, 0);
return err;
@@ -623,7 +613,7 @@ static int __abx80x_wdog_set_timeout(struct watchdog_device *wdog,
struct abx80x_priv *priv = watchdog_get_drvdata(wdog);
u8 val = ABX8XX_WDT_WDS | timeout_bits(timeout);
- guard(mutex)(&priv->lock);
+ guard(rtc_ops)(priv->rtc);
/*
* Writing any timeout to the WDT register resets the watchdog timer.
@@ -710,7 +700,7 @@ static int abx80x_nvmem_xfer(struct abx80x_priv *priv, unsigned int offset,
len = min(lower + bytes, (size_t)ABX8XX_SRAM_WIN_SIZE) - lower;
len = min_t(u8, len, I2C_SMBUS_BLOCK_MAX);
- guard(mutex)(&priv->lock);
+ guard(rtc_ops)(priv->rtc);
ret = regmap_update_bits(priv->regmap, ABX8XX_REG_EXTRAM,
ABX8XX_EXTRAM_XADS, upper);
@@ -806,9 +796,6 @@ static int abx80x_probe(struct device *dev, struct regmap *regmap, int irq,
priv->rtc->ops = &abx80x_rtc_ops;
priv->irq = irq;
priv->regmap = regmap;
- err = devm_mutex_init(dev, &priv->lock);
- if (err)
- return err;
dev_set_drvdata(dev, priv);
--
2.56.0
prev parent reply other threads:[~2026-10-19 21:19 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 21:18 [PATCH 01/19] rtc: introduce rtc_device.ops_lock guard() alexandre.belloni
2026-10-19 21:18 ` [PATCH 02/19] rtc: ac100: use guard alexandre.belloni
2026-10-19 21:18 ` [PATCH 03/19] rtc: asm9260: " alexandre.belloni
2026-10-19 21:18 ` [PATCH 04/19] rtc: atcrtc100: " alexandre.belloni
2026-10-19 21:18 ` [PATCH 05/19] rtc: ds1305: " alexandre.belloni
2026-10-19 21:18 ` [PATCH 06/19] rtc: ds1307: " alexandre.belloni
2026-10-19 21:18 ` [PATCH 07/19] rtc: ds1343: " alexandre.belloni
2026-10-19 21:18 ` [PATCH 08/19] rtc: ds1685: " alexandre.belloni
2026-10-19 21:18 ` [PATCH 09/19] rtc: ds3232: " alexandre.belloni
2026-10-19 21:18 ` [PATCH 10/19] rtc: hym8563: " alexandre.belloni
2026-10-19 21:18 ` [PATCH 11/19] rtc: m41t80: " alexandre.belloni
2026-10-19 21:18 ` [PATCH 12/19] rtc: mcp795: " alexandre.belloni
2026-10-19 21:18 ` [PATCH 13/19] rtc: nct6694: " alexandre.belloni
2026-10-19 21:18 ` [PATCH 14/19] rtc: pcf2123: " alexandre.belloni
2026-10-19 21:18 ` [PATCH 15/19] rtc: rv3029c2: " alexandre.belloni
2026-10-19 21:18 ` [PATCH 16/19] rtc: rx8010: " alexandre.belloni
2026-10-19 21:18 ` [PATCH 17/19] rtc: rx8025: " alexandre.belloni
2026-10-19 21:18 ` [PATCH 18/19] rtc: stm32: " alexandre.belloni
2026-10-19 21:18 ` alexandre.belloni [this message]
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=20261019211827.126262-19-alexandre.belloni@bootlin.com \
--to=alexandre.belloni@bootlin.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
/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
all inboxes | Powered by JetHome®