linux-remoteproc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] rpmsg: Convert to platform remove callback returning void
@ 2023-03-21 15:40 Uwe Kleine-König
  2023-03-21 15:40 ` [PATCH 1/3] rpmsg: qcom_smd: Make qcom_smd_unregister_edge() return void Uwe Kleine-König
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2023-03-21 15:40 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Mathieu Poirier
  Cc: Konrad Dybcio, linux-arm-msm, linux-remoteproc, kernel

Hello,

this series adapts the platform drivers below drivers/rpmsg to use the
.remove_new() callback. Compared to the traditional .remove() callback
.remove_new() returns no value. This is a good thing because the driver core
doesn't (and cannot) cope for errors during remove. The only effect of a
non-zero return value in .remove() is that the driver core emits a warning. The
device is removed anyhow and an early return from .remove() usually yields a
resource leak.

By changing the remove callback to return void driver authors cannot
reasonably assume any more that there is some kind of cleanup later.

The two rpmsg platform drivers always returned zero before. This just
wasn't obvious, so the first patch simplifies a bit to make it obvious.
After that the drivers are converted without side effects to
.remove_new().

Best regards
Uwe

Uwe Kleine-König (3):
  rpmsg: qcom_smd: Make qcom_smd_unregister_edge() return void
  rpmsg: qcom_glink_rpm: Convert to platform remove callback returning
    void
  rpmsg: qcom_smd: Convert to platform remove callback returning void

 drivers/rpmsg/qcom_glink_rpm.c |  6 ++----
 drivers/rpmsg/qcom_smd.c       | 24 +++++++++++-------------
 include/linux/rpmsg/qcom_smd.h |  5 ++---
 3 files changed, 15 insertions(+), 20 deletions(-)

base-commit: fe15c26ee26efa11741a7b632e9f23b01aca4cc6
-- 
2.39.2


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

* [PATCH 1/3] rpmsg: qcom_smd: Make qcom_smd_unregister_edge() return void
  2023-03-21 15:40 [PATCH 0/3] rpmsg: Convert to platform remove callback returning void Uwe Kleine-König
@ 2023-03-21 15:40 ` Uwe Kleine-König
  2023-03-21 15:40 ` [PATCH 2/3] rpmsg: qcom_glink_rpm: Convert to platform remove callback returning void Uwe Kleine-König
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2023-03-21 15:40 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Mathieu Poirier
  Cc: Konrad Dybcio, linux-arm-msm, linux-remoteproc, kernel

This function returned zero unconditionally. Convert it to return no
value instead. This makes it more obvious what happens in the callers.

One caller is converted to return zero explicitly. The only other caller
(smd_subdev_stop() in drivers/remoteproc/qcom_common.c) already ignored
the return value before.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/rpmsg/qcom_smd.c       | 8 ++++----
 include/linux/rpmsg/qcom_smd.h | 5 ++---
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/rpmsg/qcom_smd.c b/drivers/rpmsg/qcom_smd.c
index 1044cf03c542..38352f5792f4 100644
--- a/drivers/rpmsg/qcom_smd.c
+++ b/drivers/rpmsg/qcom_smd.c
@@ -1533,7 +1533,7 @@ static int qcom_smd_remove_device(struct device *dev, void *data)
  * qcom_smd_unregister_edge() - release an edge and its children
  * @edge:      edge reference acquired from qcom_smd_register_edge
  */
-int qcom_smd_unregister_edge(struct qcom_smd_edge *edge)
+void qcom_smd_unregister_edge(struct qcom_smd_edge *edge)
 {
 	int ret;
 
@@ -1547,8 +1547,6 @@ int qcom_smd_unregister_edge(struct qcom_smd_edge *edge)
 
 	mbox_free_channel(edge->mbox_chan);
 	device_unregister(&edge->dev);
-
-	return 0;
 }
 EXPORT_SYMBOL(qcom_smd_unregister_edge);
 
@@ -1572,7 +1570,9 @@ static int qcom_smd_remove_edge(struct device *dev, void *data)
 {
 	struct qcom_smd_edge *edge = to_smd_edge(dev);
 
-	return qcom_smd_unregister_edge(edge);
+	qcom_smd_unregister_edge(edge);
+
+	return 0;
 }
 
 /*
diff --git a/include/linux/rpmsg/qcom_smd.h b/include/linux/rpmsg/qcom_smd.h
index 2e92d7407a85..3379bf4e1cb1 100644
--- a/include/linux/rpmsg/qcom_smd.h
+++ b/include/linux/rpmsg/qcom_smd.h
@@ -11,7 +11,7 @@ struct qcom_smd_edge;
 
 struct qcom_smd_edge *qcom_smd_register_edge(struct device *parent,
 					     struct device_node *node);
-int qcom_smd_unregister_edge(struct qcom_smd_edge *edge);
+void qcom_smd_unregister_edge(struct qcom_smd_edge *edge);
 
 #else
 
@@ -22,9 +22,8 @@ qcom_smd_register_edge(struct device *parent,
 	return NULL;
 }
 
-static inline int qcom_smd_unregister_edge(struct qcom_smd_edge *edge)
+static inline void qcom_smd_unregister_edge(struct qcom_smd_edge *edge)
 {
-	return 0;
 }
 
 #endif
-- 
2.39.2


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

* [PATCH 2/3] rpmsg: qcom_glink_rpm: Convert to platform remove callback returning void
  2023-03-21 15:40 [PATCH 0/3] rpmsg: Convert to platform remove callback returning void Uwe Kleine-König
  2023-03-21 15:40 ` [PATCH 1/3] rpmsg: qcom_smd: Make qcom_smd_unregister_edge() return void Uwe Kleine-König
