Skip to content

Commit

Permalink
lib/string_helpers: fix not adding strarray to device's resource list
Browse files Browse the repository at this point in the history
Add allocated strarray to device's resource list. This is a must to
automatically release strarray when the device disappears.

Without this fix we have a memory leak in the few drivers which use
devm_kasprintf_strarray().

Link: https://lkml.kernel.org/r/20220506044409.30066-1-puyou.lu@gmail.com
Link: https://lkml.kernel.org/r/20220506073623.2679-1-puyou.lu@gmail.com
Fixes: acdb89b ("lib/string_helpers: Introduce managed variant of kasprintf_strarray()")
Signed-off-by: Puyou Lu <puyou.lu@gmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
Puyou Lu authored and Andrew Morton committed May 13, 2022
1 parent a7bd57b commit cd290a9
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/string_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,9 @@ char **devm_kasprintf_strarray(struct device *dev, const char *prefix, size_t n)
return ERR_PTR(-ENOMEM);
}

ptr->n = n;
devres_add(dev, ptr);

return ptr->array;
}
EXPORT_SYMBOL_GPL(devm_kasprintf_strarray);
Expand Down

0 comments on commit cd290a9

Please sign in to comment.