Skip to content

Commit

Permalink
mtd: rawnand: gpmi: fix reference count leak in gpmi ops
Browse files Browse the repository at this point in the history
pm_runtime_get_sync() will increment pm usage at first and it
will resume the device later. If runtime of the device has
error or device is in inaccessible state(or other error state),
resume operation will fail. If we do not call put operation to
decrease the reference, it will result in reference leak in
the two functions(gpmi_init and gpmi_nfc_exec_op). Moreover,
this device cannot enter the idle state and always stay busy or
other non-idle state later. So we fixed it through adding
pm_runtime_put_noidle.

Fixes: 5bc6bb6 ("mtd: rawnand: gpmi: Fix suspend/resume problem")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Acked-by: Han Xu <han.xu@nxp.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20201107110552.1568742-1-zhangqilong3@huawei.com
  • Loading branch information
Zhang Qilong authored and Miquel Raynal committed Dec 10, 2020
1 parent 6d912c4 commit 1b391c7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ static int gpmi_init(struct gpmi_nand_data *this)
int ret;

ret = pm_runtime_get_sync(this->dev);
if (ret < 0)
if (ret < 0) {
pm_runtime_put_noidle(this->dev);
return ret;
}

ret = gpmi_reset_block(r->gpmi_regs, false);
if (ret)
Expand Down Expand Up @@ -2263,8 +2265,10 @@ static int gpmi_nfc_exec_op(struct nand_chip *chip,
this->transfers[i].direction = DMA_NONE;

ret = pm_runtime_get_sync(this->dev);
if (ret < 0)
if (ret < 0) {
pm_runtime_put_noidle(this->dev);
return ret;
}

/*
* This driver currently supports only one NAND chip. Plus, dies share
Expand Down

0 comments on commit 1b391c7

Please sign in to comment.