@ 2023-03-21 15:40 ` Uwe Kleine-König
  2023-03-21 15:40 ` [PATCH 3/3] rpmsg: qcom_smd: " Uwe Kleine-König
  2023-04-06  4:04 ` [PATCH 0/3] rpmsg: " Bjorn Andersson
  3 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2023-03-21 15:40 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Mathieu Poirier
  Cc: Konrad Dybcio, linux-arm-msm, linux-remoteproc, kernel

The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is (mostly) ignored
and this typically results in resource leaks. To improve here there is a
quest to make the remove callback return void. In the first step of this
quest all drivers are converted to .remove_new() which already returns
void.

Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/rpmsg/qcom_glink_rpm.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/rpmsg/qcom_glink_rpm.c b/drivers/rpmsg/qcom_glink_rpm.c
index f94bb7d4f1ec..357272d7062e 100644
--- a/drivers/rpmsg/qcom_glink_rpm.c
+++ b/drivers/rpmsg/qcom_glink_rpm.c
@@ -361,7 +361,7 @@ static int glink_rpm_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int glink_rpm_remove(struct platform_device *pdev)
+static void glink_rpm_remove(struct platform_device *pdev)
 {
 	struct glink_rpm *rpm = platform_get_drvdata(pdev);
 	struct qcom_glink *glink = rpm->glink;
@@ -371,8 +371,6 @@ static int glink_rpm_remove(struct platform_device *pdev)
 	qcom_glink_native_remove(glink);
 
 	mbox_free_channel(rpm->mbox_chan);
-
-	return 0;
 }
 
 static const struct of_device_id glink_rpm_of_match[] = {
@@ -383,7 +381,7 @@ MODULE_DEVICE_TABLE(of, glink_rpm_of_match);
 
 static struct platform_driver glink_rpm_driver = {
 	.probe = glink_rpm_probe,
-	.remove = glink_rpm_remove,
+	.remove_new = glink_rpm_remove,
 	.driver = {
 		.name = "qcom_glink_rpm",
 		.of_match_table = glink_rpm_of_match,
-- 
2.39.2


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

* [PATCH 3/3] rpmsg: qcom_smd: Convert to platform remove callback returning void
  2023-03-21 15:40 [PATCH 0/3] rpmsg: Convert to platform remove callback returning void Uwe Kleine-König
  2023-03-21 15:40 ` [PATCH 1/3] rpmsg: qcom_smd: Make qcom_smd_unregister_edge() return void Uwe Kleine-König
  2023-03-21 15:40 ` [PATCH 2/3] rpmsg: qcom_glink_rpm: Convert to platform remove callback returning void Uwe Kleine-König
@ 2023-03-21 15:40 ` Uwe Kleine-König
  2023-04-06  4:04 ` [PATCH 0/3] rpmsg: " Bjorn Andersson
  3 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2023-03-21 15:40 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Mathieu Poirier
  Cc: Konrad Dybcio, linux-arm-msm, linux-remoteproc, kernel

The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is (mostly) ignored
and this typically results in resource leaks. To improve here there is a
quest to make the remove callback return void. In the first step of this
quest all drivers are converted to .remove_new() which already returns
void.

qcom_smd_remove() always returned zero, though that isn't completely
trivial to see. So explain that in a comment and convert to
.remove_new().

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/rpmsg/qcom_smd.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/rpmsg/qcom_smd.c b/drivers/rpmsg/qcom_smd.c
index 38352f5792f4..7b9c298aa491 100644
--- a/drivers/rpmsg/qcom_smd.c
+++ b/drivers/rpmsg/qcom_smd.c
@@ -1579,15 +1579,13 @@ static int qcom_smd_remove_edge(struct device *dev, void *data)
  * Shut down all smd clients by making sure that each edge stops processing
  * events and scanning for new channels, then call destroy on the devices.
  */
-static int qcom_smd_remove(struct platform_device *pdev)
+static void qcom_smd_remove(struct platform_device *pdev)
 {
-	int ret;
-
-	ret = device_for_each_child(&pdev->dev, NULL, qcom_smd_remove_edge);
-	if (ret)
-		dev_warn(&pdev->dev, "can't remove smd device: %d\n", ret);
-
-	return ret;
+	/*
+	 * qcom_smd_remove_edge always returns zero, so there is no need to
+	 * check the return value of device_for_each_child.
+	 */
+	device_for_each_child(&pdev->dev, NULL, qcom_smd_remove_edge);
 }
 
 static const struct of_device_id qcom_smd_of_match[] = {
@@ -1598,7 +1596,7 @@ MODULE_DEVICE_TABLE(of, qcom_smd_of_match);
 
 static struct platform_driver qcom_smd_driver = {
 	.probe = qcom_smd_probe,
-	.remove = qcom_smd_remove,
+	.remove_new = qcom_smd_remove,
 	.driver = {
 		.name = "qcom-smd",
 		.of_match_table = qcom_smd_of_match,
-- 
2.39.2


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

* Re: [PATCH 0/3] rpmsg: Convert to platform remove callback returning void
  2023-03-21 15:40 [PATCH 0/3] rpmsg: Convert to platform remove callback returning void Uwe Kleine-König
                   ` (2 preceding siblings ...)
  2023-03-21 15:40 ` [PATCH 3/3] rpmsg: qcom_smd: " Uwe Kleine-König
@ 2023-04-06  4:04 ` Bjorn Andersson
  3 siblings, 0 replies; 5+ messages in thread
