Received: by 10.192.165.148 with SMTP id m20csp842603imm; Fri, 27 Apr 2018 08:22:10 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo8tQYkb3B1RTPU+dFSNz4KfqETmkg0MvSh8QsTXorHNmwsEkObevezOYeSQvCTrvIZ7yD9 X-Received: by 10.98.17.220 with SMTP id 89mr2621848pfr.18.1524842530833; Fri, 27 Apr 2018 08:22:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524842530; cv=none; d=google.com; s=arc-20160816; b=A8DtXg/vRNISbtei1AhWlYncEoNvIsyYPZ5UQqn4IdcHQierVW+ZVAgz3JhtXvTuY7 O0j7di+JNMqgAHG7zm35ksFzv+0M9k+KQHkAv9WBRvtf3rSCiXcUsZ2l1MJzxiR65G4A oQkbATWFO+nJOi2tMI0C90/ZYNouqwUe1zAOsFV1Ae+EqR3a7WE203jx1QmkdU5CLg84 1Irm1kt3trAGYjBKGiG2BHrNjp4JQDpTwmTmSEcoPohgP3m0Mj3mVdCQxi1wYsOpTkcD Kv634EfTR9Tgy4iQToA8P7SrUyV/pg4WhwDMZKhjaGpDiIoIXJlaQ4NwY65a5KRlt2Mp kBeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:message-id:date :mime-version:dkim-signature:arc-authentication-results; bh=/G4gg4n9OR95TLf+naocvHVTrHOrq6OU+6XH9hUr+pg=; b=QsVtMiWV9kLZQEO4ZVT0Msdqt/m01D1ZpbbOpbsG66+2sAxPcmlyot7DP+twN2qhCC Zy7t2F3E1g5D8cVWp9fH15AmeCT3jSqVeLq+Taxily90n3KiNQqTwEo2xo6aD5gsXGVx K8/n45uF4J2T46r8+2gQa6K5IRajmWSj23McgTKnc6LvdIOppTPtjDcq8/m3Udua7vbx SSrQN04pByppVsKYJQUHC5QiYPdcEwzQEw3J+Ca6EpCLwCUOgqWABNYHK6msicEEIkli AmPBSG5mUzsJwSyqQT9EgdNWEbL+wsm1nF6s52SfGjrfkRA3OxQgpgpBL6qtuoOCG2hH xyhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=H/WrDwrW; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f13-v6si1314674pgp.666.2018.04.27.08.21.56; Fri, 27 Apr 2018 08:22:10 -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=@google.com header.s=20161025 header.b=H/WrDwrW; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933742AbeD0PU4 (ORCPT + 99 others); Fri, 27 Apr 2018 11:20:56 -0400 Received: from mail-yw0-f202.google.com ([209.85.161.202]:38897 "EHLO mail-yw0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932850AbeD0PUt (ORCPT ); Fri, 27 Apr 2018 11:20:49 -0400 Received: by mail-yw0-f202.google.com with SMTP id i187-v6so948426ywg.5 for ; Fri, 27 Apr 2018 08:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:message-id:subject:from:to:cc; bh=/G4gg4n9OR95TLf+naocvHVTrHOrq6OU+6XH9hUr+pg=; b=H/WrDwrW8ohWAJHIyvx4nXaE9PuIpZdGIfWFDie1o8jOgASyVBhXijaK/W/EaL3ty5 TTEwQo6v2MFLUwLxnvooIh9eil9Y9pEQ5NdS1UXJWsml0+uxvKGD8Cd3oVPTcmuXKzOj BI1gmzoJfl5w3ND8U8DcOMZjIHt/Vl3cZEtVSWr12wu3fhIh3aofhXp+7jhygm8liX9b waBZndFCkw+PmwXFOhYI95W55HuxN4sGrr3Y0MDsDw3rNEzRkeO8y0D+K1sa4YTxq9eP 0g13jKOpB2CVbxmqkYlFp5E8kL5X9z6oTUDl94Rn9PNS0X22BQgY+7I4xoU0yv+KDZEJ HL/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc; bh=/G4gg4n9OR95TLf+naocvHVTrHOrq6OU+6XH9hUr+pg=; b=L7ogG9lBSHCahX88ti8Nmo/UaVbABFbKe3YX7oLE8vsDJxTxVVx3bArBIgeh9ks9KW VdMR7WJaA5OVVXMGv2ZwDf8rziS8PFLrL9n9D+K8yuORMCxcyjwHQ5auoBl/cXuO2/W5 FZeGbxSYX24x+J1/oJ5o6l/dKoNxW3kPGc7ytI6hXFD4kximJzOY5LJyjAW79fpSY8Bh iALRzSUE7qvu0ktBSQqeys2rEGLUCtjqUjiinG/9/fUvS81vukjkWvQMDfwzgk0iNbqU a/CuyQaRytWXV5rrHm7FvIaq8xC+s/3bllK7attsHOIoe04XPvXNsDDcYvW1GNqoHkAL iQCQ== X-Gm-Message-State: ALQs6tCuqHl1I4cLhoe9hrTV7TNi95OMj4mwb33Gs7kNkN4xY4cIPaSj 02zjPWHQg6CT3KSWI34LgN5+WmXM8w== MIME-Version: 1.0 X-Received: by 2002:a25:384b:: with SMTP id f72-v6mr758507yba.13.1524842448395; Fri, 27 Apr 2018 08:20:48 -0700 (PDT) Date: Fri, 27 Apr 2018 08:20:15 -0700 Message-Id: <20180427152015.185861-1-tarick@google.com> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog Subject: [PATCH] net/mlx4_core: Fix error handling in mlx4_init_port_info. From: Tarick Bedeir To: tariqt@mellanox.com, gthelen@google.com, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, tarick@google.com Cc: Greg Thelen , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Tarick Bedeir Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Avoid exiting the function with a lingering sysfs file (if the first call to device_create_file() fails while the second succeeds), and avoid calling devlink_port_unregister() twice. In other words, either mlx4_init_port_info() succeeds and returns zero, or it fails, returns non-zero, and requires no cleanup. Signed-off-by: Tarick Bedeir --- drivers/net/ethernet/mellanox/mlx4/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c index 4d84cab77105..e8a3a45d0b53 100644 --- a/drivers/net/ethernet/mellanox/mlx4/main.c +++ b/drivers/net/ethernet/mellanox/mlx4/main.c @@ -3007,6 +3007,7 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port) mlx4_err(dev, "Failed to create file for port %d\n", port); devlink_port_unregister(&info->devlink_port); info->port = -1; + return err; } sprintf(info->dev_mtu_name, "mlx4_port%d_mtu", port); @@ -3028,9 +3029,10 @@ static int mlx4_init_port_info(struct mlx4_dev *dev, int port) &info->port_attr); devlink_port_unregister(&info->devlink_port); info->port = -1; + return err; } - return err; + return 0; } static void mlx4_cleanup_port_info(struct mlx4_port_info *info) -- 2.17.0.441.gb46fe60e1d-goog