Skip to content

Commit

Permalink
clk: convert clock name allocations to kstrdup_const
Browse files Browse the repository at this point in the history
Clock subsystem frequently performs duplication of strings located in
read-only memory section.  Replacing kstrdup by kstrdup_const allows to
avoid such operations.

Signed-off-by: Andrzej Hajda <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Cc: Kyungmin Park <[email protected]>
Cc: Mike Turquette <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: Pekka Enberg <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Greg KH <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Andrzej Hajda authored and torvalds committed Feb 14, 2015
1 parent dfeb075 commit 612936f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions drivers/clk/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,7 @@ struct clk *clk_register(struct device *dev, struct clk_hw *hw)
goto fail_out;
}

clk->name = kstrdup(hw->init->name, GFP_KERNEL);
clk->name = kstrdup_const(hw->init->name, GFP_KERNEL);
if (!clk->name) {
pr_err("%s: could not allocate clk->name\n", __func__);
ret = -ENOMEM;
Expand All @@ -2075,7 +2075,7 @@ struct clk *clk_register(struct device *dev, struct clk_hw *hw)

/* copy each string name in case parent_names is __initdata */
for (i = 0; i < clk->num_parents; i++) {
clk->parent_names[i] = kstrdup(hw->init->parent_names[i],
clk->parent_names[i] = kstrdup_const(hw->init->parent_names[i],
GFP_KERNEL);
if (!clk->parent_names[i]) {
pr_err("%s: could not copy parent_names\n", __func__);
Expand All @@ -2090,10 +2090,10 @@ struct clk *clk_register(struct device *dev, struct clk_hw *hw)

fail_parent_names_copy:
while (--i >= 0)
kfree(clk->parent_names[i]);
kfree_const(clk->parent_names[i]);
kfree(clk->parent_names);
fail_parent_names:
kfree(clk->name);
kfree_const(clk->name);
fail_name:
kfree(clk);
fail_out:
Expand All @@ -2112,10 +2112,10 @@ static void __clk_release(struct kref *ref)

kfree(clk->parents);
while (--i >= 0)
kfree(clk->parent_names[i]);
kfree_const(clk->parent_names[i]);

kfree(clk->parent_names);
kfree(clk->name);
kfree_const(clk->name);
kfree(clk);
}

Expand Down

0 comments on commit 612936f

Please sign in to comment.