Skip to contentSkip to conversation

mailbox: core cleanup patches

PATCH In review Tudor Ambarus 1 participant 8 messages Feb 24, 2025 Mailbox API

lore
Share & tools
lore
#0 lore raw

v2 cover mailbox: core cleanup patches

Here are few small cleanup patches that I made when working on the exynos mailbox controller driver. It touches error codes, what the mutex in the core protects and what header files are included.

Cheers,
ta

---
Tudor Ambarus (6):
mailbox: use error ret code of of_parse_phandle_with_args()
mailbox: don't protect of_parse_phandle_with_args with con_mutex
mailbox: sort headers alphabetically
mailbox: explicitly include <linux/bits.h>
mailbox: remove unused header files
MAINTAINERS: add mailbox API's tree type and location

 MAINTAINERS                        |  1 +
 drivers/mailbox/mailbox.c          | 23 ++++++++++-------------
 drivers/mailbox/mailbox.h          |  2 ++
 include/linux/mailbox_client.h     |  2 +-
 include/linux/mailbox_controller.h |  6 +++---
 5 files changed, 17 insertions(+), 17 deletions(-)

---
base-commit: 4783ce32b0806911287f35cc65b799876d6f9547
change-id: 20241221-mbox-mutex-ced37c16f509

Best regards,

Signature · 1 line
Tudor Ambarus <[email protected]>
#1 lore raw

PATCH v2 1/6 mailbox: use error ret code of of_parse_phandle_with_args()

In case of error, of_parse_phandle_with_args() returns -EINVAL when the passed index is negative, or -ENOENT when the index is for an empty phandle. The mailbox core overwrote the error return code with a less precise -ENODEV. Use the error returned code from of_parse_phandle_with_args().

---
 drivers/mailbox/mailbox.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/mailbox/mailbox.c +4 -3
index d3d26a2c9895..cb174e788a96 100644
@@ -415,11 +415,12 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
 
 	mutex_lock(&con_mutex);
 
-	if (of_parse_phandle_with_args(dev->of_node, "mboxes",
-				       "#mbox-cells", index, &spec)) {
+	ret = of_parse_phandle_with_args(dev->of_node, "mboxes", "#mbox-cells",
+					 index, &spec);
+	if (ret) {
 		dev_dbg(dev, "%s: can't parse \"mboxes\" property\n", __func__);
 		mutex_unlock(&con_mutex);
-		return ERR_PTR(-ENODEV);
+		return ERR_PTR(ret);
 	}
 
 	chan = ERR_PTR(-EPROBE_DEFER);
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
#2 lore raw

PATCH v2 2/6 mailbox: don't protect of_parse_phandle_with_args with con_mutex

In reply to Tudor Ambarus

There are no concurrency problems if multiple consumers parse the phandle, don't gratuiously protect the parsing with the mutex used for the controllers list.

---
 drivers/mailbox/mailbox.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/mailbox/mailbox.c +2 -3
index cb174e788a96..784b56859a06 100644
@@ -413,16 +413,15 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
 		return ERR_PTR(-ENODEV);
 	}
 
-	mutex_lock(&con_mutex);
-
 	ret = of_parse_phandle_with_args(dev->of_node, "mboxes", "#mbox-cells",
 					 index, &spec);
 	if (ret) {
 		dev_dbg(dev, "%s: can't parse \"mboxes\" property\n", __func__);
-		mutex_unlock(&con_mutex);
 		return ERR_PTR(ret);
 	}
 
