On Fri, Mar 17, 2023 at 9:31 PM Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote: > > 'enum m5mols_restype' should be in the range 0..2, but it seems to use > a 64-bit compare against '16385' (and then a 32-bit compare against > '8199') to decide it's out-of-bounds. It is comparing against just the `.code` in the `m5mols_default_ffmt` table, i.e. the `MEDIA_BUS_FMT_VYUY8_2X8` (8199 = 0x2007) and `MEDIA_BUS_FMT_JPEG_1X8` (16385 = 0x4001), see https://elixir.bootlin.com/linux/latest/source/drivers/media/i2c/m5mols/m5mols_core.c#L52. So it is basically: if (code == m5mols_default_ffmt[0].code) return type; if (type == 2) continue; ++type; if (code == m5mols_default_ffmt[1].code) return type; if (type == 2) continue; ++type; m5mols_default_ffmt[2].code -> out of bounds UB -> unreachable If the condition had `++type` instead, it would not be a problem, because the loop stops before we go into the out of bounds access thus no UB. Cheers, Miguel