diff mbox series

PCI: mvebu: Check if reset gpio is defined

Message ID 20200724132930.7206-1-pali@kernel.org
State New
Headers show
Series PCI: mvebu: Check if reset gpio is defined | expand

Commit Message

Pali Rohár July 24, 2020, 1:29 p.m. UTC
Reset gpio is optional and it does not have to be defined for all boards.

So in mvebu_pcie_powerdown() like in mvebu_pcie_powerup() check that reset
gpio is defined prior usage to prevent NULL pointer dereference.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 drivers/pci/controller/pci-mvebu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Pali Rohár Aug. 10, 2020, 3:03 p.m. UTC | #1
On Friday 24 July 2020 15:29:30 Pali Rohár wrote:
> Reset gpio is optional and it does not have to be defined for all boards.
> 
> So in mvebu_pcie_powerdown() like in mvebu_pcie_powerup() check that reset
> gpio is defined prior usage to prevent NULL pointer dereference.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> ---
>  drivers/pci/controller/pci-mvebu.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c
> index 153a64676bc9..58607cbe84c8 100644
> --- a/drivers/pci/controller/pci-mvebu.c
> +++ b/drivers/pci/controller/pci-mvebu.c
> @@ -947,7 +947,8 @@ static int mvebu_pcie_powerup(struct mvebu_pcie_port *port)
>   */
>  static void mvebu_pcie_powerdown(struct mvebu_pcie_port *port)
>  {
> -	gpiod_set_value_cansleep(port->reset_gpio, 1);
> +	if (port->reset_gpio)
> +		gpiod_set_value_cansleep(port->reset_gpio, 1);

Please drop this patch. I have realized that gpiod_set_value_cansleep()
calls VALIDATE_DESC_VOID() macro which returns from current running
function if passed pointer is NULL. So this patch is not needed as
gpiod_set_value_cansleep() may be called with NULL pointer.

>  
>  	clk_disable_unprepare(port->clk);
>  }
> -- 
> 2.20.1
>
diff mbox series

Patch

diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c
index 153a64676bc9..58607cbe84c8 100644
--- a/drivers/pci/controller/pci-mvebu.c
+++ b/drivers/pci/controller/pci-mvebu.c
@@ -947,7 +947,8 @@  static int mvebu_pcie_powerup(struct mvebu_pcie_port *port)
  */
 static void mvebu_pcie_powerdown(struct mvebu_pcie_port *port)
 {
-	gpiod_set_value_cansleep(port->reset_gpio, 1);
+	if (port->reset_gpio)
+		gpiod_set_value_cansleep(port->reset_gpio, 1);
 
 	clk_disable_unprepare(port->clk);
 }