mtd: rawnand: fsmc: Change to non-atomic bit operations
authorFenghua Yu <fenghua.yu@intel.com>
Sat, 21 Dec 2019 00:05:55 +0000 (16:05 -0800)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Sun, 10 May 2020 19:15:52 +0000 (21:15 +0200)
No need to use expensive atomic change_bit() on dat[] and err_idx[]:
1. fsmc_bch8_correct_data() is called while mutex chip->lock is held
2. err_idx[] is a local variable.

To avoid big endian concern due to type cast to unsigned long, directly
change the bit in the specified byte instead of using non-atomic
__change_bit().

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/1576886755-9788-1-git-send-email-fenghua.yu@intel.com
drivers/mtd/nand/raw/fsmc_nand.c

index a6964fe..7e28311 100644 (file)
@@ -809,11 +809,12 @@ static int fsmc_bch8_correct_data(struct nand_chip *chip, u8 *dat,
 
        i = 0;
        while (num_err--) {
-               change_bit(0, (unsigned long *)&err_idx[i]);
-               change_bit(1, (unsigned long *)&err_idx[i]);
+               err_idx[i] ^= 3;
 
                if (err_idx[i] < chip->ecc.size * 8) {
-                       change_bit(err_idx[i], (unsigned long *)dat);
+                       int err = err_idx[i];
+
+                       dat[err >> 3] ^= BIT(err & 7);
                        i++;
                }
        }