linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc()
@ 2020-04-15 20:48 Mathieu Poirier
  2020-04-15 20:48 ` [PATCH v2 1/7] remoteproc: Fix IDR initialisation in rproc_alloc() Mathieu Poirier
                   ` (7 more replies)
  0 siblings, 8 replies; 33+ messages in thread
From: Mathieu Poirier @ 2020-04-15 20:48 UTC (permalink / raw)
  To: bjorn.andersson, ohad
  Cc: s-anna, elder, Markus.Elfring, linux-remoteproc, linux-kernel

Good afternoon,

This is the second installment in this series, the first one can be
found here[1].  The goal of the work is to consolidate modifications to
function rproc_alloc() that were made over the last weeks[2][3][4] to
provide a common foundation to work from and avoid merge conflicts.

Applies cleanly on v5.7-rc1

Thanks,
Mathieu

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=270239
[2]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=261069
[3]. https://patchwork.kernel.org/patch/11456385/
[4]. https://patchwork.kernel.org/patch/11473241/

Alex Elder (1):
  remoteproc: Fix IDR initialisation in rproc_alloc()

Mathieu Poirier (6):
  remoteproc: Split firmware name allocation from rproc_alloc()
  remoteproc: Simplify default name allocation
  remoteproc: Use kstrdup_const() rather than kstrup()
  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 | 96 +++++++++++++++-------------
 include/linux/remoteproc.h           |  2 +-
 2 files changed, 54 insertions(+), 44 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v2 1/7] remoteproc: Fix IDR initialisation in rproc_alloc()
  2020-04-15 20:48 [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
@ 2020-04-15 20:48 ` Mathieu Poirier
  2020-04-17 13:37   ` Suman Anna
  2020-04-20  5:00   ` Bjorn Andersson
  2020-04-15 20:48 ` [PATCH v2 2/7] remoteproc: Split firmware name allocation from rproc_alloc() Mathieu Poirier
                   ` (6 subsequent siblings)
  7 siblings, 2 replies; 33+ messages in thread
From: Mathieu Poirier @ 2020-04-15 20:48 UTC (permalink / raw)
  To: bjorn.andersson, ohad
  Cc: s-anna, elder, Markus.Elfring, linux-remoteproc, linux-kernel

From: Alex Elder <elder@linaro.org>

If ida_simple_get() returns an error when called in rproc_alloc(),
put_device() is called to clean things up.  By this time the rproc
device type has been assigned, with rproc_type_release() as the
release function.

The first thing rproc_type_release() does is call:
    idr_destroy(&rproc->notifyids);

But at the time the ida_simple_get() call is made, the notifyids
field in the remoteproc structure has not been initialized.

I'm not actually sure this case causes an observable problem, but
it's incorrect.  Fix this by initializing the notifyids field before
calling ida_simple_get() in rproc_alloc().

Fixes: b5ab5e24e960 ("remoteproc: maintain a generic child device for each rproc")
Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 drivers/remoteproc/remoteproc_core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index e12a54e67588..80056513ae71 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -2053,6 +2053,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
 	rproc->dev.type = &rproc_type;
 	rproc->dev.class = &rproc_class;
 	rproc->dev.driver_data = rproc;
+	idr_init(&rproc->notifyids);
 
 	/* Assign a unique device index and name */
 	rproc->index = ida_simple_get(&rproc_dev_index, 0, 0, GFP_KERNEL);
@@ -2078,8 +2079,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
 
 	mutex_init(&rproc->lock);
 
-	idr_init(&rproc->notifyids);
-
 	INIT_LIST_HEAD(&rproc->carveouts);
 	INIT_LIST_HEAD(&rproc->mappings);
 	INIT_LIST_HEAD(&rproc->traces);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v2 2/7] remoteproc: Split firmware name allocation from rproc_alloc()
  2020-04-15 20:48 [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
  2020-04-15 20:48 ` [PATCH v2 1/7] remoteproc: Fix IDR initialisation in rproc_alloc() Mathieu Poirier
@ 2020-04-15 20:48 ` Mathieu Poirier
  2020-04-15 21:28   ` Alex Elder
                     ` (2 more replies)
  2020-04-15 20:48 ` [PATCH v2 3/7] remoteproc: Simplify default name allocation Mathieu Poirier
                   ` (5 subsequent siblings)
  7 siblings, 3 replies; 33+ messages in thread
From: Mathieu Poirier @ 2020-04-15 20:48 UTC (permalink / raw)
  To: bjorn.andersson, ohad
  Cc: s-anna, elder, Markus.Elfring, linux-remoteproc, linux-kernel

Make the firmware name allocation a function on its own in an
effort to cleanup function rproc_alloc().

Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 drivers/remoteproc/remoteproc_core.c | 66 ++++++++++++++++------------
 1 file changed, 39 insertions(+), 27 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 80056513ae71..4dee63f319ba 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1979,6 +1979,33 @@ static const struct device_type rproc_type = {
 	.release	= rproc_type_release,
 };
 
+static int rproc_alloc_firmware(struct rproc *rproc,
+				const char *name, const char *firmware)
+{
+	char *p, *template = "rproc-%s-fw";
+	int name_len;
+
+	if (!firmware) {
+		/*
+		 * If the caller didn't pass in a firmware name then
+		 * construct a default name.
+		 */
+		name_len = strlen(name) + strlen(template) - 2 + 1;
+		p = kmalloc(name_len, GFP_KERNEL);
+		if (!p)
+			return -ENOMEM;
+		snprintf(p, name_len, template, name);
+	} else {
+		p = kstrdup(firmware, GFP_KERNEL);
+		if (!p)
+			return -ENOMEM;
+	}
+
+	rproc->firmware = p;
+
+	return 0;
+}
+
 /**
  * rproc_alloc() - allocate a remote processor handle
  * @dev: the underlying device
@@ -2007,42 +2034,21 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
 			  const char *firmware, int len)
 {
 	struct rproc *rproc;
-	char *p, *template = "rproc-%s-fw";
-	int name_len;
 
 	if (!dev || !name || !ops)
 		return NULL;
 
-	if (!firmware) {
-		/*
-		 * If the caller didn't pass in a firmware name then
-		 * construct a default name.
-		 */
-		name_len = strlen(name) + strlen(template) - 2 + 1;
-		p = kmalloc(name_len, GFP_KERNEL);
-		if (!p)
-			return NULL;
-		snprintf(p, name_len, template, name);
-	} else {
-		p = kstrdup(firmware, GFP_KERNEL);
-		if (!p)
-			return NULL;
-	}
-
 	rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL);
-	if (!rproc) {
-		kfree(p);
+	if (!rproc)
 		return NULL;
-	}
+
+	if (rproc_alloc_firmware(rproc, name, firmware))
+		goto free_rproc;
 
 	rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL);
-	if (!rproc->ops) {
-		kfree(p);
-		kfree(rproc);
-		return NULL;
-	}
+	if (!rproc->ops)
+		goto free_firmware;
 
-	rproc->firmware = p;
 	rproc->name = name;
 	rproc->priv = &rproc[1];
 	rproc->auto_boot = true;
@@ -2091,6 +2097,12 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
 	rproc->state = RPROC_OFFLINE;
 
 	return rproc;
+
+free_firmware:
+	kfree(rproc->firmware);
+free_rproc:
+	kfree(rproc);
+	return NULL;
 }
 EXPORT_SYMBOL(rproc_alloc);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v2 3/7] remoteproc: Simplify default name allocation
  2020-04-15 20:48 [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
  2020-04-15 20:48 ` [PATCH v2 1/7] remoteproc: Fix IDR initialisation in rproc_alloc() Mathieu Poirier
  2020-04-15 20:48 ` [PATCH v2 2/7] remoteproc: Split firmware name allocation from rproc_alloc() Mathieu Poirier
@ 2020-04-15 20:48 ` Mathieu Poirier
  2020-04-15 21:26   ` Alex Elder
  2020-04-20  5:10   ` Bjorn Andersson
  2020-04-15 20:48 ` [PATCH v2 4/7] remoteproc: Use kstrdup_const() rather than kstrup() Mathieu Poirier
                   ` (4 subsequent siblings)
  7 siblings, 2 replies; 33+ messages in thread
From: Mathieu Poirier @ 2020-04-15 20:48 UTC (permalink / raw)
  To: bjorn.andersson, ohad
  Cc: s-anna, elder, Markus.Elfring, linux-remoteproc, linux-kernel

In an effort to cleanup firmware name allocation, replace the
cumbersome mechanic used to allocate a default firmware name with
function kasprintf().

Suggested-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 drivers/remoteproc/remoteproc_core.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 4dee63f319ba..9899467fa1cf 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1982,24 +1982,19 @@ static const struct device_type rproc_type = {
 static int rproc_alloc_firmware(struct rproc *rproc,
 				const char *name, const char *firmware)
 {
-	char *p, *template = "rproc-%s-fw";
-	int name_len;
+	char *p;
 
-	if (!firmware) {
+	if (!firmware)
 		/*
 		 * If the caller didn't pass in a firmware name then
 		 * construct a default name.
 		 */
-		name_len = strlen(name) + strlen(template) - 2 + 1;
-		p = kmalloc(name_len, GFP_KERNEL);
-		if (!p)
-			return -ENOMEM;
-		snprintf(p, name_len, template, name);
-	} else {
+		p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
+	else
 		p = kstrdup(firmware, GFP_KERNEL);
-		if (!p)
-			return -ENOMEM;
-	}
+
+	if (!p)
+		return -ENOMEM;
 
 	rproc->firmware = p;
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v2 4/7] remoteproc: Use kstrdup_const() rather than kstrup()
  2020-04-15 20:48 [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
                   ` (2 preceding siblings ...)
  2020-04-15 20:48 ` [PATCH v2 3/7] remoteproc: Simplify default name allocation Mathieu Poirier
@ 2020-04-15 20:48 ` Mathieu Poirier
  2020-04-15 21:25   ` Alex Elder
  2020-04-17 16:12   ` [v2 4/7] remoteproc: Use kstrdup_const() rather than kstrdup() Markus Elfring
  2020-04-15 20:48 ` [PATCH v2 5/7] remoteproc: Restructure firmware name allocation Mathieu Poirier
                   ` (3 subsequent siblings)
  7 siblings, 2 replies; 33+ messages in thread
From: Mathieu Poirier @ 2020-04-15 20:48 UTC (permalink / raw)
  To: bjorn.andersson, ohad
  Cc: s-anna, elder, 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>
---
 drivers/remoteproc/remoteproc_core.c | 4 ++--
 include/linux/remoteproc.h           | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 9899467fa1cf..ebaff496ef81 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1982,7 +1982,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)
 		/*
@@ -1991,7 +1991,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;
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index 9c07d7958c53..38607107b7cb 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] 33+ messages in thread

* [PATCH v2 5/7] remoteproc: Restructure firmware name allocation
  2020-04-15 20:48 [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
                   ` (3 preceding siblings ...)
  2020-04-15 20:48 ` [PATCH v2 4/7] remoteproc: Use kstrdup_const() rather than kstrup() Mathieu Poirier
@ 2020-04-15 20:48 ` Mathieu Poirier
  2020-04-15 21:23   ` Alex Elder
  2020-04-16  6:26   ` Markus Elfring
  2020-04-15 20:48 ` [PATCH v2 6/7] remoteproc: Split rproc_ops allocation from rproc_alloc() Mathieu Poirier
                   ` (2 subsequent siblings)
  7 siblings, 2 replies; 33+ messages in thread
From: Mathieu Poirier @ 2020-04-15 20:48 UTC (permalink / raw)
  To: bjorn.andersson, ohad
  Cc: s-anna, elder, Markus.Elfring, linux-remoteproc, linux-kernel

Improve the readability of function rproc_alloc_firmware() by using
a non-negated condition.

Suggested-by: Alex Elder <elder@linaro.org>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 drivers/remoteproc/remoteproc_core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index ebaff496ef81..0bfa6998705d 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1984,14 +1984,14 @@ static int rproc_alloc_firmware(struct rproc *rproc,
 {
 	const char *p;
 
-	if (!firmware)
+	if (firmware)
+		p = kstrdup_const(firmware, GFP_KERNEL);
+	else
 		/*
 		 * If the caller didn't pass in a firmware name then
 		 * construct a default name.
 		 */
 		p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
-	else
-		p = kstrdup_const(firmware, GFP_KERNEL);
 
 	if (!p)
 		return -ENOMEM;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v2 6/7] remoteproc: Split rproc_ops allocation from rproc_alloc()
  2020-04-15 20:48 [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
                   ` (4 preceding siblings ...)
  2020-04-15 20:48 ` [PATCH v2 5/7] remoteproc: Restructure firmware name allocation Mathieu Poirier
@ 2020-04-15 20:48 ` Mathieu Poirier
  2020-04-17 13:49   ` Suman Anna
  2020-04-15 20:48 ` [PATCH v2 7/7] remoteproc: Get rid of tedious error path Mathieu Poirier
  2020-04-17 13:34 ` [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc() Suman Anna
  7 siblings, 1 reply; 33+ messages in thread
From: Mathieu Poirier @ 2020-04-15 20:48 UTC (permalink / raw)
  To: bjorn.andersson, ohad
  Cc: s-anna, elder, 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 | 32 +++++++++++++++++-----------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 0bfa6998705d..a5a0ceb86b3f 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -2001,6 +2001,25 @@ 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;
+
+	/* 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;
+		rproc->ops->sanity_check = rproc_elf_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
@@ -2040,8 +2059,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;
@@ -2068,16 +2086,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] 33+ messages in thread

* [PATCH v2 7/7] remoteproc: Get rid of tedious error path
  2020-04-15 20:48 [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
                   ` (5 preceding siblings ...)
  2020-04-15 20:48 ` [PATCH v2 6/7] remoteproc: Split rproc_ops allocation from rproc_alloc() Mathieu Poirier
@ 2020-04-15 20:48 ` Mathieu Poirier
  2020-04-17 13:50   ` Suman Anna
  2020-04-17 13:34 ` [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc() Suman Anna
  7 siblings, 1 reply; 33+ messages in thread
From: Mathieu Poirier @ 2020-04-15 20:48 UTC (permalink / raw)
  To: bjorn.andersson, ohad
  Cc: s-anna, elder, 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>
---
 drivers/remoteproc/remoteproc_core.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index a5a0ceb86b3f..405c94f151a7 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -2056,12 +2056,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;
@@ -2074,12 +2068,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);
@@ -2100,11 +2099,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
 	rproc->state = RPROC_OFFLINE;
 
 	return rproc;
-
-free_firmware:
-	kfree(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] 33+ messages in thread

* Re: [PATCH v2 5/7] remoteproc: Restructure firmware name allocation
  2020-04-15 20:48 ` [PATCH v2 5/7] remoteproc: Restructure firmware name allocation Mathieu Poirier
@ 2020-04-15 21:23   ` Alex Elder
  2020-04-20  5:17     ` Bjorn Andersson
  2020-04-16  6:26   ` Markus Elfring
  1 sibling, 1 reply; 33+ messages in thread
From: Alex Elder @ 2020-04-15 21:23 UTC (permalink / raw)
  To: Mathieu Poirier, bjorn.andersson, ohad
  Cc: s-anna, Markus.Elfring, linux-remoteproc, linux-kernel

On 4/15/20 3:48 PM, Mathieu Poirier wrote:
> Improve the readability of function rproc_alloc_firmware() by using
> a non-negated condition.
> 
> Suggested-by: Alex Elder <elder@linaro.org>
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>

If it were me, I'd move the comment above the if statement and
perhaps reword it a little bit to describe what's happening.
But no matter, this looks good.

Reviewed-by: Alex Elder <elder@linaro.org>

> ---
>  drivers/remoteproc/remoteproc_core.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index ebaff496ef81..0bfa6998705d 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1984,14 +1984,14 @@ static int rproc_alloc_firmware(struct rproc *rproc,
>  {
>  	const char *p;
>  
> -	if (!firmware)
> +	if (firmware)
> +		p = kstrdup_const(firmware, GFP_KERNEL);
> +	else
>  		/*
>  		 * If the caller didn't pass in a firmware name then
>  		 * construct a default name.
>  		 */
>  		p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
> -	else
> -		p = kstrdup_const(firmware, GFP_KERNEL);
>  
>  	if (!p)
>  		return -ENOMEM;
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 4/7] remoteproc: Use kstrdup_const() rather than kstrup()
  2020-04-15 20:48 ` [PATCH v2 4/7] remoteproc: Use kstrdup_const() rather than kstrup() Mathieu Poirier
@ 2020-04-15 21:25   ` Alex Elder
  2020-04-17 13:44     ` Suman Anna
  2020-04-17 16:12   ` [v2 4/7] remoteproc: Use kstrdup_const() rather than kstrdup() Markus Elfring
  1 sibling, 1 reply; 33+ messages in thread
From: Alex Elder @ 2020-04-15 21:25 UTC (permalink / raw)
  To: Mathieu Poirier, bjorn.andersson, ohad
  Cc: s-anna, Markus.Elfring, linux-remoteproc, linux-kernel

On 4/15/20 3:48 PM, 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>

Looks good.

Reviewed-by: Alex Elder <elder@linaro.org>

> ---
>  drivers/remoteproc/remoteproc_core.c | 4 ++--
>  include/linux/remoteproc.h           | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 9899467fa1cf..ebaff496ef81 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1982,7 +1982,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)
>  		/*
> @@ -1991,7 +1991,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;
> diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
> index 9c07d7958c53..38607107b7cb 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;
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 3/7] remoteproc: Simplify default name allocation
  2020-04-15 20:48 ` [PATCH v2 3/7] remoteproc: Simplify default name allocation Mathieu Poirier
@ 2020-04-15 21:26   ` Alex Elder
  2020-04-20  5:10   ` Bjorn Andersson
  1 sibling, 0 replies; 33+ messages in thread
From: Alex Elder @ 2020-04-15 21:26 UTC (permalink / raw)
  To: Mathieu Poirier, bjorn.andersson, ohad
  Cc: s-anna, Markus.Elfring, linux-remoteproc, linux-kernel

On 4/15/20 3:48 PM, Mathieu Poirier wrote:
> In an effort to cleanup firmware name allocation, replace the
> cumbersome mechanic used to allocate a default firmware name with
> function kasprintf().
> 
> Suggested-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>

Looks good to me.

Reviewed-by: Alex Elder <elder@linaro.org>

> ---
>  drivers/remoteproc/remoteproc_core.c | 19 +++++++------------
>  1 file changed, 7 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 4dee63f319ba..9899467fa1cf 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1982,24 +1982,19 @@ static const struct device_type rproc_type = {
>  static int rproc_alloc_firmware(struct rproc *rproc,
>  				const char *name, const char *firmware)
>  {
> -	char *p, *template = "rproc-%s-fw";
> -	int name_len;
> +	char *p;
>  
> -	if (!firmware) {
> +	if (!firmware)
>  		/*
>  		 * If the caller didn't pass in a firmware name then
>  		 * construct a default name.
>  		 */
> -		name_len = strlen(name) + strlen(template) - 2 + 1;
> -		p = kmalloc(name_len, GFP_KERNEL);
> -		if (!p)
> -			return -ENOMEM;
> -		snprintf(p, name_len, template, name);
> -	} else {
> +		p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
> +	else
>  		p = kstrdup(firmware, GFP_KERNEL);
> -		if (!p)
> -			return -ENOMEM;
> -	}
> +
> +	if (!p)
> +		return -ENOMEM;
>  
>  	rproc->firmware = p;
>  
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 2/7] remoteproc: Split firmware name allocation from rproc_alloc()
  2020-04-15 20:48 ` [PATCH v2 2/7] remoteproc: Split firmware name allocation from rproc_alloc() Mathieu Poirier
@ 2020-04-15 21:28   ` Alex Elder
  2020-04-20  5:09   ` Bjorn Andersson
  2020-04-20  9:24   ` Arnaud POULIQUEN
  2 siblings, 0 replies; 33+ messages in thread
From: Alex Elder @ 2020-04-15 21:28 UTC (permalink / raw)
  To: Mathieu Poirier, bjorn.andersson, ohad
  Cc: s-anna, Markus.Elfring, linux-remoteproc, linux-kernel

On 4/15/20 3:48 PM, Mathieu Poirier wrote:
> Make the firmware name allocation a function on its own in an
> effort to cleanup function rproc_alloc().
> 
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>

Looks good.

Reviewed-by: Alex Elder <elder@linaro.org>

> ---
>  drivers/remoteproc/remoteproc_core.c | 66 ++++++++++++++++------------
>  1 file changed, 39 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 80056513ae71..4dee63f319ba 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1979,6 +1979,33 @@ static const struct device_type rproc_type = {
>  	.release	= rproc_type_release,
>  };
>  
> +static int rproc_alloc_firmware(struct rproc *rproc,
> +				const char *name, const char *firmware)
> +{
> +	char *p, *template = "rproc-%s-fw";
> +	int name_len;
> +
> +	if (!firmware) {
> +		/*
> +		 * If the caller didn't pass in a firmware name then
> +		 * construct a default name.
> +		 */
> +		name_len = strlen(name) + strlen(template) - 2 + 1;
> +		p = kmalloc(name_len, GFP_KERNEL);
> +		if (!p)
> +			return -ENOMEM;
> +		snprintf(p, name_len, template, name);
> +	} else {
> +		p = kstrdup(firmware, GFP_KERNEL);
> +		if (!p)
> +			return -ENOMEM;
> +	}
> +
> +	rproc->firmware = p;
> +
> +	return 0;
> +}
> +
>  /**
>   * rproc_alloc() - allocate a remote processor handle
>   * @dev: the underlying device
> @@ -2007,42 +2034,21 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>  			  const char *firmware, int len)
>  {
>  	struct rproc *rproc;
> -	char *p, *template = "rproc-%s-fw";
> -	int name_len;
>  
>  	if (!dev || !name || !ops)
>  		return NULL;
>  
> -	if (!firmware) {
> -		/*
> -		 * If the caller didn't pass in a firmware name then
> -		 * construct a default name.
> -		 */
> -		name_len = strlen(name) + strlen(template) - 2 + 1;
> -		p = kmalloc(name_len, GFP_KERNEL);
> -		if (!p)
> -			return NULL;
> -		snprintf(p, name_len, template, name);
> -	} else {
> -		p = kstrdup(firmware, GFP_KERNEL);
> -		if (!p)
> -			return NULL;
> -	}
> -
>  	rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL);
> -	if (!rproc) {
> -		kfree(p);
> +	if (!rproc)
>  		return NULL;
> -	}
> +
> +	if (rproc_alloc_firmware(rproc, name, firmware))
> +		goto free_rproc;
>  
>  	rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL);
> -	if (!rproc->ops) {
> -		kfree(p);
> -		kfree(rproc);
> -		return NULL;
> -	}
> +	if (!rproc->ops)
> +		goto free_firmware;
>  
> -	rproc->firmware = p;
>  	rproc->name = name;
>  	rproc->priv = &rproc[1];
>  	rproc->auto_boot = true;
> @@ -2091,6 +2097,12 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>  	rproc->state = RPROC_OFFLINE;
>  
>  	return rproc;
> +
> +free_firmware:
> +	kfree(rproc->firmware);
> +free_rproc:
> +	kfree(rproc);
> +	return NULL;
>  }
>  EXPORT_SYMBOL(rproc_alloc);
>  
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 5/7] remoteproc: Restructure firmware name allocation
  2020-04-15 20:48 ` [PATCH v2 5/7] remoteproc: Restructure firmware name allocation Mathieu Poirier
  2020-04-15 21:23   ` Alex Elder
@ 2020-04-16  6:26   ` Markus Elfring
  2020-04-17 13:39     ` Suman Anna
  1 sibling, 1 reply; 33+ messages in thread
From: Markus Elfring @ 2020-04-16  6:26 UTC (permalink / raw)
  To: Mathieu Poirier, linux-remoteproc
  Cc: linux-kernel, Alex Elder, Bjorn Andersson, Ohad Ben-Cohen, Suman Anna

…
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1984,14 +1984,14 @@ static int rproc_alloc_firmware(struct rproc *rproc,
>  {
>  	const char *p;
>
> -	if (!firmware)
> +	if (firmware)
> +		p = kstrdup_const(firmware, GFP_KERNEL);
> +	else
>  		/*
>  		 * If the caller didn't pass in a firmware name then
>  		 * construct a default name.
>  		 */
>  		p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
> -	else
> -		p = kstrdup_const(firmware, GFP_KERNEL);

Can the use of the conditional operator make sense at such source code places?

	p = firmware ? kstrdup_const(…) : kasprintf(…);

Regards,
Markus

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc()
  2020-04-15 20:48 [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
                   ` (6 preceding siblings ...)
  2020-04-15 20:48 ` [PATCH v2 7/7] remoteproc: Get rid of tedious error path Mathieu Poirier
@ 2020-04-17 13:34 ` Suman Anna
  7 siblings, 0 replies; 33+ messages in thread
From: Suman Anna @ 2020-04-17 13:34 UTC (permalink / raw)
  To: Mathieu Poirier, bjorn.andersson, ohad
  Cc: elder, Markus.Elfring, linux-remoteproc, linux-kernel

Hi Mathieu,
On 4/15/20 3:48 PM, Mathieu Poirier wrote:
> Good afternoon,
> 
> This is the second installment in this series, the first one can be
> found here[1].  The goal of the work is to consolidate modifications to
> function rproc_alloc() that were made over the last weeks[2][3][4] to
> provide a common foundation to work from and avoid merge conflicts.
> 
> Applies cleanly on v5.7-rc1

Thanks for the patches. Overall looks good. I have couple of minor 
comments, will post them in the respective patches.

> 
> Thanks,
> Mathieu
> 
> 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=270239
> [2]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=261069
> [3]. https://patchwork.kernel.org/patch/11456385/

I have since reworked this and posted the next version on top of this 
series.
https://patchwork.kernel.org/patch/11493941/

regards
Suman

> [4]. https://patchwork.kernel.org/patch/11473241/
> 
> Alex Elder (1):
>    remoteproc: Fix IDR initialisation in rproc_alloc()
> 
> Mathieu Poirier (6):
>    remoteproc: Split firmware name allocation from rproc_alloc()
>    remoteproc: Simplify default name allocation
>    remoteproc: Use kstrdup_const() rather than kstrup()
>    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 | 96 +++++++++++++++-------------
>   include/linux/remoteproc.h           |  2 +-
>   2 files changed, 54 insertions(+), 44 deletions(-)
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 1/7] remoteproc: Fix IDR initialisation in rproc_alloc()
  2020-04-15 20:48 ` [PATCH v2 1/7] remoteproc: Fix IDR initialisation in rproc_alloc() Mathieu Poirier
@ 2020-04-17 13:37   ` Suman Anna
  2020-04-20  5:00   ` Bjorn Andersson
  1 sibling, 0 replies; 33+ messages in thread
From: Suman Anna @ 2020-04-17 13:37 UTC (permalink / raw)
  To: Mathieu Poirier, bjorn.andersson, ohad
  Cc: elder, Markus.Elfring, linux-remoteproc, linux-kernel

On 4/15/20 3:48 PM, Mathieu Poirier wrote:
> From: Alex Elder <elder@linaro.org>
> 
> If ida_simple_get() returns an error when called in rproc_alloc(),
> put_device() is called to clean things up.  By this time the rproc
> device type has been assigned, with rproc_type_release() as the
> release function.
> 
> The first thing rproc_type_release() does is call:
>      idr_destroy(&rproc->notifyids);
> 
> But at the time the ida_simple_get() call is made, the notifyids
> field in the remoteproc structure has not been initialized.
> 
> I'm not actually sure this case causes an observable problem, but
> it's incorrect.  Fix this by initializing the notifyids field before
> calling ida_simple_get() in rproc_alloc().
> 
> Fixes: b5ab5e24e960 ("remoteproc: maintain a generic child device for each rproc")
> Signed-off-by: Alex Elder <elder@linaro.org>
> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

Reviewed-by: Suman Anna <s-anna@ti.com>

Thanks Alex. I had exactly this particular comment on Mathieu's sync 
patch series [1].

regards
Suman

[1] https://patchwork.kernel.org/comment/23254901/

> ---
>   drivers/remoteproc/remoteproc_core.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index e12a54e67588..80056513ae71 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -2053,6 +2053,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>   	rproc->dev.type = &rproc_type;
>   	rproc->dev.class = &rproc_class;
>   	rproc->dev.driver_data = rproc;
> +	idr_init(&rproc->notifyids);
>   
>   	/* Assign a unique device index and name */
>   	rproc->index = ida_simple_get(&rproc_dev_index, 0, 0, GFP_KERNEL);
> @@ -2078,8 +2079,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>   
>   	mutex_init(&rproc->lock);
>   
> -	idr_init(&rproc->notifyids);
> -
>   	INIT_LIST_HEAD(&rproc->carveouts);
>   	INIT_LIST_HEAD(&rproc->mappings);
>   	INIT_LIST_HEAD(&rproc->traces);
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 5/7] remoteproc: Restructure firmware name allocation
  2020-04-16  6:26   ` Markus Elfring
@ 2020-04-17 13:39     ` Suman Anna
  2020-04-17 15:48       ` [v2 " Markus Elfring
  2020-04-17 21:28       ` [PATCH v2 " Mathieu Poirier
  0 siblings, 2 replies; 33+ messages in thread
From: Suman Anna @ 2020-04-17 13:39 UTC (permalink / raw)
  To: Markus Elfring, Mathieu Poirier, linux-remoteproc
  Cc: linux-kernel, Alex Elder, Bjorn Andersson, Ohad Ben-Cohen

Hi Markus,

On 4/16/20 1:26 AM, Markus Elfring wrote:
> …
>> +++ b/drivers/remoteproc/remoteproc_core.c
>> @@ -1984,14 +1984,14 @@ static int rproc_alloc_firmware(struct rproc *rproc,
>>   {
>>   	const char *p;
>>
>> -	if (!firmware)
>> +	if (firmware)
>> +		p = kstrdup_const(firmware, GFP_KERNEL);
>> +	else
>>   		/*
>>   		 * If the caller didn't pass in a firmware name then
>>   		 * construct a default name.
>>   		 */
>>   		p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
>> -	else
>> -		p = kstrdup_const(firmware, GFP_KERNEL);
> 
> Can the use of the conditional operator make sense at such source code places?
> 
> 	p = firmware ? kstrdup_const(…) : kasprintf(…);

For simple assignments, I too prefer the ternary operator, but in this 
case, I think it is better to leave the current code as is.

regards
Suman

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 4/7] remoteproc: Use kstrdup_const() rather than kstrup()
  2020-04-15 21:25   ` Alex Elder
@ 2020-04-17 13:44     ` Suman Anna
  2020-04-20  5:21       ` Bjorn Andersson
  0 siblings, 1 reply; 33+ messages in thread
From: Suman Anna @ 2020-04-17 13:44 UTC (permalink / raw)
  To: Alex Elder, Mathieu Poirier, bjorn.andersson, ohad
  Cc: Markus.Elfring, linux-remoteproc, linux-kernel

On 4/15/20 4:25 PM, Alex Elder wrote:
> On 4/15/20 3:48 PM, 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>
> 
> Looks good.
> 
> Reviewed-by: Alex Elder <elder@linaro.org>
> 
>> ---
>>   drivers/remoteproc/remoteproc_core.c | 4 ++--
>>   include/linux/remoteproc.h           | 2 +-
>>   2 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
>> index 9899467fa1cf..ebaff496ef81 100644
>> --- a/drivers/remoteproc/remoteproc_core.c
>> +++ b/drivers/remoteproc/remoteproc_core.c
>> @@ -1982,7 +1982,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)
>>   		/*
>> @@ -1991,7 +1991,7 @@ static int rproc_alloc_firmware(struct rproc *rproc,
>>   		 */
>>   		p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);

So, to be consistent for both paths, should we be using 
kvasprintf_const() here and kfree_const() in release. The kfree_const() 
is needed to account for the kstrdup_const below for sure.

regards
Suman

>>   	else
>> -		p = kstrdup(firmware, GFP_KERNEL);
>> +		p = kstrdup_const(firmware, GFP_KERNEL);
>>   
>>   	if (!p)
>>   		return -ENOMEM;
>> diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
>> index 9c07d7958c53..38607107b7cb 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;
>>
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 6/7] remoteproc: Split rproc_ops allocation from rproc_alloc()
  2020-04-15 20:48 ` [PATCH v2 6/7] remoteproc: Split rproc_ops allocation from rproc_alloc() Mathieu Poirier
@ 2020-04-17 13:49   ` Suman Anna
  2020-04-17 15:35     ` Suman Anna
  2020-04-17 21:56     ` Mathieu Poirier
  0 siblings, 2 replies; 33+ messages in thread
From: Suman Anna @ 2020-04-17 13:49 UTC (permalink / raw)
  To: Mathieu Poirier, bjorn.andersson, ohad
  Cc: elder, Markus.Elfring, linux-remoteproc, linux-kernel

On 4/15/20 3:48 PM, 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>
> ---
>   drivers/remoteproc/remoteproc_core.c | 32 +++++++++++++++++-----------
>   1 file changed, 20 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 0bfa6998705d..a5a0ceb86b3f 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -2001,6 +2001,25 @@ 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;
> +
> +	/* 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;
> +		rproc->ops->sanity_check = rproc_elf_sanity_check;

So, the conditional check on sanity check is dropped and the callback 
switched here without the changelog reflecting anything why. You should 
just rebase this patch on top of Clement's patch [1] that removes the 
conditional flag, and also usage from the remoteproc platform drivers.

regards
Suman

[1] https://patchwork.kernel.org/patch/11462013/


> +		rproc->ops->get_boot_addr = rproc_elf_get_boot_addr;
> +	}
> +
> +	return 0;
> +}
> +
>   /**
>    * rproc_alloc() - allocate a remote processor handle
>    * @dev: the underlying device
> @@ -2040,8 +2059,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;
> @@ -2068,16 +2086,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);
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 7/7] remoteproc: Get rid of tedious error path
  2020-04-15 20:48 ` [PATCH v2 7/7] remoteproc: Get rid of tedious error path Mathieu Poirier
@ 2020-04-17 13:50   ` Suman Anna
  0 siblings, 0 replies; 33+ messages in thread
From: Suman Anna @ 2020-04-17 13:50 UTC (permalink / raw)
  To: Mathieu Poirier, bjorn.andersson, ohad
  Cc: elder, Markus.Elfring, linux-remoteproc, linux-kernel

On 4/15/20 3:48 PM, 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>

regards
Suman

> ---
>   drivers/remoteproc/remoteproc_core.c | 22 +++++++++-------------
>   1 file changed, 9 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index a5a0ceb86b3f..405c94f151a7 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -2056,12 +2056,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;
> @@ -2074,12 +2068,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);
> @@ -2100,11 +2099,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>   	rproc->state = RPROC_OFFLINE;
>   
>   	return rproc;
> -
> -free_firmware:
> -	kfree(rproc->firmware);
> -free_rproc:
> -	kfree(rproc);
> +put_device:
> +	put_device(&rproc->dev);
>   	return NULL;
>   }
>   EXPORT_SYMBOL(rproc_alloc);
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 6/7] remoteproc: Split rproc_ops allocation from rproc_alloc()
  2020-04-17 13:49   ` Suman Anna
@ 2020-04-17 15:35     ` Suman Anna
  2020-04-17 21:56     ` Mathieu Poirier
  1 sibling, 0 replies; 33+ messages in thread
From: Suman Anna @ 2020-04-17 15:35 UTC (permalink / raw)
  To: Mathieu Poirier, bjorn.andersson, ohad
  Cc: elder, Markus.Elfring, linux-remoteproc, linux-kernel

On 4/17/20 8:49 AM, Suman Anna wrote:
> On 4/15/20 3:48 PM, 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>
>> ---
>>   drivers/remoteproc/remoteproc_core.c | 32 +++++++++++++++++-----------
>>   1 file changed, 20 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/remoteproc/remoteproc_core.c 
>> b/drivers/remoteproc/remoteproc_core.c
>> index 0bfa6998705d..a5a0ceb86b3f 100644
>> --- a/drivers/remoteproc/remoteproc_core.c
>> +++ b/drivers/remoteproc/remoteproc_core.c
>> @@ -2001,6 +2001,25 @@ 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;
>> +
>> +    /* 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;
>> +        rproc->ops->sanity_check = rproc_elf_sanity_check;
> 
> So, the conditional check on sanity check is dropped and the callback 
> switched here without the changelog reflecting anything why. You should 
> just rebase this patch on top of Clement's patch [1] that removes the 
> conditional flag, and also usage from the remoteproc platform drivers.
> 
> regards
> Suman
> 
> [1] https://patchwork.kernel.org/patch/11462013/

Sorry, gave the wrong link, that was v1. This is the latest,
https://patchwork.kernel.org/patch/11466955/

> 
> 
>> +        rproc->ops->get_boot_addr = rproc_elf_get_boot_addr;
>> +    }
>> +
>> +    return 0;
>> +}
>> +
>>   /**
>>    * rproc_alloc() - allocate a remote processor handle
>>    * @dev: the underlying device
>> @@ -2040,8 +2059,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;
>> @@ -2068,16 +2086,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);
>>
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [v2 5/7] remoteproc: Restructure firmware name allocation
  2020-04-17 13:39     ` Suman Anna
@ 2020-04-17 15:48       ` Markus Elfring
  2020-04-17 16:15         ` Suman Anna
  2020-04-17 20:58         ` Mathieu Poirier
  2020-04-17 21:28       ` [PATCH v2 " Mathieu Poirier
  1 sibling, 2 replies; 33+ messages in thread
From: Markus Elfring @ 2020-04-17 15:48 UTC (permalink / raw)
  To: Suman Anna, Mathieu Poirier, linux-remoteproc
  Cc: linux-kernel, Alex Elder, Bjorn Andersson, Ohad Ben-Cohen

>>     p = firmware ? kstrdup_const(…) : kasprintf(…);
>
> For simple assignments, I too prefer the ternary operator,

Thanks for your feedback.


> but in this case, I think it is better to leave the current code as is.

Would you like to consider the use of the function “kvasprintf_const”
according to your review comment for the update step “[PATCH v2 4/7] remoteproc:
Use kstrdup_const() rather than kstrup()”?

Regards,
Markus

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [v2 4/7] remoteproc: Use kstrdup_const() rather than kstrdup()
  2020-04-15 20:48 ` [PATCH v2 4/7] remoteproc: Use kstrdup_const() rather than kstrup() Mathieu Poirier
  2020-04-15 21:25   ` Alex Elder
@ 2020-04-17 16:12   ` Markus Elfring
  1 sibling, 0 replies; 33+ messages in thread
From: Markus Elfring @ 2020-04-17 16:12 UTC (permalink / raw)
  To: Mathieu Poirier, linux-remoteproc
  Cc: linux-kernel, Alex Elder, Bjorn Andersson, Ohad Ben-Cohen, Suman Anna

…
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1982,7 +1982,7 @@ static const struct device_type rproc_type = {
> -		p = kstrdup(firmware, GFP_KERNEL);
> +		p = kstrdup_const(firmware, GFP_KERNEL);

How do you think about to avoid a typo for a function name in
the final commit subject?

Regards,
Markus

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [v2 5/7] remoteproc: Restructure firmware name allocation
  2020-04-17 15:48       ` [v2 " Markus Elfring
@ 2020-04-17 16:15         ` Suman Anna
  2020-04-17 20:58         ` Mathieu Poirier
  1 sibling, 0 replies; 33+ messages in thread
From: Suman Anna @ 2020-04-17 16:15 UTC (permalink / raw)
  To: Markus Elfring, Mathieu Poirier, linux-remoteproc
  Cc: linux-kernel, Alex Elder, Bjorn Andersson, Ohad Ben-Cohen

On 4/17/20 10:48 AM, Markus Elfring wrote:
>>>      p = firmware ? kstrdup_const(…) : kasprintf(…);
>>
>> For simple assignments, I too prefer the ternary operator,
> 
> Thanks for your feedback.
> 
> 
>> but in this case, I think it is better to leave the current code as is.
> 
> Would you like to consider the use of the function “kvasprintf_const”
> according to your review comment for the update step “[PATCH v2 4/7] remoteproc:
> Use kstrdup_const() rather than kstrup()”?

This patch is just swapping the condition order, so will automatically 
be adjusted for any changes in patch 4 during the rebase.

regards
Suman

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [v2 5/7] remoteproc: Restructure firmware name allocation
  2020-04-17 15:48       ` [v2 " Markus Elfring
  2020-04-17 16:15         ` Suman Anna
@ 2020-04-17 20:58         ` Mathieu Poirier
  1 sibling, 0 replies; 33+ messages in thread
From: Mathieu Poirier @ 2020-04-17 20:58 UTC (permalink / raw)
  To: Markus Elfring
  Cc: Suman Anna, linux-remoteproc, linux-kernel, Alex Elder,
	Bjorn Andersson, Ohad Ben-Cohen

Hi Markus,

On Fri, Apr 17, 2020 at 05:48:49PM +0200, Markus Elfring wrote:
> >>     p = firmware ? kstrdup_const(…) : kasprintf(…);
> >
> > For simple assignments, I too prefer the ternary operator,
> 
> Thanks for your feedback.
> 
> 
> > but in this case, I think it is better to leave the current code as is.
> 
> Would you like to consider the use of the function “kvasprintf_const”
> according to your review comment for the update step “[PATCH v2 4/7] remoteproc:
> Use kstrdup_const() rather than kstrup()”?
> 

Looking at the implementation of kvasprintf_const(), using it here wouldn't give
us anything.  Indeed allocation of duplicate memory is avoided only if the
string is pre determined of if it is exactly %s, which isn't the case here.
Otherwise things default to kvasprintf().

Thanks,
Mathieu 

> Regards,
> Markus

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 5/7] remoteproc: Restructure firmware name allocation
  2020-04-17 13:39     ` Suman Anna
  2020-04-17 15:48       ` [v2 " Markus Elfring
@ 2020-04-17 21:28       ` Mathieu Poirier
  1 sibling, 0 replies; 33+ messages in thread
From: Mathieu Poirier @ 2020-04-17 21:28 UTC (permalink / raw)
  To: Suman Anna
  Cc: Markus Elfring, linux-remoteproc, linux-kernel, Alex Elder,
	Bjorn Andersson, Ohad Ben-Cohen

On Fri, Apr 17, 2020 at 08:39:39AM -0500, Suman Anna wrote:
> Hi Markus,
> 
> On 4/16/20 1:26 AM, Markus Elfring wrote:
> > …
> > > +++ b/drivers/remoteproc/remoteproc_core.c
> > > @@ -1984,14 +1984,14 @@ static int rproc_alloc_firmware(struct rproc *rproc,
> > >   {
> > >   	const char *p;
> > > 
> > > -	if (!firmware)
> > > +	if (firmware)
> > > +		p = kstrdup_const(firmware, GFP_KERNEL);
> > > +	else
> > >   		/*
> > >   		 * If the caller didn't pass in a firmware name then
> > >   		 * construct a default name.
> > >   		 */
> > >   		p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
> > > -	else
> > > -		p = kstrdup_const(firmware, GFP_KERNEL);
> > 
> > Can the use of the conditional operator make sense at such source code places?
> > 
> > 	p = firmware ? kstrdup_const(…) : kasprintf(…);
> 
> For simple assignments, I too prefer the ternary operator, but in this case,
> I think it is better to leave the current code as is.

I agree with Suman, that's why I didn't use the conditional operator.

> 
> regards
> Suman

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 6/7] remoteproc: Split rproc_ops allocation from rproc_alloc()
  2020-04-17 13:49   ` Suman Anna
  2020-04-17 15:35     ` Suman Anna
@ 2020-04-17 21:56     ` Mathieu Poirier
  1 sibling, 0 replies; 33+ messages in thread
From: Mathieu Poirier @ 2020-04-17 21:56 UTC (permalink / raw)
  To: Suman Anna
  Cc: bjorn.andersson, ohad, elder, Markus.Elfring, linux-remoteproc,
	linux-kernel

On Fri, Apr 17, 2020 at 08:49:25AM -0500, Suman Anna wrote:
> On 4/15/20 3:48 PM, 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>
> > ---
> >   drivers/remoteproc/remoteproc_core.c | 32 +++++++++++++++++-----------
> >   1 file changed, 20 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> > index 0bfa6998705d..a5a0ceb86b3f 100644
> > --- a/drivers/remoteproc/remoteproc_core.c
> > +++ b/drivers/remoteproc/remoteproc_core.c
> > @@ -2001,6 +2001,25 @@ 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;
> > +
> > +	/* 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;
> > +		rproc->ops->sanity_check = rproc_elf_sanity_check;
> 
> So, the conditional check on sanity check is dropped and the callback
> switched here without the changelog reflecting anything why. You should just
> rebase this patch on top of Clement's patch [1] that removes the conditional
> flag, and also usage from the remoteproc platform drivers.

That's a rebase that went very wrong...

Thanks for pointing it out,
Mathieu

> 
> regards
> Suman
> 
> [1] https://patchwork.kernel.org/patch/11462013/
> 
> 
> > +		rproc->ops->get_boot_addr = rproc_elf_get_boot_addr;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> >   /**
> >    * rproc_alloc() - allocate a remote processor handle
> >    * @dev: the underlying device
> > @@ -2040,8 +2059,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;
> > @@ -2068,16 +2086,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);
> > 
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 1/7] remoteproc: Fix IDR initialisation in rproc_alloc()
  2020-04-15 20:48 ` [PATCH v2 1/7] remoteproc: Fix IDR initialisation in rproc_alloc() Mathieu Poirier
  2020-04-17 13:37   ` Suman Anna
@ 2020-04-20  5:00   ` Bjorn Andersson
  1 sibling, 0 replies; 33+ messages in thread
From: Bjorn Andersson @ 2020-04-20  5:00 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: ohad, s-anna, elder, Markus.Elfring, linux-remoteproc, linux-kernel

On Wed 15 Apr 13:48 PDT 2020, Mathieu Poirier wrote:

> From: Alex Elder <elder@linaro.org>
> 
> If ida_simple_get() returns an error when called in rproc_alloc(),
> put_device() is called to clean things up.  By this time the rproc
> device type has been assigned, with rproc_type_release() as the
> release function.
> 
> The first thing rproc_type_release() does is call:
>     idr_destroy(&rproc->notifyids);
> 
> But at the time the ida_simple_get() call is made, the notifyids
> field in the remoteproc structure has not been initialized.
> 
> I'm not actually sure this case causes an observable problem, but
> it's incorrect.  Fix this by initializing the notifyids field before
> calling ida_simple_get() in rproc_alloc().
> 
> Fixes: b5ab5e24e960 ("remoteproc: maintain a generic child device for each rproc")
> Signed-off-by: Alex Elder <elder@linaro.org>
> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

> ---
>  drivers/remoteproc/remoteproc_core.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index e12a54e67588..80056513ae71 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -2053,6 +2053,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>  	rproc->dev.type = &rproc_type;
>  	rproc->dev.class = &rproc_class;
>  	rproc->dev.driver_data = rproc;
> +	idr_init(&rproc->notifyids);
>  
>  	/* Assign a unique device index and name */
>  	rproc->index = ida_simple_get(&rproc_dev_index, 0, 0, GFP_KERNEL);
> @@ -2078,8 +2079,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>  
>  	mutex_init(&rproc->lock);
>  
> -	idr_init(&rproc->notifyids);
> -
>  	INIT_LIST_HEAD(&rproc->carveouts);
>  	INIT_LIST_HEAD(&rproc->mappings);
>  	INIT_LIST_HEAD(&rproc->traces);
> -- 
> 2.20.1
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 2/7] remoteproc: Split firmware name allocation from rproc_alloc()
  2020-04-15 20:48 ` [PATCH v2 2/7] remoteproc: Split firmware name allocation from rproc_alloc() Mathieu Poirier
  2020-04-15 21:28   ` Alex Elder
@ 2020-04-20  5:09   ` Bjorn Andersson
  2020-04-20  9:24   ` Arnaud POULIQUEN
  2 siblings, 0 replies; 33+ messages in thread
From: Bjorn Andersson @ 2020-04-20  5:09 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: ohad, s-anna, elder, Markus.Elfring, linux-remoteproc, linux-kernel

On Wed 15 Apr 13:48 PDT 2020, Mathieu Poirier wrote:

> Make the firmware name allocation a function on its own in an
> effort to cleanup function rproc_alloc().
> 
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> ---
>  drivers/remoteproc/remoteproc_core.c | 66 ++++++++++++++++------------
>  1 file changed, 39 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 80056513ae71..4dee63f319ba 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1979,6 +1979,33 @@ static const struct device_type rproc_type = {
>  	.release	= rproc_type_release,
>  };
>  
> +static int rproc_alloc_firmware(struct rproc *rproc,
> +				const char *name, const char *firmware)
> +{
> +	char *p, *template = "rproc-%s-fw";
> +	int name_len;
> +
> +	if (!firmware) {
> +		/*
> +		 * If the caller didn't pass in a firmware name then
> +		 * construct a default name.
> +		 */
> +		name_len = strlen(name) + strlen(template) - 2 + 1;
> +		p = kmalloc(name_len, GFP_KERNEL);
> +		if (!p)
> +			return -ENOMEM;
> +		snprintf(p, name_len, template, name);
> +	} else {
> +		p = kstrdup(firmware, GFP_KERNEL);
> +		if (!p)
> +			return -ENOMEM;
> +	}
> +
> +	rproc->firmware = p;
> +
> +	return 0;
> +}
> +
>  /**
>   * rproc_alloc() - allocate a remote processor handle
>   * @dev: the underlying device
> @@ -2007,42 +2034,21 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>  			  const char *firmware, int len)
>  {
>  	struct rproc *rproc;
> -	char *p, *template = "rproc-%s-fw";
> -	int name_len;
>  
>  	if (!dev || !name || !ops)
>  		return NULL;
>  
> -	if (!firmware) {
> -		/*
> -		 * If the caller didn't pass in a firmware name then
> -		 * construct a default name.
> -		 */
> -		name_len = strlen(name) + strlen(template) - 2 + 1;
> -		p = kmalloc(name_len, GFP_KERNEL);
> -		if (!p)
> -			return NULL;
> -		snprintf(p, name_len, template, name);
> -	} else {
> -		p = kstrdup(firmware, GFP_KERNEL);
> -		if (!p)
> -			return NULL;
> -	}
> -
>  	rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL);
> -	if (!rproc) {
> -		kfree(p);
> +	if (!rproc)
>  		return NULL;
> -	}
> +
> +	if (rproc_alloc_firmware(rproc, name, firmware))
> +		goto free_rproc;
>  
>  	rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL);
> -	if (!rproc->ops) {
> -		kfree(p);
> -		kfree(rproc);
> -		return NULL;
> -	}
> +	if (!rproc->ops)
> +		goto free_firmware;
>  
> -	rproc->firmware = p;
>  	rproc->name = name;
>  	rproc->priv = &rproc[1];
>  	rproc->auto_boot = true;
> @@ -2091,6 +2097,12 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>  	rproc->state = RPROC_OFFLINE;
>  
>  	return rproc;
> +
> +free_firmware:
> +	kfree(rproc->firmware);
> +free_rproc:
> +	kfree(rproc);
> +	return NULL;
>  }
>  EXPORT_SYMBOL(rproc_alloc);
>  
> -- 
> 2.20.1
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 3/7] remoteproc: Simplify default name allocation
  2020-04-15 20:48 ` [PATCH v2 3/7] remoteproc: Simplify default name allocation Mathieu Poirier
  2020-04-15 21:26   ` Alex Elder
