bpf: delete meaningless code

Message ID 1619004925-58869-1-git-send-email-humin29@huawei.com (mailing list archive)
State Rejected, archived
Delegated to: Thomas Monjalon
Headers
Series bpf: delete meaningless code |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply issues

Commit Message

humin (Q) April 21, 2021, 11:35 a.m. UTC
  'rd->u.max = rd->u.max' is meaningless which should be deleted.

This patch fixed it.

Fixes: 8021917293d0 ("bpf: add extra validation for input BPF program")
Cc: stable@dpdk.org

Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 lib/librte_bpf/bpf_validate.c | 2 --
 1 file changed, 2 deletions(-)
  

Comments

Ananyev, Konstantin April 21, 2021, 11:43 a.m. UTC | #1
> 
> 'rd->u.max = rd->u.max' is meaningless which should be deleted.
> 
> This patch fixed it.
> 
> Fixes: 8021917293d0 ("bpf: add extra validation for input BPF program")
> Cc: stable@dpdk.org

As I remember, I did it on purpose.
Some old (but still supported) version of clang complained
about unitialized variable.

> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> ---
>  lib/librte_bpf/bpf_validate.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/lib/librte_bpf/bpf_validate.c b/lib/librte_bpf/bpf_validate.c
> index 9214f15..c5ad951 100644
> --- a/lib/librte_bpf/bpf_validate.c
> +++ b/lib/librte_bpf/bpf_validate.c
> @@ -517,8 +517,6 @@ eval_divmod(uint32_t op, struct bpf_reg_val *rd, struct bpf_reg_val *rs,
>  	} else {
>  		if (op == BPF_MOD)
>  			rd->u.max = RTE_MIN(rd->u.max, rs->u.max - 1);
> -		else
> -			rd->u.max = rd->u.max;
>  		rd->u.min = 0;
>  	}
> 
> --
> 2.7.4
  
humin (Q) April 21, 2021, 12:02 p.m. UTC | #2
在 2021/4/21 19:43, Ananyev, Konstantin 写道:
>>
>> 'rd->u.max = rd->u.max' is meaningless which should be deleted.
>>
>> This patch fixed it.
>>
>> Fixes: 8021917293d0 ("bpf: add extra validation for input BPF program")
>> Cc: stable@dpdk.org
> 
> As I remember, I did it on purpose.
> Some old (but still supported) version of clang complained
> about unitialized variable.

Well, how about like this ?
		uint64_t tmp = rd->u.max;
		if (op == BPF_MOD)
			tmp = RTE_MIN(tmp, tmp - 1);
		rd->u.max = tmp;

> 
>> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
>> ---
>>   lib/librte_bpf/bpf_validate.c | 2 --
>>   1 file changed, 2 deletions(-)
>>
>> diff --git a/lib/librte_bpf/bpf_validate.c b/lib/librte_bpf/bpf_validate.c
>> index 9214f15..c5ad951 100644
>> --- a/lib/librte_bpf/bpf_validate.c
>> +++ b/lib/librte_bpf/bpf_validate.c
>> @@ -517,8 +517,6 @@ eval_divmod(uint32_t op, struct bpf_reg_val *rd, struct bpf_reg_val *rs,
>>   	} else {
>>   		if (op == BPF_MOD)
>>   			rd->u.max = RTE_MIN(rd->u.max, rs->u.max - 1);
>> -		else
>> -			rd->u.max = rd->u.max;
>>   		rd->u.min = 0;
>>   	}
>>
>> --
>> 2.7.4
> 
> .
>
  
Ananyev, Konstantin April 22, 2021, 11:29 a.m. UTC | #3
> 
> 在 2021/4/21 19:43, Ananyev, Konstantin 写道:
> >>
> >> 'rd->u.max = rd->u.max' is meaningless which should be deleted.
> >>
> >> This patch fixed it.
> >>
> >> Fixes: 8021917293d0 ("bpf: add extra validation for input BPF program")
> >> Cc: stable@dpdk.org
> >
> > As I remember, I did it on purpose.
> > Some old (but still supported) version of clang complained
> > about unitialized variable.
> 
> Well, how about like this ?
> 		uint64_t tmp = rd->u.max;
> 		if (op == BPF_MOD)
> 			tmp = RTE_MIN(tmp, tmp - 1);
> 		rd->u.max = tmp;


Then, I think it should be:
tmp = RTE_MIN(tmp, rs->u.max - 1);

Or just leave things as they are right now.
Nothing is broken here.

> >
> >> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> >> ---
> >>   lib/librte_bpf/bpf_validate.c | 2 --
> >>   1 file changed, 2 deletions(-)
> >>
> >> diff --git a/lib/librte_bpf/bpf_validate.c b/lib/librte_bpf/bpf_validate.c
> >> index 9214f15..c5ad951 100644
> >> --- a/lib/librte_bpf/bpf_validate.c
> >> +++ b/lib/librte_bpf/bpf_validate.c
> >> @@ -517,8 +517,6 @@ eval_divmod(uint32_t op, struct bpf_reg_val *rd, struct bpf_reg_val *rs,
> >>   	} else {
> >>   		if (op == BPF_MOD)
> >>   			rd->u.max = RTE_MIN(rd->u.max, rs->u.max - 1);
> >> -		else
> >> -			rd->u.max = rd->u.max;
> >>   		rd->u.min = 0;
> >>   	}
> >>
> >> --
> >> 2.7.4
> >
> > .
> >
  
humin (Q) April 22, 2021, 11:39 a.m. UTC | #4
在 2021/4/22 19:29, Ananyev, Konstantin 写道:
> 
>   
>>
>> 在 2021/4/21 19:43, Ananyev, Konstantin 写道:
>>>>
>>>> 'rd->u.max = rd->u.max' is meaningless which should be deleted.
>>>>
>>>> This patch fixed it.
>>>>
>>>> Fixes: 8021917293d0 ("bpf: add extra validation for input BPF program")
>>>> Cc: stable@dpdk.org
>>>
>>> As I remember, I did it on purpose.
>>> Some old (but still supported) version of clang complained
>>> about unitialized variable.
>>
>> Well, how about like this ?
>> 		uint64_t tmp = rd->u.max;
>> 		if (op == BPF_MOD)
>> 			tmp = RTE_MIN(tmp, tmp - 1);
>> 		rd->u.max = tmp;
> 
> 
> Then, I think it should be:
> tmp = RTE_MIN(tmp, rs->u.max - 1);
> 
> Or just leave things as they are right now.
> Nothing is broken here.
> 
OK, this patch can be abandoned ,thanks.
>>>
>>>> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
>>>> ---
>>>>    lib/librte_bpf/bpf_validate.c | 2 --
>>>>    1 file changed, 2 deletions(-)
>>>>
>>>> diff --git a/lib/librte_bpf/bpf_validate.c b/lib/librte_bpf/bpf_validate.c
>>>> index 9214f15..c5ad951 100644
>>>> --- a/lib/librte_bpf/bpf_validate.c
>>>> +++ b/lib/librte_bpf/bpf_validate.c
>>>> @@ -517,8 +517,6 @@ eval_divmod(uint32_t op, struct bpf_reg_val *rd, struct bpf_reg_val *rs,
>>>>    	} else {
>>>>    		if (op == BPF_MOD)
>>>>    			rd->u.max = RTE_MIN(rd->u.max, rs->u.max - 1);
>>>> -		else
>>>> -			rd->u.max = rd->u.max;
>>>>    		rd->u.min = 0;
>>>>    	}
>>>>
>>>> --
>>>> 2.7.4
>>>
>>> .
>>>
> .
>
  

Patch

diff --git a/lib/librte_bpf/bpf_validate.c b/lib/librte_bpf/bpf_validate.c
index 9214f15..c5ad951 100644
--- a/lib/librte_bpf/bpf_validate.c
+++ b/lib/librte_bpf/bpf_validate.c
@@ -517,8 +517,6 @@  eval_divmod(uint32_t op, struct bpf_reg_val *rd, struct bpf_reg_val *rs,
 	} else {
 		if (op == BPF_MOD)
 			rd->u.max = RTE_MIN(rd->u.max, rs->u.max - 1);
-		else
-			rd->u.max = rd->u.max;
 		rd->u.min = 0;
 	}