History

remoteproc: Use kstrdup_const() rather than kstrdup()

For cases where @firmware is declared "const char *", use function kstrdup_const() to avoid needlessly creating another copy on the heap.

Mathieu Poirier committed 6 years ago

Commit 1487ded1 parent 1f36ab32 files · +5 −5Browse files

Unified · Split

2 files
  1. drivers/remoteproc/remoteproc_core.c +4 −4
  2. include/linux/remoteproc.h +1 −1
drivers/remoteproc/remoteproc_core.c+4−4
@@ -1996,7 +1996,7 @@ static void rproc_type_release(struct device *dev) · 1995 unmodified lines
1996 if (rproc->index >= 0)1996 if (rproc->index >= 0)
1997 ida_simple_remove(&rproc_dev_index, rproc->index);1997 ida_simple_remove(&rproc_dev_index, rproc->index);
1998 1998
1999 kfree(rproc->firmware);1999 kfree_const(rproc->firmware);
2000 kfree(rproc->ops);2000 kfree(rproc->ops);
2001 kfree(rproc);2001 kfree(rproc);
2002}2002}
@@ -2009,7 +2009,7 @@ static const struct device_type rproc_type = { · 6 unmodified lines
2009static int rproc_alloc_firmware(struct rproc *rproc,2009static int rproc_alloc_firmware(struct rproc *rproc,
2010 const char *name, const char *firmware)2010 const char *name, const char *firmware)
2011{2011{
2012 char *p;2012 const char *p;
2013 2013
2014 if (!firmware)2014 if (!firmware)
2015 /*2015 /*
@@ -2018,7 +2018,7 @@ static int rproc_alloc_firmware(struct rproc *rproc, · 2 unmodified lines
2018 */2018 */
2019 p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);2019 p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
2020 else2020 else
2021 p = kstrdup(firmware, GFP_KERNEL);2021 p = kstrdup_const(firmware, GFP_KERNEL);
2022 2022
2023 if (!p)2023 if (!p)
2024 return -ENOMEM;2024 return -ENOMEM;
@@ -2122,7 +2122,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, · 97 unmodified lines
2122 return rproc;2122 return rproc;
2123 2123
2124free_firmware:2124free_firmware:
2125 kfree(rproc->firmware);2125 kfree_const(rproc->firmware);
2126free_rproc:2126free_rproc:
2127 kfree(rproc);2127 kfree(rproc);
2128 return NULL;2128 return NULL;
include/linux/remoteproc.h+1−1
@@ -489,7 +489,7 @@ struct rproc { · 488 unmodified lines
489 struct list_head node;489 struct list_head node;
490 struct iommu_domain *domain;490 struct iommu_domain *domain;
491 const char *name;491 const char *name;
492 char *firmware;492 const char *firmware;
493 void *priv;493 void *priv;
494 struct rproc_ops *ops;494 struct rproc_ops *ops;
495 struct device dev;495 struct device dev;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t