@ 2020-04-20  5:10   ` Bjorn Andersson
  1 sibling, 0 replies; 33+ messages in thread
From: Bjorn Andersson @ 2020-04-20  5:10 UTC (permalink / raw)
  To: Mathieu Poirier
  Cc: ohad, s-anna, elder, Markus.Elfring, linux-remoteproc, linux-kernel

On Wed 15 Apr 13:48 PDT 2020, Mathieu Poirier wrote:

> In an effort to cleanup firmware name allocation, replace the
> cumbersome mechanic used to allocate a default firmware name with
> function kasprintf().
> 
> Suggested-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

> ---
>  drivers/remoteproc/remoteproc_core.c | 19 +++++++------------
>  1 file changed, 7 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 4dee63f319ba..9899467fa1cf 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1982,24 +1982,19 @@ static const struct device_type rproc_type = {
>  static int rproc_alloc_firmware(struct rproc *rproc,
>  				const char *name, const char *firmware)
>  {
> -	char *p, *template = "rproc-%s-fw";
> -	int name_len;
> +	char *p;
>  
> -	if (!firmware) {
> +	if (!firmware)
>  		/*
>  		 * If the caller didn't pass in a firmware name then
>  		 * construct a default name.
>  		 */
> -		name_len = strlen(name) + strlen(template) - 2 + 1;
> -		p = kmalloc(name_len, GFP_KERNEL);
> -		if (!p)
> -			return -ENOMEM;
> -		snprintf(p, name_len, template, name);
> -	} else {
> +		p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
> +	else
>  		p = kstrdup(firmware, GFP_KERNEL);
> -		if (!p)
> -			return -ENOMEM;
> -	}
> +
> +	if (!p)
> +		return -ENOMEM;
>  
>  	rproc->firmware = p;
>  
> -- 
> 2.20.1
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 5/7] remoteproc: Restructure firmware name allocation
  2020-04-15 21:23   ` Alex Elder
