diff mbox series

[v2,1/4] gpio: pca953x: avoid to use uninitialized value pinctrl

Message ID 20221210220601.77648-1-andriy.shevchenko@linux.intel.com
State New
Headers show
Series [v2,1/4] gpio: pca953x: avoid to use uninitialized value pinctrl | expand

Commit Message

Andy Shevchenko Dec. 10, 2022, 10:05 p.m. UTC
From: Haibo Chen <haibo.chen@nxp.com>

There is a variable pinctrl declared without initializer. And then
has the case (switch operation chose the default case) to directly
use this uninitialized value, this is not a safe behavior. So here
initialize the pinctrl as 0 to avoid this issue.
This is reported by Coverity.

Fixes: 13c5d4ce8060 ("gpio: pca953x: Add support for PCAL6534")
Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: used default case (Andy)
 drivers/gpio/gpio-pca953x.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Andy Shevchenko Dec. 30, 2022, 12:04 p.m. UTC | #1
On Sun, Dec 11, 2022 at 12:05:58AM +0200, Andy Shevchenko wrote:
> From: Haibo Chen <haibo.chen@nxp.com>
> 
> There is a variable pinctrl declared without initializer. And then
> has the case (switch operation chose the default case) to directly
> use this uninitialized value, this is not a safe behavior. So here
> initialize the pinctrl as 0 to avoid this issue.
> This is reported by Coverity.

Bart, any comments on the series?
Bartosz Golaszewski Dec. 30, 2022, 12:48 p.m. UTC | #2
On Fri, Dec 30, 2022 at 1:04 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Sun, Dec 11, 2022 at 12:05:58AM +0200, Andy Shevchenko wrote:
> > From: Haibo Chen <haibo.chen@nxp.com>
> >
> > There is a variable pinctrl declared without initializer. And then
> > has the case (switch operation chose the default case) to directly
> > use this uninitialized value, this is not a safe behavior. So here
> > initialize the pinctrl as 0 to avoid this issue.
> > This is reported by Coverity.
>
> Bart, any comments on the series?
>

Now applied. I just got back from Christmas break, give me a moment. :)

Bart
Andy Shevchenko Dec. 30, 2022, 9:36 p.m. UTC | #3
On Fri, Dec 30, 2022 at 01:48:20PM +0100, Bartosz Golaszewski wrote:
> On Fri, Dec 30, 2022 at 1:04 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Sun, Dec 11, 2022 at 12:05:58AM +0200, Andy Shevchenko wrote:
> > > From: Haibo Chen <haibo.chen@nxp.com>
> > >
> > > There is a variable pinctrl declared without initializer. And then
> > > has the case (switch operation chose the default case) to directly
> > > use this uninitialized value, this is not a safe behavior. So here
> > > initialize the pinctrl as 0 to avoid this issue.
> > > This is reported by Coverity.
> >
> > Bart, any comments on the series?
> 
> Now applied. I just got back from Christmas break, give me a moment. :)

Sure and thank you! Merry xmas!
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index a59d61cd44b2..5299e5bb76d6 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -474,6 +474,9 @@  static u8 pcal6534_recalc_addr(struct pca953x_chip *chip, int reg, int off)
 	case PCAL6524_DEBOUNCE:
 		pinctrl = ((reg & PCAL_PINCTRL_MASK) >> 1) + 0x1c;
 		break;
+	default:
+		pinctrl = 0;
+		break;
 	}
 
 	return pinctrl + addr + (off / BANK_SZ);