From: sashiko-bot@kernel.org
To: "Prasanth Kumar Padarthi" <prasanth.padarthi10@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 2/2] nvmem: aspeed: Add read-only AST2600 OTP support
Date: Fri, 20 Nov 2026 17:57:39 +0000 [thread overview]
Message-ID: <sashiko-outbox-225751@kernel.org> (raw)
In-Reply-To: <20261120174440.123487-3-prasanth.padarthi10@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] nvmem: aspeed: mix of guard(mutex) and goto cleanup in OTP
helpers
--
commit 34b51f06ae272e72e9e379fc1f5bbb493333d824
Author: Prasanth Kumar Padarthi <prasanth.padarthi10@gmail.com>
nvmem: aspeed: Add read-only AST2600 OTP support
This commit adds a read-only NVMEM provider driver for the ASPEED AST2600
OTP controller, masking the secure prefix with an NVMEM keepout and
serializing hardware unlock, read, and relock transactions.
Link: https://github.com/AspeedTech-BMC/linux/blob/769f62b7baa84d6998723b0ea60280e380183553/drivers/soc/aspeed/ast2600-otp.c
Link: https://lore.kernel.org/linux-aspeed/KL1PR0601MB3986A356BD06F98D0FF9AD5E80792@KL1PR0601MB3986.apcprd06.prod.outlook.com/
> diff --git a/drivers/nvmem/nvmem-aspeed-otp.c b/drivers/nvmem/nvmem-aspeed-otp.c
> new file mode 100644
> index 0000000000000..8a433dccaaaf0
> --- /dev/null
> +++ b/drivers/nvmem/nvmem-aspeed-otp.c
> @@ -0,0 +1,297 @@
[ ... ]
> +static int ast2600_otp_init_keepout(struct ast2600_otp *priv)
> +{
> + u32 conf0, unused;
> + int ret;
> +
> + guard(mutex)(&priv->lock);
> +
> + writel(AST2600_OTP_UNLOCK_KEY, priv->base + AST2600_OTP_PROTECT_KEY);
> + if (readl(priv->base + AST2600_OTP_PROTECT_KEY) != 1) {
> + ret = -EACCES;
> + goto out_lock;
> + }
> +
> + ret = ast2600_otp_init_read_mode(priv);
> + if (ret)
> + goto out_lock;
> +
> + ret = ast2600_otp_read_pair(priv, AST2600_OTP_CONF0_ADDR,
> + &conf0, &unused);
> + if (ret)
> + goto out_lock;
> +
> + priv->secure_keepout.start = 0;
> + priv->secure_keepout.end =
> + FIELD_GET(AST2600_OTP_CONF0_SEC_SIZE, conf0) *
> + AST2600_OTP_SEC_SIZE_UNIT;
> + priv->secure_keepout.value = 0;
> +
> +out_lock:
> + writel(0, priv->base + AST2600_OTP_PROTECT_KEY);
> + /* Complete the lock write before returning and releasing the mutex. */
> + readl(priv->base + AST2600_OTP_PROTECT_KEY);
> + return ret;
> +}
> +
> +static int ast2600_otp_read(void *context, unsigned int offset,
> + void *val, size_t bytes)
> +{
> + struct ast2600_otp *priv = context;
> + u8 *buf = val;
> + unsigned int word_index;
> + unsigned int aligned_word;
> + unsigned int secure_size;
> + u32 extra_read;
> + u32 word0, word1;
> + int ret;
> +
> + if (!bytes)
> + return 0;
> +
> + if (offset % sizeof(u32) || bytes % sizeof(u32))
> + return -EINVAL;
> +
> + if (offset >= AST2600_OTP_SIZE ||
> + bytes > AST2600_OTP_SIZE - offset)
> + return -EINVAL;
> +
> + guard(mutex)(&priv->lock);
> +
> + if (priv->failed)
> + return -EIO;
> +
> + /* SEC54 can grow after probe; keep the registered keepout immutable. */
> + extra_read = readl(priv->base + AST2600_OTP_EXTRA_READ_PROTECT);
> + secure_size = FIELD_GET(AST2600_OTP_EXTRA_READ_RANGE, extra_read) *
> + AST2600_OTP_SEC_SIZE_UNIT;
> + secure_size = max(priv->secure_keepout.end, secure_size);
> + if (offset < secure_size)
> + return -EACCES;
> +
> + writel(AST2600_OTP_UNLOCK_KEY, priv->base + AST2600_OTP_PROTECT_KEY);
> + if (readl(priv->base + AST2600_OTP_PROTECT_KEY) != 1) {
> + ret = -EACCES;
> + goto out_lock;
> + }
> +
> + ret = ast2600_otp_wait_complete(priv);
> + if (ret)
> + goto out_lock;
> +
> + word_index = offset / sizeof(u32);
> + while (bytes) {
> + aligned_word = word_index & ~1U;
> +
> + ret = ast2600_otp_read_pair(priv, aligned_word,
> + &word0, &word1);
> + if (ret)
> + goto out_lock;
> +
> + if (!(word_index & 1)) {
> + put_unaligned_le32(word0, buf);
> + buf += sizeof(u32);
> + bytes -= sizeof(u32);
> + word_index++;
> + }
> + if (bytes) {
> + put_unaligned_le32(word1, buf);
> + buf += sizeof(u32);
> + bytes -= sizeof(u32);
> + word_index++;
> + }
> + }
> +
> + ret = 0;
> +
> +out_lock:
> + writel(0, priv->base + AST2600_OTP_PROTECT_KEY);
> + /* Complete the lock write before returning and releasing the mutex. */
> + readl(priv->base + AST2600_OTP_PROTECT_KEY);
> + return ret;
> +}
[Severity: Low]
This isn't a bug, but both ast2600_otp_init_keepout() and
ast2600_otp_read() mix guard(mutex) with goto out_lock cleanup within the
same function, contrary to the Cleanup API convention in
include/linux/cleanup.h. Moving the work performed while
AST2600_OTP_PROTECT_KEY is unlocked into inner helpers (or using consistent
cleanup) would avoid mixing guard() with goto labels and also share the
duplicated unlock/relock sequence.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120174440.123487-1-prasanth.padarthi10@gmail.com?part=2
prev parent reply other threads:[~2026-11-20 17:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261113034213.158390-1-prasanth.padarthi10@gmail.com>
2026-11-20 17:44 ` [PATCH v2 0/2] nvmem: aspeed: Add read-only AST2600 OTP support Prasanth Kumar Padarthi
2026-11-20 17:44 ` [PATCH v2 1/2] dt-bindings: arm: aspeed: sbc: Describe OTP NVMEM provider Prasanth Kumar Padarthi
2026-11-20 17:44 ` [PATCH v2 2/2] nvmem: aspeed: Add read-only AST2600 OTP support Prasanth Kumar Padarthi
2026-11-20 17:57 ` 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=sashiko-outbox-225751@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=prasanth.padarthi10@gmail.com \
--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