Skip to content

Commit 27fcfb4

Browse files
weiny2davejiang
authored andcommitted
cxl/hdm: Use guard() in cxl_dpa_set_mode()
Additional DCD functionality is being added to this call which will be simplified by the use of guard() with the cxl_dpa_rwsem. Convert the function to use guard() prior to adding DCD functionality. Suggested-by: Jonathan Cameron <Jonathan.Cameron@Huawei.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Davidlohr Bueso <dave@stgolabs.net> Signed-off-by: Ira Weiny <ira.weiny@intel.com> Link: https://patch.msgid.link/20241107-dcd-type2-upstream-v7-5-56a84e66bc36@intel.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 0f6f0d6 commit 27fcfb4

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

drivers/cxl/core/hdm.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,
424424
struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
425425
struct cxl_dev_state *cxlds = cxlmd->cxlds;
426426
struct device *dev = &cxled->cxld.dev;
427-
int rc;
428427

429428
switch (mode) {
430429
case CXL_DECODER_RAM:
@@ -435,33 +434,25 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,
435434
return -EINVAL;
436435
}
437436

438-
down_write(&cxl_dpa_rwsem);
439-
if (cxled->cxld.flags & CXL_DECODER_F_ENABLE) {
440-
rc = -EBUSY;
441-
goto out;
442-
}
437+
guard(rwsem_write)(&cxl_dpa_rwsem);
438+
if (cxled->cxld.flags & CXL_DECODER_F_ENABLE)
439+
return -EBUSY;
443440

444441
/*
445442
* Only allow modes that are supported by the current partition
446443
* configuration
447444
*/
448445
if (mode == CXL_DECODER_PMEM && !resource_size(&cxlds->pmem_res)) {
449446
dev_dbg(dev, "no available pmem capacity\n");
450-
rc = -ENXIO;
451-
goto out;
447+
return -ENXIO;
452448
}
453449
if (mode == CXL_DECODER_RAM && !resource_size(&cxlds->ram_res)) {
454450
dev_dbg(dev, "no available ram capacity\n");
455-
rc = -ENXIO;
456-
goto out;
451+
return -ENXIO;
457452
}
458453

459454
cxled->mode = mode;
460-
rc = 0;
461-
out:
462-
up_write(&cxl_dpa_rwsem);
463-
464-
return rc;
455+
return 0;
465456
}
466457

467458
int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size)

0 commit comments

Comments
 (0)