@ 2020-04-20  5:17     ` Bjorn Andersson
  0 siblings, 0 replies; 33+ messages in thread
From: Bjorn Andersson @ 2020-04-20  5:17 UTC (permalink / raw)
  To: Alex Elder
  Cc: Mathieu Poirier, ohad, s-anna, Markus.Elfring, linux-remoteproc,
	linux-kernel

On Wed 15 Apr 14:23 PDT 2020, Alex Elder wrote:

> On 4/15/20 3:48 PM, Mathieu Poirier wrote:
> > Improve the readability of function rproc_alloc_firmware() by using
> > a non-negated condition.
> > 
> > Suggested-by: Alex Elder <elder@linaro.org>
> > Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> 
> If it were me, I'd move the comment above the if statement and
> perhaps reword it a little bit to describe what's happening.
> But no matter, this looks good.
> 

This would also avoid the fact that we have a multiline block without
braces (which isn't needed, but looks odd to me). So that sounds like a
good idea.

Regards,
Bjorn

> Reviewed-by: Alex Elder <elder@linaro.org>
> 
> > ---
> >  drivers/remoteproc/remoteproc_core.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> > index ebaff496ef81..0bfa6998705d 100644
> > --- a/drivers/remoteproc/remoteproc_core.c
> > +++ b/drivers/remoteproc/remoteproc_core.c
> > @@ -1984,14 +1984,14 @@ static int rproc_alloc_firmware(struct rproc *rproc,
> >  {
> >  	const char *p;
> >  
> > -	if (!firmware)
> > +	if (firmware)
> > +		p = kstrdup_const(firmware, GFP_KERNEL);
> > +	else
> >  		/*
> >  		 * If the caller didn't pass in a firmware name then
> >  		 * construct a default name.
> >  		 */
> >  		p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
> > -	else
> > -		p = kstrdup_const(firmware, GFP_KERNEL);
> >  
> >  	if (!p)
> >  		return -ENOMEM;
> > 
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 4/7] remoteproc: Use kstrdup_const() rather than kstrup()
  2020-04-17 13:44     ` Suman Anna
