From patchwork Wed May 5 17:42:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland Dreier X-Patchwork-Id: 97160 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o45HgGo1011184 for ; Wed, 5 May 2010 17:42:17 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754529Ab0EERmQ (ORCPT ); Wed, 5 May 2010 13:42:16 -0400 Received: from sj-iport-4.cisco.com ([171.68.10.86]:51285 "EHLO sj-iport-4.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752889Ab0EERmP (ORCPT ); Wed, 5 May 2010 13:42:15 -0400 Authentication-Results: sj-iport-4.cisco.com; dkim=neutral (message not signed) header.i=none X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAJRK4UurR7H+/2dsb2JhbACdTXGlLplkhRMEgz4 X-IronPort-AV: E=Sophos;i="4.52,335,1270425600"; d="scan'208";a="125209821" Received: from sj-core-2.cisco.com ([171.71.177.254]) by sj-iport-4.cisco.com with ESMTP; 05 May 2010 17:42:15 +0000 Received: from roland-alpha.cisco.com (roland-alpha.cisco.com [10.33.42.9]) by sj-core-2.cisco.com (8.13.8/8.14.3) with ESMTP id o45HgF0r023526; Wed, 5 May 2010 17:42:15 GMT Received: by roland-alpha.cisco.com (Postfix, from userid 33217) id D286D20464; Wed, 5 May 2010 10:42:11 -0700 (PDT) From: Roland Dreier To: sebastien dugue Cc: Eli Cohen , linux-rdma Subject: Re: [PATCH] mlx4: Fix chunk sg list overflow in mlx4_alloc_icm() References: <20100430132131.0d829b3c@frecb007965> X-Message-Flag: Warning: May contain useful information Date: Wed, 05 May 2010 10:42:11 -0700 In-Reply-To: <20100430132131.0d829b3c@frecb007965> (sebastien dugue's message of "Fri, 30 Apr 2010 13:21:31 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 05 May 2010 17:42:17 +0000 (UTC) diff --git a/drivers/net/mlx4/icm.c b/drivers/net/mlx4/icm.c index ef62f17..b07e4de 100644 --- a/drivers/net/mlx4/icm.c +++ b/drivers/net/mlx4/icm.c @@ -163,29 +163,30 @@ struct mlx4_icm *mlx4_alloc_icm(struct mlx4_dev *dev, int npages, ret = mlx4_alloc_icm_pages(&chunk->mem[chunk->npages], cur_order, gfp_mask); - if (!ret) { - ++chunk->npages; - - if (coherent) - ++chunk->nsg; - else if (chunk->npages == MLX4_ICM_CHUNK_LEN) { - chunk->nsg = pci_map_sg(dev->pdev, chunk->mem, - chunk->npages, - PCI_DMA_BIDIRECTIONAL); - - if (chunk->nsg <= 0) - goto fail; - } + if (ret) { + if (--cur_order < 0) + goto fail; + else + continue; + } - if (chunk->npages == MLX4_ICM_CHUNK_LEN) - chunk = NULL; + ++chunk->npages; - npages -= 1 << cur_order; - } else { - --cur_order; - if (cur_order < 0) + if (coherent) + ++chunk->nsg; + else if (chunk->npages == MLX4_ICM_CHUNK_LEN) { + chunk->nsg = pci_map_sg(dev->pdev, chunk->mem, + chunk->npages, + PCI_DMA_BIDIRECTIONAL); + + if (chunk->nsg <= 0) goto fail; } + + if (chunk->npages == MLX4_ICM_CHUNK_LEN) + chunk = NULL; + + npages -= 1 << cur_order; } if (!coherent && chunk) {