+	mutex_lock(&con_mutex);
+
 	chan = ERR_PTR(-EPROBE_DEFER);
 	list_for_each_entry(mbox, &mbox_cons, node)
 		if (mbox->dev->of_node == spec.np) {
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
#3 lore raw

PATCH v2 3/6 mailbox: sort headers alphabetically

In reply to Tudor Ambarus

Sorting headers alphabetically helps locating duplicates, and makes it easier to figure out where to insert new headers.

---
 drivers/mailbox/mailbox.c          | 14 +++++++-------
 include/linux/mailbox_client.h     |  2 +-
 include/linux/mailbox_controller.h |  6 +++---
 3 files changed, 11 insertions(+), 11 deletions(-)
drivers/mailbox/mailbox.c +7 -7
index 784b56859a06..fa3dcec63940 100644
@@ -6,18 +6,18 @@
  * Author: Jassi Brar <[email protected]>
  */
 
-#include <linux/interrupt.h>
-#include <linux/spinlock.h>
-#include <linux/mutex.h>
+#include <linux/bitops.h>
 #include <linux/delay.h>
-#include <linux/slab.h>
-#include <linux/err.h>
-#include <linux/module.h>
 #include <linux/device.h>
-#include <linux/bitops.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
 #include <linux/mailbox_client.h>
 #include <linux/mailbox_controller.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/of.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
 
 #include "mailbox.h"
 
include/linux/mailbox_client.h +1 -1
index 734694912ef7..c6eea9afb943 100644
@@ -7,8 +7,8 @@
 #ifndef __MAILBOX_CLIENT_H
 #define __MAILBOX_CLIENT_H
 
-#include <linux/of.h>
 #include <linux/device.h>
+#include <linux/of.h>
 
 struct mbox_chan;
 
include/linux/mailbox_controller.h +3 -3
index 6fee33cb52f5..5fb0b65f45a2 100644
@@ -3,11 +3,11 @@
 #ifndef __MAILBOX_CONTROLLER_H
 #define __MAILBOX_CONTROLLER_H
 
+#include <linux/completion.h>
+#include <linux/device.h>
+#include <linux/hrtimer.h>
 #include <linux/of.h>
 #include <linux/types.h>
-#include <linux/hrtimer.h>
-#include <linux/device.h>
-#include <linux/completion.h>
 
 struct mbox_chan;
 
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
#4 lore raw

PATCH v2 4/6 mailbox: explicitly include <linux/bits.h>

In reply to Tudor Ambarus

Don't rely on those including the header file to already include the needed <linux/bits.h>. Include it in the header file.

---
 drivers/mailbox/mailbox.h | 2 ++
 1 file changed, 2 insertions(+)
drivers/mailbox/mailbox.h +2 -0
index 046d6d258b32..e1ec4efab693 100644
@@ -3,6 +3,8 @@
 #ifndef __MAILBOX_H
 #define __MAILBOX_H
 
+#include <linux/bits.h>
+
 #define TXDONE_BY_IRQ	BIT(0) /* controller has remote RTR irq */
 #define TXDONE_BY_POLL	BIT(1) /* controller can read status of last TX */
 #define TXDONE_BY_ACK	BIT(2) /* S/W ACK received by Client ticks the TX */
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
#5 lore raw

PATCH v2 5/6 mailbox: remove unused header files

In reply to Tudor Ambarus

There's nothing used from these header files, remove their inclusion.

---
 drivers/mailbox/mailbox.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/mailbox/mailbox.c +0 -3
index fa3dcec63940..5e3a1d0315f9 100644
@@ -6,17 +6,14 @@
  * Author: Jassi Brar <[email protected]>
  */
 
-#include <linux/bitops.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/err.h>
-#include <linux/interrupt.h>
 #include <linux/mailbox_client.h>
 #include <linux/mailbox_controller.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/of.h>
-#include <linux/slab.h>
 #include <linux/spinlock.h>
 
 #include "mailbox.h"
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
#6 lore raw

PATCH v2 6/6 MAINTAINERS: add mailbox API's tree type and location

In reply to Tudor Ambarus

Add mailbox API tree type and location. It helps contributors know what's currently queued.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 20163d8a8d90..94f8f59c71e9 100644
@@ -13735,6 +13735,7 @@ MAILBOX API
 M:	Jassi Brar <[email protected]>
 L:	[email protected]
 S:	Maintained
+T:	git git://git.kernel.org/pub/scm/linux/kernel/git/jassibrar/mailbox.git for-next
 F:	Documentation/devicetree/bindings/mailbox/
 F:	drivers/mailbox/
 F:	include/dt-bindings/mailbox/
Signature · 1 line
2.48.1.601.g30ceb7b040-goog