From: Bjorn Andersson @ 2023-04-06  4:04 UTC (permalink / raw)
  To: Mathieu Poirier, Uwe Kleine-König, Andy Gross
  Cc: Konrad Dybcio, kernel, linux-arm-msm, linux-remoteproc

On Tue, 21 Mar 2023 16:40:36 +0100, Uwe Kleine-König wrote:
> this series adapts the platform drivers below drivers/rpmsg to use the
> .remove_new() callback. Compared to the traditional .remove() callback
> .remove_new() returns no value. This is a good thing because the driver core
> doesn't (and cannot) cope for errors during remove. The only effect of a
> non-zero return value in .remove() is that the driver core emits a warning. The
> device is removed anyhow and an early return from .remove() usually yields a
> resource leak.
> 
> [...]

Applied, thanks!

[1/3] rpmsg: qcom_smd: Make qcom_smd_unregister_edge() return void
      commit: 810c03d9d7c978b4ee5287d8987043a9be1d614e
[2/3] rpmsg: qcom_glink_rpm: Convert to platform remove callback returning void
      commit: 49446e573bf591eef71c1e8c7cf87ec19aa2569f
[3/3] rpmsg: qcom_smd: Convert to platform remove callback returning void
      commit: 38be89514b88f53ff772d1e016a68b59814aef72

Best regards,
-- 
Bjorn Andersson <andersson@kernel.org>

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

end of thread, other threads:[~2023-04-06  4:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-21 15:40 [PATCH 0/3] rpmsg: Convert to platform remove callback returning void Uwe Kleine-König
2023-03-21 15:40 ` [PATCH 1/3] rpmsg: qcom_smd: Make qcom_smd_unregister_edge() return void Uwe Kleine-König
2023-03-21 15:40 ` [PATCH 2/3] rpmsg: qcom_glink_rpm: Convert to platform remove callback returning void Uwe Kleine-König
2023-03-21 15:40 ` [PATCH 3/3] rpmsg: qcom_smd: " Uwe Kleine-König
2023-04-06  4:04 ` [PATCH 0/3] rpmsg: " 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).