Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4081652ybi; Mon, 29 Jul 2019 18:51:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqw0Oy88c9kE+7U+YuPoLfMXaaIzhoqJw8uOQDFHeUjBwUTGfSCbpQCmqeK2LQ2Jzejhg4oL X-Received: by 2002:a17:90a:d814:: with SMTP id a20mr115035627pjv.48.1564451497928; Mon, 29 Jul 2019 18:51:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564451497; cv=none; d=google.com; s=arc-20160816; b=AFO1WGPVHWEv+MC4mO0xq1ttRXmnv0qOtcGQH91XIbFKIfPFfeTRSsxswzltpBX+Pp D9H2X2UAwvY19ATfSGcTW4mO/+DoBY20REUj8PX2SXsOhPhGrj1CvwFccP+hOAGEOYdN rmmjY6+DfPEMzqKDbBRPe+0k6sc0Y5m74LzTDuMKfvGZtjicyCTOMaIKExiatfO8N7+0 iI3yFERRY+3EhQnsskoqLyAZRUYRFp9UGxXzXZnLbUggpoJH/Joz8ghIJ/616OQehNrx Fxff9pCLb6PZwAHf/IJXvdim+Ti8OjaSmX1XkogiZygP14mezMavATglMurgrvLbOR90 WLRA== 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=f5eWInr5OwCFs9ZVbg7KwOgdacdrPcW7xXtFI1kRa2c=; b=bEzpKPPhirZTH78VQmQ1aHLFZ97l3BfeMK7puMgUcEZfwLz9LQsW5x+LlEPXjolTu+ aKzAQMQePGMoOyD85k6yPsCwGTDLvcOmw8ylj3iOYGYmPuCTCRNbeQOGO5Xa53RijOF7 vgVgoAWiHlKRQhwgGVll4HH0hKKZUG5LrKxCdpQ38SRRDUDtRizxANgwH3MQ21hDO1vJ wpQLn51UQa0/cFPSqxyMcnOXneCANd3qlvG2HU/KPHoMsi6gp99rkvMsr069X5TZla/d fuEAVvsgSXXXlk8PkAZvLaAUIm1WemxZpinw1ZZGP51jK4J0CvRtaJPcFn3mSH27q6b0 L6Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b7iB2uHd; 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 h6si28552186pgc.202.2019.07.29.18.51.23; Mon, 29 Jul 2019 18:51:37 -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=b7iB2uHd; 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 S2389096AbfG2TmC (ORCPT + 99 others); Mon, 29 Jul 2019 15:42:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:57580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388566AbfG2TmB (ORCPT ); Mon, 29 Jul 2019 15:42:01 -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 5E08220C01; Mon, 29 Jul 2019 19:41:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429319; bh=O1vQYt8aWgXf55lft2fOPPZ64nQp9DyO7NU2Lkv8ZnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b7iB2uHdW6QDgQKk/tLV8jwWHpAh7qSOzzXcoD6kjFaQ+8cXkPJdiAFt9NeHXBm0M K+K/V9ZG6k5m1N7wX3Y/tIXbjq/tGspHck4DJ57HXhwp2aQzus82OfUIdevFWtJxde LCw5QgT6Pe4jJA83l01TrJP/CnNXhJIuxAz4BXTk= 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 4.19 060/113] IB/ipoib: Add child to parent list only if device initialized Date: Mon, 29 Jul 2019 21:22:27 +0200 Message-Id: <20190729190709.867511240@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190655.455345569@linuxfoundation.org> References: <20190729190655.455345569@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 009615499b37..78dd36daac00 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_main.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c @@ -1892,12 +1892,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); @@ -1940,6 +1934,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; @@ -1957,6 +1962,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); @@ -1968,15 +1981,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