Linux RTC
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Antoni Pokusinski" <apokusinski01@gmail.com>
Cc: robh@kernel.org, devicetree@vger.kernel.org,
	linux-rtc@vger.kernel.org,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	conor+dt@kernel.org
Subject: Re: [PATCH v3 6/8] rtc: abx80x: replace read-modify-write pattern with regmap helpers
Date: Fri, 31 Jul 2026 19:01:37 +0000	[thread overview]
Message-ID: <20260731190137.E8A701F00AC4@smtp.kernel.org> (raw)
In-Reply-To: <20260731184831.44037-7-apokusinski01@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Using `guard(mutex)` inside a `switch` statement case without an enclosing block causes a compilation failure (or uninitialized cleanup execution).
- [High] Configuration Key unlock sequence is broken by unprotected concurrent reads and newly introduced read-modify-write regmap helpers.
--

--- Patch [6]: [PATCH v3 6/8] rtc: abx80x: replace read-modify-write pattern with regmap helpers ---
commit 68e1add63890d6b130ad7ce142d172f06e590b90
Author: Antoni Pokusinski <apokusinski01@gmail.com>

rtc: abx80x: replace read-modify-write pattern with regmap helpers

This commit replaces manual read-modify-write register operations in the 
rtc-abx80x driver with regmap_update_bits() and regmap_write_bits() 
functions to simplify the code.

> diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
> index 23823fc2f5458..52f958e2aecd2 100644
> --- a/drivers/rtc/rtc-abx80x.c
> +++ b/drivers/rtc/rtc-abx80x.c
[ ... ]
> @@ -371,7 +364,7 @@ static int abx80x_rtc_set_autocalibration(struct device *dev,
>  					  int autocalibration)
>  {
[ ... ]
>  	/* Unlock write access to Oscillator Control Register */
>  	if (abx80x_write_config_key(dev, ABX8XX_CFG_KEY_OSC) < 0)
>  		return -EIO;
>  
> -	retval = regmap_write(priv->regmap, ABX8XX_REG_OSC, flags);
> -
> -	return retval;
> +	return regmap_write_bits(priv->regmap, ABX8XX_REG_OSC,
> +				 ABX8XX_OSC_ACAL_1024 | ABX8XX_OSC_ACAL_512,
> +				 flags);
>  }

[Severity: High]
Does switching to regmap_write_bits() break the configuration key unlock
sequence here?

The hardware requires writing the configuration key immediately before 
writing a protected register. If any other register is accessed in between, 
the unlock state is cleared. 

Because regmap_write_bits() performs a read operation internally before 
writing, does that read happen after the configuration key is written,
causing the hardware to relock itself before the write can execute?

Additionally, can an unlocked concurrent read sequence interleave here and
clear the unlock state? Looking at abx80x_rtc_read_time(), it performs I2C 
reads without taking priv->lock:

abx80x_rtc_read_time() {
    ...
    err = regmap_bulk_read(priv->regmap, ABX8XX_REG_HTH, buf, sizeof(buf));
    ...
}

[ ... ]
> @@ -566,17 +545,8 @@ static int abx80x_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
>  	case RTC_VL_CLR:
>  		guard(mutex)(&priv->lock);
>  
> -		err = regmap_read(priv->regmap, ABX8XX_REG_STATUS, &status);
> -		if (err < 0)
> -			return err;
> -
> -		status &= ~ABX8XX_STATUS_BLF;
> -
> -		err = regmap_write(priv->regmap, ABX8XX_REG_STATUS, status);
> -		if (err < 0)
> -			return err;
> -
> -		return 0;
> +		return regmap_update_bits(priv->regmap, ABX8XX_REG_STATUS,
> +					  ABX8XX_STATUS_BLF, 0);
>  
>  	default:
>  		return -ENOIOCTLCMD;
>  	}

[Severity: High]
Will this cause a compiler error or undefined behavior?

The guard(mutex) is declared inside the case block, but without an 
enclosing scope. If cmd is an unhandled ioctl, the switch statement jumps 
to the default label, bypassing the initialization of the guard(mutex) 
variable. 

Does this require adding braces around the RTC_VL_CLR case to restrict the 
lifetime of the guard?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260731184831.44037-1-apokusinski01@gmail.com?part=6

  reply	other threads:[~2026-07-31 19:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-31 18:48 [PATCH v3 0/8] rtc: abx80x: add support for abx81x Antoni Pokusinski
2026-07-31 18:48 ` [PATCH v3 1/8] dt-bindings: rtc: abx80x: document ABX81X RTCs Antoni Pokusinski
2026-07-31 18:57   ` sashiko-bot
2026-07-31 18:48 ` [PATCH v3 2/8] rtc: abx80x: add mutex protection for register writes Antoni Pokusinski
2026-07-31 19:02   ` sashiko-bot
2026-07-31 18:48 ` [PATCH v3 3/8] rtc: abx80x: properly handle shared IRQs Antoni Pokusinski
2026-07-31 19:05   ` sashiko-bot
2026-07-31 18:48 ` [PATCH v3 4/8] rtc: abx80x: add irq to struct abx80x_priv Antoni Pokusinski
2026-07-31 19:04   ` sashiko-bot
2026-07-31 18:48 ` [PATCH v3 5/8] rtc: abx80x: use regmap instead of I2C specific API Antoni Pokusinski
2026-07-31 19:05   ` sashiko-bot
2026-07-31 18:48 ` [PATCH v3 6/8] rtc: abx80x: replace read-modify-write pattern with regmap helpers Antoni Pokusinski
2026-07-31 19:01   ` sashiko-bot [this message]
2026-07-31 18:48 ` [PATCH v3 7/8] rtc: abx80x: create abx80x_i2c_probe() Antoni Pokusinski
2026-07-31 19:02   ` sashiko-bot
2026-07-31 18:48 ` [PATCH v3 8/8] rtc: abx80x: add support for ABX81X Antoni Pokusinski
2026-07-31 19:05   ` sashiko-bot

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=20260731190137.E8A701F00AC4@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=apokusinski01@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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