Skip to contentSkip to conversation

MTD: OneNAND: Avoid deadlock in erase callback; release chip lock first.

PATCH In review Adrian Hunter 2 participants 3 messages Oct 12, 2007 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MTD: OneNAND: Avoid deadlock in erase callback; release chip lock first.

When the erase callback performs some other action on the flash, it's highly likely to deadlock unless we actually release the chip lock before calling it.

This patch mirrors that same change already done for NAND.

---
drivers/mtd/onenand/onenand_base.c | 7 ++++---

1 files changed, 4 insertions(+), 3 deletions(-)
drivers/mtd/onenand/onenand_base.c +0 -0
index a8c426b..dd28355 100644
@@ -1711,13 +1711,14 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)

erase_exit:

	ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO;

- /* Do call back function */
- if (!ret)
- mtd_erase_callback(instr);

	/* Deselect and wake up anyone waiting on the device */
	onenand_release_device(mtd);

+ /* Do call back function */
+ if (!ret)
+ mtd_erase_callback(instr);
+

	return ret;
}
Signature · 1 line
1.4.4.2
#1 lore raw
Quoted 17 lines · Adrian Hunter

When the erase callback performs some other action on the flash, it's highly likely to deadlock unless we actually release the chip lock before calling it.

This patch mirrors that same change already done for NAND.

---
 drivers/mtd/onenand/onenand_base.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
drivers/mtd/onenand/onenand_base.c +0 -0
index a8c426b..dd28355 100644

drivers/mtd/onenand/onenand_base.c static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr) · line 1713

Quoted 3 lines
drivers/mtd/onenand/onenand_base.c +0 -0
@@ -1711,13 +1711,14 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
 erase_exit:
 
 	ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO;

Can you move this line down as well? There is no point in holding the lock here and shrinking critical sections - even if only minimally - is generally advantageous.

drivers/mtd/onenand/onenand_base.c static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr) · line 1723

Quoted 13 lines
drivers/mtd/onenand/onenand_base.c +4 -3
-	/* Do call back function */
-	if (!ret)
-		mtd_erase_callback(instr);
 
 	/* Deselect and wake up anyone waiting on the device */
 	onenand_release_device(mtd);
 
+	/* Do call back function */
+	if (!ret)
+		mtd_erase_callback(instr);
+
 	return ret;
 }

Jörn

Signature · 3 lines
But this is not to say that the main benefit of Linux and other GPL
software is lower-cost. Control is the main benefit--cost is secondary.
-- Bruce Perens
#2 lore raw
Quoted 32 lines · ext Jörn Engel
Quoted 16 lines · Adrian Hunter

When the erase callback performs some other action on the flash, it's highly likely to deadlock unless we actually release the chip lock before calling it.

This patch mirrors that same change already done for NAND.

---
 drivers/mtd/onenand/onenand_base.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
drivers/mtd/onenand/onenand_base.c +0 -0
index a8c426b..dd28355 100644

drivers/mtd/onenand/onenand_base.c static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr) · line 1713

Quoted 3 lines
drivers/mtd/onenand/onenand_base.c +0 -0
@@ -1711,13 +1711,14 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
 erase_exit:
 
 	ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO;

Can you move this line down as well? There is no point in holding the lock here and shrinking critical sections - even if only minimally - is generally advantageous.

Quoted 7 lines
drivers/mtd/onenand/onenand_base.c +0 -3
-	/* Do call back function */
-	if (!ret)
-		mtd_erase_callback(instr);
 
 	/* Deselect and wake up anyone waiting on the device */
 	onenand_release_device(mtd);
 
Quoted 9 lines

drivers/mtd/onenand/onenand_base.c static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr) · line 1723

Quoted 6 lines
drivers/mtd/onenand/onenand_base.c +4 -0
+	/* Do call back function */
+	if (!ret)
+		mtd_erase_callback(instr);
+
 	return ret;
 }

Jörn

I wanted the patch to be the same as NAND

see http://git.infradead.org/?p=mtd-2.6.git;a=commitdiff;h=49defc015ff58fda46a3afa3462dfdfa69bc8401

Anyone who feels strongly should change both places ;-)