Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: map: BUG() in non handled cases

Several map-related functions look like a serie of ifs, checking
widths of map. Those functions do not have any handling for default
case. Instead of fiddling with uninitialized_var in those functions,
let's just add a (correct) BUG() to the default case on those maps. This
will also allow us to catch potential errors in maps setup in future.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry_eremin@mentor.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

authored by

Dmitry Eremin-Solenikov and committed by
Artem Bityutskiy
24dea0c9 be0638d9

+6 -2
+6 -2
include/linux/mtd/map.h
··· 329 329 330 330 static inline map_word map_word_load(struct map_info *map, const void *ptr) 331 331 { 332 - map_word r = {{0} }; 332 + map_word r; 333 333 334 334 if (map_bankwidth_is_1(map)) 335 335 r.x[0] = *(unsigned char *)ptr; ··· 343 343 #endif 344 344 else if (map_bankwidth_is_large(map)) 345 345 memcpy(r.x, ptr, map->bankwidth); 346 + else 347 + BUG(); 346 348 347 349 return r; 348 350 } ··· 394 392 395 393 static inline map_word inline_map_read(struct map_info *map, unsigned long ofs) 396 394 { 397 - map_word uninitialized_var(r); 395 + map_word r; 398 396 399 397 if (map_bankwidth_is_1(map)) 400 398 r.x[0] = __raw_readb(map->virt + ofs); ··· 428 426 #endif 429 427 else if (map_bankwidth_is_large(map)) 430 428 memcpy_toio(map->virt+ofs, datum.x, map->bankwidth); 429 + else 430 + BUG(); 431 431 mb(); 432 432 } 433 433