2020-07-20 02:55:16

by Wang Hai

[permalink] [raw]
Subject: [PATCH net-next v2] net: ena: Fix using plain integer as NULL pointer in ena_init_napi_in_range

Fix sparse build warning:

drivers/net/ethernet/amazon/ena/ena_netdev.c:2193:34: warning:
Using plain integer as NULL pointer

Reported-by: Hulk Robot <[email protected]>
Signed-off-by: Wang Hai <[email protected]>
Suggested-by: Joe Perches <[email protected]>
Acked-by: Shay Agroskin <[email protected]>
---
v1->v2:
Improve code readability based on Joe Perches's suggestion
drivers/net/ethernet/amazon/ena/ena_netdev.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 91be3ffa1c5c..470d8f38b824 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -2190,11 +2190,10 @@ static void ena_del_napi_in_range(struct ena_adapter *adapter,
static void ena_init_napi_in_range(struct ena_adapter *adapter,
int first_index, int count)
{
- struct ena_napi *napi = {0};
int i;

for (i = first_index; i < first_index + count; i++) {
- napi = &adapter->ena_napi[i];
+ struct ena_napi *napi = &adapter->ena_napi[i];

netif_napi_add(adapter->netdev,
&adapter->ena_napi[i].napi,
--
2.17.1


2020-07-20 03:16:20

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH net-next v2] net: ena: Fix using plain integer as NULL pointer in ena_init_napi_in_range

On Mon, 2020-07-20 at 10:53 +0800, Wang Hai wrote:
> Fix sparse build warning:
>
> drivers/net/ethernet/amazon/ena/ena_netdev.c:2193:34: warning:
> Using plain integer as NULL pointer
[]
> diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c
[]
> @@ -2190,11 +2190,10 @@ static void ena_del_napi_in_range(struct ena_adapter *adapter,
> static void ena_init_napi_in_range(struct ena_adapter *adapter,
> int first_index, int count)
> {
> - struct ena_napi *napi = {0};
> int i;
>
> for (i = first_index; i < first_index + count; i++) {
> - napi = &adapter->ena_napi[i];
> + struct ena_napi *napi = &adapter->ena_napi[i];
>
> netif_napi_add(adapter->netdev,
> &adapter->ena_napi[i].napi,

Another possible change is to this statement:

netif_napi_add(adapter->netdev,
&napi->napi,
etc...);



2020-07-20 06:41:06

by Shay Agroskin

[permalink] [raw]
Subject: Re: [PATCH net-next v2] net: ena: Fix using plain integer as NULL pointer in ena_init_napi_in_range


Joe Perches <[email protected]> writes:

> On Mon, 2020-07-20 at 10:53 +0800, Wang Hai wrote:
>> Fix sparse build warning:
>>
>> drivers/net/ethernet/amazon/ena/ena_netdev.c:2193:34: warning:
>> Using plain integer as NULL pointer
> []
>> diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c
>> b/drivers/net/ethernet/amazon/ena/ena_netdev.c
> []
>> @@ -2190,11 +2190,10 @@ static void
>> ena_del_napi_in_range(struct ena_adapter *adapter,
>> static void ena_init_napi_in_range(struct ena_adapter
>> *adapter,
>> int first_index, int count)
>> {
>> - struct ena_napi *napi = {0};
>> int i;
>>
>> for (i = first_index; i < first_index + count; i++) {
>> - napi = &adapter->ena_napi[i];
>> + struct ena_napi *napi = &adapter->ena_napi[i];
>>
>> netif_napi_add(adapter->netdev,
>> &adapter->ena_napi[i].napi,
>
> Another possible change is to this statement:
>
> netif_napi_add(adapter->netdev,
> &napi->napi,
> etc...);

Yup, missed that myself. Wang, if you don't mind please apply
Joe's change as well.

Thanks, Shay

2020-07-20 07:10:10

by Wang Hai

[permalink] [raw]
Subject: Re: [PATCH net-next v2] net: ena: Fix using plain integer as NULL pointer in ena_init_napi_in_range


?? 2020/7/20 11:15, Joe Perches ะด??:
> On Mon, 2020-07-20 at 10:53 +0800, Wang Hai wrote:
>> Fix sparse build warning:
>>
>> drivers/net/ethernet/amazon/ena/ena_netdev.c:2193:34: warning:
>> Using plain integer as NULL pointer
> []
>> diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c
> []
>> @@ -2190,11 +2190,10 @@ static void ena_del_napi_in_range(struct ena_adapter *adapter,
>> static void ena_init_napi_in_range(struct ena_adapter *adapter,
>> int first_index, int count)
>> {
>> - struct ena_napi *napi = {0};
>> int i;
>>
>> for (i = first_index; i < first_index + count; i++) {
>> - napi = &adapter->ena_napi[i];
>> + struct ena_napi *napi = &adapter->ena_napi[i];
>>
>> netif_napi_add(adapter->netdev,
>> &adapter->ena_napi[i].napi,
> Another possible change is to this statement:
>
> netif_napi_add(adapter->netdev,
> &napi->napi,
> etc...);
>
Good catch. I'll add this change, Thanks.
>
>
> .
>