PCI: amlogic: The check for devm_add_action_or_reset's return value added
Subsystems (4)
PATCH 1/1 PCI: amlogic: The check for devm_add_action_or_reset's return value added
The return value of the function devm_add_action_or_reset() was not checked hence an error code would not be returned.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/pci/controller/dwc/pci-meson.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pci-meson.c +5 -1
@@ -187,9 +187,13 @@ static inline struct clk *meson_pcie_probe_clock(struct device *dev,return ERR_PTR (ret); } -devm_add_action_or_reset (dev, + ret =devm_add_action_or_reset (dev, (void (*) (void *))clk_disable_unprepare, clk); +if (ret) { +dev_err (dev,"couldn't reset clk\n" ); +return ERR_PTR (ret); + }return clk; }
Signature · 7 lines
2.25.1 _______________________________________________ linux-amlogic mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-amlogic
Hi Aleksandr,
Thanks for the patch!
Quoted 2 lines · Aleksandr Burakov
The return value of the function
devm_add_action_or_reset()was not checked hence an error code would not be returned.
You can save Lorenzo and Krzysztof some work by:
- Rewording the subject line in the typical "<verb> <object>" imperative form, e.g., "Check for devm_add_action_or_reset() failure"
- Rewording the commit log similarly. Note that the existing commit only describes the current situation and doesn't actually say what the patch does.
Here's a good guide to commit logs: https://cbea.ms/git-commit/
Quoted 28 lines
Fixes 9c0ef6d34fdb ("PCI: amlogic: Add the Amlogic Meson PCIe controller driver")Signed-off-by Aleksandr Burakov <[email protected]>--- drivers/pci/controller/dwc/pci-meson.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/pci/controller/dwc/pci-meson.c +5
-1@@ -187,9 +187,13 @@ static inline struct clk *meson_pcie_probe_clock(struct device *dev,return ERR_PTR (ret); } -devm_add_action_or_reset (dev, + ret =devm_add_action_or_reset (dev, (void (*) (void *))clk_disable_unprepare, clk); +if (ret) { +dev_err (dev,"couldn't reset clk\n" ); +return ERR_PTR (ret); + }return clk; }Signature · 1 line
2.25.1
Le 20/12/2022 à 10:21, Aleksandr Burakov a écrit :
Quoted 16 lines
The return value of the function
devm_add_action_or_reset()was not checked hence an error code would not be returned.Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes 9c0ef6d34fdb ("PCI: amlogic: Add the Amlogic Meson PCIe controller driver")Signed-off-by Aleksandr Burakov <[email protected]>--- drivers/pci/controller/dwc/pci-meson.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/pci/controller/dwc/pci-meson.c +0
-0
drivers/pci/controller/dwc/pci-meson.c static inline struct clk *meson_pcie_probe_clock(struct device *dev, · line 191
Quoted 6 lines
drivers/pci/controller/dwc/pci-meson.c +1
-1@@ -187,9 +187,13 @@ static inline struct clk *meson_pcie_probe_clock(struct device *dev,return ERR_PTR (ret); } - devm_add_action_or_reset(dev, + ret = devm_add_action_or_reset(dev, (void (*) (void *))clk_disable_unprepare,
Hi,
using devm_clk_get_enabled() a few lines above would be IMHO much more elegant than these casts.
This also saves a few LoC and avoid some other warnings/issues. (see [1])
Such an approach has already been used in [2].
Just my 2c,
CJ
[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/
Quoted 8 lines
drivers/pci/controller/dwc/pci-meson.c +4
-0clk); +if (ret) { +dev_err (dev,"couldn't reset clk\n" ); +return ERR_PTR (ret); + }return clk; }