2024-04-29 14:47:13

by Michał Mirosław

[permalink] [raw]
Subject: [PATCH v2 08/12] regulator/core: set_consumer_device_supply: avoid copying const data

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

Signed-off-by: Michał Mirosław <[email protected]>
---
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 efb68a5c85af..431e1c164b11 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1747,7 +1747,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;
@@ -1782,7 +1782,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;
}
@@ -1794,7 +1794,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