Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3099601ybi; Thu, 18 Jul 2019 21:01:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUPnabh+2jsBw6xw4UF/mPlkmn6iDAVDQNoqC3MfHicyqkZDV+1YsKXwTNcXX3gAsuRDEy X-Received: by 2002:a63:e010:: with SMTP id e16mr46227395pgh.285.1563508901131; Thu, 18 Jul 2019 21:01:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563508901; cv=none; d=google.com; s=arc-20160816; b=vrt12BiyfAsbidElgexZkbFAfUO9nO9OO1gHgS+tgbWZgKfw5GGUZEGogOe12SM7E6 iHT8WkN2Ooyy/BRAil73Q7LRGpTiJfd8Ne+MjVXdMg9mNfNSggMWhJmWjk7TWXhJ4HMg viFV14Z+HFE6/qDauhjLr5VsZI+yL8gTHTFHJbBxJJFXYxJK1q9DOhKrZTE5VgZx9TSo qpWfvJe0GXUO2gIH8lc8SYg7oQvGFAx3AxKOfc7cfJsdeioxyv7s5TvDVKY71DU/9nFf 6NaqyVzMWnNv1KedW9KAChm6AEyEtpNvlDkRPIyTjnWXplXfpJ4vR9yNgbmOkSMqRuZT /j0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=W9/RszGK6e/lLEP6592qYysbfcgU/E9lJ/uTWuPo3zE=; b=Ij3QXaHQr48yKmTMZR9tph1N9JBRHbGNcMyeSMzIm7V+xEiASJGiT9kRPMS1pW7Fzn BzS9O/1RSz0lYnOMQg62jG1UUBCVJqCQ/Fm9CTCO41HtITqp/7dto8T2ZS6JICyT+T/v m2FlcbHoEvIKHaqVt/Jp5ns1g4qbDeOrFyq1thJ0Z8BbysWZn5iWa7T72hZwELIbzILq xkmx9/JR5I0mJsZf0RFQc8F6uy4jTI+sYBRVSk78xzwIoFAUNJv/edzUc/zC5ca3Jkx1 eSy3TqK65eCGB2oKcqbPxamoJHXoki6mGPz2tA4svVF0uYwoMFsiVL7grYW8yovKZz7a lbiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yRti8pnJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f7si740387pgr.536.2019.07.18.21.01.25; Thu, 18 Jul 2019 21:01:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yRti8pnJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727437AbfGSEAi (ORCPT + 99 others); Fri, 19 Jul 2019 00:00:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:60396 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729053AbfGSEAb (ORCPT ); Fri, 19 Jul 2019 00:00:31 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6A2AB21873; Fri, 19 Jul 2019 04:00:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508830; bh=4bB8qtrnRPBP80hwpyceHPKXuR1qkIAQivDFdyKUZ9Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yRti8pnJ3v8NaBtXQjjuVYkhF8JD/9pfQXnGY4m6UaIKQ0sjfYOgEiRnueix2a/ez oPQtHCTIL1p+USf6wolwsWkyF3q8cxM7sVrSMuxpupiSaroa88b2++cyE3Bqsa3p3z FWeGEe9Xpy2GSsjPW14tnE0ptUTSaJ2WP3nwjmQs= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Valentine Fatiev , Feras Daoud , Leon Romanovsky , Jason Gunthorpe , Sasha Levin , linux-rdma@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 113/171] IB/ipoib: Add child to parent list only if device initialized Date: Thu, 18 Jul 2019 23:55:44 -0400 Message-Id: <20190719035643.14300-113-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719035643.14300-1-sashal@kernel.org> References: <20190719035643.14300-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Valentine Fatiev [ Upstream commit 91b01061fef9c57d2f5b712a6322ef51061f4efd ] Despite failure in ipoib_dev_init() we continue with initialization flow and creation of child device. It causes to the situation where this child device is added too early to parent device list. Change the logic, so in case of failure we properly return error from ipoib_dev_init() and add child only in success path. Fixes: eaeb39842508 ("IB/ipoib: Move init code to ndo_init") Signed-off-by: Valentine Fatiev Reviewed-by: Feras Daoud Signed-off-by: Leon Romanovsky Reviewed-by: Jason Gunthorpe Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/ulp/ipoib/ipoib_main.c | 34 +++++++++++++---------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c index 9b5e11d3fb85..bb904ec511be 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_main.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c @@ -1893,12 +1893,6 @@ static void ipoib_child_init(struct net_device *ndev) struct ipoib_dev_priv *priv = ipoib_priv(ndev); struct ipoib_dev_priv *ppriv = ipoib_priv(priv->parent); - dev_hold(priv->parent); - - down_write(&ppriv->vlan_rwsem); - list_add_tail(&priv->list, &ppriv->child_intfs); - up_write(&ppriv->vlan_rwsem); - priv->max_ib_mtu = ppriv->max_ib_mtu; set_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags); memcpy(priv->dev->dev_addr, ppriv->dev->dev_addr, INFINIBAND_ALEN); @@ -1941,6 +1935,17 @@ static int ipoib_ndo_init(struct net_device *ndev) if (rc) { pr_warn("%s: failed to initialize device: %s port %d (ret = %d)\n", priv->ca->name, priv->dev->name, priv->port, rc); + return rc; + } + + if (priv->parent) { + struct ipoib_dev_priv *ppriv = ipoib_priv(priv->parent); + + dev_hold(priv->parent); + + down_write(&ppriv->vlan_rwsem); + list_add_tail(&priv->list, &ppriv->child_intfs); + up_write(&ppriv->vlan_rwsem); } return 0; @@ -1958,6 +1963,14 @@ static void ipoib_ndo_uninit(struct net_device *dev) */ WARN_ON(!list_empty(&priv->child_intfs)); + if (priv->parent) { + struct ipoib_dev_priv *ppriv = ipoib_priv(priv->parent); + + down_write(&ppriv->vlan_rwsem); + list_del(&priv->list); + up_write(&ppriv->vlan_rwsem); + } + ipoib_neigh_hash_uninit(dev); ipoib_ib_dev_cleanup(dev); @@ -1969,15 +1982,8 @@ static void ipoib_ndo_uninit(struct net_device *dev) priv->wq = NULL; } - if (priv->parent) { - struct ipoib_dev_priv *ppriv = ipoib_priv(priv->parent); - - down_write(&ppriv->vlan_rwsem); - list_del(&priv->list); - up_write(&ppriv->vlan_rwsem); - + if (priv->parent) dev_put(priv->parent); - } } static int ipoib_set_vf_link_state(struct net_device *dev, int vf, int link_state) -- 2.20.1