Skip to contentSkip to conversation

regmap: debugfs: Fix handling of name string for debugfs init delays

PATCH In review Charles Keepax 3 participants 3 messages Sep 17, 2020 – Sep 18, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 regmap: debugfs: Fix handling of name string for debugfs init delays

In regmap_debugfs_init the initialisation of the debugfs is delayed if the root node isn't ready yet. Most callers of regmap_debugfs_init pass the name from the regmap_config, which is considered temporary ie. may be unallocated after the regmap_init call returns. This leads to a potential use after free, where config->name has been freed by the time it is used in regmap_debugfs_initcall.

This situation can be seen on Zynq, where the architecture init_irq callback registers a syscon device, using a local variable for the regmap_config. As init_irq is very early in the platform bring up the regmap debugfs root isn't ready yet. Although this doesn't crash it does result in the debugfs entry not having the correct name.

Regmap already sets map->name from config->name on the regmap_init path and the fact that a separate field is used to pass the name to regmap_debugfs_init appears to be an artifact of the debugfs name being added before the map name. As such this patch updates regmap_debugfs_init to use map->name, which is already duplicated from the config avoiding the issue.

This does however leave two lose ends, both regmap_attach_dev and regmap_reinit_cache can be called after a regmap is registered and would have had the effect of applying a new name to the debugfs entries. In both of these cases it was chosen to update the map name. In the case of regmap_attach_dev there are 3 users that currently use this function to update the name, thus doing so avoids changes for those users and it seems reasonable that attaching a device would want to set the name of the map. In the case of regmap_reinit_cache the primary use-case appears to be devices that need some register access to identify the device (for example devices in the same family) and then update the cache to match the exact hardware. Whilst no users do currently update the name here, given the use-case it seemed reasonable the name might want to be updated once the device is better identified.

---
 drivers/base/regmap/internal.h       |  4 ++--
 drivers/base/regmap/regmap-debugfs.c |  7 +++---
 drivers/base/regmap/regmap.c         | 44 +++++++++++++++++++++++++++---------
 3 files changed, 38 insertions(+), 17 deletions(-)
