Patch set 10:Code-Review -1
1 comment:
Patch Set #8, 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;
To view, visit change 47655. To unsubscribe, or for help writing mail filters, visit settings.