gpio: pca953x: initialize ret to zero to avoid returning garbage
diff mbox

Message ID 20160909083154.26442-1-colin.king@canonical.com
State New
Headers show

Commit Message

Colin Ian King Sept. 9, 2016, 8:31 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

ret is not initialized so it contains garbage.  Ensure garbage
is not returned in the case that pdata && pdata->teardown is false
by initializing ret to 0.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/gpio/gpio-pca953x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Linus Walleij Sept. 12, 2016, 1:40 p.m. UTC | #1
On Fri, Sep 9, 2016 at 10:31 AM, Colin King <colin.king@canonical.com> wrote:

> From: Colin Ian King <colin.king@canonical.com>
>
> ret is not initialized so it contains garbage.  Ensure garbage
> is not returned in the case that pdata && pdata->teardown is false
> by initializing ret to 0.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Patch applied.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Phil Reid Sept. 13, 2016, 4:04 a.m. UTC | #2
On 12/09/2016 21:40, Linus Walleij wrote:
> On Fri, Sep 9, 2016 at 10:31 AM, Colin King <colin.king@canonical.com> wrote:
>
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> ret is not initialized so it contains garbage.  Ensure garbage
>> is not returned in the case that pdata && pdata->teardown is false
>> by initializing ret to 0.
>>
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>
> Patch applied.
G'day Linus,


I believe this does the same as Arnd Bergmanns patch from 26 Aug.
[PATCH 1/5] gpio: pca954x: fix undefined error code from remove

IMO Colin's is the cleaner solution.
Arnd's could be removed.
Linus Walleij Sept. 13, 2016, 11:49 a.m. UTC | #3
On Tue, Sep 13, 2016 at 6:04 AM, Phil Reid <preid@electromag.com.au> wrote:
> On 12/09/2016 21:40, Linus Walleij wrote:
>>
>> On Fri, Sep 9, 2016 at 10:31 AM, Colin King <colin.king@canonical.com>
>> wrote:
>>
>>> From: Colin Ian King <colin.king@canonical.com>
>>>
>>> ret is not initialized so it contains garbage.  Ensure garbage
>>> is not returned in the case that pdata && pdata->teardown is false
>>> by initializing ret to 0.
>>>
>>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>>
>>
>> Patch applied.
>
> G'day Linus,
>
>
> I believe this does the same as Arnd Bergmanns patch from 26 Aug.
> [PATCH 1/5] gpio: pca954x: fix undefined error code from remove
>
> IMO Colin's is the cleaner solution.
> Arnd's could be removed.

OK you're right. I reverted Arnd's patch.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Arnd Bergmann Sept. 13, 2016, 12:31 p.m. UTC | #4
On Tuesday, September 13, 2016 12:04:00 PM CEST Phil Reid wrote:
> On 12/09/2016 21:40, Linus Walleij wrote:
> > On Fri, Sep 9, 2016 at 10:31 AM, Colin King <colin.king@canonical.com> wrote:
> >
> >> From: Colin Ian King <colin.king@canonical.com>
> >>
> >> ret is not initialized so it contains garbage.  Ensure garbage
> >> is not returned in the case that pdata && pdata->teardown is false
> >> by initializing ret to 0.
> >>
> >> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> >
> > Patch applied.
> G'day Linus,
> 
> 
> I believe this does the same as Arnd Bergmanns patch from 26 Aug.
> [PATCH 1/5] gpio: pca954x: fix undefined error code from remove
> 
> IMO Colin's is the cleaner solution.
> Arnd's could be removed.
> 

Please try to avoid adding initializations in the local variable
declaration, they just hide otherwise useful warnings when
you get a function that actually does something incorrect
in some code paths.

See also https://rusty.ozlabs.org/?p=232

	Arnd

--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Colin Ian King Sept. 13, 2016, 12:45 p.m. UTC | #5
On 13/09/16 13:46, Linus Walleij wrote:
> On Tue, Sep 13, 2016 at 2:31 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> 
>> Please try to avoid adding initializations in the local variable
>> declaration, they just hide otherwise useful warnings when
>> you get a function that actually does something incorrect
>> in some code paths.
> 
> Agreed, sorry for my ignorance :(
> 
> I duly corrected the git and reverted the other patch instead of yours.
> 
> Yours,
> Linus Walleij
> 
Makes sense. Thanks Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij Sept. 13, 2016, 12:46 p.m. UTC | #6
On Tue, Sep 13, 2016 at 2:31 PM, Arnd Bergmann <arnd@arndb.de> wrote:

> Please try to avoid adding initializations in the local variable
> declaration, they just hide otherwise useful warnings when
> you get a function that actually does something incorrect
> in some code paths.

Agreed, sorry for my ignorance :(

I duly corrected the git and reverted the other patch instead of yours.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index cbe2824..52f3d5c 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -845,7 +845,7 @@  static int pca953x_remove(struct i2c_client *client)
 {
 	struct pca953x_platform_data *pdata = dev_get_platdata(&client->dev);
 	struct pca953x_chip *chip = i2c_get_clientdata(client);
-	int ret;
+	int ret = 0;
 
 	if (pdata && pdata->teardown) {
 		ret = pdata->teardown(client, chip->gpio_chip.base,