drivers/base/regmap/internal.h +2 -2
index 8a59359e145f6..e7ab94cc327a9 100644
@@ -220,7 +220,7 @@ struct regmap_field {
 
 #ifdef CONFIG_DEBUG_FS
 extern void regmap_debugfs_initcall(void);
-extern void regmap_debugfs_init(struct regmap *map, const char *name);
+extern void regmap_debugfs_init(struct regmap *map);
 extern void regmap_debugfs_exit(struct regmap *map);
 
 static inline void regmap_debugfs_disable(struct regmap *map)
@@ -230,7 +230,7 @@ static inline void regmap_debugfs_disable(struct regmap *map)
 
 #else
 static inline void regmap_debugfs_initcall(void) { }
-static inline void regmap_debugfs_init(struct regmap *map, const char *name) { }
+static inline void regmap_debugfs_init(struct regmap *map) { }
 static inline void regmap_debugfs_exit(struct regmap *map) { }
 static inline void regmap_debugfs_disable(struct regmap *map) { }
 #endif
drivers/base/regmap/regmap-debugfs.c +3 -4
index f58baff2be0af..b6d63ef16b442 100644
@@ -17,7 +17,6 @@
 
 struct regmap_debugfs_node {
 	struct regmap *map;
-	const char *name;
 	struct list_head link;
 };
 
@@ -544,11 +543,12 @@ static const struct file_operations regmap_cache_bypass_fops = {
 	.write = regmap_cache_bypass_write_file,
 };
 
-void regmap_debugfs_init(struct regmap *map, const char *name)
+void regmap_debugfs_init(struct regmap *map)
 {
 	struct rb_node *next;
 	struct regmap_range_node *range_node;
 	const char *devname = "dummy";
+	const char *name = map->name;
 
 	/*
 	 * Userspace can initiate reads from the hardware over debugfs.
@@ -569,7 +569,6 @@ void regmap_debugfs_init(struct regmap *map, const char *name)
 		if (!node)
 			return;
 		node->map = map;
-		node->name = name;
 		mutex_lock(&regmap_debugfs_early_lock);
 		list_add(&node->link, &regmap_debugfs_early_list);
 		mutex_unlock(&regmap_debugfs_early_lock);
@@ -679,7 +678,7 @@ void regmap_debugfs_initcall(void)
 
 	mutex_lock(&regmap_debugfs_early_lock);
 	list_for_each_entry_safe(node, tmp, &regmap_debugfs_early_list, link) {
-		regmap_debugfs_init(node->map, node->name);
+		regmap_debugfs_init(node->map);
 		list_del(&node->link);
 		kfree(node);
 	}
drivers/base/regmap/regmap.c +33 -11

89 lines not on this page · raw message

Signature · 1 line
2.11.0
maintainer
#1 lore raw
Quoted 8 lines · Charles Keepax

In regmap_debugfs_init the initialisation of the debugfs is delayed if the root node isn't ready yet. Most callers of regmap_debugfs_init pass the name from the regmap_config, which is considered temporary ie. may be unallocated after the regmap_init call returns. This leads to a potential use after free, where config->name has been freed by the time it is used in regmap_debugfs_initcall.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next

Thanks!

[1/1] regmap: debugfs: Fix handling of name string for debugfs init delays

      commit: 94cc89eb8fa5039fcb6e3e3d50f929ddcccee095

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

#2 lore raw
In reply to Charles Keepax

Hi Charles,

url:    https://github.com/0day-ci/linux/commits/Charles-Keepax/regmap-debugfs-Fix-handling-of-name-string-for-debugfs-init-delays/20200917-204117
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next
config: x86_64-randconfig-m001-20200917 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate

New smatch warnings:
drivers/base/regmap/regmap.c:1177 __regmap_init() error: uninitialized symbol 'ret'. drivers/base/regmap/regmap.c:1177 __regmap_init() warn: passing zero to 'ERR_PTR'

Old smatch warnings:
drivers/base/regmap/regmap.c:1901 _regmap_raw_write() error: uninitialized symbol 'ret'. drivers/base/regmap/regmap.c:2685 regmap_raw_read() error: uninitialized symbol 'ret'.

# https://github.com/0day-ci/linux/commit/d1cea9a7b51682f9b773cf376db0fe14656869a7
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Charles-Keepax/regmap-debugfs-Fix-handling-of-name-string-for-debugfs-init-delays/20200917-204117 git checkout d1cea9a7b51682f9b773cf376db0fe14656869a7
vim +/ret +1177 drivers/base/regmap/regmap.c

afcc00b91f1865f Xiubo Li            2015-12-03   948  
b83a313bf252018 Mark Brown          2011-05-11   949  	default:
8698b9364710e7b Baolin Wang         2017-11-01   950  		goto err_hwlock;

"ret" not set before the gotos and is uninitialized before the very first gotos in the function.

b83a313bf252018 Mark Brown          2011-05-11   951  	}
b83a313bf252018 Mark Brown          2011-05-11   952  
8a819ff8abac9ad Mark Brown          2013-03-04   953  	if (val_endian == REGMAP_ENDIAN_NATIVE)
8a819ff8abac9ad Mark Brown          2013-03-04   954  		map->format.parse_inplace = regmap_parse_inplace_noop;
8a819ff8abac9ad Mark Brown          2013-03-04   955  
b83a313bf252018 Mark Brown          2011-05-11   956  	switch (config->val_bits) {
b83a313bf252018 Mark Brown          2011-05-11   957  	case 8:
b83a313bf252018 Mark Brown          2011-05-11   958  		map->format.format_val = regmap_format_8;
b83a313bf252018 Mark Brown          2011-05-11   959  		map->format.parse_val = regmap_parse_8;
8a819ff8abac9ad Mark Brown          2013-03-04   960  		map->format.parse_inplace = regmap_parse_inplace_noop;
b83a313bf252018 Mark Brown          2011-05-11   961  		break;
b83a313bf252018 Mark Brown          2011-05-11   962  	case 16:
141eba2e006dd81 Stephen Warren      2012-05-24   963  		switch (val_endian) {
141eba2e006dd81 Stephen Warren      2012-05-24   964  		case REGMAP_ENDIAN_BIG:
141eba2e006dd81 Stephen Warren      2012-05-24   965  			map->format.format_val = regmap_format_16_be;
141eba2e006dd81 Stephen Warren      2012-05-24   966  			map->format.parse_val = regmap_parse_16_be;
8a819ff8abac9ad Mark Brown          2013-03-04   967  			map->format.parse_inplace = regmap_parse_16_be_inplace;
141eba2e006dd81 Stephen Warren      2012-05-24   968  			break;
4aa8c0694c731e0 Xiubo Li            2014-04-02   969  		case REGMAP_ENDIAN_LITTLE:
4aa8c0694c731e0 Xiubo Li            2014-04-02   970  			map->format.format_val = regmap_format_16_le;
4aa8c0694c731e0 Xiubo Li            2014-04-02   971  			map->format.parse_val = regmap_parse_16_le;
4aa8c0694c731e0 Xiubo Li            2014-04-02   972  			map->format.parse_inplace = regmap_parse_16_le_inplace;
4aa8c0694c731e0 Xiubo Li            2014-04-02   973  			break;
141eba2e006dd81 Stephen Warren      2012-05-24   974  		case REGMAP_ENDIAN_NATIVE:
141eba2e006dd81 Stephen Warren      2012-05-24   975  			map->format.format_val = regmap_format_16_native;
141eba2e006dd81 Stephen Warren      2012-05-24   976  			map->format.parse_val = regmap_parse_16_native;
141eba2e006dd81 Stephen Warren      2012-05-24   977  			break;
141eba2e006dd81 Stephen Warren      2012-05-24   978  		default:
8698b9364710e7b Baolin Wang         2017-11-01   979  			goto err_hwlock;
141eba2e006dd81 Stephen Warren      2012-05-24   980  		}
b83a313bf252018 Mark Brown          2011-05-11   981  		break;
ea279fc5619e254 Marc Reilly         2012-03-16   982  	case 24:
141eba2e006dd81 Stephen Warren      2012-05-24   983  		if (val_endian != REGMAP_ENDIAN_BIG)
8698b9364710e7b Baolin Wang         2017-11-01   984  			goto err_hwlock;
ea279fc5619e254 Marc Reilly         2012-03-16   985  		map->format.format_val = regmap_format_24;
ea279fc5619e254 Marc Reilly         2012-03-16   986  		map->format.parse_val = regmap_parse_24;
ea279fc5619e254 Marc Reilly         2012-03-16   987  		break;
7d5e525b9ceda0e Mark Brown          2012-02-17   988  	case 32:
141eba2e006dd81 Stephen Warren      2012-05-24   989  		switch (val_endian) {
141eba2e006dd81 Stephen Warren      2012-05-24   990  		case REGMAP_ENDIAN_BIG:
141eba2e006dd81 Stephen Warren      2012-05-24   991  			map->format.format_val = regmap_format_32_be;
141eba2e006dd81 Stephen Warren      2012-05-24   992  			map->format.parse_val = regmap_parse_32_be;
8a819ff8abac9ad Mark Brown          2013-03-04   993  			map->format.parse_inplace = regmap_parse_32_be_inplace;
141eba2e006dd81 Stephen Warren      2012-05-24   994  			break;
4aa8c0694c731e0 Xiubo Li            2014-04-02   995  		case REGMAP_ENDIAN_LITTLE:
4aa8c0694c731e0 Xiubo Li            2014-04-02   996  			map->format.format_val = regmap_format_32_le;
4aa8c0694c731e0 Xiubo Li            2014-04-02   997  			map->format.parse_val = regmap_parse_32_le;
4aa8c0694c731e0 Xiubo Li            2014-04-02   998  			map->format.parse_inplace = regmap_parse_32_le_inplace;
4aa8c0694c731e0 Xiubo Li            2014-04-02   999  			break;
141eba2e006dd81 Stephen Warren      2012-05-24  1000  		case REGMAP_ENDIAN_NATIVE:
141eba2e006dd81 Stephen Warren      2012-05-24  1001  			map->format.format_val = regmap_format_32_native;
141eba2e006dd81 Stephen Warren      2012-05-24  1002  			map->format.parse_val = regmap_parse_32_native;
141eba2e006dd81 Stephen Warren      2012-05-24  1003  			break;
141eba2e006dd81 Stephen Warren      2012-05-24  1004  		default:
8698b9364710e7b Baolin Wang         2017-11-01  1005  			goto err_hwlock;
141eba2e006dd81 Stephen Warren      2012-05-24  1006  		}
7d5e525b9ceda0e Mark Brown          2012-02-17  1007  		break;
afcc00b91f1865f Xiubo Li            2015-12-03  1008  #ifdef CONFIG_64BIT
782035ea94dc402 Dan Carpenter       2015-12-12  1009  	case 64:
afcc00b91f1865f Xiubo Li            2015-12-03  1010  		switch (val_endian) {
afcc00b91f1865f Xiubo Li            2015-12-03  1011  		case REGMAP_ENDIAN_BIG:
afcc00b91f1865f Xiubo Li            2015-12-03  1012  			map->format.format_val = regmap_format_64_be;
afcc00b91f1865f Xiubo Li            2015-12-03  1013  			map->format.parse_val = regmap_parse_64_be;
afcc00b91f1865f Xiubo Li            2015-12-03  1014  			map->format.parse_inplace = regmap_parse_64_be_inplace;
afcc00b91f1865f Xiubo Li            2015-12-03  1015  			break;
afcc00b91f1865f Xiubo Li            2015-12-03  1016  		case REGMAP_ENDIAN_LITTLE:
afcc00b91f1865f Xiubo Li            2015-12-03  1017  			map->format.format_val = regmap_format_64_le;
afcc00b91f1865f Xiubo Li            2015-12-03  1018  			map->format.parse_val = regmap_parse_64_le;
afcc00b91f1865f Xiubo Li            2015-12-03  1019  			map->format.parse_inplace = regmap_parse_64_le_inplace;
afcc00b91f1865f Xiubo Li            2015-12-03  1020  			break;
afcc00b91f1865f Xiubo Li            2015-12-03  1021  		case REGMAP_ENDIAN_NATIVE:
afcc00b91f1865f Xiubo Li            2015-12-03  1022  			map->format.format_val = regmap_format_64_native;
afcc00b91f1865f Xiubo Li            2015-12-03  1023  			map->format.parse_val = regmap_parse_64_native;
afcc00b91f1865f Xiubo Li            2015-12-03  1024  			break;
afcc00b91f1865f Xiubo Li            2015-12-03  1025  		default:
8698b9364710e7b Baolin Wang         2017-11-01  1026  			goto err_hwlock;
afcc00b91f1865f Xiubo Li            2015-12-03  1027  		}
afcc00b91f1865f Xiubo Li            2015-12-03  1028  		break;
afcc00b91f1865f Xiubo Li            2015-12-03  1029  #endif
b83a313bf252018 Mark Brown          2011-05-11  1030  	}
b83a313bf252018 Mark Brown          2011-05-11  1031  
141eba2e006dd81 Stephen Warren      2012-05-24  1032  	if (map->format.format_write) {
141eba2e006dd81 Stephen Warren      2012-05-24  1033  		if ((reg_endian != REGMAP_ENDIAN_BIG) ||
141eba2e006dd81 Stephen Warren      2012-05-24  1034  		    (val_endian != REGMAP_ENDIAN_BIG))
8698b9364710e7b Baolin Wang         2017-11-01  1035  			goto err_hwlock;
67921a1a6660d32 Markus Pargmann     2015-08-21  1036  		map->use_single_write = true;
141eba2e006dd81 Stephen Warren      2012-05-24  1037  	}
7a6476143270d94 Mark Brown          2012-04-30  1038  
b83a313bf252018 Mark Brown          2011-05-11  1039  	if (!map->format.format_write &&
b83a313bf252018 Mark Brown          2011-05-11  1040  	    !(map->format.format_reg && map->format.format_val))
8698b9364710e7b Baolin Wang         2017-11-01  1041  		goto err_hwlock;
b83a313bf252018 Mark Brown          2011-05-11  1042  
82159ba8e6ef8c3 Mark Brown          2012-01-18  1043  	map->work_buf = kzalloc(map->format.buf_size, GFP_KERNEL);
b83a313bf252018 Mark Brown          2011-05-11  1044  	if (map->work_buf == NULL) {
b83a313bf252018 Mark Brown          2011-05-11  1045  		ret = -ENOMEM;
8698b9364710e7b Baolin Wang         2017-11-01  1046  		goto err_hwlock;
b83a313bf252018 Mark Brown          2011-05-11  1047  	}
b83a313bf252018 Mark Brown          2011-05-11  1048  
d2a5884a64161b5 Andrey Smirnov      2013-01-27  1049  	if (map->format.format_write) {
d2a5884a64161b5 Andrey Smirnov      2013-01-27  1050  		map->defer_caching = false;
07c320dc31d757b Andrey Smirnov      2013-01-12  1051  		map->reg_write = _regmap_bus_formatted_write;
d2a5884a64161b5 Andrey Smirnov      2013-01-27  1052  	} else if (map->format.format_val) {
d2a5884a64161b5 Andrey Smirnov      2013-01-27  1053  		map->defer_caching = true;
07c320dc31d757b Andrey Smirnov      2013-01-12  1054  		map->reg_write = _regmap_bus_raw_write;
d2a5884a64161b5 Andrey Smirnov      2013-01-27  1055  	}
d2a5884a64161b5 Andrey Smirnov      2013-01-27  1056  
d2a5884a64161b5 Andrey Smirnov      2013-01-27  1057  skip_format_initialization:
07c320dc31d757b Andrey Smirnov      2013-01-12  1058  
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1059  	map->range_tree = RB_ROOT;
e3549cd01347ef2 Mark Brown          2012-10-02  1060  	for (i = 0; i < config->num_ranges; i++) {
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1061  		const struct regmap_range_cfg *range_cfg = &config->ranges[i];
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1062  		struct regmap_range_node *new;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1063  
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1064  		/* Sanity check */
061adc064adbbdd Mark Brown          2012-10-03  1065  		if (range_cfg->range_max < range_cfg->range_min) {
061adc064adbbdd Mark Brown          2012-10-03  1066  			dev_err(map->dev, "Invalid range %d: %d < %d\n", i,
061adc064adbbdd Mark Brown          2012-10-03  1067  				range_cfg->range_max, range_cfg->range_min);
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1068  			goto err_range;
061adc064adbbdd Mark Brown          2012-10-03  1069  		}
061adc064adbbdd Mark Brown          2012-10-03  1070  
061adc064adbbdd Mark Brown          2012-10-03  1071  		if (range_cfg->range_max > map->max_register) {
061adc064adbbdd Mark Brown          2012-10-03  1072  			dev_err(map->dev, "Invalid range %d: %d > %d\n", i,
061adc064adbbdd Mark Brown          2012-10-03  1073  				range_cfg->range_max, map->max_register);
061adc064adbbdd Mark Brown          2012-10-03  1074  			goto err_range;
061adc064adbbdd Mark Brown          2012-10-03  1075  		}
061adc064adbbdd Mark Brown          2012-10-03  1076  
061adc064adbbdd Mark Brown          2012-10-03  1077  		if (range_cfg->selector_reg > map->max_register) {
061adc064adbbdd Mark Brown          2012-10-03  1078  			dev_err(map->dev,
061adc064adbbdd Mark Brown          2012-10-03  1079  				"Invalid range %d: selector out of map\n", i);
061adc064adbbdd Mark Brown          2012-10-03  1080  			goto err_range;
061adc064adbbdd Mark Brown          2012-10-03  1081  		}
061adc064adbbdd Mark Brown          2012-10-03  1082  
061adc064adbbdd Mark Brown          2012-10-03  1083  		if (range_cfg->window_len == 0) {
061adc064adbbdd Mark Brown          2012-10-03  1084  			dev_err(map->dev, "Invalid range %d: window_len 0\n",
061adc064adbbdd Mark Brown          2012-10-03  1085  				i);
061adc064adbbdd Mark Brown          2012-10-03  1086  			goto err_range;
061adc064adbbdd Mark Brown          2012-10-03  1087  		}
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1088  
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1089  		/* Make sure, that this register range has no selector
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1090  		   or data window within its boundary */
e3549cd01347ef2 Mark Brown          2012-10-02  1091  		for (j = 0; j < config->num_ranges; j++) {
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1092  			unsigned sel_reg = config->ranges[j].selector_reg;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1093  			unsigned win_min = config->ranges[j].window_start;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1094  			unsigned win_max = win_min +
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1095  					   config->ranges[j].window_len - 1;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1096  
f161d22081e9b81 Philipp Zabel       2013-07-23  1097  			/* Allow data window inside its own virtual range */
f161d22081e9b81 Philipp Zabel       2013-07-23  1098  			if (j == i)
f161d22081e9b81 Philipp Zabel       2013-07-23  1099  				continue;
f161d22081e9b81 Philipp Zabel       2013-07-23  1100  
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1101  			if (range_cfg->range_min <= sel_reg &&
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1102  			    sel_reg <= range_cfg->range_max) {
061adc064adbbdd Mark Brown          2012-10-03  1103  				dev_err(map->dev,
061adc064adbbdd Mark Brown          2012-10-03  1104  					"Range %d: selector for %d in window\n",
061adc064adbbdd Mark Brown          2012-10-03  1105  					i, j);
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1106  				goto err_range;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1107  			}
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1108  
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1109  			if (!(win_max < range_cfg->range_min ||
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1110  			      win_min > range_cfg->range_max)) {
061adc064adbbdd Mark Brown          2012-10-03  1111  				dev_err(map->dev,
061adc064adbbdd Mark Brown          2012-10-03  1112  					"Range %d: window for %d in window\n",
061adc064adbbdd Mark Brown          2012-10-03  1113  					i, j);
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1114  				goto err_range;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1115  			}
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1116  		}
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1117  
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1118  		new = kzalloc(sizeof(*new), GFP_KERNEL);
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1119  		if (new == NULL) {
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1120  			ret = -ENOMEM;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1121  			goto err_range;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1122  		}
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1123  
4b020b3f9ba2af8 Mark Brown          2012-10-03  1124  		new->map = map;
d058bb49618482f Mark Brown          2012-10-03  1125  		new->name = range_cfg->name;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1126  		new->range_min = range_cfg->range_min;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1127  		new->range_max = range_cfg->range_max;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1128  		new->selector_reg = range_cfg->selector_reg;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1129  		new->selector_mask = range_cfg->selector_mask;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1130  		new->selector_shift = range_cfg->selector_shift;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1131  		new->window_start = range_cfg->window_start;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1132  		new->window_len = range_cfg->window_len;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1133  
53e87f88b14c011 Nenghua Cao         2014-02-21  1134  		if (!_regmap_range_add(map, new)) {
061adc064adbbdd Mark Brown          2012-10-03  1135  			dev_err(map->dev, "Failed to add range %d\n", i);
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1136  			kfree(new);
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1137  			goto err_range;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1138  		}
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1139  
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1140  		if (map->selector_work_buf == NULL) {
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1141  			map->selector_work_buf =
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1142  				kzalloc(map->format.buf_size, GFP_KERNEL);
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1143  			if (map->selector_work_buf == NULL) {
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1144  				ret = -ENOMEM;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1145  				goto err_range;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1146  			}
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1147  		}
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1148  	}
052d2cd123e7e36 Mark Brown          2011-11-21  1149  
e5e3b8abeda1cf4 Lars-Peter Clausen  2011-11-16  1150  	ret = regcache_init(map, config);
0ff3e62ff119f2b Mark Brown          2012-10-04  1151  	if (ret != 0)
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1152  		goto err_range;
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1153  
a7a037c837cb0f9 Daeseok Youn        2014-04-01  1154  	if (dev) {
6cfec04bcc05a82 Michal Simek        2014-02-10  1155  		ret = regmap_attach_dev(dev, map, config);
6cfec04bcc05a82 Michal Simek        2014-02-10  1156  		if (ret != 0)
6cfec04bcc05a82 Michal Simek        2014-02-10  1157  			goto err_regcache;
9b947a13e7f6017 David Lechner       2018-02-19  1158  	} else {
d1cea9a7b51682f Charles Keepax      2020-09-17  1159  		regmap_debugfs_init(map);
a7a037c837cb0f9 Daeseok Youn        2014-04-01  1160  	}
72b39f6f2b5a6b0 Mark Brown          2012-05-08  1161  
b83a313bf252018 Mark Brown          2011-05-11  1162  	return map;
b83a313bf252018 Mark Brown          2011-05-11  1163  
6cfec04bcc05a82 Michal Simek        2014-02-10  1164  err_regcache:
72b39f6f2b5a6b0 Mark Brown          2012-05-08  1165  	regcache_exit(map);
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1166  err_range:
6863ca6227598d1 Krystian Garbaciak  2012-06-15  1167  	regmap_range_exit(map);
58072cbfc522c25 Lars-Peter Clausen  2011-11-10  1168  	kfree(map->work_buf);
8698b9364710e7b Baolin Wang         2017-11-01  1169  err_hwlock:
a1a68fcaf165a6e Baolin Wang         2017-11-20  1170  	if (map->hwlock)
8698b9364710e7b Baolin Wang         2017-11-01  1171  		hwspin_lock_free(map->hwlock);
8253bb3f82554ce Bartosz Golaszewski 2017-12-13  1172  err_name:
8253bb3f82554ce Bartosz Golaszewski 2017-12-13  1173  	kfree_const(map->name);
b83a313bf252018 Mark Brown          2011-05-11  1174  err_map:
b83a313bf252018 Mark Brown          2011-05-11  1175  	kfree(map);
b83a313bf252018 Mark Brown          2011-05-11  1176  err:
b83a313bf252018 Mark Brown          2011-05-11 @1177  	return ERR_PTR(ret);
                                                        ^^^^^^^^^^^^^^^^^^^

Leads to an Oops in the caller.

b83a313bf252018 Mark Brown          2011-05-11  1178  }
3cfe7a74d42b7e3 Nicolas Boichat     2015-07-08  1179  EXPORT_SYMBOL_GPL(__regmap_init);

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org