Skip to content

stm32xx-i2c: remove I2cControl function table #2121

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

cbiffle
Copy link
Collaborator

@cbiffle cbiffle commented Jun 30, 2025

It turns out that, in practice, we only ever provide a single function for each of wfi and enable here. This makes the table itself an unnecessary level of indirection, which has some deleterious effects:

  • It opens the possibility for different I2cControl structs containing different function pointers to be passed to each call, complicating analysis. (Searching for this phenomenon was what led me to notice that we only ever use one implementation.)

  • It makes it a lot harder to recognize use of syscalls (or misuse of syscalls) in the I2C layer.

  • It routes important parts of the I2C stack through indirect function calls, defeating stack analysis.

  • It adds a bunch of code that isn't really necessary, as it turns out.

This commit removes the dispatch table, inlining the existing functions into their callsites (and introducing a utility function for the wfi behavior).

@cbiffle cbiffle requested review from bcantrill and mkeeter June 30, 2025 19:34
@cbiffle cbiffle force-pushed the cbiffle/i2c branch 2 times, most recently from b37b0c4 to 1667d48 Compare July 1, 2025 14:05
cbiffle and others added 2 commits July 23, 2025 16:38
It turns out that, in practice, we only ever provide a single function
for each of `wfi` and `enable` here. This makes the table itself an
unnecessary level of indirection, which has some deleterious effects:

- It opens the possibility for _different_ I2cControl structs containing
  _different_ function pointers to be passed to each call, complicating
  analysis. (Searching for this phenomenon was what led me to notice
  that we only ever use one implementation.)

- It makes it a lot harder to recognize use of syscalls (or misuse of
  syscalls) in the I2C layer.

- It routes important parts of the I2C stack through indirect function
  calls, defeating stack analysis.

- It adds a bunch of code that isn't really necessary, as it turns out.

This commit removes the dispatch table, inlining the existing functions
into their callsites (and introducing a utility function for the wfi
behavior).
@mkeeter
Copy link
Collaborator

mkeeter commented Jul 23, 2025

I've rebased this onto master and update the docstring. I think it should be good to go, but will do some hardware testing tomorrow to be certain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants