All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bluetooth-next] ieee802154/mrf24j40: make sure we do not override return values
@ 2015-06-08 13:04 Stefan Schmidt
  2015-06-09  7:42 ` Marcel Holtmann
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Schmidt @ 2015-06-08 13:04 UTC (permalink / raw)
  To: linux-wpan; +Cc: Alexander Aring, Alan Ott, Stefan Schmidt

If we run into an error during rx we set the the error code in ret, but override
it afterwards. Using a different variable for the extra case avoids this
situation.

CID: 1226982, 1226983
Signed-off-by: Stefan Schmidt <stefan@osg.samsung.com>
Cc: Alan Ott <alan@signal11.us>
---
 drivers/net/ieee802154/mrf24j40.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ieee802154/mrf24j40.c b/drivers/net/ieee802154/mrf24j40.c
index 99c7676..0b9b2ae 100644
--- a/drivers/net/ieee802154/mrf24j40.c
+++ b/drivers/net/ieee802154/mrf24j40.c
@@ -533,6 +533,7 @@ static int mrf24j40_handle_rx(struct mrf24j40 *devrec)
 	u8 lqi = 0;
 	u8 val;
 	int ret = 0;
+	int ret2 = 0;
 	struct sk_buff *skb;
 
 	/* Turn off reception of packets off the air. This prevents the
@@ -569,9 +570,9 @@ static int mrf24j40_handle_rx(struct mrf24j40 *devrec)
 
 out:
 	/* Turn back on reception of packets off the air. */
-	ret = read_short_reg(devrec, REG_BBREG1, &val);
-	if (ret)
-		return ret;
+	ret2 = read_short_reg(devrec, REG_BBREG1, &val);
+	if (ret2)
+		return ret2;
 	val &= ~0x4; /* Clear RXDECINV */
 	write_short_reg(devrec, REG_BBREG1, val);
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bluetooth-next] ieee802154/mrf24j40: make sure we do not override return values
  2015-06-08 13:04 [PATCH bluetooth-next] ieee802154/mrf24j40: make sure we do not override return values Stefan Schmidt
@ 2015-06-09  7:42 ` Marcel Holtmann
  2015-06-09  8:52   ` Stefan Schmidt
  0 siblings, 1 reply; 5+ messages in thread
From: Marcel Holtmann @ 2015-06-09  7:42 UTC (permalink / raw)
  To: Stefan Schmidt; +Cc: linux-wpan, Alexander Aring, Alan Ott

Hi Stefan,

> If we run into an error during rx we set the the error code in ret, but override
> it afterwards. Using a different variable for the extra case avoids this
> situation.
> 
> CID: 1226982, 1226983
> Signed-off-by: Stefan Schmidt <stefan@osg.samsung.com>
> Cc: Alan Ott <alan@signal11.us>
> ---
> drivers/net/ieee802154/mrf24j40.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ieee802154/mrf24j40.c b/drivers/net/ieee802154/mrf24j40.c
> index 99c7676..0b9b2ae 100644
> --- a/drivers/net/ieee802154/mrf24j40.c
> +++ b/drivers/net/ieee802154/mrf24j40.c
> @@ -533,6 +533,7 @@ static int mrf24j40_handle_rx(struct mrf24j40 *devrec)
> 	u8 lqi = 0;
> 	u8 val;
> 	int ret = 0;
> +	int ret2 = 0;
> 	struct sk_buff *skb;
> 
> 	/* Turn off reception of packets off the air. This prevents the
> @@ -569,9 +570,9 @@ static int mrf24j40_handle_rx(struct mrf24j40 *devrec)
> 
> out:
> 	/* Turn back on reception of packets off the air. */
> -	ret = read_short_reg(devrec, REG_BBREG1, &val);
> -	if (ret)
> -		return ret;
> +	ret2 = read_short_reg(devrec, REG_BBREG1, &val);
> +	if (ret2)
> +		return ret2;

one of the general rule is to not declare a variable and assign it with a value unless really needed. In this case I think a simple int ret2; would be enough.

Regards

Marcel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bluetooth-next] ieee802154/mrf24j40: make sure we do not override return values
  2015-06-09  7:42 ` Marcel Holtmann
@ 2015-06-09  8:52   ` Stefan Schmidt
  2015-06-09 11:30     ` Alan Ott
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Schmidt @ 2015-06-09  8:52 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-wpan, Alexander Aring, Alan Ott

Hello.

On 09/06/15 09:42, Marcel Holtmann wrote:
> Hi Stefan,
>
>> If we run into an error during rx we set the the error code in ret, but override
>> it afterwards. Using a different variable for the extra case avoids this
>> situation.
>>
>> CID: 1226982, 1226983
>> Signed-off-by: Stefan Schmidt <stefan@osg.samsung.com>
>> Cc: Alan Ott <alan@signal11.us>
>> ---
>> drivers/net/ieee802154/mrf24j40.c | 7 ++++---
>> 1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/net/ieee802154/mrf24j40.c b/drivers/net/ieee802154/mrf24j40.c
>> index 99c7676..0b9b2ae 100644
>> --- a/drivers/net/ieee802154/mrf24j40.c
>> +++ b/drivers/net/ieee802154/mrf24j40.c
>> @@ -533,6 +533,7 @@ static int mrf24j40_handle_rx(struct mrf24j40 *devrec)
>> 	u8 lqi = 0;
>> 	u8 val;
>> 	int ret = 0;
>> +	int ret2 = 0;
>> 	struct sk_buff *skb;
>>
>> 	/* Turn off reception of packets off the air. This prevents the
>> @@ -569,9 +570,9 @@ static int mrf24j40_handle_rx(struct mrf24j40 *devrec)
>>
>> out:
>> 	/* Turn back on reception of packets off the air. */
>> -	ret = read_short_reg(devrec, REG_BBREG1, &val);
>> -	if (ret)
>> -		return ret;
>> +	ret2 = read_short_reg(devrec, REG_BBREG1, &val);
>> +	if (ret2)
>> +		return ret2;
> one of the general rule is to not declare a variable and assign it with a value unless really needed. In this case I think a simple int ret2; would be enough.

