[PATCH 6/7] regmap: return errors directly before map allocation in __regmap_init()
From: Peng Fan (OSS)
Date: Wed Sep 30 2026 - 05:56:16 EST
From: Peng Fan <peng.fan@xxxxxxx>
The two early error paths in __regmap_init() - a NULL config check and a
failed kzalloc - jumped to the 'err' label which only did return
ERR_PTR(ret). Since neither path has anything to clean up (the map
hasn't been allocated yet), replace the gotos with direct return
ERR_PTR() calls.
Removes the 'err' label entirely and the pre-initialisation of ret to
simplify code.
No functional change.
Assisted-by: LLM
Signed-off-by: Peng Fan <peng.fan@xxxxxxx>
---
drivers/base/regmap/regmap.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index bb5553ce58d1..88000d535985 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -681,18 +681,15 @@ struct regmap *__regmap_init(struct device *dev,
const char *lock_name)
{
struct regmap *map;
- int ret = -EINVAL;
enum regmap_endian reg_endian, val_endian;
- int i, j;
+ int i, j, ret;
if (!config)
- goto err;
+ return ERR_PTR(-EINVAL);
map = kzalloc_obj(*map);
- if (map == NULL) {
- ret = -ENOMEM;
- goto err;
- }
+ if (map == NULL)
+ return ERR_PTR(-ENOMEM);
ret = regmap_set_name(map, config);
if (ret)
@@ -1174,7 +1171,6 @@ struct regmap *__regmap_init(struct device *dev,
kfree_const(map->name);
err_map:
kfree(map);
-err:
return ERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(__regmap_init);
--
2.51.0