Skip to contentSkip to conversation

mtd: nand: vf610: Check the return value from clk_prepare_enable()

PATCH Superseded Fabio Estevam 2 participants 4 messages Jul 17, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: nand: vf610: Check the return value from clk_prepare_enable()

From: Fabio Estevam <[email protected]>

clk_prepare_enable() may fail, so we should better check its return value and propagate it in the case of error.

---
 drivers/mtd/nand/vf610_nfc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/mtd/nand/vf610_nfc.c +5 -1
index 744ab10..9e49672 100644
@@ -814,12 +814,16 @@ static int vf610_nfc_suspend(struct device *dev)
 
 static int vf610_nfc_resume(struct device *dev)
 {
+	int err;
+
 	struct mtd_info *mtd = dev_get_drvdata(dev);
 	struct vf610_nfc *nfc = mtd_to_nfc(mtd);
 
 	pinctrl_pm_select_default_state(dev);
 
-	clk_prepare_enable(nfc->clk);
+	err = clk_prepare_enable(nfc->clk);
+	if (err)
+		return err;
 
 	vf610_nfc_preinit_controller(nfc);
 	vf610_nfc_init_controller(nfc);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 15 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

clk_prepare_enable() may fail, so we should better check its return value and propagate it in the case of error.

---
 drivers/mtd/nand/vf610_nfc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/mtd/nand/vf610_nfc.c +0 -0
index 744ab10..9e49672 100644

drivers/mtd/nand/vf610_nfc.c static int vf610_nfc_suspend(struct device *dev) · line 822

Quoted 9 lines
drivers/mtd/nand/vf610_nfc.c +2 -0
@@ -814,12 +814,16 @@ static int vf610_nfc_suspend(struct device *dev)
 
 static int vf610_nfc_resume(struct device *dev)
 {
+	int err;
+
 	struct mtd_info *mtd = dev_get_drvdata(dev);
 	struct vf610_nfc *nfc = mtd_to_nfc(mtd);
 
 	pinctrl_pm_select_default_state(dev);

AFAICT pinctrl_pm_select_default_state() can also fail. What makes it different from clk_prepare_enable() failures?

drivers/mtd/nand/vf610_nfc.c static int vf610_nfc_suspend(struct device *dev) · line 827

Quoted 6 lines
drivers/mtd/nand/vf610_nfc.c +3 -1
-	clk_prepare_enable(nfc->clk);
+	err = clk_prepare_enable(nfc->clk);
+	if (err)
+		return err;
 

I guess the idea was that clk_prepare_enabled already succeeded at probe time and there was not real reason for it to fail at resume time. But extra checks are never bad. BTW, I don't remember what happens if ->resume() returns an error. Does it prevent the whole system from resuming or just make this specific device unusable?

Quoted 2 lines
drivers/mtd/nand/vf610_nfc.c +0 -0
 	vf610_nfc_preinit_controller(nfc);
 	vf610_nfc_init_controller(nfc);
#2 lore raw
Quoted 32 lines · Boris Brezillon
Quoted 15 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

clk_prepare_enable() may fail, so we should better check its return value and propagate it in the case of error.

---
 drivers/mtd/nand/vf610_nfc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/mtd/nand/vf610_nfc.c +0 -0
index 744ab10..9e49672 100644

drivers/mtd/nand/vf610_nfc.c static int vf610_nfc_suspend(struct device *dev) · line 822

Quoted 9 lines
drivers/mtd/nand/vf610_nfc.c +2 -0
@@ -814,12 +814,16 @@ static int vf610_nfc_suspend(struct device *dev)
 
 static int vf610_nfc_resume(struct device *dev)
 {
+	int err;
+
 	struct mtd_info *mtd = dev_get_drvdata(dev);
 	struct vf610_nfc *nfc = mtd_to_nfc(mtd);
 
 	pinctrl_pm_select_default_state(dev);  

AFAICT pinctrl_pm_select_default_state() can also fail. What makes it different from clk_prepare_enable() failures?

Quoted 1 line
Quoted 11 lines

drivers/mtd/nand/vf610_nfc.c static int vf610_nfc_suspend(struct device *dev) · line 826

Quoted 5 lines
drivers/mtd/nand/vf610_nfc.c +3 -1
-	clk_prepare_enable(nfc->clk);
+	err = clk_prepare_enable(nfc->clk);
+	if (err)
+		return err;

I guess the idea was that clk_prepare_enabled already succeeded at probe time and there was not real reason for it to fail at resume time. But extra checks are never bad. BTW, I don't remember what happens if ->resume() returns an error. Does it prevent the whole system from resuming or just make this specific device unusable?

Just found the answer [1]: it's harmless.

[1]http://elixir.free-electrons.com/linux/latest/source/include/linux/pm.h#L262

#3 lore raw
In reply to Boris Brezillon

Hi Boris,

Quoted 2 lines · Boris Brezillon

AFAICT pinctrl_pm_select_default_state() can also fail. What makes it different from clk_prepare_enable() failures?

IMHO we could even remove pinctrl_pm_select_default_state() from this driver since pinctrl_pm_select_sleep_state() is never used.

This is the only driver that uses pinctrl_pm_select_default_state() inside drivers/mtd/.