Fair enough. I just followed what was there already. Patch v2 send.

regards
Stefan Schmidt

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bluetooth-next] ieee802154/mrf24j40: make sure we do not override return values
  2015-06-09  8:52   ` Stefan Schmidt
@ 2015-06-09 11:30     ` Alan Ott
  2015-06-09 11:33       ` Alan Ott
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Ott @ 2015-06-09 11:30 UTC (permalink / raw)
  To: Stefan Schmidt, Marcel Holtmann; +Cc: linux-wpan, Alexander Aring

On 06/09/2015 04:52 AM, Stefan Schmidt wrote:
> Hello.
>
> On 09/06/15 09:42, Marcel Holtmann wrote:
>> Hi Stefan,
>>
>>> If we run into an error during rx we set the the error code in ret, 
>>> but override
>>> it afterwards. Using a different variable for the extra case avoids 
>>> this
>>> situation.
>>>
>>> CID: 1226982, 1226983
>>> Signed-off-by: Stefan Schmidt <stefan@osg.samsung.com>
>>> Cc: Alan Ott <alan@signal11.us>
>>> ---
>>> drivers/net/ieee802154/mrf24j40.c | 7 ++++---
>>> 1 file changed, 4 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/net/ieee802154/mrf24j40.c 
>>> b/drivers/net/ieee802154/mrf24j40.c
>>> index 99c7676..0b9b2ae 100644
>>> --- a/drivers/net/ieee802154/mrf24j40.c
>>> +++ b/drivers/net/ieee802154/mrf24j40.c
>>> @@ -533,6 +533,7 @@ static int mrf24j40_handle_rx(struct mrf24j40 
>>> *devrec)
>>>     u8 lqi = 0;
>>>     u8 val;
>>>     int ret = 0;
>>> +    int ret2 = 0;
>>>     struct sk_buff *skb;
>>>
>>>     /* Turn off reception of packets off the air. This prevents the
>>> @@ -569,9 +570,9 @@ static int mrf24j40_handle_rx(struct mrf24j40 
>>> *devrec)
>>>
>>> out:
>>>     /* Turn back on reception of packets off the air. */
>>> -    ret = read_short_reg(devrec, REG_BBREG1, &val);
>>> -    if (ret)
>>> -        return ret;
>>> +    ret2 = read_short_reg(devrec, REG_BBREG1, &val);
>>> +    if (ret2)
>>> +        return ret2;

Don't you want to say "return ret" here?

Alan.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bluetooth-next] ieee802154/mrf24j40: make sure we do not override return values
  2015-06-09 11:30     ` Alan Ott
@ 2015-06-09 11:33       ` Alan Ott
  0 siblings, 0 replies; 5+ messages in thread
From: Alan Ott @ 2015-06-09 11:33 UTC (permalink / raw)
  To: Stefan Schmidt, Marcel Holtmann; +Cc: linux-wpan, Alexander Aring

On 06/09/2015 07:30 AM, Alan Ott wrote:
> On 06/09/2015 04:52 AM, Stefan Schmidt wrote:
>> Hello.
>>
>> On 09/06/15 09:42, Marcel Holtmann wrote:
>>> Hi Stefan,
>>>
>>>> If we run into an error during rx we set the the error code in ret, 
>>>> but override
>>>> it afterwards. Using a different variable for the extra case avoids 
>>>> this
>>>> situation.
>>>>
>>>> CID: 1226982, 1226983
>>>> Signed-off-by: Stefan Schmidt <stefan@osg.samsung.com>
>>>> Cc: Alan Ott <alan@signal11.us>
>>>> ---
>>>> drivers/net/ieee802154/mrf24j40.c | 7 ++++---
>>>> 1 file changed, 4 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/drivers/net/ieee802154/mrf24j40.c 
>>>> b/drivers/net/ieee802154/mrf24j40.c
>>>> index 99c7676..0b9b2ae 100644
>>>> --- a/drivers/net/ieee802154/mrf24j40.c
>>>> +++ b/drivers/net/ieee802154/mrf24j40.c
>>>> @@ -533,6 +533,7 @@ static int mrf24j40_handle_rx(struct mrf24j40 
>>>> *devrec)
>>>>     u8 lqi = 0;
>>>>     u8 val;
>>>>     int ret = 0;
>>>> +    int ret2 = 0;
>>>>     struct sk_buff *skb;
>>>>
>>>>     /* Turn off reception of packets off the air. This prevents the
>>>> @@ -569,9 +570,9 @@ static int mrf24j40_handle_rx(struct mrf24j40 
>>>> *devrec)
>>>>
>>>> out:
>>>>     /* Turn back on reception of packets off the air. */
>>>> -    ret = read_short_reg(devrec, REG_BBREG1, &val);
>>>> -    if (ret)
>>>> -        return ret;
>>>> +    ret2 = read_short_reg(devrec, REG_BBREG1, &val);
>>>> +    if (ret2)
>>>> +        return ret2;
>
> Don't you want to say "return ret" here?
>

Sorry, you're right. Never mind.

Alan.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-09 11:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-08 13:04 [PATCH bluetooth-next] ieee802154/mrf24j40: make sure we do not override return values Stefan Schmidt
2015-06-09  7:42 ` Marcel Holtmann
2015-06-09  8:52   ` Stefan Schmidt
2015-06-09 11:30     ` Alan Ott
2015-06-09 11:33       ` Alan Ott

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.