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

powerpc/pmac: Use string library in nvram code

- Use memchr_inv to check if the data contains all 0xFF bytes.
It is faster than looping for each byte.

- Use memcmp to compare memory areas

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

authored by

Akinobu Mita and committed by
Benjamin Herrenschmidt
2d4b9712 ad5b7f13

+19 -23
+19 -23
arch/powerpc/platforms/powermac/nvram.c
··· 279 279 280 280 static int sm_erase_bank(int bank) 281 281 { 282 - int stat, i; 282 + int stat; 283 283 unsigned long timeout; 284 284 285 285 u8 __iomem *base = (u8 __iomem *)nvram_data + core99_bank*NVRAM_SIZE; ··· 301 301 out_8(base, SM_FLASH_CMD_CLEAR_STATUS); 302 302 out_8(base, SM_FLASH_CMD_RESET); 303 303 304 - for (i=0; i<NVRAM_SIZE; i++) 305 - if (base[i] != 0xff) { 306 - printk(KERN_ERR "nvram: Sharp/Micron flash erase failed !\n"); 307 - return -ENXIO; 308 - } 304 + if (memchr_inv(base, 0xff, NVRAM_SIZE)) { 305 + printk(KERN_ERR "nvram: Sharp/Micron flash erase failed !\n"); 306 + return -ENXIO; 307 + } 309 308 return 0; 310 309 } 311 310 ··· 335 336 } 336 337 out_8(base, SM_FLASH_CMD_CLEAR_STATUS); 337 338 out_8(base, SM_FLASH_CMD_RESET); 338 - for (i=0; i<NVRAM_SIZE; i++) 339 - if (base[i] != datas[i]) { 340 - printk(KERN_ERR "nvram: Sharp/Micron flash write failed !\n"); 341 - return -ENXIO; 342 - } 339 + if (memcmp(base, datas, NVRAM_SIZE)) { 340 + printk(KERN_ERR "nvram: Sharp/Micron flash write failed !\n"); 341 + return -ENXIO; 342 + } 343 343 return 0; 344 344 } 345 345 346 346 static int amd_erase_bank(int bank) 347 347 { 348 - int i, stat = 0; 348 + int stat = 0; 349 349 unsigned long timeout; 350 350 351 351 u8 __iomem *base = (u8 __iomem *)nvram_data + core99_bank*NVRAM_SIZE; ··· 380 382 /* Reset */ 381 383 out_8(base, 0xf0); 382 384 udelay(1); 383 - 384 - for (i=0; i<NVRAM_SIZE; i++) 385 - if (base[i] != 0xff) { 386 - printk(KERN_ERR "nvram: AMD flash erase failed !\n"); 387 - return -ENXIO; 388 - } 385 + 386 + if (memchr_inv(base, 0xff, NVRAM_SIZE)) { 387 + printk(KERN_ERR "nvram: AMD flash erase failed !\n"); 388 + return -ENXIO; 389 + } 389 390 return 0; 390 391 } 391 392 ··· 426 429 out_8(base, 0xf0); 427 430 udelay(1); 428 431 429 - for (i=0; i<NVRAM_SIZE; i++) 430 - if (base[i] != datas[i]) { 431 - printk(KERN_ERR "nvram: AMD flash write failed !\n"); 432 - return -ENXIO; 433 - } 432 + if (memcmp(base, datas, NVRAM_SIZE)) { 433 + printk(KERN_ERR "nvram: AMD flash write failed !\n"); 434 + return -ENXIO; 435 + } 434 436 return 0; 435 437 } 436 438