The mana_adev_idx_alloc() can return negative value. Save its return value in ret which is signed variable and check if it is correct value. Fixes: ee928282bfa7 ("net: mana: Add support for auxiliary device") Signed-off-by: Muhammad Usama Anjum <usama.anjum@xxxxxxxxxxxxx> --- drivers/net/ethernet/microsoft/mana/mana_en.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c index 7ca313c7b7b3..1c59502d34b5 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -2203,11 +2203,10 @@ static int add_adev(struct gdma_dev *gd) return -ENOMEM; adev = &madev->adev; - adev->id = mana_adev_idx_alloc(); - if (adev->id < 0) { - ret = adev->id; + ret = mana_adev_idx_alloc(); + if (ret < 0) goto idx_fail; - } + adev->id = ret; adev->name = "rdma"; adev->dev.parent = gd->gdma_context->dev; -- 2.30.2