[dpdk-dev] [PATCH] lib/librte_power: fix using variables before validity check

Min Hu (Connor) humin29 at huawei.com
Thu Apr 29 02:43:24 CEST 2021



在 2021/4/28 23:13, Pattan, Reshma 写道:
> 
> 
>> -----Original Message-----
>> From: dev <dev-bounces at dpdk.org> On Behalf Of Min Hu (Connor)
>>
>> +	if (lcore_id >= RTE_MAX_LCORE) {
>> +		RTE_LOG(ERR, GUEST_CHANNEL, "Channel(%u) is out of range
>> 0...%d\n",
>> +				lcore_id, RTE_MAX_LCORE-1);
>> +		return -1;
>> +	}
>> +
> 
> This looks good.
> 
>>   	fds.fd = global_fds[lcore_id];
>>   	fds.events = POLLIN;
>>
> <snip>
> 
>>   	if (global_fds[lcore_id] < 0) {
>>   		RTE_LOG(ERR, GUEST_CHANNEL, "Channel is not
>> connected\n");
> 
> 
> Another suggestion if you would like to improve the code, is below,
> You can move "global_fds[lcore_id]"  check to immediate after  the line  "fds.fd = global_fds[lcore_id]; "
Hi, thanks Pattan.
But I think "global_fds[lcore_id]"  check may move before the line 
"fds.fd = global_fds[lcore_id];
If it failed, "fds.fd = global_fds[lcore_id];" should not be performed.
What's your opinion?

> 
> Reviewed-by: Reshma Pattan <reshma.pattan at intel.com>
> 
> .
> 


More information about the dev mailing list