Skip to contentSkip to conversation

mtd: rawnand: fsmc: Change to non-atomic bit operations

PATCH Applied Fenghua Yu 2 participants 2 messages Dec 20, 2019 – May 10, 2020

Subsystems (2)
lore
Share & tools
lore

Fenghua Yu

author
#0 lore raw

PATCH 1/1 mtd: rawnand: fsmc: Change to non-atomic bit operations

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().

---

This driver only works on ARM. We find unaligned access in change_bit() is quite expensive on x86. Although this driver is not configured and compiled on x86, I send this patch to you in case it's useful. I haven't compiled or tested this patch yet.

 drivers/mtd/nand/raw/fsmc_nand.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/mtd/nand/raw/fsmc_nand.c +4 -3
index a6964feeec77..7e28311dffcb 100644
@@ -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++;
 		}
 	}
Signature · 6 lines
2.19.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer Applied
#1 lore raw
Quoted 11 lines · Fenghua Yu

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().

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/