net/kni: initialize rte_kni_conf to 0 before using it

Message ID 20220302123400.188209-1-baymaxhuang@gmail.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series net/kni: initialize rte_kni_conf to 0 before using it |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/github-robot: build fail github build: failed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Harold Huang March 2, 2022, 12:33 p.m. UTC
  When kni driver calls eth_kni_start to start device, some fields such as
min_mtu and max_mtu of rte_kni_conf are not initialized. It will cause
kni_ioctl_create create a kni netdevice with a random min_mtu and max_mtu
value. This is unexpected and in some time we could not change the kni
device mtu with ip link command.

Fixes: ff1e35fb5f8 ("kni: calculate MTU from mbuf size")
Signed-off-by: Harold Huang <baymaxhuang@gmail.com>
---
 drivers/net/kni/rte_eth_kni.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Ferruh Yigit March 2, 2022, 6:16 p.m. UTC | #1
On 3/2/2022 12:33 PM, Harold Huang wrote:
> When kni driver calls eth_kni_start to start device, some fields such as
> min_mtu and max_mtu of rte_kni_conf are not initialized. It will cause
> kni_ioctl_create create a kni netdevice with a random min_mtu and max_mtu
> value. This is unexpected and in some time we could not change the kni
> device mtu with ip link command.
> 

Agree on the problem and the solution, thanks for the fix.

> Fixes: ff1e35fb5f8 ("kni: calculate MTU from mbuf size")
> Signed-off-by: Harold Huang <baymaxhuang@gmail.com>
> ---
>   drivers/net/kni/rte_eth_kni.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.c
> index c428caf441..23b15edfac 100644
> --- a/drivers/net/kni/rte_eth_kni.c
> +++ b/drivers/net/kni/rte_eth_kni.c
> @@ -128,6 +128,7 @@ eth_kni_start(struct rte_eth_dev *dev)
>   	const char *name = dev->device->name + 4; /* remove net_ */
>   
>   	mb_pool = internals->rx_queues[0].mb_pool;
> +	memset(&conf, 0, sizeof(conf));

Can you prefer initialize to zero, instead of 'memset', I think it
is more clear that way:

  -       struct rte_kni_conf conf;
  +       struct rte_kni_conf conf = { 0 };

>   	strlcpy(conf.name, name, RTE_KNI_NAMESIZE);
>   	conf.force_bind = 0;
>   	conf.group_id = port_id;
  
Harold Huang March 3, 2022, 1:57 a.m. UTC | #2
On Thu, Mar 3, 2022 at 2:16 AM Ferruh Yigit <ferruh.yigit@intel.com> wrote:
>
> On 3/2/2022 12:33 PM, Harold Huang wrote:
> > When kni driver calls eth_kni_start to start device, some fields such as
> > min_mtu and max_mtu of rte_kni_conf are not initialized. It will cause
> > kni_ioctl_create create a kni netdevice with a random min_mtu and max_mtu
> > value. This is unexpected and in some time we could not change the kni
> > device mtu with ip link command.
> >
>
> Agree on the problem and the solution, thanks for the fix.
>
> > Fixes: ff1e35fb5f8 ("kni: calculate MTU from mbuf size")
> > Signed-off-by: Harold Huang <baymaxhuang@gmail.com>
> > ---
> >   drivers/net/kni/rte_eth_kni.c | 1 +
> >   1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.c
> > index c428caf441..23b15edfac 100644
> > --- a/drivers/net/kni/rte_eth_kni.c
> > +++ b/drivers/net/kni/rte_eth_kni.c
> > @@ -128,6 +128,7 @@ eth_kni_start(struct rte_eth_dev *dev)
> >       const char *name = dev->device->name + 4; /* remove net_ */
> >
> >       mb_pool = internals->rx_queues[0].mb_pool;
> > +     memset(&conf, 0, sizeof(conf));
>
> Can you prefer initialize to zero, instead of 'memset', I think it
> is more clear that way:

Thanks. Sounds good,  fix it.

>
>   -       struct rte_kni_conf conf;
>   +       struct rte_kni_conf conf = { 0 };
>
> >       strlcpy(conf.name, name, RTE_KNI_NAMESIZE);
> >       conf.force_bind = 0;
> >       conf.group_id = port_id;
>
  

Patch

diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.c
index c428caf441..23b15edfac 100644
--- a/drivers/net/kni/rte_eth_kni.c
+++ b/drivers/net/kni/rte_eth_kni.c
@@ -128,6 +128,7 @@  eth_kni_start(struct rte_eth_dev *dev)
 	const char *name = dev->device->name + 4; /* remove net_ */
 
 	mb_pool = internals->rx_queues[0].mb_pool;
+	memset(&conf, 0, sizeof(conf));
 	strlcpy(conf.name, name, RTE_KNI_NAMESIZE);
 	conf.force_bind = 0;
 	conf.group_id = port_id;