[POWERPC] PS3: Fix printing of os-area magic numbers

Fix a bug in the printing of the os-area magic numbers which assumed
that magic numbers were zero terminated strings. The magic numbers
are represented in memory as integers. If the os-area sections are
not initialized correctly they could contained random data that would
be printed to the display. Also unify the handling of header and db
magic numbers and make both of type array of u8.

Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>

authored by Geoff Levand and committed by Paul Mackerras ec5d2dfe aed3a8c9

+30 -10
+30 -10
arch/powerpc/platforms/ps3/os-area.c
··· 23 23 #include <linux/workqueue.h> 24 24 #include <linux/fs.h> 25 25 #include <linux/syscalls.h> 26 + #include <linux/ctype.h> 26 27 27 28 #include <asm/lmb.h> 28 29 ··· 37 36 HEADER_LDR_FORMAT_RAW = 0, 38 37 HEADER_LDR_FORMAT_GZIP = 1, 39 38 }; 39 + 40 + #define OS_AREA_HEADER_MAGIC_NUM "cell_ext_os_area" 40 41 41 42 /** 42 43 * struct os_area_header - os area header segment. ··· 117 114 u8 _reserved_5[8]; 118 115 }; 119 116 120 - enum { 121 - OS_AREA_DB_MAGIC_NUM = 0x2d64622dU, 122 - }; 117 + #define OS_AREA_DB_MAGIC_NUM "-db-" 123 118 124 119 /** 125 120 * struct os_area_db - Shared flash memory database. 126 - * @magic_num: Always '-db-' = 0x2d64622d. 121 + * @magic_num: Always '-db-'. 127 122 * @version: os_area_db format version number. 128 123 * @index_64: byte offset of the database id index for 64 bit variables. 129 124 * @count_64: number of usable 64 bit index entries ··· 136 135 */ 137 136 138 137 struct os_area_db { 139 - u32 magic_num; 138 + u8 magic_num[4]; 140 139 u16 version; 141 140 u16 _reserved_1; 142 141 u16 index_64; ··· 266 265 prop->name); 267 266 } 268 267 268 + static void dump_field(char *s, const u8 *field, int size_of_field) 269 + { 270 + #if defined(DEBUG) 271 + int i; 272 + 273 + for (i = 0; i < size_of_field; i++) 274 + s[i] = isprint(field[i]) ? field[i] : '.'; 275 + s[i] = 0; 276 + #endif 277 + } 278 + 269 279 #define dump_header(_a) _dump_header(_a, __func__, __LINE__) 270 280 static void _dump_header(const struct os_area_header *h, const char *func, 271 281 int line) 272 282 { 283 + char str[sizeof(h->magic_num) + 1]; 284 + 285 + dump_field(str, h->magic_num, sizeof(h->magic_num)); 273 286 pr_debug("%s:%d: h.magic_num: '%s'\n", func, line, 274 - h->magic_num); 287 + str); 275 288 pr_debug("%s:%d: h.hdr_version: %u\n", func, line, 276 289 h->hdr_version); 277 290 pr_debug("%s:%d: h.db_area_offset: %u\n", func, line, ··· 326 311 327 312 static int verify_header(const struct os_area_header *header) 328 313 { 329 - if (memcmp(header->magic_num, "cell_ext_os_area", 16)) { 314 + if (memcmp(header->magic_num, OS_AREA_HEADER_MAGIC_NUM, 315 + sizeof(header->magic_num))) { 330 316 pr_debug("%s:%d magic_num failed\n", __func__, __LINE__); 331 317 return -1; 332 318 } ··· 347 331 348 332 static int db_verify(const struct os_area_db *db) 349 333 { 350 - if (db->magic_num != OS_AREA_DB_MAGIC_NUM) { 334 + if (memcmp(db->magic_num, OS_AREA_DB_MAGIC_NUM, 335 + sizeof(db->magic_num))) { 351 336 pr_debug("%s:%d magic_num failed\n", __func__, __LINE__); 352 337 return -1; 353 338 } ··· 501 484 static void _dump_db(const struct os_area_db *db, const char *func, 502 485 int line) 503 486 { 487 + char str[sizeof(db->magic_num) + 1]; 488 + 489 + dump_field(str, db->magic_num, sizeof(db->magic_num)); 504 490 pr_debug("%s:%d: db.magic_num: '%s'\n", func, line, 505 - (const char*)&db->magic_num); 491 + str); 506 492 pr_debug("%s:%d: db.version: %u\n", func, line, 507 493 db->version); 508 494 pr_debug("%s:%d: db.index_64: %u\n", func, line, ··· 536 516 537 517 memset(db, 0, sizeof(struct os_area_db)); 538 518 539 - db->magic_num = OS_AREA_DB_MAGIC_NUM; 519 + memcpy(db->magic_num, OS_AREA_DB_MAGIC_NUM, sizeof(db->magic_num)); 540 520 db->version = 1; 541 521 db->index_64 = HEADER_SIZE; 542 522 db->count_64 = VALUES_64_COUNT;