Skip to content

Commit a0916c9

Browse files
Boris Brezillonmiquelraynal
authored andcommitted
mtd: rawnand: tmio: Do not abuse nand_controller->wq
nand_controller->wq has never been meant to be used by NAND controller drivers. This waitqueue is used by the framework to serialize accesses to a NAND controller, and messing up with its state is a really bad idea. Declare a completion object in tmio_nand and use it to wait for RB transitions. Signed-off-by: Boris Brezillon <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent b5c2def commit a0916c9

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

drivers/mtd/nand/raw/tmio_nand.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104

105105
struct tmio_nand {
106106
struct nand_chip chip;
107+
struct completion comp;
107108

108109
struct platform_device *dev;
109110

@@ -168,15 +169,11 @@ static int tmio_nand_dev_ready(struct nand_chip *chip)
168169
static irqreturn_t tmio_irq(int irq, void *__tmio)
169170
{
170171
struct tmio_nand *tmio = __tmio;
171-
struct nand_chip *nand_chip = &tmio->chip;
172172

173173
/* disable RDYREQ interrupt */
174174
tmio_iowrite8(0x00, tmio->fcr + FCR_IMR);
175+
complete(&tmio->comp);
175176

176-
if (unlikely(!waitqueue_active(&nand_chip->controller->wq)))
177-
dev_warn(&tmio->dev->dev, "spurious interrupt\n");
178-
179-
wake_up(&nand_chip->controller->wq);
180177
return IRQ_HANDLED;
181178
}
182179

@@ -193,12 +190,14 @@ static int tmio_nand_wait(struct nand_chip *nand_chip)
193190
u8 status;
194191

195192
/* enable RDYREQ interrupt */
193+
196194
tmio_iowrite8(0x0f, tmio->fcr + FCR_ISR);
195+
reinit_completion(&tmio->comp);
197196
tmio_iowrite8(0x81, tmio->fcr + FCR_IMR);
198197

199-
timeout = wait_event_timeout(nand_chip->controller->wq,
200-
tmio_nand_dev_ready(nand_chip),
201-
msecs_to_jiffies(nand_chip->state == FL_ERASING ? 400 : 20));
198+
timeout = nand_chip->state == FL_ERASING ? 400 : 20;
199+
timeout = wait_for_completion_timeout(&tmio->comp,
200+
msecs_to_jiffies(timeout));
202201

203202
if (unlikely(!tmio_nand_dev_ready(nand_chip))) {
204203
tmio_iowrite8(0x00, tmio->fcr + FCR_IMR);
@@ -378,6 +377,8 @@ static int tmio_probe(struct platform_device *dev)
378377
if (!tmio)
379378
return -ENOMEM;
380379

380+
init_completion(&tmio->comp);
381+
381382
tmio->dev = dev;
382383

383384
platform_set_drvdata(dev, tmio);

0 commit comments

Comments
 (0)