Skip to content

Commit 9da667e

Browse files
stefano-garzarellamstsirkin
authored andcommitted
vdpa_sim_net: complete the initialization before register the device
Initialization must be completed before calling _vdpa_register_device() since it can connect the device to the vDPA bus, so requests can arrive after that call. So for example vdpasim_net_work(), which uses the net->*_stats variables, can be scheduled before they are initialized. Let's move _vdpa_register_device() to the end of vdpasim_net_dev_add() and add a comment to avoid future issues. Fixes: 0899774 ("vdpa_sim_net: vendor satistics") Signed-off-by: Stefano Garzarella <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Jason Wang <[email protected]>
1 parent f0417e7 commit 9da667e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

drivers/vdpa/vdpa_sim/vdpa_sim_net.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,16 +466,21 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
466466

467467
vdpasim_net_setup_config(simdev, config);
468468

469-
ret = _vdpa_register_device(&simdev->vdpa, VDPASIM_NET_VQ_NUM);
470-
if (ret)
471-
goto reg_err;
472-
473469
net = sim_to_net(simdev);
474470

475471
u64_stats_init(&net->tx_stats.syncp);
476472
u64_stats_init(&net->rx_stats.syncp);
477473
u64_stats_init(&net->cq_stats.syncp);
478474

475+
/*
476+
* Initialization must be completed before this call, since it can
477+
* connect the device to the vDPA bus, so requests can arrive after
478+
* this call.
479+
*/
480+
ret = _vdpa_register_device(&simdev->vdpa, VDPASIM_NET_VQ_NUM);
481+
if (ret)
482+
goto reg_err;
483+
479484
return 0;
480485

481486
reg_err:

0 commit comments

Comments
 (0)