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

DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET is a layering violation that shouldn't exist #42149

Closed
mbolivar-nordic opened this issue Jan 26, 2022 · 0 comments · Fixed by #42150
Closed

DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET is a layering violation that shouldn't exist #42149

mbolivar-nordic opened this issue Jan 26, 2022 · 0 comments · Fixed by #42150
Labels
bug The issue is a bug, or the PR is fixing a bug priority: high High impact/importance bug Release Blocker Use this label for justified release blockers
Milestone

Comments

@mbolivar-nordic
Copy link
Contributor

Describe the bug

This macro, introduced in commit 4d1c90e (pull request #39116), should not have been added to the devicetree API.

It is a layering violation that introduces an unnecessary circular dependency:

  • struct gpio_dt_spec is defined by the GPIO API (drivers/gpio.h)
  • the GPIO API depends on the devicetree API (devicetree.h), and uses this dependency to define struct gpio_dt_spec
  • the DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET macro was added to the devicetree API in the above commit
  • this macro creates a c99 designated initializer for a struct gpio_dt_spec
  • therefore, it creates a dependency on the GPIO API in the devicetree API, i.e. it creates a circular dependency between the two

This is bad design. We don't add such things to the DT API, in order to keep our API dependencies clean.

This should have been added to the SPI API, not the devicetree API.

Impact

DT showstopper for v3.0, since devicetree.h is a stable API, and we really should not have this macro added to it in any release.

We haven't created a release with DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET in it yet as far as I can tell, so there's still time to fix it without having to go through a deprecation cycle and stable API change.

@mbolivar-nordic mbolivar-nordic added bug The issue is a bug, or the PR is fixing a bug priority: high High impact/importance bug labels Jan 26, 2022
@mbolivar-nordic mbolivar-nordic added this to the v3.0.0 milestone Jan 26, 2022
@mbolivar-nordic mbolivar-nordic added the Release Blocker Use this label for justified release blockers label Jan 26, 2022
mbolivar-nordic added a commit to mbolivar-nordic/zephyr that referenced this issue Jan 26, 2022
The DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET macro belongs in drivers/spi.h,
not devicetree.h.

It is creating a struct gpio_dt_spec, but the devicetree.h API does
not (other than in this case) and should not depend on structures that
are defined in the GPIO API. This is because the GPIO API already
depends on the devicetree.h API, so making a dependency in the reverse
direction creates a needless circular dependency.

This macro should have been added to the drivers/spi.h API from the
beginning. Move it there under a new name, SPI_CS_GPIOS_DT_SPEC_GET.

We haven't created a Zephyr release with
DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET in it, so there is no need to go
through the stable API change process for devicetree.h to deprecate
and eventually remove it. We can just remove it directly.

Fixes: zephyrproject-rtos#42149
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
carlescufi pushed a commit that referenced this issue Jan 26, 2022
The DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET macro belongs in drivers/spi.h,
not devicetree.h.

It is creating a struct gpio_dt_spec, but the devicetree.h API does
not (other than in this case) and should not depend on structures that
are defined in the GPIO API. This is because the GPIO API already
depends on the devicetree.h API, so making a dependency in the reverse
direction creates a needless circular dependency.

This macro should have been added to the drivers/spi.h API from the
beginning. Move it there under a new name, SPI_CS_GPIOS_DT_SPEC_GET.

We haven't created a Zephyr release with
DT_SPI_DEV_CS_GPIOS_DT_SPEC_GET in it, so there is no need to go
through the stable API change process for devicetree.h to deprecate
and eventually remove it. We can just remove it directly.

Fixes: #42149
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug priority: high High impact/importance bug Release Blocker Use this label for justified release blockers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant