diff mbox series

[3/3] gpio: zynq: Check return value of irq_get_irq_data

Message ID 20210409140806.31824-4-srinivas.neeli@xilinx.com
State New
Headers show
Series gpio: zynq: Update on gpio zynq driver | expand

Commit Message

Srinivas Neeli April 9, 2021, 2:08 p.m. UTC
In two different instances the return value of "irq_get_irq_data"
API was neither captured nor checked.
Fixed it by capturing the return value and then checking for any error.

Addresses-Coverity: "returned_null"
Signed-off-by: Srinivas Neeli <srinivas.neeli@xilinx.com>
---
 drivers/gpio/gpio-zynq.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Deepak R Varma April 17, 2021, 6:02 p.m. UTC | #1
On Fri, Apr 09, 2021 at 07:38:06PM +0530, Srinivas Neeli wrote:
> In two different instances the return value of "irq_get_irq_data"
> API was neither captured nor checked.
> Fixed it by capturing the return value and then checking for any error.
> 
> Addresses-Coverity: "returned_null"
> Signed-off-by: Srinivas Neeli <srinivas.neeli@xilinx.com>
> ---
>  drivers/gpio/gpio-zynq.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/gpio/gpio-zynq.c b/drivers/gpio/gpio-zynq.c
> index c91302a16c77..f0cb8ccd03ed 100644
> --- a/drivers/gpio/gpio-zynq.c
> +++ b/drivers/gpio/gpio-zynq.c
> @@ -736,6 +736,11 @@ static int __maybe_unused zynq_gpio_suspend(struct device *dev)
>  	struct zynq_gpio *gpio = dev_get_drvdata(dev);
>  	struct irq_data *data = irq_get_irq_data(gpio->irq);
>  
> +	if (!data) {
> +		dev_err(dev, "irq_get_irq_data() failed\n");

It will be useful to include a tag such as "suspend: " in the error
message to uniquely identify where it failed from.

> +		return -EINVAL;
> +	}
> +
>  	if (!device_may_wakeup(dev))
>  		disable_irq(gpio->irq);
>  
> @@ -753,6 +758,11 @@ static int __maybe_unused zynq_gpio_resume(struct device *dev)
>  	struct irq_data *data = irq_get_irq_data(gpio->irq);
>  	int ret;
>  
> +	if (!data) {
> +		dev_err(dev, "irq_get_irq_data() failed\n");

Ditto. Suggest using "resume: " tag here.

> +		return -EINVAL;
> +	}
> +
>  	if (!device_may_wakeup(dev))
>  		enable_irq(gpio->irq);
>  
> -- 
> 2.9.1
>
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-zynq.c b/drivers/gpio/gpio-zynq.c
index c91302a16c77..f0cb8ccd03ed 100644
--- a/drivers/gpio/gpio-zynq.c
+++ b/drivers/gpio/gpio-zynq.c
@@ -736,6 +736,11 @@  static int __maybe_unused zynq_gpio_suspend(struct device *dev)
 	struct zynq_gpio *gpio = dev_get_drvdata(dev);
 	struct irq_data *data = irq_get_irq_data(gpio->irq);
 
+	if (!data) {
+		dev_err(dev, "irq_get_irq_data() failed\n");
+		return -EINVAL;
+	}
+
 	if (!device_may_wakeup(dev))
 		disable_irq(gpio->irq);
 
@@ -753,6 +758,11 @@  static int __maybe_unused zynq_gpio_resume(struct device *dev)
 	struct irq_data *data = irq_get_irq_data(gpio->irq);
 	int ret;
 
+	if (!data) {
+		dev_err(dev, "irq_get_irq_data() failed\n");
+		return -EINVAL;
+	}
+
 	if (!device_may_wakeup(dev))
 		enable_irq(gpio->irq);