From: sashiko-bot@kernel.org
To: "Akshay Gupta" <Akshay.Gupta@amd.com>,
linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v1 1/4] misc: amd-sbi: use guard() for data->lock mutex
Date: Mon, 16 Nov 2026 12:15:25 +0000 [thread overview]
Message-ID: <sashiko-outbox-217000@kernel.org> (raw)
In-Reply-To: <20261116120228.865196-2-Akshay.Gupta@amd.com>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] misc: amd-sbi: uninitialized ec and error overwrite in
rmi_mailbox_xfer() [1]
--
commit 8e0c735b23732b6b78100642d3a437c0cd3041c0
Author: Prathima Lk <Prathima.Lk@amd.com>
misc: amd-sbi: use guard() for data->lock mutex
This commit converts manual mutex_lock() and mutex_unlock() calls on
data->lock in drivers/misc/amd-sbi/rmi-core.c to guard() and
scoped_guard(), simplifying the error-return paths.
> diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c
> index 95c9109101b53..277f121409728 100644
> --- a/drivers/misc/amd-sbi/rmi-core.c
> +++ b/drivers/misc/amd-sbi/rmi-core.c
[ ... ]
> @@ -425,29 +425,27 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,
> ret = regmap_read_poll_timeout(data->regmap, SBRMI_STATUS, sw_status,
> sw_status & SW_ALERT_MASK, 500, 2000000);
> if (ret)
> - goto exit_unlock;
> + return ret;
>
> ret = regmap_read(data->regmap, SBRMI_OUTBNDMSG7, &ec);
> - if (ret || ec)
> - goto exit_clear_alert;
> -
> - /* Clear the input value before updating the output data */
> - msg->mb_in_out = 0;
> -
> - /*
> - * For a read operation, the initiator (BMC) reads the firmware
> - * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1]
> - * {SBRMI_x34(MSB):SBRMI_x31(LSB)}.
> - */
> - for (i = 0; i < AMD_SBI_MB_DATA_SIZE; i++) {
> - ret = regmap_read(data->regmap,
> - SBRMI_OUTBNDMSG1 + i, &bytes);
> - if (ret < 0)
> - break;
> - msg->mb_in_out |= bytes << i * 8;
> + if (!ret && !ec) {
> + /* Clear the input value before updating the output data */
> + msg->mb_in_out = 0;
> +
> + /*
> + * For a read operation, the initiator (BMC) reads the firmware
> + * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1]
> + * {SBRMI_x34(MSB):SBRMI_x31(LSB)}.
> + */
> + for (i = 0; i < AMD_SBI_MB_DATA_SIZE; i++) {
> + ret = regmap_read(data->regmap,
> + SBRMI_OUTBNDMSG1 + i, &bytes);
> + if (ret < 0)
> + break;
> + msg->mb_in_out |= bytes << i * 8;
> + }
> }
>
> -exit_clear_alert:
> /*
> * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the
> * ALERT to initiator
> @@ -458,8 +456,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,
> ret = -EPROTOTYPE;
> msg->fw_ret_code = ec;
> }
> -exit_unlock:
> - mutex_unlock(&data->lock);
> +
> return ret;
> }
[Severity: High]
This problem wasn't introduced by this patch [1], but what happens
if regmap_read() fails when reading SBRMI_OUTBNDMSG7 or
SBRMI_OUTBNDMSG1..4?
ec is declared on the stack without initialization in rmi_mailbox_xfer().
If reading SBRMI_OUTBNDMSG7 fails, ec remains uninitialized when checked
at "if (ec)" at the end of the function; if it happens to be non-zero, the
uninitialized value is stored into msg->fw_ret_code and copied to
userspace by apml_mailbox_xfer().
In addition, the regmap_write() to SBRMI_STATUS unconditionally overwrites
ret, so a failed read of SBRMI_OUTBNDMSG7 (when ec happens to be 0) or
SBRMI_OUTBNDMSG1..4 returns 0 when clearing the alert succeeds, leaving
callers with stale or partial msg->mb_in_out data.
[1] https://sashiko.dev/#/bug/linux-37f3c6ab-ea0e-4ada-a81e-e6c232558ae3
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116120228.865196-1-Akshay.Gupta@amd.com?part=1
next prev parent reply other threads:[~2026-11-16 12:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 12:02 [PATCH v1 0/4] misc: amd-sbi: add DIMM thermal sensors to sbrmi Akshay Gupta
2026-11-16 12:02 ` [PATCH v1 1/4] misc: amd-sbi: use guard() for data->lock mutex Akshay Gupta
2026-11-16 12:15 ` sashiko-bot [this message]
2026-11-16 12:02 ` [PATCH v1 2/4] dt-bindings: hwmon: add DIMM thermal sensor properties Akshay Gupta
2026-11-16 12:11 ` sashiko-bot
2026-11-16 12:02 ` [PATCH v1 3/4] misc: amd-sbi: add DIMM thermal sensor support Akshay Gupta
2026-11-16 12:13 ` sashiko-bot
2026-11-16 12:02 ` [PATCH v1 4/4] Documentation: hwmon: document DIMM thermal sensor channels Akshay Gupta
2026-11-16 12:08 ` 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=sashiko-outbox-217000@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Akshay.Gupta@amd.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-hwmon@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.