2014-11-11 12:21:47

by Octavian Purdila

[permalink] [raw]
Subject: [PATCH 0/2] fixes for ib-mfd-gpio-i2c-3.19

Hi Lee,

A couple of patches that fixes a coccinelle warning found by Julia and
kbuild test robot. They are not critical and I don't know if they must
be pull through ib-mfd-gpio-i2c-3.19, please let me know if I need to
submit them elsewhere.

Thanks,
Tavi


Octavian Purdila (2):
mfd: dln2: fix _dln2_transfer return code
i2c: dln2: simplify return flow for dln2_i2c_enable

drivers/i2c/busses/i2c-dln2.c | 7 +------
drivers/mfd/dln2.c | 3 ++-
2 files changed, 3 insertions(+), 7 deletions(-)

--
1.9.1


2014-11-11 12:21:48

by Octavian Purdila

[permalink] [raw]
Subject: [PATCH 2/2] i2c: dln2: simplify return flow for dln2_i2c_enable

This fixes the following kbuild test robot warning:

>> drivers/i2c/busses/i2c-dln2.c:70:1-4: WARNING: end returns can be simplified if negative or 0 value

Reported-by: kbuild test robot <[email protected]>
Reported-by: Julia Lawall <[email protected]>

Signed-off-by: Octavian Purdila <[email protected]>
---
drivers/i2c/busses/i2c-dln2.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-dln2.c b/drivers/i2c/busses/i2c-dln2.c
index 010a5fa..b3fb86a 100644
--- a/drivers/i2c/busses/i2c-dln2.c
+++ b/drivers/i2c/busses/i2c-dln2.c
@@ -54,7 +54,6 @@ struct dln2_i2c {

static int dln2_i2c_enable(struct dln2_i2c *dln2, bool enable)
{
- int ret;
u16 cmd;
struct {
u8 port;
@@ -67,11 +66,7 @@ static int dln2_i2c_enable(struct dln2_i2c *dln2, bool enable)
else
cmd = DLN2_I2C_DISABLE;

- ret = dln2_transfer_tx(dln2->pdev, cmd, &tx, sizeof(tx));
- if (ret < 0)
- return ret;
-
- return 0;
+ return dln2_transfer_tx(dln2->pdev, cmd, &tx, sizeof(tx));
}

static int dln2_i2c_write(struct dln2_i2c *dln2, u8 addr,
--
1.9.1

2014-11-11 12:22:19

by Octavian Purdila

[permalink] [raw]
Subject: [PATCH 1/2] mfd: dln2: fix _dln2_transfer return code

If wait_for_completion_interruptible_timeout returns a positive value
it may be propagated as the return value of _dln2_transfer. This
contradicts the documentation of the function and exposes unnecessary
internals to the callers.

This patch makes sure to set the return value to 0 in that case.

Reported-by: Julia Lawall <[email protected]>
Signed-off-by: Octavian Purdila <[email protected]>
---
drivers/mfd/dln2.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/dln2.c b/drivers/mfd/dln2.c
index 9765a17..f0747a1 100644
--- a/drivers/mfd/dln2.c
+++ b/drivers/mfd/dln2.c
@@ -462,7 +462,8 @@ static int _dln2_transfer(struct dln2_dev *dln2, u16 handle, u16 cmd,
if (!ret)
ret = -ETIMEDOUT;
goto out_free_rx_slot;
- }
+ } else
+ ret = 0;

if (dln2->disconnect) {
ret = -ENODEV;
--
1.9.1

2014-11-11 12:23:56

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 1/2] mfd: dln2: fix _dln2_transfer return code

On Tue, Nov 11, 2014 at 02:20:56PM +0200, Octavian Purdila wrote:
> If wait_for_completion_interruptible_timeout returns a positive value
> it may be propagated as the return value of _dln2_transfer. This
> contradicts the documentation of the function and exposes unnecessary
> internals to the callers.
>
> This patch makes sure to set the return value to 0 in that case.
>
> Reported-by: Julia Lawall <[email protected]>
> Signed-off-by: Octavian Purdila <[email protected]>
> ---
> drivers/mfd/dln2.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mfd/dln2.c b/drivers/mfd/dln2.c
> index 9765a17..f0747a1 100644
> --- a/drivers/mfd/dln2.c
> +++ b/drivers/mfd/dln2.c
> @@ -462,7 +462,8 @@ static int _dln2_transfer(struct dln2_dev *dln2, u16 handle, u16 cmd,
> if (!ret)
> ret = -ETIMEDOUT;
> goto out_free_rx_slot;
> - }
> + } else
> + ret = 0;

You need braces on both branches (without commenting on the fix itself).

Johan

2014-11-11 12:26:43

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 2/2] i2c: dln2: simplify return flow for dln2_i2c_enable

