Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'regulator-fix-v5.9-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator

Pull regulator fixes from Mark Brown:
"The biggest set of fixes here is those from Michał Mirosław fixing
some locking issues with coupled regulators that are triggered in
cases where a coupled regulator is used by a device involved in
fs_reclaim like eMMC storage.

These are relatively serious for the affected systems, though the
circumstances where they trigger are very rare"

* tag 'regulator-fix-v5.9-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator:
regulator: pwm: Fix machine constraints application
regulator: core: Fix slab-out-of-bounds in regulator_unlock_recursive()
regulator: remove superfluous lock in regulator_resolve_coupling()
regulator: cleanup regulator_ena_gpio_free()
regulator: plug of_node leak in regulator_register()'s error path
regulator: push allocation in set_consumer_device_supply() out of lock
regulator: push allocations in create_regulator() outside of lock
regulator: push allocation in regulator_ena_gpio_request() out of lock
regulator: push allocation in regulator_init_coupling() outside of lock
regulator: fix spelling mistake "Cant" -> "Can't"
regulator: cros-ec-regulator: Add NULL test for devm_kmemdup call

+101 -85
+96 -83
drivers/regulator/core.c
··· 236 236 static void regulator_unlock_recursive(struct regulator_dev *rdev, 237 237 unsigned int n_coupled) 238 238 { 239 - struct regulator_dev *c_rdev; 240 - int i; 239 + struct regulator_dev *c_rdev, *supply_rdev; 240 + int i, supply_n_coupled; 241 241 242 242 for (i = n_coupled; i > 0; i--) { 243 243 c_rdev = rdev->coupling_desc.coupled_rdevs[i - 1]; ··· 245 245 if (!c_rdev) 246 246 continue; 247 247 248 - if (c_rdev->supply && !regulator_supply_is_couple(c_rdev)) 249 - regulator_unlock_recursive( 250 - c_rdev->supply->rdev, 251 - c_rdev->coupling_desc.n_coupled); 248 + if (c_rdev->supply && !regulator_supply_is_couple(c_rdev)) { 249 + supply_rdev = c_rdev->supply->rdev; 250 + supply_n_coupled = supply_rdev->coupling_desc.n_coupled; 251 + 252 + regulator_unlock_recursive(supply_rdev, 253 + supply_n_coupled); 254 + } 252 255 253 256 regulator_unlock(c_rdev); 254 257 } ··· 1464 1461 const char *consumer_dev_name, 1465 1462 const char *supply) 1466 1463 { 1467 - struct regulator_map *node; 1464 + struct regulator_map *node, *new_node; 1468 1465 int has_dev; 1469 1466 1470 1467 if (supply == NULL) ··· 1475 1472 else 1476 1473 has_dev = 0; 1477 1474 1475 + new_node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL); 1476 + if (new_node == NULL) 1477 + return -ENOMEM; 1478 + 1479 + new_node->regulator = rdev; 1480 + new_node->supply = supply; 1481 + 1482 + if (has_dev) { 1483 + new_node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL); 1484 + if (new_node->dev_name == NULL) { 1485 + kfree(new_node); 1486 + return -ENOMEM; 1487 + } 1488 + } 1489 + 1490 + mutex_lock(&regulator_list_mutex); 1478 1491 list_for_each_entry(node, &regulator_map_list, list) { 1479 1492 if (node->dev_name && consumer_dev_name) { 1480 1493 if (strcmp(node->dev_name, consumer_dev_name) != 0) ··· 1508 1489 node->regulator->desc->name, 1509 1490 supply, 1510 1491 dev_name(&rdev->dev), rdev_get_name(rdev)); 1511 - return -EBUSY; 1492 + goto fail; 1512 1493 } 1513 1494 1514 - node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL); 1515 - if (node == NULL) 1516 - return -ENOMEM; 1495 + list_add(&new_node->list, &regulator_map_list); 1496 + mutex_unlock(&regulator_list_mutex); 1517 1497 1518 - node->regulator = rdev; 1519 - node->supply = supply; 1520 - 1521 - if (has_dev) { 1522 - node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL); 1523 - if (node->dev_name == NULL) { 1524 - kfree(node); 1525 - return -ENOMEM; 1526 - } 1527 - } 1528 - 1529 - list_add(&node->list, &regulator_map_list); 1530 1498 return 0; 1499 + 1500 + fail: 1501 + mutex_unlock(&regulator_list_mutex); 1502 + kfree(new_node->dev_name); 1503 + kfree(new_node); 1504 + return -EBUSY; 1531 1505 } 1532 1506 1533 1507 static void unset_regulator_supplies(struct regulator_dev *rdev) ··· 1592 1580 const char *supply_name) 1593 1581 { 1594 1582 struct regulator *regulator; 1595 - char buf[REG_STR_SIZE]; 1596 - int err, size; 1583 + int err; 1584 + 1585 + if (dev) { 1586 + char buf[REG_STR_SIZE]; 1587 + int size; 1588 + 1589 + size = snprintf(buf, REG_STR_SIZE, "%s-%s", 1590 + dev->kobj.name, supply_name); 1591 + if (size >= REG_STR_SIZE) 1592 + return NULL; 1593 + 1594 + supply_name = kstrdup(buf, GFP_KERNEL); 1595 + if (supply_name == NULL) 1596 + return NULL; 1597 + } else { 1598 + supply_name = kstrdup_const(supply_name, GFP_KERNEL); 1599 + if (supply_name == NULL) 1600 + return NULL; 1601 + } 1597 1602 1598 1603 regulator = kzalloc(sizeof(*regulator), GFP_KERNEL); 1599 - if (regulator == NULL) 1604 + if (regulator == NULL) { 1605 + kfree(supply_name); 1600 1606 return NULL; 1607 + } 1608 + 1609 + regulator->rdev = rdev; 1610 + regulator->supply_name = supply_name; 1601 1611 1602 1612 regulator_lock(rdev); 1603 - regulator->rdev = rdev; 1604 1613 list_add(&regulator->list, &rdev->consumer_list); 1614 + regulator_unlock(rdev); 1605 1615 1606 1616 if (dev) { 1607 1617 regulator->dev = dev; 1608 1618 1609 1619 /* Add a link to the device sysfs entry */ 1610 - size = snprintf(buf, REG_STR_SIZE, "%s-%s", 1611 - dev->kobj.name, supply_name); 1612 - if (size >= REG_STR_SIZE) 1613 - goto overflow_err; 1614 - 1615 - regulator->supply_name = kstrdup(buf, GFP_KERNEL); 1616 - if (regulator->supply_name == NULL) 1617 - goto overflow_err; 1618 - 1619 1620 err = sysfs_create_link_nowarn(&rdev->dev.kobj, &dev->kobj, 1620 - buf); 1621 + supply_name); 1621 1622 if (err) { 1622 1623 rdev_dbg(rdev, "could not add device link %s err %d\n", 1623 1624 dev->kobj.name, err); 1624 1625 /* non-fatal */ 1625 1626 } 1626 - } else { 1627 - regulator->supply_name = kstrdup_const(supply_name, GFP_KERNEL); 1628 - if (regulator->supply_name == NULL) 1629 - goto overflow_err; 1630 1627 } 1631 1628 1632 - regulator->debugfs = debugfs_create_dir(regulator->supply_name, 1629 + regulator->debugfs = debugfs_create_dir(supply_name, 1633 1630 rdev->debugfs); 1634 1631 if (!regulator->debugfs) { 1635 1632 rdev_dbg(rdev, "Failed to create debugfs directory\n"); ··· 1663 1642 _regulator_is_enabled(rdev)) 1664 1643 regulator->always_on = true; 1665 1644 1666 - regulator_unlock(rdev); 1667 1645 return regulator; 1668 - overflow_err: 1669 - list_del(&regulator->list); 1670 - kfree(regulator); 1671 - regulator_unlock(rdev); 1672 - return NULL; 1673 1646 } 1674 1647 1675 1648 static int _regulator_get_enable_time(struct regulator_dev *rdev) ··· 2245 2230 static int regulator_ena_gpio_request(struct regulator_dev *rdev, 2246 2231 const struct regulator_config *config) 2247 2232 { 2248 - struct regulator_enable_gpio *pin; 2233 + struct regulator_enable_gpio *pin, *new_pin; 2249 2234 struct gpio_desc *gpiod; 2250 2235 2251 2236 gpiod = config->ena_gpiod; 2237 + new_pin = kzalloc(sizeof(*new_pin), GFP_KERNEL); 2238 + 2239 + mutex_lock(&regulator_list_mutex); 2252 2240 2253 2241 list_for_each_entry(pin, &regulator_ena_gpio_list, list) { 2254 2242 if (pin->gpiod == gpiod) { ··· 2260 2242 } 2261 2243 } 2262 2244 2263 - pin = kzalloc(sizeof(struct regulator_enable_gpio), GFP_KERNEL); 2264 - if (pin == NULL) 2245 + if (new_pin == NULL) { 2246 + mutex_unlock(&regulator_list_mutex); 2265 2247 return -ENOMEM; 2248 + } 2249 + 2250 + pin = new_pin; 2251 + new_pin = NULL; 2266 2252 2267 2253 pin->gpiod = gpiod; 2268 2254 list_add(&pin->list, &regulator_ena_gpio_list); ··· 2274 2252 update_ena_gpio_to_rdev: 2275 2253 pin->request_count++; 2276 2254 rdev->ena_pin = pin; 2255 + 2256 + mutex_unlock(&regulator_list_mutex); 2257 + kfree(new_pin); 2258 + 2277 2259 return 0; 2278 2260 } 2279 2261 ··· 2290 2264 2291 2265 /* Free the GPIO only in case of no use */ 2292 2266 list_for_each_entry_safe(pin, n, &regulator_ena_gpio_list, list) { 2293 - if (pin->gpiod == rdev->ena_pin->gpiod) { 2294 - if (pin->request_count <= 1) { 2295 - pin->request_count = 0; 2296 - gpiod_put(pin->gpiod); 2297 - list_del(&pin->list); 2298 - kfree(pin); 2299 - rdev->ena_pin = NULL; 2300 - return; 2301 - } else { 2302 - pin->request_count--; 2303 - } 2304 - } 2267 + if (pin != rdev->ena_pin) 2268 + continue; 2269 + 2270 + if (--pin->request_count) 2271 + break; 2272 + 2273 + gpiod_put(pin->gpiod); 2274 + list_del(&pin->list); 2275 + kfree(pin); 2276 + break; 2305 2277 } 2278 + 2279 + rdev->ena_pin = NULL; 2306 2280 } 2307 2281 2308 2282 /** ··· 4975 4949 return; 4976 4950 } 4977 4951 4978 - regulator_lock(c_rdev); 4979 - 4980 4952 c_desc->coupled_rdevs[i] = c_rdev; 4981 4953 c_desc->n_resolved++; 4982 - 4983 - regulator_unlock(c_rdev); 4984 4954 4985 4955 regulator_resolve_coupling(c_rdev); 4986 4956 } ··· 5062 5040 if (!of_check_coupling_data(rdev)) 5063 5041 return -EPERM; 5064 5042 5043 + mutex_lock(&regulator_list_mutex); 5065 5044 rdev->coupling_desc.coupler = regulator_find_coupler(rdev); 5045 + mutex_unlock(&regulator_list_mutex); 5046 + 5066 5047 if (IS_ERR(rdev->coupling_desc.coupler)) { 5067 5048 err = PTR_ERR(rdev->coupling_desc.coupler); 5068 5049 rdev_err(rdev, "failed to get coupler: %d\n", err); ··· 5166 5141 ret = -ENOMEM; 5167 5142 goto rinse; 5168 5143 } 5144 + device_initialize(&rdev->dev); 5169 5145 5170 5146 /* 5171 5147 * Duplicate the config so the driver could override it after ··· 5174 5148 */ 5175 5149 config = kmemdup(cfg, sizeof(*cfg), GFP_KERNEL); 5176 5150 if (config == NULL) { 5177 - kfree(rdev); 5178 5151 ret = -ENOMEM; 5179 - goto rinse; 5152 + goto clean; 5180 5153 } 5181 5154 5182 5155 init_data = regulator_of_get_init_data(dev, regulator_desc, config, ··· 5187 5162 * from a gpio extender or something else. 5188 5163 */ 5189 5164 if (PTR_ERR(init_data) == -EPROBE_DEFER) { 5190 - kfree(config); 5191 - kfree(rdev); 5192 5165 ret = -EPROBE_DEFER; 5193 - goto rinse; 5166 + goto clean; 5194 5167 } 5195 5168 5196 5169 /* ··· 5229 5206 } 5230 5207 5231 5208 if (config->ena_gpiod) { 5232 - mutex_lock(&regulator_list_mutex); 5233 5209 ret = regulator_ena_gpio_request(rdev, config); 5234 - mutex_unlock(&regulator_list_mutex); 5235 5210 if (ret != 0) { 5236 5211 rdev_err(rdev, "Failed to request enable GPIO: %d\n", 5237 5212 ret); ··· 5241 5220 } 5242 5221 5243 5222 /* register with sysfs */ 5244 - device_initialize(&rdev->dev); 5245 5223 rdev->dev.class = &regulator_class; 5246 5224 rdev->dev.parent = dev; 5247 5225 dev_set_name(&rdev->dev, "regulator.%lu", ··· 5268 5248 if (ret < 0) 5269 5249 goto wash; 5270 5250 5271 - mutex_lock(&regulator_list_mutex); 5272 5251 ret = regulator_init_coupling(rdev); 5273 - mutex_unlock(&regulator_list_mutex); 5274 5252 if (ret < 0) 5275 5253 goto wash; 5276 5254 5277 5255 /* add consumers devices */ 5278 5256 if (init_data) { 5279 - mutex_lock(&regulator_list_mutex); 5280 5257 for (i = 0; i < init_data->num_consumer_supplies; i++) { 5281 5258 ret = set_consumer_device_supply(rdev, 5282 5259 init_data->consumer_supplies[i].dev_name, 5283 5260 init_data->consumer_supplies[i].supply); 5284 5261 if (ret < 0) { 5285 - mutex_unlock(&regulator_list_mutex); 5286 5262 dev_err(dev, "Failed to set supply %s\n", 5287 5263 init_data->consumer_supplies[i].supply); 5288 5264 goto unset_supplies; 5289 5265 } 5290 5266 } 5291 - mutex_unlock(&regulator_list_mutex); 5292 5267 } 5293 5268 5294 5269 if (!rdev->desc->ops->get_voltage && ··· 5318 5303 mutex_lock(&regulator_list_mutex); 5319 5304 regulator_ena_gpio_free(rdev); 5320 5305 mutex_unlock(&regulator_list_mutex); 5321 - put_device(&rdev->dev); 5322 - rdev = NULL; 5323 5306 clean: 5324 5307 if (dangling_of_gpiod) 5325 5308 gpiod_put(config->ena_gpiod); 5326 - kfree(rdev); 5327 5309 kfree(config); 5310 + put_device(&rdev->dev); 5328 5311 rinse: 5329 5312 if (dangling_cfg_gpiod) 5330 5313 gpiod_put(cfg->ena_gpiod);
+3
drivers/regulator/cros-ec-regulator.c
··· 170 170 data->voltages_mV = 171 171 devm_kmemdup(dev, resp.voltages_mv, 172 172 sizeof(u16) * data->num_voltages, GFP_KERNEL); 173 + if (!data->voltages_mV) 174 + return -ENOMEM; 175 + 173 176 data->desc.n_voltages = data->num_voltages; 174 177 175 178 /* Make sure the returned name is always a valid string */
+1 -1
drivers/regulator/fixed.c
··· 182 182 183 183 drvdata->enable_clock = devm_clk_get(dev, NULL); 184 184 if (IS_ERR(drvdata->enable_clock)) { 185 - dev_err(dev, "Cant get enable-clock from devicetree\n"); 185 + dev_err(dev, "Can't get enable-clock from devicetree\n"); 186 186 return -ENOENT; 187 187 } 188 188 } else {
+1 -1
drivers/regulator/pwm-regulator.c
··· 279 279 return ret; 280 280 } 281 281 282 - drvdata->state = -EINVAL; 282 + drvdata->state = -ENOTRECOVERABLE; 283 283 drvdata->duty_cycle_table = duty_cycle_table; 284 284 drvdata->desc.ops = &pwm_regulator_voltage_table_ops; 285 285 drvdata->desc.n_voltages = length / sizeof(*duty_cycle_table);