hinic3_set_vport_enable() dereferences hwdev->dev_handle in the
declaration block, before checking hwdev. Move the dereference below the
hwdev check so a NULL hwdev returns an error instead of crashing during
early PF initialization.
Fixes: 9204b6b7bb1a ("net/hinic3: split new/old command queue operations")
Signed-off-by: Jiacheng Ye <[email protected]>
---
drivers/net/hinic3/base/hinic3_nic_cfg.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/hinic3/base/hinic3_nic_cfg.c
b/drivers/net/hinic3/base/hinic3_nic_cfg.c
index 5387626b98..1520f88a1b 100644
--- a/drivers/net/hinic3/base/hinic3_nic_cfg.c
+++ b/drivers/net/hinic3/base/hinic3_nic_cfg.c
@@ -443,12 +443,13 @@ int
hinic3_set_vport_enable(struct hinic3_hwdev *hwdev, bool enable)
{
struct hinic3_vport_state en_state;
- struct hinic3_nic_dev *nic_dev = hwdev->dev_handle;
+ struct hinic3_nic_dev *nic_dev;
uint16_t out_size = sizeof(en_state);
int err;
if (!hwdev)
return -EINVAL;
+ nic_dev = hwdev->dev_handle;
memset(&en_state, 0, sizeof(en_state));
en_state.func_id = hinic3_global_func_id(hwdev);
--
2.33.0