net: ena: initialize dim_sample
PATCH 1/1 net: ena: initialize dim_sample
clang static analysis reports this problem drivers/net/ethernet/amazon/ena/ena_netdev.c:1821:2: warning: Passed-by-value struct
argument contains uninitialized data (e.g., field: 'comp_ctr') [core.CallAndMessage]
net_dim(&ena_napi->dim, dim_sample);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~net_dim can call dim_calc_stats() which uses the comp_ctr element, so it must be initialized.
--- drivers/net/ethernet/amazon/ena/ena_netdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/amazon/ena/ena_netdev.c +1 -1
@@ -1805,7 +1805,7 @@ static void ena_dim_work(struct work_struct *w)static void ena_adjust_adaptive_rx_intr_moderation (struct ena_napi *ena_napi) { -struct dim_sample dim_sample; +struct dim_sample dim_sample = {};struct ena_ring *rx_ring = ena_napi->rx_ring;if (!rx_ring->per_napi_packets)
Signature · 1 line
2.27.0
Quoted 9 lines · Tom Rix
clang static analysis reports this problem
drivers/net/ethernet/amazon/ena/ena_netdev.c:1821:2: warning: Passed-by-value struct
argument contains uninitialized data (e.g., field: 'comp_ctr') [core.CallAndMessage]net_dim(&ena_napi->dim, dim_sample); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net_dimcan calldim_calc_stats()which uses thecomp_ctrelement, so it must be initialized.
This seems to be a dim_update_sample() problem really, when comp_ctr has been added...
Your patch works, but we could avoid pre-initializing dim_sample in all callers, then re-writing all but one field...
include/linux/dim.h +0 -0
100644
include/linux/dim.h +0 -0
@@ -254,6 +254,7 @@ dim_update_sample(u16 event_ctr, u64 packets, u64
bytes, struct dim_sample *s)
s->pkt_ctr = packets;
s->byte_ctr = bytes;
s->event_ctr = event_ctr;+ s->comp_ctr = 0;
}
/**
Quoted 26 lines · Eric Dumazet
Quoted 10 lines · Tom Rix
clang static analysis reports this problem
drivers/net/ethernet/amazon/ena/ena_netdev.c:1821:2: warning: Passed-by-value struct
argument contains uninitialized data (e.g., field:
'comp_ctr') [core.CallAndMessage]net_dim(&ena_napi->dim, dim_sample); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net_dimcan calldim_calc_stats()which uses thecomp_ctrelement, so it must be initialized.This seems to be a
dim_update_sample()problem really, whencomp_ctrhas been added...Your patch works, but we could avoid pre-initializing
dim_samplein all callers, then re-writing all but one field...include/linux/dim.h +0
-0100644
include/linux/dim.h +0
-0@@ -254,6 +254,7 @@ dim_update_sample(u16 event_ctr, u64packets, u64
bytes, structdim_sample*s)
Quoted 7 lines
s->pkt_ctr = packets; s->byte_ctr = bytes; s->event_ctr = event_ctr;+
s->comp_ctr= 0;
}/**
Hi,
I'd rather go with Eric's solution to this issue than zero the whole struct in ENA
Thanks,
Shay
Quoted 33 lines · Shay Agroskin
Quoted 30 lines · Eric Dumazet
Quoted 9 lines · Tom Rix
clang static analysis reports this problem
drivers/net/ethernet/amazon/ena/ena_netdev.c:1821:2: warning: Passed-by-value struct argument contains uninitialized data (e.g., field: 'comp_ctr') [core.CallAndMessage]net_dim(&ena_napi->dim, dim_sample); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net_dimcan calldim_calc_stats()which uses thecomp_ctrelement, so it must be initialized.This seems to be a
dim_update_sample()problem really, whencomp_ctrhas been added...Your patch works, but we could avoid pre-initializing
dim_samplein all callers, then re-writing all but one field...include/linux/dim.h +0
-0100644
include/linux/dim.h +1
-0@@ -254,6 +254,7 @@ dim_update_sample(u16 event_ctr, u64 packets, u64 bytes, struct dim_sample *s) s->pkt_ctr = packets; s->byte_ctr = bytes; s->event_ctr = event_ctr; + s->comp_ctr = 0; }
Quoted 5 lines
Quoted 1 line
/**
Hi,
I'd rather go with Eric's solution to this issue than zero the whole struct in ENA
Please look at the other callers of dim_update_sample. The common pattern is to initialize the struct.
This alternative will work, but the pattern of initializing the struct the other (~20) callers should be refactored.
Tom
Quoted 4 lines
Thanks,
Shay
Quoted 46 lines · Tom Rix
Quoted 38 lines · Shay Agroskin
Quoted 35 lines · Eric Dumazet
Quoted 11 lines · Tom Rix
clang static analysis reports this problem
drivers/net/ethernet/amazon/ena/ena_netdev.c:1821:2: warning:
Passed-by-value struct
argument contains uninitialized data (e.g., field: 'comp_ctr') [core.CallAndMessage]
net_dim(&ena_napi->dim, dim_sample); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net_dimcan calldim_calc_stats()which uses thecomp_ctrelement, so it must be initialized.This seems to be a
dim_update_sample()problem really, whencomp_ctrhas been added...Your patch works, but we could avoid pre-initializing
dim_samplein all callers,
then re-writing all but one field...include/linux/dim.h +0
-0index
6c5733981563eadf5f06c59c5dc97df961692b02..4604ced4517268ef8912cd8053ac8f4d2630f977100644include/linux/dim.h +0
-0@@ -254,6 +254,7 @@ dim_update_sample(u16 event_ctr, u64packets, u64
bytes, structdim_sample*s)
s->pkt_ctr = packets;
s->byte_ctr = bytes;
s->event_ctr=event_ctr;
+ s->comp_ctr = 0;
}Quoted 6 lines
Quoted 1 line
/**
Hi,
I'd rather go with Eric's solution to this issue than zero the whole struct in ENA
Quoted 8 lines
Please look at the other callers of dim_update_sample. The common pattern is to initialize the struct.
This alternative will work, but the pattern of initializing the struct the other (~20) callers should be refactored.
Tom
While Eric's patch might be bigger if you also remove the pre-initialization in the other drivers, the Linux code itself would be smaller (granted not significantly) and it make less room for pitfalls in adding DIM support in other drivers.
Is there a good argument against using Eric's patch other than 'the other patch would be bigger' ?
Shay
Quoted 4 lines
Quoted 4 lines
Thanks,
Shay
Quoted 55 lines · Shay Agroskin
Quoted 52 lines · Tom Rix
Quoted 38 lines · Shay Agroskin
Quoted 35 lines · Eric Dumazet
Quoted 11 lines · Tom Rix
clang static analysis reports this problem
drivers/net/ethernet/amazon/ena/ena_netdev.c:1821:2: warning:
Passed-by-value struct
argument contains uninitialized data (e.g., field: 'comp_ctr') [core.CallAndMessage]
net_dim(&ena_napi->dim, dim_sample); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net_dimcan calldim_calc_stats()which uses thecomp_ctrelement, so it must be initialized.This seems to be a
dim_update_sample()problem really, whencomp_ctrhas been added...Your patch works, but we could avoid pre-initializing
dim_samplein all callers,
then re-writing all but one field...include/linux/dim.h +0
-0index
6c5733981563eadf5f06c59c5dc97df961692b02..4604ced4517268ef8912cd8053ac8f4d2630f977100644
include/linux/dim.h +1
-0@@ -254,6 +254,7 @@ dim_update_sample(u16 event_ctr, u64 packets, u64 bytes, struct dim_sample *s) s->pkt_ctr = packets; s->byte_ctr = bytes; s->event_ctr = event_ctr; + s->comp_ctr = 0; }Quoted 6 lines
Quoted 1 line
/**
Hi,
I'd rather go with Eric's solution to this issue than zero the whole struct in ENA
Please look at the other callers of dim_update_sample. The common pattern is to initialize the struct.
This alternative will work, but the pattern of initializing the struct the other (~20) callers should be refactored.
Quoted 7 lines
Quoted 2 lines
Tom
While Eric's patch might be bigger if you also remove the pre-initialization in the other drivers, the Linux code itself would be smaller (granted not significantly) and it make less room for pitfalls in adding DIM support in other drivers.
Is there a good argument against using Eric's patch other than 'the other patch would be bigger' ?
No, I think it a better approach and if Eric can take it forward that would be great.
However when you start refactoring, it may grow larger than the single fix.
For instance, passing the structure by value could be changed to passing by reference.
Tom
Quoted 8 lines
Shay
Quoted 4 lines
Quoted 4 lines
Thanks,
Shay
Quoted 11 lines · Sun, Jan 08, 2023 at 03:38:43PM CET, [email protected] wrote:
clang static analysis reports this problem
drivers/net/ethernet/amazon/ena/ena_netdev.c:1821:2: warning: Passed-by-value struct
argument contains uninitialized data (e.g., field: 'comp_ctr') [core.CallAndMessage]net_dim(&ena_napi->dim, dim_sample); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
net_dimcan calldim_calc_stats()which uses thecomp_ctrelement, so it must be initialized.Fixes 282faf61a053 ("net: ena: switch to dim algorithm for rx adaptive interrupt moderation")Signed-off-by Tom Rix <[email protected]>