Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3799745ybi; Mon, 29 Jul 2019 12:52:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqy/4Bp7qBM5JSnMzM+75lnx2kl/51Qk4WUB/udSCDqcSgaWd/yxJt3CvxyNpMA01gqynaVy X-Received: by 2002:a17:90a:2305:: with SMTP id f5mr119400963pje.128.1564429942644; Mon, 29 Jul 2019 12:52:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429942; cv=none; d=google.com; s=arc-20160816; b=q7NbWvd3tqEfd4MlINb5EctOaDT1BF4jIgn/2BzXjUswuus13ZTuKhMSLHxuSxmdOX vqREkRBEz25St/+etbv9lXfB0PwTIl0qQTC0fZktGkf27ArwRKnEuYKWx0It1mbvZjET /lNAsAsPuGiLCdHPjWZYpTNv2hfLY2G1lKxOfs0UHVYA9jzlXOE7v8gnmCNWzzidBq2G 75xnI3W9dR56UX0Uo7DIxFs7Xbvi0i3nFUpMQmBroYGvN/A8rz2YNSCOR9vSYAOCOdPI 43wuyxmVumYX7CeqvRrTIDOz/Gb3RtsrxXHtL5uhYVPhzmOtasYwUnYush3CME2jp5FN Z4cQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zDHta7fm8q3wkkhaS/7oBRhkiC1OAxb9VbdwFoDxbdE=; b=k9/2cYFGTV+QVDaCfptZrQfy0+BJm5440znem+wSCNX1xL1h1ISKYH1pMkQyLkBeq6 Z2br16s0sYwCyAGd57CzBUyQMbU6udcDHjIONFz2NNdoP3gqMgqrVB+oHAStN5wE5TlZ 7QtVLzTJvenUdwo85aPQUQ+qkZZQwH9buSY3C1QBqAEmC6dGdzsIoow/yn/mJ+fBZsuR M/m/8nvvWiGL2XjZL/iirUdoooJ7lEccRjJI0g9mWoUgG2WmEL7U/QJzxKyJ/9Ma83LM Bzk+N8bnlU63kMGDlQm1C/IV6ufcD1JwLrZ536fb9fH6dbJ8tqsNMdXW7aQfMnQdRejJ PCMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="t/Oxu7GT"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j66si25074128plb.375.2019.07.29.12.52.07; Mon, 29 Jul 2019 12:52:22 -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="t/Oxu7GT"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403783AbfG2Tun (ORCPT + 99 others); Mon, 29 Jul 2019 15:50:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:41696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390689AbfG2Tul (ORCPT ); Mon, 29 Jul 2019 15:50:41 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F3FFD217D4; Mon, 29 Jul 2019 19:50:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429840; bh=4Xp/Wz0f66uXN/TMOUoQ0CTQLjGaQbFCqB8iIXAjPIw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t/Oxu7GTZETaNZ6Q8+u8rWn1i7jjtWQr690DapcKAlRhMm70xKl1oEFyK2oCsfibg RuZJtYrZEXCmx+N/ZJu35mvk0zFItkG28uOeJ1K23ZylsotWylA2kMWAGBEFapwLr1 F/26accjyJGJUJDNwFIhG4KE7G3hXoloQ2bcRVQc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Valentine Fatiev , Feras Daoud , Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.2 111/215] IB/ipoib: Add child to parent list only if device initialized Date: Mon, 29 Jul 2019 21:21:47 +0200 Message-Id: <20190729190758.172267917@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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 04ea7db08e87..ac0583ff280d 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