Skip to contentSkip to conversation

rpmsg: char - treat `ENOMEM` as `EAGAIN`

PATCH Superseded Tim Blechmann 2 participants 5 messages Feb 14, 2022 – Mar 13, 2022 Remote processor messaging (rpmsg)

lore
Share & tools
lore
#0 lore raw

cover rpmsg: char - treat `ENOMEM` as `EAGAIN`

This patch should allow the use of rpmsg_char character devices with libraries that do a poll/write loop and expect EAGAIN when sending fails and the user space application needs to poll to wait for more space to be available.
boost::asio::write is a notable example of a library, which implements such a loop.

Tim Blechmann (1):
rpmsg: char - treat ENOMEM as EAGAIN

 drivers/rpmsg/rpmsg_char.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Signature · 1 line
2.35.1
#1 lore raw

PATCH 1/1 rpmsg: char - treat `ENOMEM` as `EAGAIN`

rpmsg_trysend returns -ENOMEM when no rpmsg buffer can be allocated. this causes ::write to fail with this error as opposed to -EAGAIN. this is what user space applications (and libraries like boost.asio) would expect when using normal character devices.

CC Arnaud Pouliquen <[email protected]>
---
 drivers/rpmsg/rpmsg_char.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/rpmsg/rpmsg_char.c +4 -1
index 5663cf799c95..5b9e708d595a 100644
@@ -239,14 +239,17 @@ static ssize_t rpmsg_eptdev_write_iter(struct kiocb *iocb,
 
 	if (!eptdev->ept) {
 		ret = -EPIPE;
 		goto unlock_eptdev;
 	}
 
-	if (filp->f_flags & O_NONBLOCK)
+	if (filp->f_flags & O_NONBLOCK) {
 		ret = rpmsg_trysendto(eptdev->ept, kbuf, len, eptdev->chinfo.dst);
+		if (ret == -ENOMEM)
+			ret = -EAGAIN;
+	}
 	else
 		ret = rpmsg_sendto(eptdev->ept, kbuf, len, eptdev->chinfo.dst);
 
 unlock_eptdev:
 	mutex_unlock(&eptdev->ept_lock);
 
Signature · 1 line
2.35.1
#2 lore raw
Quoted 1 line · Tim Blechmann

rpmsg_trysend returns -ENOMEM when no rpmsg buffer can be allocated.

Please use the form rpmsg_trysend() - without ``. You can omit that around -ENOMEM as well.

Quoted 1 line

this causes ::write to fail with this error as opposed to -EAGAIN.

Please drop the :: here as well.

Quoted 4 lines

this is what user space applications (and libraries like boost.asio) would expect when using normal character devices.

I attempted to fix up the above details, but unfortunately your Signed-off-by doesn't match your From:, so I can't apply the patch anyways.

Can you please resubmit this with appropriate author/s-o-b?

Quoted 14 lines
CC Arnaud Pouliquen <[email protected]>
---
 drivers/rpmsg/rpmsg_char.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/rpmsg/rpmsg_char.c +0 -0
index 5663cf799c95..5b9e708d595a 100644
@@ -239,14 +239,17 @@ static ssize_t rpmsg_eptdev_write_iter(struct kiocb *iocb,
 
 	if (!eptdev->ept) {
 		ret = -EPIPE;
 		goto unlock_eptdev;

drivers/rpmsg/rpmsg_char.c static ssize_t rpmsg_eptdev_write_iter(struct kiocb *iocb, · line 251

Quoted 10 lines
drivers/rpmsg/rpmsg_char.c +4 -1
 	}
 
-	if (filp->f_flags & O_NONBLOCK)
+	if (filp->f_flags & O_NONBLOCK) {
 		ret = rpmsg_trysendto(eptdev->ept, kbuf, len, eptdev->chinfo.dst);
+		if (ret == -ENOMEM)
+			ret = -EAGAIN;
+	}
 	else
 		ret = rpmsg_sendto(eptdev->ept, kbuf, len, eptdev->chinfo.dst);

./script/checkpatch.pl --strict tells me that you should have {} around the else block as well..

Thanks,
Bjorn

Quoted 7 lines
drivers/rpmsg/rpmsg_char.c +0 -0
 unlock_eptdev:
 	mutex_unlock(&eptdev->ept_lock);
 
Signature · 1 line
2.35.1
#3 lore raw

v2 cover rpmsg: char - treat `ENOMEM` as `EAGAIN`

From: Tim Blechmann <[email protected]>

This patch should allow the use of rpmsg_char character devices with libraries that do a poll/write loop and expect EAGAIN when sending fails and the user space application needs to poll to wait for more space to be available.
boost::asio::write is a notable example of a library, which implements such a loop.

Tim Blechmann (1):
rpmsg: char - treat ENOMEM as EAGAIN

 drivers/rpmsg/rpmsg_char.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Signature · 1 line
2.35.1
#4 lore raw

PATCH 1/1 rpmsg: char - treat ENOMEM as EAGAIN

From: Tim Blechmann <[email protected]>

rpmsg_trysend() returns -ENOMEM when no rpmsg buffer can be allocated. this causes write to fail with this error as opposed to -EAGAIN. this is what user space applications (and libraries like boost.asio) would expect when using normal character devices.

CC Arnaud Pouliquen <[email protected]>
---
 drivers/rpmsg/rpmsg_char.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/rpmsg/rpmsg_char.c +4 -1
index 5663cf799c95..5b9e708d595a 100644
@@ -239,14 +239,17 @@ static ssize_t rpmsg_eptdev_write_iter(struct kiocb *iocb,
 
 	if (!eptdev->ept) {
 		ret = -EPIPE;
 		goto unlock_eptdev;
 	}
 
-	if (filp->f_flags & O_NONBLOCK)
+	if (filp->f_flags & O_NONBLOCK) {
 		ret = rpmsg_trysendto(eptdev->ept, kbuf, len, eptdev->chinfo.dst);
+		if (ret == -ENOMEM)
+			ret = -EAGAIN;
+	}
 	else
 		ret = rpmsg_sendto(eptdev->ept, kbuf, len, eptdev->chinfo.dst);
 
 unlock_eptdev:
 	mutex_unlock(&eptdev->ept_lock);
 
Signature · 1 line
2.35.1