Attention is currently required from: Edward O'Callaghan, Anastasia Klimchuk. Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/52256 )
Change subject: ft2232_spi.c: Refactor singleton states into reentrant pattern ......................................................................
Patch Set 2: Code-Review+1
(3 comments)
File ft2232_spi.c:
https://review.coreboot.org/c/flashrom/+/52256/comment/b07653d7_87d2ccf3 PS2, Line 614: spi_data = calloc(1, sizeof(struct ft2232_data)); Can calloc() fail?
https://review.coreboot.org/c/flashrom/+/52256/comment/4d550236_40623ecf PS2, Line 614: sizeof(struct ft2232_data) Using type names in sizeof() is discouraged. If someone retypes `spi_data`, this sizeof() would also need to be updated to avoid problems, but it's easy to miss it because this sizeof() is almost 300 lines away from the `spi_data` definition.
Instead, one can apply sizeof() to variables. In this case, since `spi_data` is a pointer, `sizeof(spi_data)` would return the size of a pointer. It is possible to "dereference" it in order to obtain the size of the data it points to. This works even if the pointer is NULL, as sizeof() only cares about the type.
TL;DR: You can and should use this as the size argument for calloc():
sizeof(*spi_data)
https://review.coreboot.org/c/flashrom/+/52256/comment/5fe77ebf_de3696ee PS2, Line 617: memcpy(&spi_data->ftdic_context, &ftdic, sizeof(struct ftdi_context)); It should be possible to do a direct assignment:
spi_data->ftdic_context = ftdic;
If it doesn't work, I'm fine with keeping the memcpy(). However, please use `sizeof(ftdic)` for the length argument (see comment above).