2014-06-25 14:03:25

by Rickard Strandqvist

[permalink] [raw]
Subject: [PATCH] scsi: bnx2i: bnx2i_iscsi.c: Cleaning up variable is set more than once

A struct member variable is set to different values without having used in between.

This was found using a static code analysis program called cppcheck

Signed-off-by: Rickard Strandqvist <[email protected]>
---
drivers/scsi/bnx2i/bnx2i_iscsi.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c
index 166543f..fdf7bc3 100644
--- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
+++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
@@ -1643,7 +1643,6 @@ static void bnx2i_conn_get_stats(struct iscsi_cls_conn *cls_conn,
stats->r2t_pdus = conn->r2t_pdus_cnt;
stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
- stats->custom_length = 3;
strcpy(stats->custom[2].desc, "eh_abort_cnt");
stats->custom[2].value = conn->eh_abort_cnt;
stats->digest_err = 0;
--
1.7.10.4


2014-06-25 14:26:45

by Maurizio Lombardi

[permalink] [raw]
Subject: Re: [PATCH] scsi: bnx2i: bnx2i_iscsi.c: Cleaning up variable is set more than once

Hi,

On 06/25/2014 04:04 PM, Rickard Strandqvist wrote:
> A struct member variable is set to different values without having used in between.
>
> This was found using a static code analysis program called cppcheck
>
> Signed-off-by: Rickard Strandqvist <[email protected]>
> ---
> drivers/scsi/bnx2i/bnx2i_iscsi.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c
> index 166543f..fdf7bc3 100644
> --- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
> +++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
> @@ -1643,7 +1643,6 @@ static void bnx2i_conn_get_stats(struct iscsi_cls_conn *cls_conn,
> stats->r2t_pdus = conn->r2t_pdus_cnt;
> stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
> stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
> - stats->custom_length = 3;
> strcpy(stats->custom[2].desc, "eh_abort_cnt");
> stats->custom[2].value = conn->eh_abort_cnt;
> stats->digest_err = 0;
>

Eddie,

The code modifies the content of stats->custom[2], so shouldn't custom_length be set to 3?
Why is it set to zero at the end of this function?

Regards,
Maurizio Lombardi

2014-06-25 17:18:11

by Eddie Wai

[permalink] [raw]
Subject: Re: [PATCH] scsi: bnx2i: bnx2i_iscsi.c: Cleaning up variable is set more than once

On Wed, 2014-06-25 at 16:26 +0200, Maurizio Lombardi wrote:
> Hi,
>
> On 06/25/2014 04:04 PM, Rickard Strandqvist wrote:
> > A struct member variable is set to different values without having used in between.
> >
> > This was found using a static code analysis program called cppcheck
> >
> > Signed-off-by: Rickard Strandqvist <[email protected]>
> > ---
> > drivers/scsi/bnx2i/bnx2i_iscsi.c | 1 -
> > 1 file changed, 1 deletion(-)
> >
> > diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c
> > index 166543f..fdf7bc3 100644
> > --- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
> > +++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
> > @@ -1643,7 +1643,6 @@ static void bnx2i_conn_get_stats(struct iscsi_cls_conn *cls_conn,
> > stats->r2t_pdus = conn->r2t_pdus_cnt;
> > stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
> > stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
> > - stats->custom_length = 3;
> > strcpy(stats->custom[2].desc, "eh_abort_cnt");
> > stats->custom[2].value = conn->eh_abort_cnt;
> > stats->digest_err = 0;
> >
>
> Eddie,
>
> The code modifies the content of stats->custom[2], so shouldn't custom_length be set to 3?
> Why is it set to zero at the end of this function?
Nice find. This is literally a day1 bug. Yes, I agree that the
custom_length should be left at 3. Otherwise, the nlmsg replied back to
the application would not have the custom message. Thanks.
>
> Regards,
> Maurizio Lombardi

2014-06-26 00:28:16

by Rickard Strandqvist

[permalink] [raw]
Subject: Re: [PATCH] scsi: bnx2i: bnx2i_iscsi.c: Cleaning up variable is set more than once

2014-06-25 19:13 GMT+02:00 Eddie Wai <[email protected]>:
> On Wed, 2014-06-25 at 16:26 +0200, Maurizio Lombardi wrote:
>> Hi,
>>
>> On 06/25/2014 04:04 PM, Rickard Strandqvist wrote:
>> > A struct member variable is set to different values without having used in between.
>> >
>> > This was found using a static code analysis program called cppcheck
>> >
>> > Signed-off-by: Rickard Strandqvist <[email protected]>
>> > ---
>> > drivers/scsi/bnx2i/bnx2i_iscsi.c | 1 -
>> > 1 file changed, 1 deletion(-)
>> >
>> > diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c
>> > index 166543f..fdf7bc3 100644
>> > --- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
>> > +++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
>> > @@ -1643,7 +1643,6 @@ static void bnx2i_conn_get_stats(struct iscsi_cls_conn *cls_conn,
>> > stats->r2t_pdus = conn->r2t_pdus_cnt;
>> > stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
>> > stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
>> > - stats->custom_length = 3;
>> > strcpy(stats->custom[2].desc, "eh_abort_cnt");
>> > stats->custom[2].value = conn->eh_abort_cnt;
>> > stats->digest_err = 0;
>> >
>>
>> Eddie,
>>
>> The code modifies the content of stats->custom[2], so shouldn't custom_length be set to 3?
>> Why is it set to zero at the end of this function?
> Nice find. This is literally a day1 bug. Yes, I agree that the
> custom_length should be left at 3. Otherwise, the nlmsg replied back to
> the application would not have the custom message. Thanks.
>>
>> Regards,
>> Maurizio Lombardi
>
>


Hi, and thank you!

If it's not obvious, I do all my fixes without changing the previous
intent. But obviously it is not always right, rather it is one of main
reasons to fix this type of error :)

But I'll make a new patch then, with = 3 ?


Kind regards
Rickard Strandqvist

2014-06-26 08:05:11

by Maurizio Lombardi

[permalink] [raw]
Subject: Re: [PATCH] scsi: bnx2i: bnx2i_iscsi.c: Cleaning up variable is set more than once

Hi,

On 06/26/2014 02:28 AM, Rickard Strandqvist wrote:
>
> If it's not obvious, I do all my fixes without changing the previous
> intent. But obviously it is not always right, rather it is one of main
> reasons to fix this type of error :)

Yes it is obvious, your patch was correct (it didn't modify the function behaviour)
but helped to spot a defect.

>
> But I'll make a new patch then, with = 3 ?

Yes, please submit a new patch which sets custom_length = 3 at the end of the function.

Thanks,
Maurizio Lombardi