From: Andrew Gaylard <ag@ffroot.co.za>
To: Vinod Koul <vkoul@kernel.org>, Vincent Shih <vincent.sunplus@gmail.com>
Cc: Neil Armstrong <neil.armstrong@linaro.org>,
Manivannan Sadhasivam <mani@kernel.org>,
linux-phy@lists.infradead.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] phy: sunplus: don't read the disc_vol cell after nvmem_cell_get() fails
Date: Mon, 16 Nov 2026 09:40:05 +0200 [thread overview]
Message-ID: <20261116074006.20357-1-ag@ffroot.co.za> (raw)
update_disc_vol() returns early only when nvmem_cell_get() gives
-EPROBE_DEFER. On any other error, such as -ENOENT for a device tree
without a disc_vol cell, it passes the error pointer to
nvmem_cell_read() and nvmem_cell_put(), which dereference it.
Use the default disconnect-voltage level on these errors, as the function
already does when the read fails. nvmem_cell_get() never returns NULL,
so IS_ERR() is enough.
Tested on a Tibbo LTPP3G2 board.
Fixes: 99d9ccd97385 ("phy: usb: Add USB2.0 phy driver for Sunplus SP7021")
Signed-off-by: Andrew Gaylard <ag@ffroot.co.za>
---
drivers/phy/sunplus/phy-sunplus-usb2.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/phy/sunplus/phy-sunplus-usb2.c b/drivers/phy/sunplus/phy-sunplus-usb2.c
index 0ad4c7160d17..52d80a06abdc 100644
--- a/drivers/phy/sunplus/phy-sunplus-usb2.c
+++ b/drivers/phy/sunplus/phy-sunplus-usb2.c
@@ -84,14 +84,15 @@ static int update_disc_vol(struct sp_usbphy *usbphy)
u32 val, set;
cell = nvmem_cell_get(usbphy->dev, disc_name);
- if (IS_ERR_OR_NULL(cell)) {
+ if (IS_ERR(cell)) {
if (PTR_ERR(cell) == -EPROBE_DEFER)
return -EPROBE_DEFER;
+ otp_v = ERR_CAST(cell);
+ } else {
+ otp_v = nvmem_cell_read(cell, &otp_l);
+ nvmem_cell_put(cell);
}
- otp_v = nvmem_cell_read(cell, &otp_l);
- nvmem_cell_put(cell);
-
if (!IS_ERR(otp_v)) {
set = *(otp_v + 1);
set = (set << (sizeof(char) * 8)) | *otp_v;
base-commit: 6bdfbe223ed4735073c299a6645ebd3faac3f51f
--
2.53.0
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
WARNING: multiple messages have this Message-ID (diff)
From: Andrew Gaylard <ag@ffroot.co.za>
To: Vinod Koul <vkoul@kernel.org>, Vincent Shih <vincent.sunplus@gmail.com>
Cc: Neil Armstrong <neil.armstrong@linaro.org>,
Manivannan Sadhasivam <mani@kernel.org>,
linux-phy@lists.infradead.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] phy: sunplus: don't read the disc_vol cell after nvmem_cell_get() fails
Date: Mon, 16 Nov 2026 09:40:05 +0200 [thread overview]
Message-ID: <20261116074006.20357-1-ag@ffroot.co.za> (raw)
update_disc_vol() returns early only when nvmem_cell_get() gives
-EPROBE_DEFER. On any other error, such as -ENOENT for a device tree
without a disc_vol cell, it passes the error pointer to
nvmem_cell_read() and nvmem_cell_put(), which dereference it.
Use the default disconnect-voltage level on these errors, as the function
already does when the read fails. nvmem_cell_get() never returns NULL,
so IS_ERR() is enough.
Tested on a Tibbo LTPP3G2 board.
Fixes: 99d9ccd97385 ("phy: usb: Add USB2.0 phy driver for Sunplus SP7021")
Signed-off-by: Andrew Gaylard <ag@ffroot.co.za>
---
drivers/phy/sunplus/phy-sunplus-usb2.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/phy/sunplus/phy-sunplus-usb2.c b/drivers/phy/sunplus/phy-sunplus-usb2.c
index 0ad4c7160d17..52d80a06abdc 100644
--- a/drivers/phy/sunplus/phy-sunplus-usb2.c
+++ b/drivers/phy/sunplus/phy-sunplus-usb2.c
@@ -84,14 +84,15 @@ static int update_disc_vol(struct sp_usbphy *usbphy)
u32 val, set;
cell = nvmem_cell_get(usbphy->dev, disc_name);
- if (IS_ERR_OR_NULL(cell)) {
+ if (IS_ERR(cell)) {
if (PTR_ERR(cell) == -EPROBE_DEFER)
return -EPROBE_DEFER;
+ otp_v = ERR_CAST(cell);
+ } else {
+ otp_v = nvmem_cell_read(cell, &otp_l);
+ nvmem_cell_put(cell);
}
- otp_v = nvmem_cell_read(cell, &otp_l);
- nvmem_cell_put(cell);
-
if (!IS_ERR(otp_v)) {
set = *(otp_v + 1);
set = (set << (sizeof(char) * 8)) | *otp_v;
base-commit: 6bdfbe223ed4735073c299a6645ebd3faac3f51f
--
2.53.0
next reply other threads:[~2026-11-16 7:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 7:40 Andrew Gaylard [this message]
2026-11-16 7:40 ` [PATCH 1/2] phy: sunplus: don't read the disc_vol cell after nvmem_cell_get() fails Andrew Gaylard
2026-11-16 7:40 ` [PATCH 2/2] phy: sunplus: free the disc_vol buffer in update_disc_vol() Andrew Gaylard
2026-11-16 7:40 ` Andrew Gaylard
2026-11-16 7:46 ` sashiko-bot
2026-11-16 7:49 ` [PATCH 1/2] phy: sunplus: don't read the disc_vol cell after nvmem_cell_get() fails 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=20261116074006.20357-1-ag@ffroot.co.za \
--to=ag@ffroot.co.za \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=linux-usb@vger.kernel.org \
--cc=mani@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=vincent.sunplus@gmail.com \
--cc=vkoul@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 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.