-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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: uart: samd0: add missing .configure API functionality #23234
drivers: uart: samd0: add missing .configure API functionality #23234
Conversation
All checks are passing now. checkpatch (informational only, not a failure)
Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages. |
bf9192e
to
c25357a
Compare
c4676d5
to
0dd4721
Compare
a248844
to
6ff59fc
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.
This PR adds the .configure
interface implementation without .config_get
. Both should be implemented to pass the UART driver test.
p.s. As far as I can see, all the other UART drivers that support .configure
implement .config_get
as well.
afb01da
to
0c47fbd
Compare
d56d7f6
to
712fca1
Compare
712fca1
to
08522b4
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.
The conventional way of implementing config_get
would be to cache configurations in struct uart_config
or data variables in the driver context and simply return those values.
The assumption is, and should be, that an application will not make arbitrary direct configuration changes to the UART hardware.
(e.g. see uart_ns16550.c
, uart_nrfx_uart.c
and others)
p.s. I am neither +1 nor -1 on the current implementation; the API specification does not state exactly how it should be implemented. With that being the case, the current implementation would cause a problem if an application relies on the behaviour in which the configured and retrieved baudrates exactly match, or the retrieved baudrates are expected to match one of the preset values.
EDIT:
the API specification does not state exactly how it should be implemented
though the test (tests/drivers/uart/uart_basic_api
) does.
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 the UART driver test (tests/drivers/uart/uart_basic_api
) goes, the configured and retrieved data MUST EXACTLY MATCH:
if (memcmp(&uart_cfg, &uart_cfg_check, sizeof(uart_cfg)) != 0) { |
So the current implementation will not pass the test.
@stephanosio Ah, this branch was actually created before the |
2ab0fe7
to
8f62f6c
Compare
The UART driver for samd0 was is missing the .configure and .config_get functionality expected from api for serial driver. This commit fixes this by providing basic configuration Signed-off-by: Kuba Sanak <[email protected]>
8f62f6c
to
0bb40e4
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.
Looks ok to me.
return 0; | ||
} | ||
|
||
static int uart_sam0_config_get(struct device *dev, |
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.
jw - Is it worth considering a way to accomplish this task without using memcpy()
? I ask because I am curious about it from a secure coding perspective atm. Can this use of memcpy introduce a vulnerability? Please see uart_nrfx_uart.c and uart_ns16550.c for example implementations.
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.
In choosing the memcpy()
I was aiming for making absolutely sure that the implementation passes relevant tests which currently use memcmp()
to establish whether the set and retrieved struct uart_config
's match. Doing things the way uart_nrfx_uart.c or uart_ns16550.c do it can potentially introduce a corner case where the test won't pass because of potential content of padding in the struct which won't be carried across without memcpy()
.
I guess the proper thing to do would be to edit the tests to use comparison of individual struct member variables instead of memcmp()
, but I wanted to avoid doing changes not related to the work I'm doing.
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.
Ah that makes sense, thanks for clarifying! I am learning more with your help.
I wonder if you might want to add the cast to void in anticipation of the MISRA-C coding guidelines currently in discussion, namely regarding memcpy --> (void) memcpy()
(see #18344). Adding @ceolin in case he wants to share thoughts 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 long as the copy size is static (i.e. sizeof(dev_data->config_cache)
), that is highly unlikely.
As for the out_cfg
pointer checking, that is a whole another issue.
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.
Enforcement of MISRA-C, especially arguably ridiculous ones like (void)func()
is a no-go for now IIRC.
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.
Hi @jenmwms, regarding MISRA, it is not sepcific to memcpy
. The rule says that we should check all return values from non-void functions. It happens, that memcpy() return is quite useless, so we just explicitly ignore it casting to void.
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 for the
out_cfg
pointer checking, that is a whole another issue.
Do you mean the checking in function or in the test. In short, is there any other changes I should make to this PR?
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.
@KubaFYI As far as my comments are concerned, no changes necessary in this PR.
I was simply alluding that we can go very far with advanced security checks and functional safety rules; but, given that the current Zephyr codebase is really not ready for compliance, I see no reason to enforce them in this particular PR.
The UART driver for samd0 was is missing the .configure
functionality expected from api for serial driver. This commit
fixes this by providing basic configuration.
Note, using the function will briefly switch the peripheral off
taking the data line low.
Signed-off-by: Kuba Sanak [email protected]