linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: amlogic: The check for devm_add_action_or_reset's return value added
@ 2022-12-20  9:21 Aleksandr Burakov
  2022-12-29 19:43 ` Bjorn Helgaas
  2022-12-29 21:43 ` Christophe JAILLET
  0 siblings, 2 replies; 3+ messages in thread
From: Aleksandr Burakov @ 2022-12-20  9:21 UTC (permalink / raw)
  To: Yue Wang, Hanjie Lin, Lorenzo Pieralisi, Rob Herring,
	Krzysztof Wilczyński, Bjorn Helgaas, Neil Armstrong,
	Kevin Hilman, Jerome Brunet, Martin Blumenstingl
  Cc: Aleksandr Burakov, linux-pci, linux-amlogic, linux-kernel,
	lvc-project

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 <a.burakov@rosalinux.ru>
---
 drivers/pci/controller/dwc/pci-meson.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/controller/dwc/pci-meson.c b/drivers/pci/controller/dwc/pci-meson.c
index c1527693bed9..3d82f0b65480 100644
--- a/drivers/pci/controller/dwc/pci-meson.c
+++ b/drivers/pci/controller/dwc/pci-meson.c
@@ -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;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: amlogic: The check for devm_add_action_or_reset's return value added
  2022-12-20  9:21 [PATCH] PCI: amlogic: The check for devm_add_action_or_reset's return value added Aleksandr Burakov
@ 2022-12-29 19:43 ` Bjorn Helgaas
  2022-12-29 21:43 ` Christophe JAILLET
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2022-12-29 19:43 UTC (permalink / raw)
  To: Aleksandr Burakov
  Cc: Yue Wang, Hanjie Lin, Lorenzo Pieralisi, Rob Herring,
	Krzysztof Wilczyński, Bjorn Helgaas, Neil Armstrong,
	Kevin Hilman, Jerome Brunet, Martin Blumenstingl, linux-pci,
	linux-amlogic, linux-kernel, lvc-project

Hi Aleksandr,

Thanks for the patch!

On Tue, Dec 20, 2022 at 12:21:37PM +0300, Aleksandr Burakov wrote:
> 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/

> Fixes: 9c0ef6d34fdb ("PCI: amlogic: Add the Amlogic Meson PCIe controller driver")
> Signed-off-by: Aleksandr Burakov <a.burakov@rosalinux.ru>
> ---
>  drivers/pci/controller/dwc/pci-meson.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/controller/dwc/pci-meson.c b/drivers/pci/controller/dwc/pci-meson.c
> index c1527693bed9..3d82f0b65480 100644
> --- a/drivers/pci/controller/dwc/pci-meson.c
> +++ b/drivers/pci/controller/dwc/pci-meson.c
> @@ -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;
>  }
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PCI: amlogic: The check for devm_add_action_or_reset's return value added
  2022-12-20  9:21 [PATCH] PCI: amlogic: The check for devm_add_action_or_reset's return value added Aleksandr Burakov
  2022-12-29 19:43 ` Bjorn Helgaas
@ 2022-12-29 21:43 ` Christophe JAILLET
  1 sibling, 0 replies; 3+ messages in thread
From: Christophe JAILLET @ 2022-12-29 21:43 UTC (permalink / raw)
  To: Aleksandr Burakov
  Cc: linux-pci, linux-amlogic, linux-kernel, lvc-project, Yue Wang,
	Hanjie Lin, Lorenzo Pieralisi, Rob Herring,
	Krzysztof Wilczyński, Bjorn Helgaas, Neil Armstrong,
	Kevin Hilman, Jerome Brunet, Martin Blumenstingl

Le 20/12/2022 à 10:21, Aleksandr Burakov a écrit :
> 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 <a.burakov@rosalinux.ru>
> ---
>   drivers/pci/controller/dwc/pci-meson.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/controller/dwc/pci-meson.c b/drivers/pci/controller/dwc/pci-meson.c
> index c1527693bed9..3d82f0b65480 100644
> --- a/drivers/pci/controller/dwc/pci-meson.c
> +++ b/drivers/pci/controller/dwc/pci-meson.c
> @@ -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/20221118233101.never.215-kees@kernel.org/
[2]: https://lore.kernel.org/all/20221202184525.gonna.423-kees@kernel.org/

>   				 clk);
> +	if (ret) {
> +		dev_err(dev, "couldn't reset clk\n");
> +		return ERR_PTR(ret);
> +	}
>   
>   	return clk;
>   }


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-29 21:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-20  9:21 [PATCH] PCI: amlogic: The check for devm_add_action_or_reset's return value added Aleksandr Burakov
2022-12-29 19:43 ` Bjorn Helgaas
2022-12-29 21:43 ` Christophe JAILLET

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).