Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jorijn van der Graaf" <jorijnvdgraaf@catcrafts.net>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next 2/2] nfc: s3fwrn5: support the S3NRN4V variant
Date: Sat, 04 Jul 2026 20:35:54 +0000	[thread overview]
Message-ID: <20260704203555.648551F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260703202601.78563-3-jorijnvdgraaf@catcrafts.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] A Time-of-Check to Time-of-Use (TOCTOU) race condition in clock request seeding can leave the NFC reference clock permanently enabled, breaking the TX PLL lock.
--

commit 342a387574bb664bcbcb353a01bca5f492266532
Author: Jorijn van der Graaf <jorijnvdgraaf@catcrafts.net>

nfc: s3fwrn5: support the S3NRN4V variant

This commit adds support for the S3NRN4V NFC controller variant. It skips
the firmware download step and configures the reference clock via the
setup hook. It also adds optional clock request gpio handling to gate the
clock dynamically.

> diff --git a/drivers/nfc/s3fwrn5/i2c.c b/drivers/nfc/s3fwrn5/i2c.c
> index e9a34d27a3698..88a4988791efd 100644
> --- a/drivers/nfc/s3fwrn5/i2c.c
> +++ b/drivers/nfc/s3fwrn5/i2c.c
[ ... ]
> @@ -172,15 +217,63 @@ static int s3fwrn5_i2c_probe(struct i2c_client *client)
[ ... ]
> +		ret = devm_request_threaded_irq(&client->dev, clk_req_irq, NULL,
> +						s3fwrn5_i2c_clk_req_thread,
> +						IRQF_TRIGGER_RISING |
> +						IRQF_TRIGGER_FALLING |
> +						IRQF_ONESHOT,
> +						"s3fwrn5_clk_req", phy);
> +		if (ret)
> +			return ret;
> +
> +		/* Seed the clock state from the current CLK_REQ level. */
> +		s3fwrn5_i2c_clk_set(phy,
> +				    gpiod_get_value_cansleep(phy->gpio_clk_req) > 0);

[Severity: High]
Could this introduce a race condition that leaves the clock permanently enabled?

Because devm_request_threaded_irq() is called before the initial clock state
is seeded, the interrupt is unmasked and can fire immediately. If the
hardware toggles the gpio during this window, the sequence could look like:

Probe thread in s3fwrn5_i2c_probe():
    evaluates gpiod_get_value_cansleep() and reads a high state.

Hardware:
    toggles the gpio to low.

IRQ thread running s3fwrn5_i2c_clk_req_thread():
    reads the new low state
    calls s3fwrn5_i2c_clk_set(phy, false)
    correctly disables the clock

Probe thread resumes:
    calls s3fwrn5_i2c_clk_set(phy, true) using the stale time-of-check state
    acquires clk_lock and overrides the correct state from the IRQ

Since the gpio is already low, no subsequent falling edge will occur to
disable the clock. As mentioned in the commit message, leaving the clock
always-on prevents the chip's transmit pll from locking on a fresh start.

Should the initial clock state be seeded before requesting the interrupt, or
perhaps synchronized with clk_lock to ensure the probe thread does not apply
a stale state?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260703202601.78563-1-jorijnvdgraaf@catcrafts.net?part=2

      reply	other threads:[~2026-07-04 20:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-03 20:25 [PATCH net-next 0/2] nfc: s3fwrn5: support the S3NRN4V variant Jorijn van der Graaf
2026-07-03 20:26 ` [PATCH net-next 1/2] dt-bindings: net: nfc: samsung,s3fwrn5: add S3NRN4V and clk-req-gpios Jorijn van der Graaf
2026-07-05 14:47   ` Conor Dooley
2026-07-03 20:26 ` [PATCH net-next 2/2] nfc: s3fwrn5: support the S3NRN4V variant Jorijn van der Graaf
2026-07-04 20:35   ` sashiko-bot [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=20260704203555.648551F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jorijnvdgraaf@catcrafts.net \
    --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