mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-06 10:58:48 +09:00
mfd: syscon: Use scoped variables with memory allocators to simplify error paths
[ Upstream commit 82f898f47112bc7b787cb9ce8803c4e2f9f60c89 ] Allocate the memory with scoped/cleanup.h to reduce error handling and make the code a bit simpler. Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Link: https://lore.kernel.org/r/20240707114823.9175-2-krzysztof.kozlowski@linaro.org Signed-off-by: Lee Jones <lee@kernel.org> Stable-dep-of: 805f7aaf7fee ("mfd: syscon: Fix race in device_node_get_regmap()") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
166fd2aa73
commit
5481df0e05
@@ -8,6 +8,7 @@
|
|||||||
* Author: Dong Aisheng <dong.aisheng@linaro.org>
|
* Author: Dong Aisheng <dong.aisheng@linaro.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <linux/cleanup.h>
|
||||||
#include <linux/clk.h>
|
#include <linux/clk.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/hwspinlock.h>
|
#include <linux/hwspinlock.h>
|
||||||
@@ -43,7 +44,6 @@ static const struct regmap_config syscon_regmap_config = {
|
|||||||
static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
|
static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
|
||||||
{
|
{
|
||||||
struct clk *clk;
|
struct clk *clk;
|
||||||
struct syscon *syscon;
|
|
||||||
struct regmap *regmap;
|
struct regmap *regmap;
|
||||||
void __iomem *base;
|
void __iomem *base;
|
||||||
u32 reg_io_width;
|
u32 reg_io_width;
|
||||||
@@ -51,20 +51,16 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
|
|||||||
struct regmap_config syscon_config = syscon_regmap_config;
|
struct regmap_config syscon_config = syscon_regmap_config;
|
||||||
struct resource res;
|
struct resource res;
|
||||||
|
|
||||||
syscon = kzalloc(sizeof(*syscon), GFP_KERNEL);
|
struct syscon *syscon __free(kfree) = kzalloc(sizeof(*syscon), GFP_KERNEL);
|
||||||
if (!syscon)
|
if (!syscon)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
if (of_address_to_resource(np, 0, &res)) {
|
if (of_address_to_resource(np, 0, &res))
|
||||||
ret = -ENOMEM;
|
return ERR_PTR(-ENOMEM);
|
||||||
goto err_map;
|
|
||||||
}
|
|
||||||
|
|
||||||
base = of_iomap(np, 0);
|
base = of_iomap(np, 0);
|
||||||
if (!base) {
|
if (!base)
|
||||||
ret = -ENOMEM;
|
return ERR_PTR(-ENOMEM);
|
||||||
goto err_map;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parse the device's DT node for an endianness specification */
|
/* Parse the device's DT node for an endianness specification */
|
||||||
if (of_property_read_bool(np, "big-endian"))
|
if (of_property_read_bool(np, "big-endian"))
|
||||||
@@ -139,7 +135,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
|
|||||||
list_add_tail(&syscon->list, &syscon_list);
|
list_add_tail(&syscon->list, &syscon_list);
|
||||||
spin_unlock(&syscon_list_slock);
|
spin_unlock(&syscon_list_slock);
|
||||||
|
|
||||||
return syscon;
|
return_ptr(syscon);
|
||||||
|
|
||||||
err_attach:
|
err_attach:
|
||||||
if (!IS_ERR(clk))
|
if (!IS_ERR(clk))
|
||||||
@@ -148,8 +144,6 @@ err_clk:
|
|||||||
regmap_exit(regmap);
|
regmap_exit(regmap);
|
||||||
err_regmap:
|
err_regmap:
|
||||||
iounmap(base);
|
iounmap(base);
|
||||||
err_map:
|
|
||||||
kfree(syscon);
|
|
||||||
return ERR_PTR(ret);
|
return ERR_PTR(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user