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/sdcard_spi: make 8-bit safe #18572

Merged
merged 2 commits into from
Sep 11, 2022
Merged

Conversation

maribu
Copy link
Member

@maribu maribu commented Sep 9, 2022

Contribution description

  • replace all ints and unsigneds with integers with fixed width
  • replaced all signed integers of sizes with unsigned ones (sizes cannot be negative)
  • made bitshifts 8-bit safe (e.g. 1 << 24 is valid on 32-bit, but undefined behavior on 8-bit, as a 16 bit wide int would be shifted by more than the type width)
  • use void * / const void * for data buffers to ease use

Testing procedure

$ make BOARD=<RANDOM_BEEFY_AVR_BOARD_WITH_SD_CARD> -C examples/vfs_default
> vfs ls /sd0
2022-09-09 17:08:51,026 # main(): This is RIOT! (Version: 2022.10-devel-591-g494f5d-drivers/sdcard_spi)
2022-09-09 17:08:51,040 # mount points:
2022-09-09 17:08:51,046 # 	/sd0
2022-09-09 17:08:51,047 # 
2022-09-09 17:08:51,063 # data dir: /sd0
> vfs ls /sd0
2022-09-09 17:08:56,155 # vfs ls /sd0
2022-09-09 17:08:56,191 # FIXUP.DAT	7314 B
2022-09-09 17:08:56,210 # FIXUP4.DAT	5448 B
2022-09-09 17:08:56,234 # SYSTEM~1.MAP	4328313 B
2022-09-09 17:08:56,256 # START4.ELF	2228800 B
2022-09-09 17:08:56,275 # CONFIG~1	207723 B
2022-09-09 17:08:56,295 # VMLINU~1	19730944 B
2022-09-09 17:08:56,356 # START.ELF	2952960 B
2022-09-09 17:08:56,509 # ALPINE~1	25 B
2022-09-09 17:08:56,639 # OVERLAYS/
2022-09-09 17:08:56,769 # DTBS-R~1/
2022-09-09 17:08:56,908 # INITRA~1	4162721 B
2022-09-09 17:08:57,049 # BCM271~1.DTB	26894 B
2022-09-09 17:08:57,211 # BCM271~2.DTB	29011 B
2022-09-09 17:08:57,453 # BCM271~3.DTB	28392 B
2022-09-09 17:08:57,670 # CONFIG.TXT	378 B
2022-09-09 17:08:57,892 # BOOTCODE.BIN	52456 B
2022-09-09 17:08:58,114 # BCM271~4.DTB	26890 B
2022-09-09 17:08:58,336 # BCM271~5.DTB	49218 B
2022-09-09 17:08:58,578 # BCM283~1.DTB	20120 B
2022-09-09 17:08:58,899 # BCM283~2.DTB	20989 B
2022-09-09 17:08:59,200 # BCM283~3.DTB	20525 B
2022-09-09 17:08:59,502 # BCM283~4.DTB	19852 B
2022-09-09 17:08:59,800 # CMDLINE.TXT	162 B
2022-09-09 17:09:00,097 # USERCFG.TXT	92 B
2022-09-09 17:09:00,448 # CMDLINE.BAK	256 B
2022-09-09 17:09:00,916 # BCM271~6.DTB	49214 B
2022-09-09 17:09:01,364 # BCM271~7.DTB	49892 B
2022-09-09 17:09:01,633 # total 25 files

Issues/PRs references

Fixes issue reported in #18445 (comment)

@maribu maribu added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: drivers Area: Device drivers labels Sep 9, 2022
@github-actions github-actions bot added the Area: tests Area: tests and testing framework label Sep 9, 2022
@maribu maribu added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Sep 9, 2022
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

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

Looks good to me - please fix static checks

- replace all `int`s and `unsigned`s with integers with fixed width
- replaced all signed integers of sizes with unsigned ones (sizes
  cannot be negative)
- made bitshifts 8-bit safe (e.g. `1 << 24` is valid on 32-bit, but
  undefined behavior on 8-bit, as a 16 bit wide `int` would be shifted
  by more than the type width)
- use `void *` / `const void *` for data buffers to ease use
This avoids an stack overflow when using `vfs ls`.
@maribu maribu enabled auto-merge September 11, 2022 08:28
@maribu maribu merged commit 4c5ff03 into RIOT-OS:master Sep 11, 2022
@maribu
Copy link
Member Author

maribu commented Sep 11, 2022

Thx :)

@maribu maribu deleted the drivers/sdcard_spi branch September 11, 2022 13:37
@maribu maribu added this to the Release 2022.10 milestone Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants