Commit 83ba7e89 authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Greg Kroah-Hartman

fsi: Aspeed: Fix a potential double free

A struct device can never be devm_alloc()'ed.
Here, it is embedded in "struct fsi_master", and "struct fsi_master" is
embedded in "struct fsi_master_aspeed".

Since "struct device" is embedded, the data structure embedding it must be
released with the release function, as is already done here.

So use kzalloc() instead of devm_kzalloc() when allocating "aspeed" and
update all error handling branches accordingly.

This prevent a potential double free().

This also fix another issue if opb_readl() fails. Instead of a direct
return, it now jumps in the error handling path.

Fixes: 606397d6 ("fsi: Add ast2600 master driver")
Suggested-by: default avatarGreg KH <gregkh@linuxfoundation.org>
Suggested-by: default avatarGuenter Roeck <linux@roeck-us.net>
Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/2c123f8b0a40dc1a061fae982169fe030b4f47e6.1641765339.git.christophe.jaillet@wanadoo.frSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent aafce7bc
...@@ -542,25 +542,28 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev) ...@@ -542,25 +542,28 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev)
return rc; return rc;
} }
aspeed = devm_kzalloc(&pdev->dev, sizeof(*aspeed), GFP_KERNEL); aspeed = kzalloc(sizeof(*aspeed), GFP_KERNEL);
if (!aspeed) if (!aspeed)
return -ENOMEM; return -ENOMEM;
aspeed->dev = &pdev->dev; aspeed->dev = &pdev->dev;
aspeed->base = devm_platform_ioremap_resource(pdev, 0); aspeed->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(aspeed->base)) if (IS_ERR(aspeed->base)) {
return PTR_ERR(aspeed->base); rc = PTR_ERR(aspeed->base);
goto err_free_aspeed;
}
aspeed->clk = devm_clk_get(aspeed->dev, NULL); aspeed->clk = devm_clk_get(aspeed->dev, NULL);
if (IS_ERR(aspeed->clk)) { if (IS_ERR(aspeed->clk)) {
dev_err(aspeed->dev, "couldn't get clock\n"); dev_err(aspeed->dev, "couldn't get clock\n");
return PTR_ERR(aspeed->clk); rc = PTR_ERR(aspeed->clk);
goto err_free_aspeed;
} }
rc = clk_prepare_enable(aspeed->clk); rc = clk_prepare_enable(aspeed->clk);
if (rc) { if (rc) {
dev_err(aspeed->dev, "couldn't enable clock\n"); dev_err(aspeed->dev, "couldn't enable clock\n");
return rc; goto err_free_aspeed;
} }
rc = setup_cfam_reset(aspeed); rc = setup_cfam_reset(aspeed);
...@@ -595,7 +598,7 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev) ...@@ -595,7 +598,7 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev)
rc = opb_readl(aspeed, ctrl_base + FSI_MVER, &raw); rc = opb_readl(aspeed, ctrl_base + FSI_MVER, &raw);
if (rc) { if (rc) {
dev_err(&pdev->dev, "failed to read hub version\n"); dev_err(&pdev->dev, "failed to read hub version\n");
return rc; goto err_release;
} }
reg = be32_to_cpu(raw); reg = be32_to_cpu(raw);
...@@ -634,6 +637,8 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev) ...@@ -634,6 +637,8 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev)
err_release: err_release:
clk_disable_unprepare(aspeed->clk); clk_disable_unprepare(aspeed->clk);
err_free_aspeed:
kfree(aspeed);
return rc; return rc;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment