Skip to content

Commit 65a5464

Browse files
author
Christoph Hellwig
committed
nvme-pci: simplify nvme_dbbuf_dma_alloc
Move the OACS check and the error checking into nvme_dbbuf_dma_alloc so that an upcoming second caller doesn't have to duplicate this boilerplate code. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]>
1 parent a6ee7f1 commit 65a5464

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

drivers/nvme/host/pci.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -239,36 +239,41 @@ static inline unsigned int nvme_dbbuf_size(struct nvme_dev *dev)
239239
return dev->nr_allocated_queues * 8 * dev->db_stride;
240240
}
241241

242-
static int nvme_dbbuf_dma_alloc(struct nvme_dev *dev)
242+
static void nvme_dbbuf_dma_alloc(struct nvme_dev *dev)
243243
{
244244
unsigned int mem_size = nvme_dbbuf_size(dev);
245245

246+
if (!(dev->ctrl.oacs & NVME_CTRL_OACS_DBBUF_SUPP))
247+
return;
248+
246249
if (dev->dbbuf_dbs) {
247250
/*
248251
* Clear the dbbuf memory so the driver doesn't observe stale
249252
* values from the previous instantiation.
250253
*/
251254
memset(dev->dbbuf_dbs, 0, mem_size);
252255
memset(dev->dbbuf_eis, 0, mem_size);
253-
return 0;
256+
return;
254257
}
255258

256259
dev->dbbuf_dbs = dma_alloc_coherent(dev->dev, mem_size,
257260
&dev->dbbuf_dbs_dma_addr,
258261
GFP_KERNEL);
259262
if (!dev->dbbuf_dbs)
260-
return -ENOMEM;
263+
goto fail;
261264
dev->dbbuf_eis = dma_alloc_coherent(dev->dev, mem_size,
262265
&dev->dbbuf_eis_dma_addr,
263266
GFP_KERNEL);
264-
if (!dev->dbbuf_eis) {
265-
dma_free_coherent(dev->dev, mem_size,
266-
dev->dbbuf_dbs, dev->dbbuf_dbs_dma_addr);
267-
dev->dbbuf_dbs = NULL;
268-
return -ENOMEM;
269-
}
267+
if (!dev->dbbuf_eis)
268+
goto fail_free_dbbuf_dbs;
269+
return;
270270

271-
return 0;
271+
fail_free_dbbuf_dbs:
272+
dma_free_coherent(dev->dev, mem_size, dev->dbbuf_dbs,
273+
dev->dbbuf_dbs_dma_addr);
274+
dev->dbbuf_dbs = NULL;
275+
fail:
276+
dev_warn(dev->dev, "unable to allocate dma for dbbuf\n");
272277
}
273278

274279
static void nvme_dbbuf_dma_free(struct nvme_dev *dev)
@@ -2855,12 +2860,7 @@ static void nvme_reset_work(struct work_struct *work)
28552860
if (result)
28562861
goto out;
28572862

2858-
if (dev->ctrl.oacs & NVME_CTRL_OACS_DBBUF_SUPP) {
2859-
result = nvme_dbbuf_dma_alloc(dev);
2860-
if (result)
2861-
dev_warn(dev->dev,
2862-
"unable to allocate dma for dbbuf\n");
2863-
}
2863+
nvme_dbbuf_dma_alloc(dev);
28642864

28652865
if (dev->ctrl.hmpre) {
28662866
result = nvme_setup_host_mem(dev);

0 commit comments

Comments
 (0)