Skip to contentSkip to conversation

remoteproc: stm32: fix probe error case

PATCH Superseded Fabien Dessenne 2 participants 4 messages Oct 7, 2019 – Nov 12, 2019

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 remoteproc: stm32: fix probe error case

If the rproc driver is probed before the mailbox driver and if the rproc Device Tree node has some mailbox properties, the rproc driver probe shall be deferred instead of being probed without mailbox support.

---
Changes since v1: test IS_ERR() before checking PTR_ERR()

---
 drivers/remoteproc/stm32_rproc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/remoteproc/stm32_rproc.c +8 -2
index 2cf4b29..a507332 100644
@@ -310,7 +310,7 @@ static const struct stm32_mbox stm32_rproc_mbox[MBOX_NB_MBX] = {
 	}
 };
 
-static void stm32_rproc_request_mbox(struct rproc *rproc)
+static int stm32_rproc_request_mbox(struct rproc *rproc)
 {
 	struct stm32_rproc *ddata = rproc->priv;
 	struct device *dev = &rproc->dev;
@@ -329,10 +329,14 @@ static void stm32_rproc_request_mbox(struct rproc *rproc)
 
 		ddata->mb[i].chan = mbox_request_channel_byname(cl, name);
 		if (IS_ERR(ddata->mb[i].chan)) {
+			if (PTR_ERR(ddata->mb[i].chan) == -EPROBE_DEFER)
+				return -EPROBE_DEFER;
 			dev_warn(dev, "cannot get %s mbox\n", name);
 			ddata->mb[i].chan = NULL;
 		}
 	}
+
+	return 0;
 }
 
 static int stm32_rproc_set_hold_boot(struct rproc *rproc, bool hold)
@@ -596,7 +600,9 @@ static int stm32_rproc_probe(struct platform_device *pdev)
 	if (ret)
 		goto free_rproc;
 
-	stm32_rproc_request_mbox(rproc);
+	ret = stm32_rproc_request_mbox(rproc);
+	if (ret)
+		goto free_rproc;
 
 	ret = rproc_add(rproc);
 	if (ret)
Signature · 1 line
2.7.4
#1 lore raw
Quoted 25 lines · Fabien Dessenne

If the rproc driver is probed before the mailbox driver and if the rproc Device Tree node has some mailbox properties, the rproc driver probe shall be deferred instead of being probed without mailbox support.

---
Changes since v1: test IS_ERR() before checking PTR_ERR()

---
 drivers/remoteproc/stm32_rproc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/remoteproc/stm32_rproc.c +1 -1
index 2cf4b29..a507332 100644
@@ -310,7 +310,7 @@ static const struct stm32_mbox stm32_rproc_mbox[MBOX_NB_MBX] = {
 	}
 };
 
-static void stm32_rproc_request_mbox(struct rproc *rproc)
+static int stm32_rproc_request_mbox(struct rproc *rproc)
 {
 	struct stm32_rproc *ddata = rproc->priv;
 	struct device *dev = &rproc->dev;

drivers/remoteproc/stm32_rproc.c static void stm32_rproc_request_mbox(struct rproc *rproc) · line 333

Quoted 5 lines
drivers/remoteproc/stm32_rproc.c +2 -0
@@ -329,10 +329,14 @@ static void stm32_rproc_request_mbox(struct rproc *rproc)
 
 		ddata->mb[i].chan = mbox_request_channel_byname(cl, name);
 		if (IS_ERR(ddata->mb[i].chan)) {
+			if (PTR_ERR(ddata->mb[i].chan) == -EPROBE_DEFER)
+				return -EPROBE_DEFER;

If for some reason you get EPROBE_DEFER when i > 0 you need to mbox_free_channel() channels [0..i) before returning.

Regards,
Bjorn

Quoted 23 lines
drivers/remoteproc/stm32_rproc.c +5 -1
 			dev_warn(dev, "cannot get %s mbox\n", name);
 			ddata->mb[i].chan = NULL;
 		}
 	}
+
+	return 0;
 }
 
 static int stm32_rproc_set_hold_boot(struct rproc *rproc, bool hold)
@@ -596,7 +600,9 @@ static int stm32_rproc_probe(struct platform_device *pdev)
 	if (ret)
 		goto free_rproc;
 
-	stm32_rproc_request_mbox(rproc);
+	ret = stm32_rproc_request_mbox(rproc);
+	if (ret)
+		goto free_rproc;
 
 	ret = rproc_add(rproc);
 	if (ret)
Signature · 1 line
2.7.4
#2 lore raw

Hi Bjorn,

Quoted 28 lines · Bjorn Andersson
Quoted 26 lines · Fabien Dessenne

If the rproc driver is probed before the mailbox driver and if the rproc Device Tree node has some mailbox properties, the rproc driver probe shall be deferred instead of being probed without mailbox support.

---
Changes since v1: test IS_ERR() before checking PTR_ERR()

---
  drivers/remoteproc/stm32_rproc.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/remoteproc/stm32_rproc.c +1 -1
index 2cf4b29..a507332 100644
@@ -310,7 +310,7 @@ static const struct stm32_mbox stm32_rproc_mbox[MBOX_NB_MBX] = {
  	}
  };
 