@ 2020-04-20  5:21       ` Bjorn Andersson
  0 siblings, 0 replies; 33+ messages in thread
From: Bjorn Andersson @ 2020-04-20  5:21 UTC (permalink / raw)
  To: Suman Anna
  Cc: Alex Elder, Mathieu Poirier, ohad, Markus.Elfring,
	linux-remoteproc, linux-kernel

On Fri 17 Apr 06:44 PDT 2020, Suman Anna wrote:

> On 4/15/20 4:25 PM, Alex Elder wrote:
> > On 4/15/20 3:48 PM, 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>
> > 
> > Looks good.
> > 
> > Reviewed-by: Alex Elder <elder@linaro.org>
> > 
> > > ---
> > >   drivers/remoteproc/remoteproc_core.c | 4 ++--
> > >   include/linux/remoteproc.h           | 2 +-
> > >   2 files changed, 3 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> > > index 9899467fa1cf..ebaff496ef81 100644
> > > --- a/drivers/remoteproc/remoteproc_core.c
> > > +++ b/drivers/remoteproc/remoteproc_core.c
> > > @@ -1982,7 +1982,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)
> > >   		/*
> > > @@ -1991,7 +1991,7 @@ static int rproc_alloc_firmware(struct rproc *rproc,
> > >   		 */
> > >   		p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name);
> 
> So, to be consistent for both paths, should we be using kvasprintf_const()
> here and kfree_const() in release.

Given that the second argument is a "proper" format string
kvasprintf_const() is really just kasprintf() - but with the requirement
that we set up a va_list. So I prefer that we stick with this.

> The kfree_const() is needed to account
> for the kstrdup_const below for sure.
> 

You are correct Suman, this patch needs to also change the kfree() to a
kfree_const() or bad things will happen after a visit to
rproc_type_release().

Regards,
Bjorn

> regards
> Suman
> 
> > >   	else
> > > -		p = kstrdup(firmware, GFP_KERNEL);
> > > +		p = kstrdup_const(firmware, GFP_KERNEL);
> > >   	if (!p)
> > >   		return -ENOMEM;
> > > diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
> > > index 9c07d7958c53..38607107b7cb 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;
> > > 
> > 
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 2/7] remoteproc: Split firmware name allocation from rproc_alloc()
  2020-04-15 20:48 ` [PATCH v2 2/7] remoteproc: Split firmware name allocation from rproc_alloc() Mathieu Poirier
  2020-04-15 21:28   ` Alex Elder
  2020-04-20  5:09   ` Bjorn Andersson
@ 2020-04-20  9:24   ` Arnaud POULIQUEN
  2020-04-20 21:29     ` Mathieu Poirier
  2 siblings, 1 reply; 33+ messages in thread
From: Arnaud POULIQUEN @ 2020-04-20  9:24 UTC (permalink / raw)
  To: Mathieu Poirier, bjorn.andersson, ohad
  Cc: s-anna, elder, Markus.Elfring, linux-remoteproc, linux-kernel

Hi Mathieu,

On 4/15/20 10:48 PM, Mathieu Poirier wrote:
> Make the firmware name allocation a function on its own in an
> effort to cleanup function rproc_alloc().
> 
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> ---
>  drivers/remoteproc/remoteproc_core.c | 66 ++++++++++++++++------------
>  1 file changed, 39 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 80056513ae71..4dee63f319ba 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -1979,6 +1979,33 @@ static const struct device_type rproc_type = {
>  	.release	= rproc_type_release,
>  };
>  
> +static int rproc_alloc_firmware(struct rproc *rproc,
> +				const char *name, const char *firmware)

nitpicking: here you do not allocate memory for the firmware but for its name
The name of the function seems to me quite confusing...

Else LGTM for the series

Thanks,

Arnaud

> +{
> +	char *p, *template = "rproc-%s-fw";
> +	int name_len;
> +
> +	if (!firmware) {
> +		/*
> +		 * If the caller didn't pass in a firmware name then
> +		 * construct a default name.
> +		 */
> +		name_len = strlen(name) + strlen(template) - 2 + 1;
> +		p = kmalloc(name_len, GFP_KERNEL);
> +		if (!p)
> +			return -ENOMEM;
> +		snprintf(p, name_len, template, name);
> +	} else {
> +		p = kstrdup(firmware, GFP_KERNEL);
> +		if (!p)
> +			return -ENOMEM;
> +	}
> +
> +	rproc->firmware = p;
> +
> +	return 0;
> +}
> +
>  /**
>   * rproc_alloc() - allocate a remote processor handle
>   * @dev: the underlying device
> @@ -2007,42 +2034,21 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>  			  const char *firmware, int len)
>  {
>  	struct rproc *rproc;
> -	char *p, *template = "rproc-%s-fw";
> -	int name_len;
>  
>  	if (!dev || !name || !ops)
>  		return NULL;
>  
> -	if (!firmware) {
> -		/*
> -		 * If the caller didn't pass in a firmware name then
> -		 * construct a default name.
> -		 */
> -		name_len = strlen(name) + strlen(template) - 2 + 1;
> -		p = kmalloc(name_len, GFP_KERNEL);
> -		if (!p)
> -			return NULL;
> -		snprintf(p, name_len, template, name);
> -	} else {
> -		p = kstrdup(firmware, GFP_KERNEL);
> -		if (!p)
> -			return NULL;
> -	}
> -
>  	rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL);
> -	if (!rproc) {
> -		kfree(p);
> +	if (!rproc)
>  		return NULL;
> -	}
> +
> +	if (rproc_alloc_firmware(rproc, name, firmware))
> +		goto free_rproc;
>  
>  	rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL);
> -	if (!rproc->ops) {
> -		kfree(p);
> -		kfree(rproc);
> -		return NULL;
> -	}
> +	if (!rproc->ops)
> +		goto free_firmware;
>  
> -	rproc->firmware = p;
>  	rproc->name = name;
>  	rproc->priv = &rproc[1];
>  	rproc->auto_boot = true;
> @@ -2091,6 +2097,12 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
>  	rproc->state = RPROC_OFFLINE;
>  
>  	return rproc;
> +
> +free_firmware:
> +	kfree(rproc->firmware);
> +free_rproc:
> +	kfree(rproc);
> +	return NULL;
>  }
>  EXPORT_SYMBOL(rproc_alloc);
>  
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v2 2/7] remoteproc: Split firmware name allocation from rproc_alloc()
  2020-04-20  9:24   ` Arnaud POULIQUEN
@ 2020-04-20 21:29     ` Mathieu Poirier
  0 siblings, 0 replies; 33+ messages in thread
From: Mathieu Poirier @ 2020-04-20 21:29 UTC (permalink / raw)
  To: Arnaud POULIQUEN
  Cc: Bjorn Andersson, Ohad Ben-Cohen, Suman Anna, Alex Elder,
	Markus Elfring, linux-remoteproc, Linux Kernel Mailing List

Hey,

On Mon, 20 Apr 2020 at 03:24, Arnaud POULIQUEN <arnaud.pouliquen@st.com> wrote:
>
> Hi Mathieu,
>
> On 4/15/20 10:48 PM, Mathieu Poirier wrote:
> > Make the firmware name allocation a function on its own in an
> > effort to cleanup function rproc_alloc().
> >
> > Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> > ---
> >  drivers/remoteproc/remoteproc_core.c | 66 ++++++++++++++++------------
> >  1 file changed, 39 insertions(+), 27 deletions(-)
> >
> > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> > index 80056513ae71..4dee63f319ba 100644
> > --- a/drivers/remoteproc/remoteproc_core.c
> > +++ b/drivers/remoteproc/remoteproc_core.c
> > @@ -1979,6 +1979,33 @@ static const struct device_type rproc_type = {
> >       .release        = rproc_type_release,
> >  };
> >
> > +static int rproc_alloc_firmware(struct rproc *rproc,
> > +                             const char *name, const char *firmware)
>
> nitpicking: here you do not allocate memory for the firmware but for its name
> The name of the function seems to me quite confusing...

Ok, I'll see if I can find something better.

>
> Else LGTM for the series

V3 will be out shortly and it will be fairly different from this one.

>
> Thanks,
>
> Arnaud
>
> > +{
> > +     char *p, *template = "rproc-%s-fw";
> > +     int name_len;
> > +
> > +     if (!firmware) {
> > +             /*
> > +              * If the caller didn't pass in a firmware name then
> > +              * construct a default name.
> > +              */
> > +             name_len = strlen(name) + strlen(template) - 2 + 1;
> > +             p = kmalloc(name_len, GFP_KERNEL);
> > +             if (!p)
> > +                     return -ENOMEM;
> > +             snprintf(p, name_len, template, name);
> > +     } else {
> > +             p = kstrdup(firmware, GFP_KERNEL);
> > +             if (!p)
> > +                     return -ENOMEM;
> > +     }
> > +
> > +     rproc->firmware = p;
> > +
> > +     return 0;
> > +}
> > +
> >  /**
> >   * rproc_alloc() - allocate a remote processor handle
> >   * @dev: the underlying device
> > @@ -2007,42 +2034,21 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
> >                         const char *firmware, int len)
> >  {
> >       struct rproc *rproc;
> > -     char *p, *template = "rproc-%s-fw";
> > -     int name_len;
> >
> >       if (!dev || !name || !ops)
> >               return NULL;
> >
> > -     if (!firmware) {
> > -             /*
> > -              * If the caller didn't pass in a firmware name then
> > -              * construct a default name.
> > -              */
> > -             name_len = strlen(name) + strlen(template) - 2 + 1;
> > -             p = kmalloc(name_len, GFP_KERNEL);
> > -             if (!p)
> > -                     return NULL;
> > -             snprintf(p, name_len, template, name);
> > -     } else {
> > -             p = kstrdup(firmware, GFP_KERNEL);
> > -             if (!p)
> > -                     return NULL;
> > -     }
> > -
> >       rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL);
> > -     if (!rproc) {
> > -             kfree(p);
> > +     if (!rproc)
> >               return NULL;
> > -     }
> > +
> > +     if (rproc_alloc_firmware(rproc, name, firmware))
> > +             goto free_rproc;
> >
> >       rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL);
> > -     if (!rproc->ops) {
> > -             kfree(p);
> > -             kfree(rproc);
> > -             return NULL;
> > -     }
> > +     if (!rproc->ops)
> > +             goto free_firmware;
> >
> > -     rproc->firmware = p;
> >       rproc->name = name;
> >       rproc->priv = &rproc[1];
> >       rproc->auto_boot = true;
> > @@ -2091,6 +2097,12 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
> >       rproc->state = RPROC_OFFLINE;
> >
> >       return rproc;
> > +
> > +free_firmware:
> > +     kfree(rproc->firmware);
> > +free_rproc:
> > +     kfree(rproc);
> > +     return NULL;
> >  }
> >  EXPORT_SYMBOL(rproc_alloc);
> >
> >

^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2020-04-20 21:29 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-15 20:48 [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc() Mathieu Poirier
2020-04-15 20:48 ` [PATCH v2 1/7] remoteproc: Fix IDR initialisation in rproc_alloc() Mathieu Poirier
2020-04-17 13:37   ` Suman Anna
2020-04-20  5:00   ` Bjorn Andersson
2020-04-15 20:48 ` [PATCH v2 2/7] remoteproc: Split firmware name allocation from rproc_alloc() Mathieu Poirier
2020-04-15 21:28   ` Alex Elder
2020-04-20  5:09   ` Bjorn Andersson
2020-04-20  9:24   ` Arnaud POULIQUEN
2020-04-20 21:29     ` Mathieu Poirier
2020-04-15 20:48 ` [PATCH v2 3/7] remoteproc: Simplify default name allocation Mathieu Poirier
2020-04-15 21:26   ` Alex Elder
2020-04-20  5:10   ` Bjorn Andersson
2020-04-15 20:48 ` [PATCH v2 4/7] remoteproc: Use kstrdup_const() rather than kstrup() Mathieu Poirier
2020-04-15 21:25   ` Alex Elder
2020-04-17 13:44     ` Suman Anna
2020-04-20  5:21       ` Bjorn Andersson
2020-04-17 16:12   ` [v2 4/7] remoteproc: Use kstrdup_const() rather than kstrdup() Markus Elfring
2020-04-15 20:48 ` [PATCH v2 5/7] remoteproc: Restructure firmware name allocation Mathieu Poirier
2020-04-15 21:23   ` Alex Elder
2020-04-20  5:17     ` Bjorn Andersson
2020-04-16  6:26   ` Markus Elfring
2020-04-17 13:39     ` Suman Anna
2020-04-17 15:48       ` [v2 " Markus Elfring
2020-04-17 16:15         ` Suman Anna
2020-04-17 20:58         ` Mathieu Poirier
2020-04-17 21:28       ` [PATCH v2 " Mathieu Poirier
2020-04-15 20:48 ` [PATCH v2 6/7] remoteproc: Split rproc_ops allocation from rproc_alloc() Mathieu Poirier
2020-04-17 13:49   ` Suman Anna
2020-04-17 15:35     ` Suman Anna
2020-04-17 21:56     ` Mathieu Poirier
2020-04-15 20:48 ` [PATCH v2 7/7] remoteproc: Get rid of tedious error path Mathieu Poirier
2020-04-17 13:50   ` Suman Anna
2020-04-17 13:34 ` [PATCH v2 0/7] remoteproc: Refactor function rproc_alloc() Suman Anna

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).