On Tue, Nov 11, 2014 at 02:20:57PM +0200, Octavian Purdila wrote:
> This fixes the following kbuild test robot warning:
>
> >> drivers/i2c/busses/i2c-dln2.c:70:1-4: WARNING: end returns can be simplified if negative or 0 value
>
> Reported-by: kbuild test robot <[email protected]>
> Reported-by: Julia Lawall <[email protected]>
>
> Signed-off-by: Octavian Purdila <[email protected]>
> ---
> drivers/i2c/busses/i2c-dln2.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-dln2.c b/drivers/i2c/busses/i2c-dln2.c
> index 010a5fa..b3fb86a 100644
> --- a/drivers/i2c/busses/i2c-dln2.c
> +++ b/drivers/i2c/busses/i2c-dln2.c
> @@ -54,7 +54,6 @@ struct dln2_i2c {
>
> static int dln2_i2c_enable(struct dln2_i2c *dln2, bool enable)
> {
> - int ret;
> u16 cmd;
> struct {
> u8 port;
> @@ -67,11 +66,7 @@ static int dln2_i2c_enable(struct dln2_i2c *dln2, bool enable)
> else
> cmd = DLN2_I2C_DISABLE;
>
> - ret = dln2_transfer_tx(dln2->pdev, cmd, &tx, sizeof(tx));
> - if (ret < 0)
> - return ret;
> -
> - return 0;
> + return dln2_transfer_tx(dln2->pdev, cmd, &tx, sizeof(tx));

This looks like a bogus warning. It's not generally equivalent (ret > 0)
and is not mandated by any style guide lines.

Johan

2014-11-11 12:49:30

by Octavian Purdila

[permalink] [raw]
Subject: Re: [PATCH 2/2] i2c: dln2: simplify return flow for dln2_i2c_enable

On Tue, Nov 11, 2014 at 2:26 PM, Johan Hovold <[email protected]> wrote:
> On Tue, Nov 11, 2014 at 02:20:57PM +0200, Octavian Purdila wrote:
>> This fixes the following kbuild test robot warning:
>>
>> >> drivers/i2c/busses/i2c-dln2.c:70:1-4: WARNING: end returns can be simplified if negative or 0 value
>>
>> Reported-by: kbuild test robot <[email protected]>
>> Reported-by: Julia Lawall <[email protected]>
>>
>> Signed-off-by: Octavian Purdila <[email protected]>
>> ---
>> drivers/i2c/busses/i2c-dln2.c | 7 +------
>> 1 file changed, 1 insertion(+), 6 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-dln2.c b/drivers/i2c/busses/i2c-dln2.c
>> index 010a5fa..b3fb86a 100644
>> --- a/drivers/i2c/busses/i2c-dln2.c
>> +++ b/drivers/i2c/busses/i2c-dln2.c
>> @@ -54,7 +54,6 @@ struct dln2_i2c {
>>
>> static int dln2_i2c_enable(struct dln2_i2c *dln2, bool enable)
>> {
>> - int ret;
>> u16 cmd;
>> struct {
>> u8 port;
>> @@ -67,11 +66,7 @@ static int dln2_i2c_enable(struct dln2_i2c *dln2, bool enable)
>> else
>> cmd = DLN2_I2C_DISABLE;
>>
>> - ret = dln2_transfer_tx(dln2->pdev, cmd, &tx, sizeof(tx));
>> - if (ret < 0)
>> - return ret;
>> -
>> - return 0;
>> + return dln2_transfer_tx(dln2->pdev, cmd, &tx, sizeof(tx));
>
> This looks like a bogus warning. It's not generally equivalent (ret > 0)
> and is not mandated by any style guide lines.
>

In this particular it should be equivalent (with the previous fix) and
it saves 5 lines, so I think its worth it.

2014-11-11 16:18:22

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 1/2] mfd: dln2: fix _dln2_transfer return code

On Tue, 11 Nov 2014, Octavian Purdila wrote:

> If wait_for_completion_interruptible_timeout returns a positive value
> it may be propagated as the return value of _dln2_transfer. This
> contradicts the documentation of the function and exposes unnecessary
> internals to the callers.
>
> This patch makes sure to set the return value to 0 in that case.

I didn't keep around the code or the address of the git tree, but I wonder
if this makes a later assignment of ret to 0 unnecessary?

julia

> Reported-by: Julia Lawall <[email protected]>
> Signed-off-by: Octavian Purdila <[email protected]>
> ---
> drivers/mfd/dln2.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mfd/dln2.c b/drivers/mfd/dln2.c
> index 9765a17..f0747a1 100644
> --- a/drivers/mfd/dln2.c
> +++ b/drivers/mfd/dln2.c
> @@ -462,7 +462,8 @@ static int _dln2_transfer(struct dln2_dev *dln2, u16 handle, u16 cmd,
> if (!ret)
> ret = -ETIMEDOUT;
> goto out_free_rx_slot;
> - }
> + } else
> + ret = 0;
>
> if (dln2->disconnect) {
> ret = -ENODEV;
> --
> 1.9.1
>
>

2014-11-11 16:20:41

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 2/2] i2c: dln2: simplify return flow for dln2_i2c_enable

On Tue, 11 Nov 2014, Octavian Purdila wrote:

> On Tue, Nov 11, 2014 at 2:26 PM, Johan Hovold <[email protected]> wrote:
> > On Tue, Nov 11, 2014 at 02:20:57PM +0200, Octavian Purdila wrote:
> >> This fixes the following kbuild test robot warning:
> >>
> >> >> drivers/i2c/busses/i2c-dln2.c:70:1-4: WARNING: end returns can be simplified if negative or 0 value
> >>
> >> Reported-by: kbuild test robot <[email protected]>
> >> Reported-by: Julia Lawall <[email protected]>
> >>
> >> Signed-off-by: Octavian Purdila <[email protected]>
> >> ---
> >> drivers/i2c/busses/i2c-dln2.c | 7 +------
> >> 1 file changed, 1 insertion(+), 6 deletions(-)
> >>
> >> diff --git a/drivers/i2c/busses/i2c-dln2.c b/drivers/i2c/busses/i2c-dln2.c
> >> index 010a5fa..b3fb86a 100644
> >> --- a/drivers/i2c/busses/i2c-dln2.c
> >> +++ b/drivers/i2c/busses/i2c-dln2.c
> >> @@ -54,7 +54,6 @@ struct dln2_i2c {
> >>
> >> static int dln2_i2c_enable(struct dln2_i2c *dln2, bool enable)
> >> {
> >> - int ret;
> >> u16 cmd;
> >> struct {
> >> u8 port;
> >> @@ -67,11 +66,7 @@ static int dln2_i2c_enable(struct dln2_i2c *dln2, bool enable)
> >> else
> >> cmd = DLN2_I2C_DISABLE;
> >>
> >> - ret = dln2_transfer_tx(dln2->pdev, cmd, &tx, sizeof(tx));
> >> - if (ret < 0)
> >> - return ret;
> >> -
> >> - return 0;
> >> + return dln2_transfer_tx(dln2->pdev, cmd, &tx, sizeof(tx));
> >
> > This looks like a bogus warning. It's not generally equivalent (ret > 0)
> > and is not mandated by any style guide lines.
> >
>
> In this particular it should be equivalent (with the previous fix) and
> it saves 5 lines, so I think its worth it.

It's marked as a warning because it is not generally equivalent. But
there may be many cases where it is equivalent, and in this case the
documentation for the function said that it should have been. So I think
that the warning is useful.

julia

2014-11-11 16:32:04

by Octavian Purdila

[permalink] [raw]
Subject: Re: [PATCH 1/2] mfd: dln2: fix _dln2_transfer return code

On Tue, Nov 11, 2014 at 6:18 PM, Julia Lawall <[email protected]> wrote:
> On Tue, 11 Nov 2014, Octavian Purdila wrote:
>
>> If wait_for_completion_interruptible_timeout returns a positive value
>> it may be propagated as the return value of _dln2_transfer. This
>> contradicts the documentation of the function and exposes unnecessary
>> internals to the callers.
>>
>> This patch makes sure to set the return value to 0 in that case.
>
> I didn't keep around the code or the address of the git tree, but I wonder
> if this makes a later assignment of ret to 0 unnecessary?
>

Yes, you are right, we can skip setting it when ibuf is NULL. I will
send v2 that fixes this and the coding style issue.

2014-11-12 10:39:53

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 2/2] i2c: dln2: simplify return flow for dln2_i2c_enable

On Tue, Nov 11, 2014 at 05:20:37PM +0100, Julia Lawall wrote:
> On Tue, 11 Nov 2014, Octavian Purdila wrote:
>
> > On Tue, Nov 11, 2014 at 2:26 PM, Johan Hovold <[email protected]> wrote:
> > > On Tue, Nov 11, 2014 at 02:20:57PM +0200, Octavian Purdila wrote:
> > >> This fixes the following kbuild test robot warning:
> > >>
> > >> >> drivers/i2c/busses/i2c-dln2.c:70:1-4: WARNING: end returns can be simplified if negative or 0 value
> > >>
> > >> Reported-by: kbuild test robot <[email protected]>
> > >> Reported-by: Julia Lawall <[email protected]>
> > >>
> > >> Signed-off-by: Octavian Purdila <[email protected]>
> > >> ---
> > >> drivers/i2c/busses/i2c-dln2.c | 7 +------
> > >> 1 file changed, 1 insertion(+), 6 deletions(-)
> > >>
> > >> diff --git a/drivers/i2c/busses/i2c-dln2.c b/drivers/i2c/busses/i2c-dln2.c
> > >> index 010a5fa..b3fb86a 100644
> > >> --- a/drivers/i2c/busses/i2c-dln2.c
> > >> +++ b/drivers/i2c/busses/i2c-dln2.c
> > >> @@ -54,7 +54,6 @@ struct dln2_i2c {
> > >>
> > >> static int dln2_i2c_enable(struct dln2_i2c *dln2, bool enable)
> > >> {
> > >> - int ret;
> > >> u16 cmd;
> > >> struct {
> > >> u8 port;
> > >> @@ -67,11 +66,7 @@ static int dln2_i2c_enable(struct dln2_i2c *dln2, bool enable)
> > >> else
> > >> cmd = DLN2_I2C_DISABLE;
> > >>
> > >> - ret = dln2_transfer_tx(dln2->pdev, cmd, &tx, sizeof(tx));
> > >> - if (ret < 0)
> > >> - return ret;
> > >> -
> > >> - return 0;
> > >> + return dln2_transfer_tx(dln2->pdev, cmd, &tx, sizeof(tx));
> > >
> > > This looks like a bogus warning. It's not generally equivalent (ret > 0)
> > > and is not mandated by any style guide lines.
> > >
> >
> > In this particular it should be equivalent (with the previous fix) and
> > it saves 5 lines, so I think its worth it.
>
> It's marked as a warning because it is not generally equivalent. But
> there may be many cases where it is equivalent, and in this case the
> documentation for the function said that it should have been. So I think
> that the warning is useful.

I still think "warning" is too strong, "hint" would perhaps be more
appropriate, if at all needed.

Sure we can save four lines of code this way, but we also hide the
return value of the function so that instead of just looking at the
function itself I now have to look at the documentation of the final
function call (and hope it is up to date) to figure out the return
value (e.g. it may return the number of bytes transfered on success).

I also believe using a temporary is preferred for purely aesthetic
reasons in case the final function call has enough parameters that it
needs to use continuation lines.

Johan

2014-11-13 16:22:09

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH 2/2] i2c: dln2: simplify return flow for dln2_i2c_enable

On Tue, Nov 11, 2014 at 02:20:57PM +0200, Octavian Purdila wrote:
> This fixes the following kbuild test robot warning:
>
> >> drivers/i2c/busses/i2c-dln2.c:70:1-4: WARNING: end returns can be simplified if negative or 0 value
>
> Reported-by: kbuild test robot <[email protected]>
> Reported-by: Julia Lawall <[email protected]>
>
> Signed-off-by: Octavian Purdila <[email protected]>

Acked-by: Wolfram Sang <[email protected]>

Lee, I think it is easiest if you simply add it to the branch you have
for this driver. OK?


Attachments:
(No filename) (544.00 B)
signature.asc (819.00 B)
Digital signature
Download all attachments

2014-11-17 14:57:03

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH 2/2] i2c: dln2: simplify return flow for dln2_i2c_enable

On Thu, 13 Nov 2014, Wolfram Sang wrote:

> On Tue, Nov 11, 2014 at 02:20:57PM +0200, Octavian Purdila wrote:
> > This fixes the following kbuild test robot warning:
> >
> > >> drivers/i2c/busses/i2c-dln2.c:70:1-4: WARNING: end returns can be simplified if negative or 0 value
> >
> > Reported-by: kbuild test robot <[email protected]>
> > Reported-by: Julia Lawall <[email protected]>
> >
> > Signed-off-by: Octavian Purdila <[email protected]>
>
> Acked-by: Wolfram Sang <[email protected]>
>
> Lee, I think it is easiest if you simply add it to the branch you have
> for this driver. OK?

Octavian indicated that he needs to send a v2 of the second patch. I
assume he will add your Ack to this patch when he does with a note
saying that it needs to be added to the I2C IB.

--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2014-11-17 15:12:08

by Octavian Purdila

[permalink] [raw]
Subject: Re: [PATCH 2/2] i2c: dln2: simplify return flow for dln2_i2c_enable

On Mon, Nov 17, 2014 at 4:56 PM, Lee Jones <[email protected]> wrote:
>
> On Thu, 13 Nov 2014, Wolfram Sang wrote:
>
> > On Tue, Nov 11, 2014 at 02:20:57PM +0200, Octavian Purdila wrote:
> > > This fixes the following kbuild test robot warning:
> > >
> > > >> drivers/i2c/busses/i2c-dln2.c:70:1-4: WARNING: end returns can be simplified if negative or 0 value
> > >
> > > Reported-by: kbuild test robot <[email protected]>
> > > Reported-by: Julia Lawall <[email protected]>
> > >
> > > Signed-off-by: Octavian Purdila <[email protected]>
> >
> > Acked-by: Wolfram Sang <[email protected]>
> >
> > Lee, I think it is easiest if you simply add it to the branch you have
> > for this driver. OK?
>
> Octavian indicated that he needs to send a v2 of the second patch. I
> assume he will add your Ack to this patch when he does with a note
> saying that it needs to be added to the I2C IB.
>

Hi Lee,

Yes, I will to that, and add a couple more fixes from Dan Carpenter, a
little bit later tonight.