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
19961996 if (rproc->index >= 0)
19971997 ida_simple_remove(&rproc_dev_index, rproc->index);
19981998
1999− kfree(rproc->firmware);
1999+ kfree_const(rproc->firmware);
20002000 kfree(rproc->ops);
20012001 kfree(rproc);
20022002 }
@@ -2009,7 +2009,7 @@ static const struct device_type rproc_type = { · 6 unmodified lines
20092009 static int rproc_alloc_firmware(struct rproc *rproc,
20102010 const char *name, const char *firmware)
20112011 {
2012− char *p;
2012+ const char *p;
20132013
20142014 if (!firmware)
20152015 /*
@@ -2018,7 +2018,7 @@ static int rproc_alloc_firmware(struct rproc *rproc, · 2 unmodified lines
20182018 */
20192019 p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
20202020 else
2021− p = kstrdup(firmware, GFP_KERNEL);
2021+ p = kstrdup_const(firmware, GFP_KERNEL);
20222022
20232023 if (!p)
20242024 return -ENOMEM;
@@ -2122,7 +2122,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, · 97 unmodified lines
21222122 return rproc;
21232123
21242124 free_firmware:
2125− kfree(rproc->firmware);
2125+ kfree_const(rproc->firmware);
21262126 free_rproc:
21272127 kfree(rproc);
21282128 return NULL;
include/linux/remoteproc.h+1−1
@@ -489,7 +489,7 @@ struct rproc { · 488 unmodified lines
489489 struct list_head node;
490490 struct iommu_domain *domain;
491491 const char *name;
492− char *firmware;
492+ const char *firmware;
493493 void *priv;
494494 struct rproc_ops *ops;
495495 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