-static void stm32_rproc_request_mbox(struct rproc *rproc)
+static int stm32_rproc_request_mbox(struct rproc *rproc)
  {
  	struct stm32_rproc *ddata = rproc->priv;
  	struct device *dev = &rproc->dev;
@@ -329,10 +329,14 @@ static void stm32_rproc_request_mbox(struct rproc *rproc)
 
Quoted 6 lines

drivers/remoteproc/stm32_rproc.c static void stm32_rproc_request_mbox(struct rproc *rproc) · line 333

Quoted 4 lines
drivers/remoteproc/stm32_rproc.c +2 -0
  		ddata->mb[i].chan = mbox_request_channel_byname(cl, name);
  		if (IS_ERR(ddata->mb[i].chan)) {
+			if (PTR_ERR(ddata->mb[i].chan) == -EPROBE_DEFER)
+				return -EPROBE_DEFER;

If for some reason you get EPROBE_DEFER when i > 0 you need to mbox_free_channel() channels [0..i) before returning.

The mailbox framework returns EPROBE_DIFFER to inform that the mailbox provider has not registered yet. I do not expected to have a success followed by a EPROBE_DEFER error.

But in the very special case where we use two different mailbox providers this may happen.

I will send an updated version, thanks for pointing this.

BR

Fabien

Quoted 27 lines

Regards,
Bjorn

Quoted 23 lines
drivers/remoteproc/stm32_rproc.c +5 -1
  			dev_warn(dev, "cannot get %s mbox\n", name);
  			ddata->mb[i].chan = NULL;
  		}
  	}
+
+	return 0;
  }
 
  static int stm32_rproc_set_hold_boot(struct rproc *rproc, bool hold)
@@ -596,7 +600,9 @@ static int stm32_rproc_probe(struct platform_device *pdev)
  	if (ret)
  		goto free_rproc;
 
-	stm32_rproc_request_mbox(rproc);
+	ret = stm32_rproc_request_mbox(rproc);
+	if (ret)
+		goto free_rproc;
 
  	ret = rproc_add(rproc);
  	if (ret)
Signature · 1 line
2.7.4
#3 lore raw
Quoted 39 lines · Fabien DESSENNE

Hi Bjorn,

Quoted 28 lines · Bjorn Andersson
Quoted 26 lines · Fabien Dessenne

If the rproc driver is probed before the mailbox driver and if the rproc Device Tree node has some mailbox properties, the rproc driver probe shall be deferred instead of being probed without mailbox support.

---
Changes since v1: test IS_ERR() before checking PTR_ERR()

---
  drivers/remoteproc/stm32_rproc.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
drivers/remoteproc/stm32_rproc.c +1 -1
index 2cf4b29..a507332 100644
@@ -310,7 +310,7 @@ static const struct stm32_mbox stm32_rproc_mbox[MBOX_NB_MBX] = {
  	}
  };
 
-static void stm32_rproc_request_mbox(struct rproc *rproc)
+static int stm32_rproc_request_mbox(struct rproc *rproc)
  {
  	struct stm32_rproc *ddata = rproc->priv;
  	struct device *dev = &rproc->dev;
@@ -329,10 +329,14 @@ static void stm32_rproc_request_mbox(struct rproc *rproc)
 
Quoted 6 lines

drivers/remoteproc/stm32_rproc.c static void stm32_rproc_request_mbox(struct rproc *rproc) · line 333

Quoted 4 lines
drivers/remoteproc/stm32_rproc.c +2 -0
  		ddata->mb[i].chan = mbox_request_channel_byname(cl, name);
  		if (IS_ERR(ddata->mb[i].chan)) {
+			if (PTR_ERR(ddata->mb[i].chan) == -EPROBE_DEFER)
+				return -EPROBE_DEFER;

If for some reason you get EPROBE_DEFER when i > 0 you need to mbox_free_channel() channels [0..i) before returning.

Quoted 7 lines

The mailbox framework returns EPROBE_DIFFER to inform that the mailbox provider has not registered yet. I do not expected to have a success followed by a EPROBE_DEFER error.

But in the very special case where we use two different mailbox providers this may happen.

I agree, it's unlikely to ever cause any problems...

Quoted 2 lines

I will send an updated version, thanks for pointing this.

I appreciate that.

Thanks,
Bjorn

Quoted 31 lines

BR

Fabien

Quoted 27 lines

Regards,
Bjorn

Quoted 23 lines
drivers/remoteproc/stm32_rproc.c +5 -1
  			dev_warn(dev, "cannot get %s mbox\n", name);
  			ddata->mb[i].chan = NULL;
  		}
  	}
+
+	return 0;
  }
 
  static int stm32_rproc_set_hold_boot(struct rproc *rproc, bool hold)
@@ -596,7 +600,9 @@ static int stm32_rproc_probe(struct platform_device *pdev)
  	if (ret)
  		goto free_rproc;
 
-	stm32_rproc_request_mbox(rproc);
+	ret = stm32_rproc_request_mbox(rproc);
+	if (ret)
+		goto free_rproc;
 
  	ret = rproc_add(rproc);
  	if (ret)
Signature · 1 line
2.7.4