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

regulator: Copy config passed during registration

Copy the 'regulator_config' structure passed to regulator_register()
function so the driver could safely modify it after parsing init data.

The driver may want to change the config as a result of specific init
data parsed by regulator core (e.g. when core handled parsing device
tree).

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Krzysztof Kozlowski and committed by
Mark Brown
1b3de223 97bf6af1

+15 -3
+15 -3
drivers/regulator/core.c
··· 3581 3581 */ 3582 3582 struct regulator_dev * 3583 3583 regulator_register(const struct regulator_desc *regulator_desc, 3584 - const struct regulator_config *config) 3584 + const struct regulator_config *cfg) 3585 3585 { 3586 3586 const struct regulation_constraints *constraints = NULL; 3587 3587 const struct regulator_init_data *init_data; 3588 + struct regulator_config *config = NULL; 3588 3589 static atomic_t regulator_no = ATOMIC_INIT(0); 3589 3590 struct regulator_dev *rdev; 3590 3591 struct device *dev; 3591 3592 int ret, i; 3592 3593 const char *supply = NULL; 3593 3594 3594 - if (regulator_desc == NULL || config == NULL) 3595 + if (regulator_desc == NULL || cfg == NULL) 3595 3596 return ERR_PTR(-EINVAL); 3596 3597 3597 - dev = config->dev; 3598 + dev = cfg->dev; 3598 3599 WARN_ON(!dev); 3599 3600 3600 3601 if (regulator_desc->name == NULL || regulator_desc->ops == NULL) ··· 3624 3623 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); 3625 3624 if (rdev == NULL) 3626 3625 return ERR_PTR(-ENOMEM); 3626 + 3627 + /* 3628 + * Duplicate the config so the driver could override it after 3629 + * parsing init data. 3630 + */ 3631 + config = kmemdup(cfg, sizeof(*cfg), GFP_KERNEL); 3632 + if (config == NULL) { 3633 + kfree(rdev); 3634 + return ERR_PTR(-ENOMEM); 3635 + } 3627 3636 3628 3637 init_data = regulator_of_get_init_data(dev, regulator_desc, 3629 3638 &rdev->dev.of_node); ··· 3763 3752 rdev_init_debugfs(rdev); 3764 3753 out: 3765 3754 mutex_unlock(&regulator_list_mutex); 3755 + kfree(config); 3766 3756 return rdev; 3767 3757 3768 3758 unset_supplies: