From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: linux-phy@lists.infradead.org
Cc: devicetree@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-arm-kernel@lists.infradead.org,
Ioana Ciornei <ioana.ciornei@nxp.com>,
Vinod Koul <vkoul@kernel.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Tanjeff Moos <tanjeff.moos@westermo.com>,
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
Michael Walle <mwalle@kernel.org>,
Shawn Guo <shawnguo@kernel.org>, Frank Li <Frank.Li@nxp.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v4 phy-next 1/9] soc: fsl: guts: perform fsl_guts_init() error teardown in reverse order of setup
Date: Wed, 22 Jul 2026 02:15:55 +0300 [thread overview]
Message-ID: <20260721231603.67865-2-vladimir.oltean@nxp.com> (raw)
In-Reply-To: <20260721231603.67865-1-vladimir.oltean@nxp.com>
fsl_guts_init() is about to get much more complicated and the central
error handling procedure cannot scale in its current design, unless we
add a lot of "if" conditions to detect what has been allocated and what
hasn't.
Currently the code relies on the fact that kfree(NULL) is safe, but this
doesn't scale to the case where "soc_dev_attr" itself is NULL, because
this would dereference "soc_dev_attr->family" and friends of a NULL
pointer.
Convert to the more typical error handling pattern where the teardown is
in the strict reverse order of setup, and a teardown step is only called
if its corresponding setup step was executed.
At the same time, maintain the optionality of soc_dev_attr->serial_number
by not checking whether that kasprintf() has returned NULL. In the error
path, kfree(NULL) is safe, so we don't need to add an "if" condition for
it. Michael Walle has confirmed that ignoring the error was intentional,
and we preserve that:
https://lore.kernel.org/linux-phy/DK44809N7Y8I.J2Z3U4N32H0Q@kernel.org/
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
v3->v4: patch is new
---
drivers/soc/fsl/guts.c | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/drivers/soc/fsl/guts.c b/drivers/soc/fsl/guts.c
index 9bee7baec2b9..453456f31800 100644
--- a/drivers/soc/fsl/guts.c
+++ b/drivers/soc/fsl/guts.c
@@ -227,17 +227,23 @@ static int __init fsl_guts_init(void)
} else {
soc_dev_attr->family = kasprintf(GFP_KERNEL, "QorIQ");
}
- if (!soc_dev_attr->family)
- goto err_nomem;
+ if (!soc_dev_attr->family) {
+ ret = -ENOMEM;
+ goto err_free_soc_dev_attr;
+ }
soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "svr:0x%08x", svr);
- if (!soc_dev_attr->soc_id)
- goto err_nomem;
+ if (!soc_dev_attr->soc_id) {
+ ret = -ENOMEM;
+ goto err_free_family;
+ }
soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d.%d",
(svr >> 4) & 0xf, svr & 0xf);
- if (!soc_dev_attr->revision)
- goto err_nomem;
+ if (!soc_dev_attr->revision) {
+ ret = -ENOMEM;
+ goto err_free_soc_id;
+ }
if (soc_data)
soc_uid = fsl_guts_get_soc_uid(soc_data->sfp_compat,
@@ -249,7 +255,7 @@ static int __init fsl_guts_init(void)
soc_dev = soc_device_register(soc_dev_attr);
if (IS_ERR(soc_dev)) {
ret = PTR_ERR(soc_dev);
- goto err;
+ goto err_free_serial_number;
}
pr_info("Machine: %s\n", soc_dev_attr->machine);
@@ -259,13 +265,14 @@ static int __init fsl_guts_init(void)
return 0;
-err_nomem:
- ret = -ENOMEM;
-err:
- kfree(soc_dev_attr->family);
- kfree(soc_dev_attr->soc_id);
- kfree(soc_dev_attr->revision);
+err_free_serial_number:
kfree(soc_dev_attr->serial_number);
+ kfree(soc_dev_attr->revision);
+err_free_soc_id:
+ kfree(soc_dev_attr->soc_id);
+err_free_family:
+ kfree(soc_dev_attr->family);
+err_free_soc_dev_attr:
kfree(soc_dev_attr);
return ret;
--
2.34.1
next prev parent reply other threads:[~2026-07-21 23:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 23:15 [PATCH v4 phy-next 0/9] RCW override for 10G Lynx dynamic protocol reconfiguration Vladimir Oltean
2026-07-21 23:15 ` Vladimir Oltean [this message]
2026-07-22 7:18 ` [PATCH v4 phy-next 1/9] soc: fsl: guts: perform fsl_guts_init() error teardown in reverse order of setup Michael Walle
2026-07-22 7:55 ` Vladimir Oltean
2026-07-22 9:15 ` Ioana Ciornei
2026-07-21 23:15 ` [PATCH v4 phy-next 2/9] soc: fsl: guts: use a macro to encode the DCFG CCSR space Vladimir Oltean
2026-07-21 23:15 ` [PATCH v4 phy-next 3/9] soc: fsl: guts: add a global structure to hold state Vladimir Oltean
2026-07-21 23:15 ` [PATCH v4 phy-next 4/9] soc: fsl: guts: add a central fsl_guts_read() function Vladimir Oltean
2026-07-21 23:15 ` [PATCH v4 phy-next 5/9] soc: fsl: guts: make it easier to determine on which SoC we are running Vladimir Oltean
2026-07-21 23:16 ` [PATCH v4 phy-next 6/9] soc: fsl: guts: make fsl_soc_data available after fsl_guts_init() Vladimir Oltean
2026-07-22 9:19 ` Ioana Ciornei
2026-07-21 23:16 ` [PATCH v4 phy-next 7/9] dt-bindings: fsl: layerscape-dcfg: define DCFG_DCSR region Vladimir Oltean
2026-07-21 23:16 ` [PATCH v4 phy-next 8/9] soc: fsl: guts: implement the RCW override procedure Vladimir Oltean
2026-07-22 11:01 ` Ioana Ciornei
2026-07-21 23:16 ` [PATCH v4 phy-next 9/9] phy: lynx-10g: use RCW override procedure for dynamic protocol change Vladimir Oltean
2026-07-22 11:03 ` Ioana Ciornei
2026-07-24 6:00 ` Vinod Koul
2026-07-23 15:01 ` [PATCH v4 phy-next 0/9] RCW override for 10G Lynx dynamic protocol reconfiguration Vladimir Oltean
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=20260721231603.67865-2-vladimir.oltean@nxp.com \
--to=vladimir.oltean@nxp.com \
--cc=Frank.Li@nxp.com \
--cc=chleroy@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=ioana.ciornei@nxp.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mwalle@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=shawnguo@kernel.org \
--cc=tanjeff.moos@westermo.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox