* [PATCH v3 0/4] remoteproc: Refactor function rproc_alloc()
@ 2020-04-20 23:15 Mathieu Poirier
2020-04-20 23:15 ` [PATCH v3 1/4] remoteproc: Use kstrdup_const() rather than kstrdup() Mathieu Poirier
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Mathieu Poirier @ 2020-04-20 23:15 UTC (permalink / raw)
To: bjorn.andersson, ohad
Cc: elder, s-anna, Markus.Elfring, linux-remoteproc, linux-kernel
These are the remaining patches from the second version [1] that have
not been applied yet.
Applies cleanly on rproc-next (3898fc99d199)
Thanks,
Mathieu
New for V3:
- Freeing firmware name allocation with kfree_const() in patch 1.
- Get the comment out of the conditional block in patch 2.
- A cleaner implementation of function rproc_alloc_ops() in patch 3.
New for V2:
- Reworked title for patch 01.
- Added "Fixes" tag to patch 01.
- Using kasprintf() instead of complex memory allocation.
- Using kstrdup_const() instead of kstrdup().
- Reworked rproc_alloc_firmware() to use non-negative form.
[1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=271809
Mathieu Poirier (4):
remoteproc: Use kstrdup_const() rather than kstrdup()
remoteproc: Restructure firmware name allocation
remoteproc: Split rproc_ops allocation from rproc_alloc()
remoteproc: Get rid of tedious error path
drivers/remoteproc/remoteproc_core.c | 70 +++++++++++++++-------------
include/linux/remoteproc.h | 2 +-
2 files changed, 39 insertions(+), 33 deletions(-)
--
2.20.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3 1/4] remoteproc: Use kstrdup_const() rather than kstrdup()
2020-04-20 23:15 [PATCH v3 0/4] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
@ 2020-04-20 23:15 ` Mathieu Poirier
2020-04-21 1:56 ` Bjorn Andersson
2020-04-20 23:15 ` [PATCH v3 2/4] remoteproc: Restructure firmware name allocation Mathieu Poirier
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Mathieu Poirier @ 2020-04-20 23:15 UTC (permalink / raw)
To: bjorn.andersson, ohad
Cc: elder, s-anna, Markus.Elfring, linux-remoteproc, linux-kernel
For cases where @firmware is declared "const char *", use function
kstrdup_const() to avoid needlessly creating another copy on the
heap.
Suggested-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
---
drivers/remoteproc/remoteproc_core.c | 8 ++++----
include/linux/remoteproc.h | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index d9e6949e4ac1..db8a15fc1e4a 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1996,7 +1996,7 @@ static void rproc_type_release(struct device *dev)
if (rproc->index >= 0)
ida_simple_remove(&rproc_dev_index, rproc->index);
- kfree(rproc->firmware);
+ kfree_const(rproc->firmware);
kfree(rproc->ops);
kfree(rproc);
}
@@ -2009,7 +2009,7 @@ static const struct device_type rproc_type = {
static int rproc_alloc_firmware(struct rproc *rproc,
const char *name, const char *firmware)
{
- char *p;
+ const char *p;
if (!firmware)
/*
@@ -2018,7 +2018,7 @@ static int rproc_alloc_firmware(struct rproc *rproc,
*/
p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
else
- p = kstrdup(firmware, GFP_KERNEL);
+ p = kstrdup_const(firmware, GFP_KERNEL);
if (!p)
return -ENOMEM;
@@ -2122,7 +2122,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
return rproc;
free_firmware:
- kfree(rproc->firmware);
+ kfree_const(rproc->firmware);
free_rproc:
kfree(rproc);
return NULL;
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index 0547676479d3..800b4f09dc98 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -489,7 +489,7 @@ struct rproc {
struct list_head node;
struct iommu_domain *domain;
const char *name;
- char *firmware;
+ const char *firmware;
void *priv;
struct rproc_ops *ops;
struct device dev;
--
2.20.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 2/4] remoteproc: Restructure firmware name allocation
2020-04-20 23:15 [PATCH v3 0/4] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
2020-04-20 23:15 ` [PATCH v3 1/4] remoteproc: Use kstrdup_const() rather than kstrdup() Mathieu Poirier
@ 2020-04-20 23:15 ` Mathieu Poirier
2020-04-21 1:56 ` Bjorn Andersson
2020-04-20 23:16 ` [PATCH v3 3/4] remoteproc: Split rproc_ops allocation from rproc_alloc() Mathieu Poirier
2020-04-20 23:16 ` [PATCH v3 4/4] remoteproc: Get rid of tedious error path Mathieu Poirier
3 siblings, 1 reply; 9+ messages in thread
From: Mathieu Poirier @ 2020-04-20 23:15 UTC (permalink / raw)
To: bjorn.andersson, ohad
Cc: elder, s-anna, Markus.Elfring, linux-remoteproc, linux-kernel
Improve the readability of function rproc_alloc_firmware() by using
a non-negated condition and moving the comment out of the conditional
block
Suggested-by: Alex Elder <elder@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
---
drivers/remoteproc/remoteproc_core.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index db8a15fc1e4a..45529d40342f 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -2011,14 +2011,14 @@ static int rproc_alloc_firmware(struct rproc *rproc,
{
const char *p;
- if (!firmware)
- /*
- * If the caller didn't pass in a firmware name then
- * construct a default name.
- */
- p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
- else
+ /*
+ * Allocate a firmware name if the caller gave us one to work
+ * with. Otherwise construct a new one using a default pattern.
+ */
+ if (firmware)
p = kstrdup_const(firmware, GFP_KERNEL);
+ else
+ p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
if (!p)
return -ENOMEM;
--
2.20.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 3/4] remoteproc: Split rproc_ops allocation from rproc_alloc()
2020-04-20 23:15 [PATCH v3 0/4] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
2020-04-20 23:15 ` [PATCH v3 1/4] remoteproc: Use kstrdup_const() rather than kstrdup() Mathieu Poirier
2020-04-20 23:15 ` [PATCH v3 2/4] remoteproc: Restructure firmware name allocation Mathieu Poirier
@ 2020-04-20 23:16 ` Mathieu Poirier
2020-04-21 1:57 ` Bjorn Andersson
2020-04-20 23:16 ` [PATCH v3 4/4] remoteproc: Get rid of tedious error path Mathieu Poirier
3 siblings, 1 reply; 9+ messages in thread
From: Mathieu Poirier @ 2020-04-20 23:16 UTC (permalink / raw)
To: bjorn.andersson, ohad
Cc: elder, s-anna, Markus.Elfring, linux-remoteproc, linux-kernel
Make the rproc_ops allocation a function on its own in an effort
to clean up function rproc_alloc().
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
---
drivers/remoteproc/remoteproc_core.c | 33 ++++++++++++++++++----------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 45529d40342f..15318507aedb 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -2028,6 +2028,26 @@ static int rproc_alloc_firmware(struct rproc *rproc,
return 0;
}
+static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops)
+{
+ rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL);
+ if (!rproc->ops)
+ return -ENOMEM;
+
+ if (rproc->ops->load)
+ return 0;
+
+ /* Default to ELF loader if no load function is specified */
+ rproc->ops->load = rproc_elf_load_segments;
+ rproc->ops->parse_fw = rproc_elf_load_rsc_table;
+ rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table;
+ if (!rproc->ops->sanity_check)
+ rproc->ops->sanity_check = rproc_elf32_sanity_check;
+ rproc->ops->get_boot_addr = rproc_elf_get_boot_addr;
+
+ return 0;
+}
+
/**
* rproc_alloc() - allocate a remote processor handle
* @dev: the underlying device
@@ -2067,8 +2087,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
if (rproc_alloc_firmware(rproc, name, firmware))
goto free_rproc;
- rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL);
- if (!rproc->ops)
+ if (rproc_alloc_ops(rproc, ops))
goto free_firmware;
rproc->name = name;
@@ -2096,16 +2115,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
atomic_set(&rproc->power, 0);
- /* Default to ELF loader if no load function is specified */
- if (!rproc->ops->load) {
- rproc->ops->load = rproc_elf_load_segments;
- rproc->ops->parse_fw = rproc_elf_load_rsc_table;
- rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table;
- if (!rproc->ops->sanity_check)
- rproc->ops->sanity_check = rproc_elf32_sanity_check;
- rproc->ops->get_boot_addr = rproc_elf_get_boot_addr;
- }
-
mutex_init(&rproc->lock);
INIT_LIST_HEAD(&rproc->carveouts);
--
2.20.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v3 4/4] remoteproc: Get rid of tedious error path
2020-04-20 23:15 [PATCH v3 0/4] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
` (2 preceding siblings ...)
2020-04-20 23:16 ` [PATCH v3 3/4] remoteproc: Split rproc_ops allocation from rproc_alloc() Mathieu Poirier
@ 2020-04-20 23:16 ` Mathieu Poirier
2020-04-21 2:01 ` Bjorn Andersson
3 siblings, 1 reply; 9+ messages in thread
From: Mathieu Poirier @ 2020-04-20 23:16 UTC (permalink / raw)
To: bjorn.andersson, ohad
Cc: elder, s-anna, Markus.Elfring, linux-remoteproc, linux-kernel
Get rid of tedious error management by moving firmware and operation
allocation after calling device_initialize(). That way we take advantage
of the automatic call to rproc_type_release() to cleanup after ourselves
when put_device() is called.
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Acked-by: Suman Anna <s-anna@ti.com>
---
drivers/remoteproc/remoteproc_core.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 15318507aedb..6fca4e2c0dd7 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -2084,12 +2084,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
if (!rproc)
return NULL;
- if (rproc_alloc_firmware(rproc, name, firmware))
- goto free_rproc;
-
- if (rproc_alloc_ops(rproc, ops))
- goto free_firmware;
-
rproc->name = name;
rproc->priv = &rproc[1];
rproc->auto_boot = true;
@@ -2103,12 +2097,17 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
rproc->dev.driver_data = rproc;
idr_init(&rproc->notifyids);
+ if (rproc_alloc_firmware(rproc, name, firmware))
+ goto put_device;
+
+ if (rproc_alloc_ops(rproc, ops))
+ goto put_device;
+
/* Assign a unique device index and name */
rproc->index = ida_simple_get(&rproc_dev_index, 0, 0, GFP_KERNEL);
if (rproc->index < 0) {
dev_err(dev, "ida_simple_get failed: %d\n", rproc->index);
- put_device(&rproc->dev);
- return NULL;
+ goto put_device;
}
dev_set_name(&rproc->dev, "remoteproc%d", rproc->index);
@@ -2130,10 +2129,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
return rproc;
-free_firmware:
- kfree_const(rproc->firmware);
-free_rproc:
- kfree(rproc);
+put_device:
+ put_device(&rproc->dev);
return NULL;
}
EXPORT_SYMBOL(rproc_alloc);
--
2.20.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v3 1/4] remoteproc: Use kstrdup_const() rather than kstrdup()
2020-04-20 23:15 ` [PATCH v3 1/4] remoteproc: Use kstrdup_const() rather than kstrdup() Mathieu Poirier
@ 2020-04-21 1:56 ` Bjorn Andersson
0 siblings, 0 replies; 9+ messages in thread
From: Bjorn Andersson @ 2020-04-21 1:56 UTC (permalink / raw)
To: Mathieu Poirier
Cc: ohad, elder, s-anna, Markus.Elfring, linux-remoteproc, linux-kernel
On Mon 20 Apr 16:15 PDT 2020, Mathieu Poirier wrote:
> For cases where @firmware is declared "const char *", use function
> kstrdup_const() to avoid needlessly creating another copy on the
> heap.
>
> Suggested-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> Reviewed-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> ---
> drivers/remoteproc/remoteproc_core.c | 8 ++++----
> include/linux/remoteproc.h | 2 +-
> 2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index d9e6949e4ac1..db8a15fc1e4a 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1996,7 +1996,7 @@ static void rproc_type_release(struct device *dev)
> if (rproc->index >= 0)
> ida_simple_remove(&rproc_dev_index, rproc->index);
>
> - kfree(rproc->firmware);
> + kfree_const(rproc->firmware);
> kfree(rproc->ops);
> kfree(rproc);
> }
> @@ -2009,7 +2009,7 @@ static const struct device_type rproc_type = {
> static int rproc_alloc_firmware(struct rproc *rproc,
> const char *name, const char *firmware)
> {
> - char *p;
> + const char *p;
>
> if (!firmware)
> /*
> @@ -2018,7 +2018,7 @@ static int rproc_alloc_firmware(struct rproc *rproc,
> */
> p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
> else
> - p = kstrdup(firmware, GFP_KERNEL);
> + p = kstrdup_const(firmware, GFP_KERNEL);
>
> if (!p)
> return -ENOMEM;
> @@ -2122,7 +2122,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
> return rproc;
>
> free_firmware:
> - kfree(rproc->firmware);
> + kfree_const(rproc->firmware);
> free_rproc:
> kfree(rproc);
> return NULL;
> diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
> index 0547676479d3..800b4f09dc98 100644
> --- a/include/linux/remoteproc.h
> +++ b/include/linux/remoteproc.h
> @@ -489,7 +489,7 @@ struct rproc {
> struct list_head node;
> struct iommu_domain *domain;
> const char *name;
> - char *firmware;
> + const char *firmware;
> void *priv;
> struct rproc_ops *ops;
> struct device dev;
> --
> 2.20.1
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 2/4] remoteproc: Restructure firmware name allocation
2020-04-20 23:15 ` [PATCH v3 2/4] remoteproc: Restructure firmware name allocation Mathieu Poirier
@ 2020-04-21 1:56 ` Bjorn Andersson
0 siblings, 0 replies; 9+ messages in thread
From: Bjorn Andersson @ 2020-04-21 1:56 UTC (permalink / raw)
To: Mathieu Poirier
Cc: ohad, elder, s-anna, Markus.Elfring, linux-remoteproc, linux-kernel
On Mon 20 Apr 16:15 PDT 2020, Mathieu Poirier wrote:
> Improve the readability of function rproc_alloc_firmware() by using
> a non-negated condition and moving the comment out of the conditional
> block
>
> Suggested-by: Alex Elder <elder@linaro.org>
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> Reviewed-by: Alex Elder <elder@linaro.org>
Looks better, thanks for respinning.
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Regards,
Bjorn
> ---
> drivers/remoteproc/remoteproc_core.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index db8a15fc1e4a..45529d40342f 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -2011,14 +2011,14 @@ static int rproc_alloc_firmware(struct rproc *rproc,
> {
> const char *p;
>
> - if (!firmware)
> - /*
> - * If the caller didn't pass in a firmware name then
> - * construct a default name.
> - */
> - p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
> - else
> + /*
> + * Allocate a firmware name if the caller gave us one to work
> + * with. Otherwise construct a new one using a default pattern.
> + */
> + if (firmware)
> p = kstrdup_const(firmware, GFP_KERNEL);
> + else
> + p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
>
> if (!p)
> return -ENOMEM;
> --
> 2.20.1
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 3/4] remoteproc: Split rproc_ops allocation from rproc_alloc()
2020-04-20 23:16 ` [PATCH v3 3/4] remoteproc: Split rproc_ops allocation from rproc_alloc() Mathieu Poirier
@ 2020-04-21 1:57 ` Bjorn Andersson
0 siblings, 0 replies; 9+ messages in thread
From: Bjorn Andersson @ 2020-04-21 1:57 UTC (permalink / raw)
To: Mathieu Poirier
Cc: ohad, elder, s-anna, Markus.Elfring, linux-remoteproc, linux-kernel
On Mon 20 Apr 16:16 PDT 2020, Mathieu Poirier wrote:
> Make the rproc_ops allocation a function on its own in an effort
> to clean up function rproc_alloc().
>
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> Reviewed-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> ---
> drivers/remoteproc/remoteproc_core.c | 33 ++++++++++++++++++----------
> 1 file changed, 21 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 45529d40342f..15318507aedb 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -2028,6 +2028,26 @@ static int rproc_alloc_firmware(struct rproc *rproc,
> return 0;
> }
>
> +static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops)
> +{
> + rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL);
> + if (!rproc->ops)
> + return -ENOMEM;
> +
> + if (rproc->ops->load)
> + return 0;
> +
> + /* Default to ELF loader if no load function is specified */
> + rproc->ops->load = rproc_elf_load_segments;
> + rproc->ops->parse_fw = rproc_elf_load_rsc_table;
> + rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table;
> + if (!rproc->ops->sanity_check)
> + rproc->ops->sanity_check = rproc_elf32_sanity_check;
> + rproc->ops->get_boot_addr = rproc_elf_get_boot_addr;
> +
> + return 0;
> +}
> +
> /**
> * rproc_alloc() - allocate a remote processor handle
> * @dev: the underlying device
> @@ -2067,8 +2087,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
> if (rproc_alloc_firmware(rproc, name, firmware))
> goto free_rproc;
>
> - rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL);
> - if (!rproc->ops)
> + if (rproc_alloc_ops(rproc, ops))
> goto free_firmware;
>
> rproc->name = name;
> @@ -2096,16 +2115,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>
> atomic_set(&rproc->power, 0);
>
> - /* Default to ELF loader if no load function is specified */
> - if (!rproc->ops->load) {
> - rproc->ops->load = rproc_elf_load_segments;
> - rproc->ops->parse_fw = rproc_elf_load_rsc_table;
> - rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table;
> - if (!rproc->ops->sanity_check)
> - rproc->ops->sanity_check = rproc_elf32_sanity_check;
> - rproc->ops->get_boot_addr = rproc_elf_get_boot_addr;
> - }
> -
> mutex_init(&rproc->lock);
>
> INIT_LIST_HEAD(&rproc->carveouts);
> --
> 2.20.1
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 4/4] remoteproc: Get rid of tedious error path
2020-04-20 23:16 ` [PATCH v3 4/4] remoteproc: Get rid of tedious error path Mathieu Poirier
@ 2020-04-21 2:01 ` Bjorn Andersson
0 siblings, 0 replies; 9+ messages in thread
From: Bjorn Andersson @ 2020-04-21 2:01 UTC (permalink / raw)
To: Mathieu Poirier
Cc: ohad, elder, s-anna, Markus.Elfring, linux-remoteproc, linux-kernel
On Mon 20 Apr 16:16 PDT 2020, Mathieu Poirier wrote:
> Get rid of tedious error management by moving firmware and operation
> allocation after calling device_initialize(). That way we take advantage
> of the automatic call to rproc_type_release() to cleanup after ourselves
> when put_device() is called.
>
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> Reviewed-by: Alex Elder <elder@linaro.org>
> Acked-by: Suman Anna <s-anna@ti.com>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> ---
> drivers/remoteproc/remoteproc_core.c | 21 +++++++++------------
> 1 file changed, 9 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 15318507aedb..6fca4e2c0dd7 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -2084,12 +2084,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
> if (!rproc)
> return NULL;
>
> - if (rproc_alloc_firmware(rproc, name, firmware))
> - goto free_rproc;
> -
> - if (rproc_alloc_ops(rproc, ops))
> - goto free_firmware;
> -
> rproc->name = name;
> rproc->priv = &rproc[1];
> rproc->auto_boot = true;
> @@ -2103,12 +2097,17 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
> rproc->dev.driver_data = rproc;
> idr_init(&rproc->notifyids);
>
> + if (rproc_alloc_firmware(rproc, name, firmware))
> + goto put_device;
> +
> + if (rproc_alloc_ops(rproc, ops))
> + goto put_device;
> +
> /* Assign a unique device index and name */
> rproc->index = ida_simple_get(&rproc_dev_index, 0, 0, GFP_KERNEL);
> if (rproc->index < 0) {
> dev_err(dev, "ida_simple_get failed: %d\n", rproc->index);
> - put_device(&rproc->dev);
> - return NULL;
> + goto put_device;
> }
>
> dev_set_name(&rproc->dev, "remoteproc%d", rproc->index);
> @@ -2130,10 +2129,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>
> return rproc;
>
> -free_firmware:
> - kfree_const(rproc->firmware);
> -free_rproc:
> - kfree(rproc);
> +put_device:
> + put_device(&rproc->dev);
> return NULL;
> }
> EXPORT_SYMBOL(rproc_alloc);
> --
> 2.20.1
>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-04-21 2:00 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-20 23:15 [PATCH v3 0/4] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
2020-04-20 23:15 ` [PATCH v3 1/4] remoteproc: Use kstrdup_const() rather than kstrdup() Mathieu Poirier
2020-04-21 1:56 ` Bjorn Andersson
2020-04-20 23:15 ` [PATCH v3 2/4] remoteproc: Restructure firmware name allocation Mathieu Poirier
2020-04-21 1:56 ` Bjorn Andersson
2020-04-20 23:16 ` [PATCH v3 3/4] remoteproc: Split rproc_ops allocation from rproc_alloc() Mathieu Poirier
2020-04-21 1:57 ` Bjorn Andersson
2020-04-20 23:16 ` [PATCH v3 4/4] remoteproc: Get rid of tedious error path Mathieu Poirier
2020-04-21 2:01 ` Bjorn Andersson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).