Daniel Kurtz has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/47655 )
Change subject: it85spi.c: Refactor singleton states into reentrant pattern ......................................................................
Patch Set 10: Code-Review-1
(1 comment)
https://review.coreboot.org/c/flashrom/+/47655/8/it85spi.c File it85spi.c:
https://review.coreboot.org/c/flashrom/+/47655/8/it85spi.c@240 PS8, Line 240: (struct it85spi_data *)
Compiler is not cooperative: […]
A motivation for removing extraneous casts is to only use casts in situations where they are adding semantic value - that is, where we are explicitly trying to change the pointer type in a fundamental way - such as converting from one memory layout (struct) to another, or removing const-ness. For all other cases, relying on default C language cast behavior provides simpler and more reliable code, and let's the compiler do its job easier...
In this particular case, removing the cast lets the compiler correctly expose a bug - that we are now trying to create a local non-const pointer to a struct that we have previously declared `const` - in particular this functions first parameter, which was declared `const struct flashctx *flash`.
Luckily, we don't actually intend to modify `data` via this pointer, so we needn't de-constify it. Thus, the fix here is to use:
const struct it85spi_data *data = flash->mst->spi.data;