Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3105905ybi; Thu, 18 Jul 2019 21:08:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8LdmZYA2hQRPZfa2cdoOVi0HL/B/G7vX3b1ENl1km9ytnoXdJzOu5P/IfjGtgWYRVPCZx X-Received: by 2002:a17:902:9896:: with SMTP id s22mr52081378plp.4.1563509298544; Thu, 18 Jul 2019 21:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563509298; cv=none; d=google.com; s=arc-20160816; b=dU+QWTdZFi/lOG8qzZxx6GbR1RhcnWvM4+IEWfUWapcc9nzsHlmg/UOvSPTP7rztjC fvAncVCCcBnxOnf0R98KeRfoR+h2FASBGOP31K3WhVdwECW4wxZ0K+Z0HiCZjb5wVD1c KwKDqzVluHzxEupEcQutqzYSQJxzpc8N4Q6t00Kg3EI3ad9MydCy+G35l4Z3bXZZsZqL UWlL3+8iuevXsBo70Lwv6GltZQarooBbvQnGjgmDTT3ObsrIHE0Sqwu+BDxpS5ogUIV4 Kbd51h2pOGksHyr7oY5HoYvyGcRv+qXrZOaXafvxSGeWQW8H2GyRcf5kVqt/5kfuUUCc 0yug== 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=M/6vNz0SJRLICbauC9fREJMFSRI30yDhHrxi+/FYALfOeq5v0Sz6uiXyc5TXw1qeHd Dt3TGpNIE2Qzca8533srqU4N/yOlKKVCuViz4ityuiLh/Aw4oxJ181Z1JU4reEouo/+U IXV2B+TxXGHhWjad9MH5AASWVy5SISTy/44PsG1VZiW5QOtsgjrfq9A/PmdZ2z4XMngk eThUKsAQ+qqcKz/Uuu0gosriXOW/gQVQNORyV8i1joRFytivnV7EL+uonuB+R9wXiJQU P1g5hOxXJzH6U0/JZeaXsONGW/23JaOQkoW8uPI4b+p0cSAiuoLrD+bk6/ERp0gbdDpu P3ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UL7NRhUQ; 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 t15si3404854pjr.46.2019.07.18.21.08.03; Thu, 18 Jul 2019 21:08:18 -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=UL7NRhUQ; 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 S1731771AbfGSEFh (ORCPT + 99 others); Fri, 19 Jul 2019 00:05:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:38032 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731747AbfGSEFc (ORCPT ); Fri, 19 Jul 2019 00:05:32 -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 731E3218A3; Fri, 19 Jul 2019 04:05:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563509131; bh=4bB8qtrnRPBP80hwpyceHPKXuR1qkIAQivDFdyKUZ9Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UL7NRhUQ0R2FogDB+gqZk+S1VdEPfA90iMJR7qKmYC+3wXqiw0ILQPo+Af+Rxbzl0 mbkPai4c7JrIMtFqpr2afVD8QXgnxDQRJhMhe/r/GH9/GDtzCMhY43rbMl9ZubKXrv 4+R7FjRwuajD4MecrTky4IOekdPB9TUT7FFGdNaQ= 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.1 087/141] IB/ipoib: Add child to parent list only if device initialized Date: Fri, 19 Jul 2019 00:01:52 -0400 Message-Id: <20190719040246.15945-87-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719040246.15945-1-sashal@kernel.org> References: <20190719040246.15945-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