[2/6] drivers/nfb: fix array indexes in deinit functions
Checks
Commit Message
From: Martin Spinler <spinler@cesnet.cz>
The indexes in the for cycle were wrongly used and
the code accessed outside of the rxmac/txmac array.
Signed-off-by: Martin Spinler <spinler@cesnet.cz>
---
drivers/net/nfb/nfb_ethdev.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
Comments
On 2/14/2022 11:25 AM, spinler@cesnet.cz wrote:
> From: Martin Spinler <spinler@cesnet.cz>
>
> The indexes in the for cycle were wrongly used and
> the code accessed outside of the rxmac/txmac array.
>
can you please add fixes tag, to help backport.
Also please add stable tag to request backport.
> Signed-off-by: Martin Spinler <spinler@cesnet.cz>
> ---
> drivers/net/nfb/nfb_ethdev.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/nfb/nfb_ethdev.c b/drivers/net/nfb/nfb_ethdev.c
> index 3c39937816..0b27fe78cc 100644
> --- a/drivers/net/nfb/nfb_ethdev.c
> +++ b/drivers/net/nfb/nfb_ethdev.c
> @@ -77,9 +77,10 @@ static void
> nfb_nc_rxmac_deinit(struct nc_rxmac *rxmac[RTE_MAX_NC_RXMAC],
> uint16_t max_rxmac)
> {
> - for (; max_rxmac > 0; --max_rxmac) {
> - nc_rxmac_close(rxmac[max_rxmac]);
> - rxmac[max_rxmac] = NULL;
> + uint16_t i;
> + for (i = 0; i < max_rxmac; i++) {
> + nc_rxmac_close(rxmac[i]);
> + rxmac[i] = NULL;
> }
> }
>
> @@ -95,9 +96,10 @@ static void
> nfb_nc_txmac_deinit(struct nc_txmac *txmac[RTE_MAX_NC_TXMAC],
> uint16_t max_txmac)
> {
> - for (; max_txmac > 0; --max_txmac) {
> - nc_txmac_close(txmac[max_txmac]);
> - txmac[max_txmac] = NULL;
> + uint16_t i;
> + for (i = 0; i < max_txmac; i++) {
> + nc_txmac_close(txmac[i]);
> + txmac[i] = NULL;
> }
> }
>
Hi Ferruh,
thanks for all comments in this series.
On Mon, 2022-02-14 at 13:34 +0000, Ferruh Yigit wrote:
> On 2/14/2022 11:25 AM, spinler@cesnet.cz wrote:
> > From: Martin Spinler <spinler@cesnet.cz>
> >
> > The indexes in the for cycle were wrongly used and
> > the code accessed outside of the rxmac/txmac array.
> >
>
> can you please add fixes tag, to help backport.
> Also please add stable tag to request backport.
Tags will be added in v2.
>
> > Signed-off-by: Martin Spinler <spinler@cesnet.cz>
> > ---
> > drivers/net/nfb/nfb_ethdev.c | 14 ++++++++------
> > 1 file changed, 8 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/net/nfb/nfb_ethdev.c b/drivers/net/nfb/nfb_ethdev.c
> > index 3c39937816..0b27fe78cc 100644
> > --- a/drivers/net/nfb/nfb_ethdev.c
> > +++ b/drivers/net/nfb/nfb_ethdev.c
> > @@ -77,9 +77,10 @@ static void
> > nfb_nc_rxmac_deinit(struct nc_rxmac *rxmac[RTE_MAX_NC_RXMAC],
> > uint16_t max_rxmac)
> > {
> > - for (; max_rxmac > 0; --max_rxmac) {
> > - nc_rxmac_close(rxmac[max_rxmac]);
> > - rxmac[max_rxmac] = NULL;
> > + uint16_t i;
> > + for (i = 0; i < max_rxmac; i++) {
> > + nc_rxmac_close(rxmac[i]);
> > + rxmac[i] = NULL;
> > }
> > }
> >
> > @@ -95,9 +96,10 @@ static void
> > nfb_nc_txmac_deinit(struct nc_txmac *txmac[RTE_MAX_NC_TXMAC],
> > uint16_t max_txmac)
> > {
> > - for (; max_txmac > 0; --max_txmac) {
> > - nc_txmac_close(txmac[max_txmac]);
> > - txmac[max_txmac] = NULL;
> > + uint16_t i;
> > + for (i = 0; i < max_txmac; i++) {
> > + nc_txmac_close(txmac[i]);
> > + txmac[i] = NULL;
> > }
> > }
> >
>
@@ -77,9 +77,10 @@ static void
nfb_nc_rxmac_deinit(struct nc_rxmac *rxmac[RTE_MAX_NC_RXMAC],
uint16_t max_rxmac)
{
- for (; max_rxmac > 0; --max_rxmac) {
- nc_rxmac_close(rxmac[max_rxmac]);
- rxmac[max_rxmac] = NULL;
+ uint16_t i;
+ for (i = 0; i < max_rxmac; i++) {
+ nc_rxmac_close(rxmac[i]);
+ rxmac[i] = NULL;
}
}
@@ -95,9 +96,10 @@ static void
nfb_nc_txmac_deinit(struct nc_txmac *txmac[RTE_MAX_NC_TXMAC],
uint16_t max_txmac)
{
- for (; max_txmac > 0; --max_txmac) {
- nc_txmac_close(txmac[max_txmac]);
- txmac[max_txmac] = NULL;
+ uint16_t i;
+ for (i = 0; i < max_txmac; i++) {
+ nc_txmac_close(txmac[i]);
+ txmac[i] = NULL;
}
}