diff options
| author | Roland Dreier <rolandd@cisco.com> | 2010-05-20 18:58:22 -0400 |
|---|---|---|
| committer | Roland Dreier <rolandd@cisco.com> | 2010-05-20 18:58:22 -0400 |
| commit | c050def076bfbc4513ee961c77fde6ba3d401158 (patch) | |
| tree | b5c6e4a7a192eea51e587a10a5bb1a627290ff4a | |
| parent | c0dc72bad9cf21071f5e4005de46f7c8b67a138a (diff) | |
mlx4_core: Clean up mlx4_alloc_icm() a bit
Handle the allocation error case first, so that we don't have further
nested if for handling the common case of success.
Signed-off-by: Roland Dreier <rolandd@cisco.com>
| -rw-r--r-- | drivers/net/mlx4/icm.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/drivers/net/mlx4/icm.c b/drivers/net/mlx4/icm.c index ef62f1749b8..b07e4dee80a 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, | |||
| 163 | ret = mlx4_alloc_icm_pages(&chunk->mem[chunk->npages], | 163 | ret = mlx4_alloc_icm_pages(&chunk->mem[chunk->npages], |
| 164 | cur_order, gfp_mask); | 164 | cur_order, gfp_mask); |
| 165 | 165 | ||
| 166 | if (!ret) { | 166 | if (ret) { |
| 167 | ++chunk->npages; | 167 | if (--cur_order < 0) |
| 168 | 168 | goto fail; | |
| 169 | if (coherent) | 169 | else |
| 170 | ++chunk->nsg; | 170 | continue; |
| 171 | else if (chunk->npages == MLX4_ICM_CHUNK_LEN) { | 171 | } |
| 172 | chunk->nsg = pci_map_sg(dev->pdev, chunk->mem, | ||
| 173 | chunk->npages, | ||
| 174 | PCI_DMA_BIDIRECTIONAL); | ||
| 175 | |||
| 176 | if (chunk->nsg <= 0) | ||
| 177 | goto fail; | ||
| 178 | } | ||
| 179 | 172 | ||
| 180 | if (chunk->npages == MLX4_ICM_CHUNK_LEN) | 173 | ++chunk->npages; |
| 181 | chunk = NULL; | ||
| 182 | 174 | ||
| 183 | npages -= 1 << cur_order; | 175 | if (coherent) |
| 184 | } else { | 176 | ++chunk->nsg; |
| 185 | --cur_order; | 177 | else if (chunk->npages == MLX4_ICM_CHUNK_LEN) { |
| 186 | if (cur_order < 0) | 178 | chunk->nsg = pci_map_sg(dev->pdev, chunk->mem, |
| 179 | chunk->npages, | ||
| 180 | PCI_DMA_BIDIRECTIONAL); | ||
| 181 | |||
| 182 | if (chunk->nsg <= 0) | ||
| 187 | goto fail; | 183 | goto fail; |
| 188 | } | 184 | } |
| 185 | |||
| 186 | if (chunk->npages == MLX4_ICM_CHUNK_LEN) | ||
| 187 | chunk = NULL; | ||
| 188 | |||
| 189 | npages -= 1 << cur_order; | ||
| 189 | } | 190 | } |
| 190 | 191 | ||
| 191 | if (!coherent && chunk) { | 192 | if (!coherent && chunk) { |
