* [PATCH v2 1/4] gpio: pca953x: avoid to use uninitialized value pinctrl
@ 2022-12-10 22:05 Andy Shevchenko
2022-12-10 22:05 ` [PATCH v2 2/4] gpio: pca953x: avoid logically dead code Andy Shevchenko
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-12-10 22:05 UTC (permalink / raw)
To: Bartosz Golaszewski, linux-gpio, linux-kernel
Cc: Linus Walleij, Bartosz Golaszewski, Haibo Chen, Andy Shevchenko
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(+)
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);
--
2.35.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/4] gpio: pca953x: avoid logically dead code
2022-12-10 22:05 [PATCH v2 1/4] gpio: pca953x: avoid to use uninitialized value pinctrl Andy Shevchenko
@ 2022-12-10 22:05 ` Andy Shevchenko
2022-12-10 22:06 ` [PATCH v2 3/4] gpio: pca953x: Clean up pcal6534_check_register() Andy Shevchenko
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-12-10 22:05 UTC (permalink / raw)
To: Bartosz Golaszewski, linux-gpio, linux-kernel
Cc: Linus Walleij, Bartosz Golaszewski, Haibo Chen, Andy Shevchenko
From: Haibo Chen <haibo.chen@nxp.com>
The current code logic make the condition "else if (reg >= 0x54)"
can't be true, cause the dead code. So fix it to match the coder
expectation. 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: shuffled code to check bigger value first (Andy)
drivers/gpio/gpio-pca953x.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 5299e5bb76d6..2c8586b3191f 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -309,26 +309,26 @@ static bool pcal6534_check_register(struct pca953x_chip *chip, unsigned int reg,
int bank;
int offset;
- if (reg >= 0x30) {
+ if (reg >= 0x54) {
/*
- * Reserved block between 14h and 2Fh does not align on
- * expected bank boundaries like other devices.
+ * Handle lack of reserved registers after output port
+ * configuration register to form a bank.
*/
- int temp = reg - 0x30;
+ int temp = reg - 0x54;
bank = temp / NBANK(chip);
offset = temp - (bank * NBANK(chip));
- bank += 8;
- } else if (reg >= 0x54) {
+ bank += 16;
+ } else if (reg >= 0x30) {
/*
- * Handle lack of reserved registers after output port
- * configuration register to form a bank.
+ * Reserved block between 14h and 2Fh does not align on
+ * expected bank boundaries like other devices.
*/
- int temp = reg - 0x54;
+ int temp = reg - 0x30;
bank = temp / NBANK(chip);
offset = temp - (bank * NBANK(chip));
- bank += 16;
+ bank += 8;
} else {
bank = reg / NBANK(chip);
offset = reg - (bank * NBANK(chip));
--
2.35.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 3/4] gpio: pca953x: Clean up pcal6534_check_register()
2022-12-10 22:05 [PATCH v2 1/4] gpio: pca953x: avoid to use uninitialized value pinctrl Andy Shevchenko
2022-12-10 22:05 ` [PATCH v2 2/4] gpio: pca953x: avoid logically dead code Andy Shevchenko
@ 2022-12-10 22:06 ` Andy Shevchenko
2022-12-10 22:06 ` [PATCH v2 4/4] gpio: pca953x: Remove unused PCAL953X_OUT_CONF from pcal6534_recalc_addr() Andy Shevchenko
2022-12-30 12:04 ` [PATCH v2 1/4] gpio: pca953x: avoid to use uninitialized value pinctrl Andy Shevchenko
3 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-12-10 22:06 UTC (permalink / raw)
To: Bartosz Golaszewski, linux-gpio, linux-kernel
Cc: Linus Walleij, Bartosz Golaszewski, Andy Shevchenko
The pcal6534_check_register() is a bit too verbose.
Clean up it, by deduplicating some operations and
switching to the modulo operation as on some architectures
/ and % can become a single assembly instruction.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: new patch
drivers/gpio/gpio-pca953x.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 2c8586b3191f..8aba8df393bd 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -306,6 +306,7 @@ static bool pca953x_check_register(struct pca953x_chip *chip, unsigned int reg,
static bool pcal6534_check_register(struct pca953x_chip *chip, unsigned int reg,
u32 checkbank)
{
+ int bank_shift;
int bank;
int offset;
@@ -314,26 +315,22 @@ static bool pcal6534_check_register(struct pca953x_chip *chip, unsigned int reg,
* Handle lack of reserved registers after output port
* configuration register to form a bank.
*/
- int temp = reg - 0x54;
-
- bank = temp / NBANK(chip);
- offset = temp - (bank * NBANK(chip));
- bank += 16;
+ reg -= 0x54;
+ bank_shift = 16;
} else if (reg >= 0x30) {
/*
* Reserved block between 14h and 2Fh does not align on
* expected bank boundaries like other devices.
*/
- int temp = reg - 0x30;
-
- bank = temp / NBANK(chip);
- offset = temp - (bank * NBANK(chip));
- bank += 8;
+ reg -= 0x30;
+ bank_shift = 8;
} else {
- bank = reg / NBANK(chip);
- offset = reg - (bank * NBANK(chip));
+ bank_shift = 0;
}
+ bank = bank_shift + reg / NBANK(chip);
+ offset = reg % NBANK(chip);
+
/* Register is not in the matching bank. */
if (!(BIT(bank) & checkbank))
return false;
--
2.35.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 4/4] gpio: pca953x: Remove unused PCAL953X_OUT_CONF from pcal6534_recalc_addr()
2022-12-10 22:05 [PATCH v2 1/4] gpio: pca953x: avoid to use uninitialized value pinctrl Andy Shevchenko
2022-12-10 22:05 ` [PATCH v2 2/4] gpio: pca953x: avoid logically dead code Andy Shevchenko
2022-12-10 22:06 ` [PATCH v2 3/4] gpio: pca953x: Clean up pcal6534_check_register() Andy Shevchenko
@ 2022-12-10 22:06 ` Andy Shevchenko
2022-12-30 12:04 ` [PATCH v2 1/4] gpio: pca953x: avoid to use uninitialized value pinctrl Andy Shevchenko
3 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-12-10 22:06 UTC (permalink / raw)
To: Bartosz Golaszewski, linux-gpio, linux-kernel
Cc: Linus Walleij, Bartosz Golaszewski, Andy Shevchenko
First of all, PCAL953X_OUT_CONF is not used in the driver.
Second, it's not a per-bank register, it's a single for the
chip and should be handled differently anyway.
To avoid confusion, drop PCAL953X_OUT_CONF from pcal6534_recalc_addr().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: new patch
drivers/gpio/gpio-pca953x.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 8aba8df393bd..1286b22ef23a 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -461,7 +461,6 @@ static u8 pcal6534_recalc_addr(struct pca953x_chip *chip, int reg, int off)
case PCAL953X_PULL_SEL:
case PCAL953X_INT_MASK:
case PCAL953X_INT_STAT:
- case PCAL953X_OUT_CONF:
pinctrl = ((reg & PCAL_PINCTRL_MASK) >> 1) + 0x20;
break;
case PCAL6524_INT_EDGE:
--
2.35.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/4] gpio: pca953x: avoid to use uninitialized value pinctrl
2022-12-10 22:05 [PATCH v2 1/4] gpio: pca953x: avoid to use uninitialized value pinctrl Andy Shevchenko
` (2 preceding siblings ...)
2022-12-10 22:06 ` [PATCH v2 4/4] gpio: pca953x: Remove unused PCAL953X_OUT_CONF from pcal6534_recalc_addr() Andy Shevchenko
@ 2022-12-30 12:04 ` Andy Shevchenko
2022-12-30 12:48 ` Bartosz Golaszewski
3 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2022-12-30 12:04 UTC (permalink / raw)
To: Bartosz Golaszewski, linux-gpio, linux-kernel
Cc: Linus Walleij, Bartosz Golaszewski, Haibo Chen
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?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/4] gpio: pca953x: avoid to use uninitialized value pinctrl
2022-12-30 12:04 ` [PATCH v2 1/4] gpio: pca953x: avoid to use uninitialized value pinctrl Andy Shevchenko
@ 2022-12-30 12:48 ` Bartosz Golaszewski
2022-12-30 21:36 ` Andy Shevchenko
0 siblings, 1 reply; 7+ messages in thread
From: Bartosz Golaszewski @ 2022-12-30 12:48 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Bartosz Golaszewski, linux-gpio, linux-kernel, Linus Walleij,
Haibo Chen
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/4] gpio: pca953x: avoid to use uninitialized value pinctrl
2022-12-30 12:48 ` Bartosz Golaszewski
@ 2022-12-30 21:36 ` Andy Shevchenko
0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2022-12-30 21:36 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Bartosz Golaszewski, linux-gpio, linux-kernel, Linus Walleij,
Haibo Chen
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!
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-12-30 21:36 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-10 22:05 [PATCH v2 1/4] gpio: pca953x: avoid to use uninitialized value pinctrl Andy Shevchenko
2022-12-10 22:05 ` [PATCH v2 2/4] gpio: pca953x: avoid logically dead code Andy Shevchenko
2022-12-10 22:06 ` [PATCH v2 3/4] gpio: pca953x: Clean up pcal6534_check_register() Andy Shevchenko
2022-12-10 22:06 ` [PATCH v2 4/4] gpio: pca953x: Remove unused PCAL953X_OUT_CONF from pcal6534_recalc_addr() Andy Shevchenko
2022-12-30 12:04 ` [PATCH v2 1/4] gpio: pca953x: avoid to use uninitialized value pinctrl Andy Shevchenko
2022-12-30 12:48 ` Bartosz Golaszewski
2022-12-30 21:36 ` Andy Shevchenko
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).