[PATCH 8/9] regulator/core: set_consumer_device_supply: avoid copying const data

From: Michał Mirosław
Date: Wed Aug 30 2023 - 18:47:51 EST


As consumer_dev_name might as well be const, don't copy it if not
required.

Signed-off-by: Michał Mirosław <mirq-linux@xxxxxxxxxxxx>
---
drivers/regulator/core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 7c4ba090d88d..8ab4de7cadcb 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1735,7 +1735,7 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
new_node->supply = supply;

if (consumer_dev_name != NULL) {
- new_node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL);
+ new_node->dev_name = kstrdup_const(consumer_dev_name, GFP_KERNEL);
if (new_node->dev_name == NULL) {
kfree(new_node);
return -ENOMEM;
@@ -1770,7 +1770,7 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,

fail:
mutex_unlock(&regulator_list_mutex);
- kfree(new_node->dev_name);
+ kfree_const(new_node->dev_name);
kfree(new_node);
return -EBUSY;
}
@@ -1782,7 +1782,7 @@ static void unset_regulator_supplies(struct regulator_dev *rdev)
list_for_each_entry_safe(node, n, &regulator_map_list, list) {
if (rdev == node->regulator) {
list_del(&node->list);
- kfree(node->dev_name);
+ kfree_const(node->dev_name);
kfree(node);
}
}
--
2.39.2