-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: serial: return int value from uart_poll_out #64081
drivers: serial: return int value from uart_poll_out #64081
Conversation
40d3e90
to
6b1617e
Compare
With the previous return type void some drivers silently dropped characters without any possibility for a user of the API to notice whether a character was transmitted successfully or not. This is not a breaking API change, as existing code (ignoring the return value) will continue working as before. Signed-off-by: Martin Jäger <martin@libre.solar>
This avoids compiler warnings because of unused return values. Signed-off-by: Martin Jäger <martin@libre.solar>
1f1bb53
to
1baf801
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, renesas part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auxdisplay, MCUmggr changes OK
|
||
SEGGER_RTT_Write(ch, &c, 1); | ||
return ret > 0 ? 0 : -EIO; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>=
? RTT can have a buffer depending upon Kconfig settings so I don't think it's right for 0 to return an error here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understood, 0 means that the character was dropped and not written into the buffer, which should be indicated with an error, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://wiki.segger.com/RTT#SEGGER_RTT_Write.28.29
>= 0 | Number of bytes which have been sent.
< 0 | Error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. How can an unsigned
function return a negative error code?
In any case: If I want to send 1 byte, but 0 bytes "have been sent", that's an error in my understanding.
@@ -206,7 +206,7 @@ static int uart_mcumgr_send_raw(const void *data, int len) | |||
|
|||
u8p = data; | |||
while (len--) { | |||
uart_poll_out(uart_mcumgr_dev, *u8p++); | |||
(void)uart_poll_out(uart_mcumgr_dev, *u8p++); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@de-nordic will need to add code to bail at this point for 3.6
@@ -47,9 +47,9 @@ static int test_poll_out(void) | |||
return TC_FAIL; | |||
} | |||
|
|||
/* Verify uart_poll_out() */ | |||
/* Verify (void)uart_poll_out() */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment update seems superfluous
@martinjaeger This is an incompatible change to the OOT UART drivers, I guess you have to follow Introducing incompatible changes |
Well, it may introduce warnings to existing code? |
I didn't have OOT drivers in mind. I agree with @jfischer-no and @carlescufi that it has to go through the stable API change process. Will prepare RFC issue etc. |
There are (void) casts added in bulk, which is not ok, IMHO, as it just does +1 to "happy debugging!" in the future. |
The idea is to make the API change as unintrusive as possible. The (void) casts keep the behaviour in the subsystems exactly as it was before. Future users of the poll out API can decide if they want to consider the return value or ignore it. |
You will have the calls keep on silently failing even though you have added a way to inform about problem. IMHO you have provided fix for a problem, to then unfix it with cast. The problem is that some of code, for example in MCUboot So we either have to wave every (void) cast line as ok or log potential bug for it. |
@martinjaeger is the RFC issue ready? |
No, not yet. Got distracted with other higher priority work. I aim at getting RFC and PR update done within the next few days. |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
Unfortunately, I don't have enough free cycles to finish this up at the moment. Feel free to pick the commits if anyone likes to go through all in-tree users of the API to consider the return values. |
With the previous return type
void
some drivers silently dropped characters without any possibility for a user of the API to notice whether a character was transmitted successfully or not.This is not a breaking change of the stable API, as existing code (ignoring the return value) will continue to work as before.