Skip to content
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

Conversation

martinjaeger
Copy link
Member

@martinjaeger martinjaeger commented Oct 18, 2023

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.

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>
@martinjaeger martinjaeger force-pushed the uart-poll-out-return-value branch from 1f1bb53 to 1baf801 Compare October 19, 2023 06:38
Copy link
Member

@aaillet aaillet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, renesas part

Copy link
Collaborator

@nordicjm nordicjm left a 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;
Copy link
Collaborator

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

Copy link
Member Author

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?

Copy link
Collaborator

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.

Copy link
Member Author

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++);
Copy link
Collaborator

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() */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment update seems superfluous

@jfischer-no
Copy link
Collaborator

@martinjaeger This is an incompatible change to the OOT UART drivers, I guess you have to follow Introducing incompatible changes

@carlescufi
Copy link
Member

This is not a breaking change of the stable API, as existing code (ignoring the return value) will continue to work as before.

Well, it may introduce warnings to existing code?

@martinjaeger
Copy link
Member Author

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.

@de-nordic
Copy link
Collaborator

This is not a breaking change of the stable API, as existing code (ignoring the return value) will continue to work as before.

Well, it may introduce warnings to existing code?

There are (void) casts added in bulk, which is not ok, IMHO, as it just does +1 to "happy debugging!" in the future.

@martinjaeger
Copy link
Member Author

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.
Why do you think this could lead to additional bugs?

@carlescufi carlescufi added DNM This PR should not be merged (Do Not Merge) Breaking API Change Breaking changes to stable, public APIs labels Oct 23, 2023
@de-nordic
Copy link
Collaborator

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. Why do you think this could lead to additional bugs?

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 console_out, has been build around the uart_poll_out that can not fail, so now, even though you consider it to behave the same, this is no longer true as we now acknowledge possible failure and need to rework the code to address such possibility. In short: the API change adds possible bug everywhere we do not check the code returned by the function.

So we either have to wave every (void) cast line as ok or log potential bug for it.

@carlescufi
Copy link
Member

@martinjaeger is the RFC issue ready?

@martinjaeger
Copy link
Member Author

@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.

Copy link

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.

@github-actions github-actions bot added the Stale label Dec 31, 2023
@martinjaeger
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking API Change Breaking changes to stable, public APIs DNM This PR should not be merged (Do Not Merge) Stale treewide 🧹
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants