mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 10:31:46 +09:00
soc: imx8m: Use devm_* to simplify probe failure handling
[ Upstream commit 22b03a4e957e462b380a982759ccf0f6554735d3 ] Use device managed functions to simplify handling of failures during probe. Remove fail paths which are no longer necessary. Signed-off-by: Marek Vasut <marex@denx.de> Signed-off-by: Shawn Guo <shawnguo@kernel.org> Stable-dep-of: cf7139aac463 ("soc: imx8m: Unregister cpufreq and soc dev in cleanup path") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
44f9ffc1fe
commit
296d16538d
@@ -51,22 +51,20 @@ static inline u32 imx8mq_soc_revision_from_atf(void) { return 0; };
|
|||||||
|
|
||||||
static int imx8mq_soc_revision(u32 *socrev, u64 *socuid)
|
static int imx8mq_soc_revision(u32 *socrev, u64 *socuid)
|
||||||
{
|
{
|
||||||
struct device_node *np;
|
struct device_node *np __free(device_node) =
|
||||||
|
of_find_compatible_node(NULL, NULL, "fsl,imx8mq-ocotp");
|
||||||
void __iomem *ocotp_base;
|
void __iomem *ocotp_base;
|
||||||
u32 magic;
|
u32 magic;
|
||||||
u32 rev;
|
u32 rev;
|
||||||
struct clk *clk;
|
struct clk *clk;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
np = of_find_compatible_node(NULL, NULL, "fsl,imx8mq-ocotp");
|
|
||||||
if (!np)
|
if (!np)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
ocotp_base = of_iomap(np, 0);
|
ocotp_base = of_iomap(np, 0);
|
||||||
if (!ocotp_base) {
|
if (!ocotp_base)
|
||||||
ret = -EINVAL;
|
return -EINVAL;
|
||||||
goto err_iomap;
|
|
||||||
}
|
|
||||||
|
|
||||||
clk = of_clk_get_by_name(np, NULL);
|
clk = of_clk_get_by_name(np, NULL);
|
||||||
if (IS_ERR(clk)) {
|
if (IS_ERR(clk)) {
|
||||||
@@ -96,35 +94,30 @@ static int imx8mq_soc_revision(u32 *socrev, u64 *socuid)
|
|||||||
clk_disable_unprepare(clk);
|
clk_disable_unprepare(clk);
|
||||||
clk_put(clk);
|
clk_put(clk);
|
||||||
iounmap(ocotp_base);
|
iounmap(ocotp_base);
|
||||||
of_node_put(np);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_clk:
|
err_clk:
|
||||||
iounmap(ocotp_base);
|
iounmap(ocotp_base);
|
||||||
err_iomap:
|
|
||||||
of_node_put(np);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int imx8mm_soc_uid(u64 *socuid)
|
static int imx8mm_soc_uid(u64 *socuid)
|
||||||
{
|
{
|
||||||
|
struct device_node *np __free(device_node) =
|
||||||
|
of_find_compatible_node(NULL, NULL, "fsl,imx8mm-ocotp");
|
||||||
void __iomem *ocotp_base;
|
void __iomem *ocotp_base;
|
||||||
struct device_node *np;
|
|
||||||
struct clk *clk;
|
struct clk *clk;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
u32 offset = of_machine_is_compatible("fsl,imx8mp") ?
|
u32 offset = of_machine_is_compatible("fsl,imx8mp") ?
|
||||||
IMX8MP_OCOTP_UID_OFFSET : 0;
|
IMX8MP_OCOTP_UID_OFFSET : 0;
|
||||||
|
|
||||||
np = of_find_compatible_node(NULL, NULL, "fsl,imx8mm-ocotp");
|
|
||||||
if (!np)
|
if (!np)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
ocotp_base = of_iomap(np, 0);
|
ocotp_base = of_iomap(np, 0);
|
||||||
if (!ocotp_base) {
|
if (!ocotp_base)
|
||||||
ret = -EINVAL;
|
return -EINVAL;
|
||||||
goto err_iomap;
|
|
||||||
}
|
|
||||||
|
|
||||||
clk = of_clk_get_by_name(np, NULL);
|
clk = of_clk_get_by_name(np, NULL);
|
||||||
if (IS_ERR(clk)) {
|
if (IS_ERR(clk)) {
|
||||||
@@ -143,38 +136,27 @@ static int imx8mm_soc_uid(u64 *socuid)
|
|||||||
|
|
||||||
err_clk:
|
err_clk:
|
||||||
iounmap(ocotp_base);
|
iounmap(ocotp_base);
|
||||||
err_iomap:
|
|
||||||
of_node_put(np);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int imx8mm_soc_revision(u32 *socrev, u64 *socuid)
|
static int imx8mm_soc_revision(u32 *socrev, u64 *socuid)
|
||||||
{
|
{
|
||||||
struct device_node *np;
|
struct device_node *np __free(device_node) =
|
||||||
|
of_find_compatible_node(NULL, NULL, "fsl,imx8mm-anatop");
|
||||||
void __iomem *anatop_base;
|
void __iomem *anatop_base;
|
||||||
int ret;
|
|
||||||
|
|
||||||
np = of_find_compatible_node(NULL, NULL, "fsl,imx8mm-anatop");
|
|
||||||
if (!np)
|
if (!np)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
anatop_base = of_iomap(np, 0);
|
anatop_base = of_iomap(np, 0);
|
||||||
if (!anatop_base) {
|
if (!anatop_base)
|
||||||
ret = -EINVAL;
|
return -EINVAL;
|
||||||
goto err_iomap;
|
|
||||||
}
|
|
||||||
|
|
||||||
*socrev = readl_relaxed(anatop_base + ANADIG_DIGPROG_IMX8MM);
|
*socrev = readl_relaxed(anatop_base + ANADIG_DIGPROG_IMX8MM);
|
||||||
|
|
||||||
iounmap(anatop_base);
|
iounmap(anatop_base);
|
||||||
of_node_put(np);
|
|
||||||
|
|
||||||
return imx8mm_soc_uid(socuid);
|
return imx8mm_soc_uid(socuid);
|
||||||
|
|
||||||
err_iomap:
|
|
||||||
of_node_put(np);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct imx8_soc_data imx8mq_soc_data = {
|
static const struct imx8_soc_data imx8mq_soc_data = {
|
||||||
@@ -205,22 +187,23 @@ static __maybe_unused const struct of_device_id imx8_soc_match[] = {
|
|||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
#define imx8_revision(soc_rev) \
|
#define imx8_revision(dev, soc_rev) \
|
||||||
soc_rev ? \
|
(soc_rev) ? \
|
||||||
kasprintf(GFP_KERNEL, "%d.%d", (soc_rev >> 4) & 0xf, soc_rev & 0xf) : \
|
devm_kasprintf((dev), GFP_KERNEL, "%d.%d", ((soc_rev) >> 4) & 0xf, (soc_rev) & 0xf) : \
|
||||||
"unknown"
|
"unknown"
|
||||||
|
|
||||||
static int imx8m_soc_probe(struct platform_device *pdev)
|
static int imx8m_soc_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct soc_device_attribute *soc_dev_attr;
|
struct soc_device_attribute *soc_dev_attr;
|
||||||
const struct imx8_soc_data *data;
|
const struct imx8_soc_data *data;
|
||||||
|
struct device *dev = &pdev->dev;
|
||||||
const struct of_device_id *id;
|
const struct of_device_id *id;
|
||||||
struct soc_device *soc_dev;
|
struct soc_device *soc_dev;
|
||||||
u32 soc_rev = 0;
|
u32 soc_rev = 0;
|
||||||
u64 soc_uid = 0;
|
u64 soc_uid = 0;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
|
soc_dev_attr = devm_kzalloc(dev, sizeof(*soc_dev_attr), GFP_KERNEL);
|
||||||
if (!soc_dev_attr)
|
if (!soc_dev_attr)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@@ -228,13 +211,11 @@ static int imx8m_soc_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
ret = of_property_read_string(of_root, "model", &soc_dev_attr->machine);
|
ret = of_property_read_string(of_root, "model", &soc_dev_attr->machine);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto free_soc;
|
return ret;
|
||||||
|
|
||||||
id = of_match_node(imx8_soc_match, of_root);
|
id = of_match_node(imx8_soc_match, of_root);
|
||||||
if (!id) {
|
if (!id)
|
||||||
ret = -ENODEV;
|
return -ENODEV;
|
||||||
goto free_soc;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = id->data;
|
data = id->data;
|
||||||
if (data) {
|
if (data) {
|
||||||
@@ -242,27 +223,21 @@ static int imx8m_soc_probe(struct platform_device *pdev)
|
|||||||
if (data->soc_revision) {
|
if (data->soc_revision) {
|
||||||
ret = data->soc_revision(&soc_rev, &soc_uid);
|
ret = data->soc_revision(&soc_rev, &soc_uid);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto free_soc;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
soc_dev_attr->revision = imx8_revision(soc_rev);
|
soc_dev_attr->revision = imx8_revision(dev, soc_rev);
|
||||||
if (!soc_dev_attr->revision) {
|
if (!soc_dev_attr->revision)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto free_soc;
|
|
||||||
}
|
|
||||||
|
|
||||||
soc_dev_attr->serial_number = kasprintf(GFP_KERNEL, "%016llX", soc_uid);
|
soc_dev_attr->serial_number = devm_kasprintf(dev, GFP_KERNEL, "%016llX", soc_uid);
|
||||||
if (!soc_dev_attr->serial_number) {
|
if (!soc_dev_attr->serial_number)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto free_rev;
|
|
||||||
}
|
|
||||||
|
|
||||||
soc_dev = soc_device_register(soc_dev_attr);
|
soc_dev = soc_device_register(soc_dev_attr);
|
||||||
if (IS_ERR(soc_dev)) {
|
if (IS_ERR(soc_dev))
|
||||||
ret = PTR_ERR(soc_dev);
|
return PTR_ERR(soc_dev);
|
||||||
goto free_serial_number;
|
|
||||||
}
|
|
||||||
|
|
||||||
pr_info("SoC: %s revision %s\n", soc_dev_attr->soc_id,
|
pr_info("SoC: %s revision %s\n", soc_dev_attr->soc_id,
|
||||||
soc_dev_attr->revision);
|
soc_dev_attr->revision);
|
||||||
@@ -271,15 +246,6 @@ static int imx8m_soc_probe(struct platform_device *pdev)
|
|||||||
platform_device_register_simple("imx-cpufreq-dt", -1, NULL, 0);
|
platform_device_register_simple("imx-cpufreq-dt", -1, NULL, 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
free_serial_number:
|
|
||||||
kfree(soc_dev_attr->serial_number);
|
|
||||||
free_rev:
|
|
||||||
if (strcmp(soc_dev_attr->revision, "unknown"))
|
|
||||||
kfree(soc_dev_attr->revision);
|
|
||||||
free_soc:
|
|
||||||
kfree(soc_dev_attr);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct platform_driver imx8m_soc_driver = {
|
static struct platform_driver imx8m_soc_driver = {
|
||||||
|
|||||||
Reference in New Issue
Block a user