From patchwork Tue Feb 9 20:11:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 8265591 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 379D6BEEE5 for ; Tue, 9 Feb 2016 20:14:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5F725201EC for ; Tue, 9 Feb 2016 20:14:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 757D4201BC for ; Tue, 9 Feb 2016 20:13:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932534AbcBIUMX (ORCPT ); Tue, 9 Feb 2016 15:12:23 -0500 Received: from mail-wm0-f50.google.com ([74.125.82.50]:33469 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932689AbcBIULa (ORCPT ); Tue, 9 Feb 2016 15:11:30 -0500 Received: by mail-wm0-f50.google.com with SMTP id g62so142390wme.0 for ; Tue, 09 Feb 2016 12:11:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XiQXkH61nNlTsW6maojuQa/hFStgJlQq5Fwcb28xzQY=; b=VG4DIsnyTDuS/Tux110Jar7l6c702xO1UJcLpCWAhe6Stg/HD5E/+qHNN1SystAayi j/SFJR6kX+6RJ1amvJQs5+N3nobyJ39/KNWy5kiCF3DLIro3qP2nvBAwPI+uqXm+jljW uQoen7uyUNB/mugwmj1LzgxrmHgOJxaMCxy5o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XiQXkH61nNlTsW6maojuQa/hFStgJlQq5Fwcb28xzQY=; b=NyrxHQnGyVRGS8d0pQ1vnlaWwXiOeh12LMdibwuhUPZaIYXhdPySJYsPK4530s+pXz dwkLEffW0hPdUVILTliF4JH/PalaxMfGvcjQbFBtGr+r237uSzwzd2bt2x9b4fLCCD1l 0jNd8iRUEsqmfDS2qkaZ5ib4TeflaaKXPaIwsZMnjBQ0/VIxdWkI6xZwESStT8fn4I+/ vY5IoemrJ3MxOHGwieFh6RGkq2HTF1ZVzM0NecZBvfGUGjx9Wi7SaaGadIdhQY2zC8ox 58jsPSL93mwaJ0XXbDNG6B1F35MHVfDQK/3w6Reyh3WuRB+f995uaxXxPxUQYbODFJCJ z7iw== X-Gm-Message-State: AG10YORzu/0MbO41KvfSLlwlqQK3HwXVD5VDCi/Cz1LdAszZbAc6onQYZ2g1jTCx0gLxxg== X-Received: by 10.28.125.211 with SMTP id y202mr6482232wmc.18.1455048689760; Tue, 09 Feb 2016 12:11:29 -0800 (PST) Received: from wildmoose.dk (lvps87-230-87-209.dedicated.hosteurope.de. [87.230.87.209]) by smtp.gmail.com with ESMTPSA id h14sm1384331wjs.41.2016.02.09.12.11.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Feb 2016 12:11:29 -0800 (PST) From: Rasmus Villemoes To: Yishai Hadas Cc: Rasmus Villemoes , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] net/mlx4: fix some error handling in mlx4_multi_func_init() Date: Tue, 9 Feb 2016 21:11:14 +0100 Message-Id: <1455048677-19882-4-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455048677-19882-1-git-send-email-linux@rasmusvillemoes.dk> References: <1455048677-19882-1-git-send-email-linux@rasmusvillemoes.dk> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The while loop after err_slaves should use post-decrement; otherwise we'll fail to do the kfrees for i==0, and will run into out-of-bounds accesses if the setup above failed already at i==0. The predecrement in the --port is ok, since ->vlan_filter is (bizarrely) 1-indexed. But I'm changing 'if' to 'while' since it's a bit ugly to rely on MLX4_MAX_PORTS being 2. [I'm not sure why one even bothers populating the ->vlan_filter array: mlx4.h isn't #included by anything outside drivers/net/ethernet/mellanox/mlx4/, and "git grep -C2 -w vlan_filter drivers/net/ethernet/mellanox/mlx4/" seems to suggest that the vlan_filter elements aren't used at all.] Signed-off-by: Rasmus Villemoes --- drivers/net/ethernet/mellanox/mlx4/cmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/cmd.c b/drivers/net/ethernet/mellanox/mlx4/cmd.c index d48d5793407d..bfe8234abbba 100644 --- a/drivers/net/ethernet/mellanox/mlx4/cmd.c +++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c @@ -2369,7 +2369,7 @@ int mlx4_multi_func_init(struct mlx4_dev *dev) kzalloc(sizeof(struct mlx4_vlan_fltr), GFP_KERNEL); if (!s_state->vlan_filter[port]) { - if (--port) + while (--port) kfree(s_state->vlan_filter[port]); goto err_slaves; } @@ -2429,7 +2429,7 @@ err_thread: flush_workqueue(priv->mfunc.master.comm_wq); destroy_workqueue(priv->mfunc.master.comm_wq); err_slaves: - while (--i) { + while (i--) { for (port = 1; port <= MLX4_MAX_PORTS; port++) kfree(priv->mfunc.master.slave_state[i].vlan_filter[port]); }