Skip to content

Commit 16fe6ec

Browse files
MingLi-4davejiang
authored andcommitted
cxl/core: Use guard() to drop the goto pattern of cxl_dpa_free()
cxl_dpa_free() has a goto pattern to call up_write() for cxl_dpa_rwsem, it can be removed by using a guard() to replace the down_write() and up_write(). Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Alison Schofield <alison.schofield@intel.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Acked-by: Davidlohr Bueso <dave@stgolabs.net> Signed-off-by: Li Ming <ming.li@zohomail.com> Link: https://patch.msgid.link/20250221012453.126366-5-ming.li@zohomail.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent a58afda commit 16fe6ec

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

drivers/cxl/core/hdm.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -382,35 +382,27 @@ int cxl_dpa_free(struct cxl_endpoint_decoder *cxled)
382382
{
383383
struct cxl_port *port = cxled_to_port(cxled);
384384
struct device *dev = &cxled->cxld.dev;
385-
int rc;
386385

387-
down_write(&cxl_dpa_rwsem);
388-
if (!cxled->dpa_res) {
389-
rc = 0;
390-
goto out;
391-
}
386+
guard(rwsem_write)(&cxl_dpa_rwsem);
387+
if (!cxled->dpa_res)
388+
return 0;
392389
if (cxled->cxld.region) {
393390
dev_dbg(dev, "decoder assigned to: %s\n",
394391
dev_name(&cxled->cxld.region->dev));
395-
rc = -EBUSY;
396-
goto out;
392+
return -EBUSY;
397393
}
398394
if (cxled->cxld.flags & CXL_DECODER_F_ENABLE) {
399395
dev_dbg(dev, "decoder enabled\n");
400-
rc = -EBUSY;
401-
goto out;
396+
return -EBUSY;
402397
}
403398
if (cxled->cxld.id != port->hdm_end) {
404399
dev_dbg(dev, "expected decoder%d.%d\n", port->id,
405400
port->hdm_end);
406-
rc = -EBUSY;
407-
goto out;
401+
return -EBUSY;
408402
}
403+
409404
devm_cxl_dpa_release(cxled);
410-
rc = 0;
411-
out:
412-
up_write(&cxl_dpa_rwsem);
413-
return rc;
405+
return 0;
414406
}
415407

416408
int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,

0 commit comments

Comments
 (0)