Message ID | 20250217144828.30651-5-ming.li@zohomail.com |
---|---|
State | New |
Headers | show |
Series | Use guard() instead of rwsem locking | expand |
On 2/17/25 7:48 AM, Li Ming wrote: > 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> > Signed-off-by: Li Ming <ming.li@zohomail.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> > --- > drivers/cxl/core/hdm.c | 24 ++++++++---------------- > 1 file changed, 8 insertions(+), 16 deletions(-) > > diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c > index 4a578092377e..874a791f8292 100644 > --- a/drivers/cxl/core/hdm.c > +++ b/drivers/cxl/core/hdm.c > @@ -382,35 +382,27 @@ int cxl_dpa_free(struct cxl_endpoint_decoder *cxled) > { > struct cxl_port *port = cxled_to_port(cxled); > struct device *dev = &cxled->cxld.dev; > - int rc; > > - down_write(&cxl_dpa_rwsem); > - if (!cxled->dpa_res) { > - rc = 0; > - goto out; > - } > + guard(rwsem_write)(&cxl_dpa_rwsem); > + if (!cxled->dpa_res) > + return 0; > if (cxled->cxld.region) { > dev_dbg(dev, "decoder assigned to: %s\n", > dev_name(&cxled->cxld.region->dev)); > - rc = -EBUSY; > - goto out; > + return -EBUSY; > } > if (cxled->cxld.flags & CXL_DECODER_F_ENABLE) { > dev_dbg(dev, "decoder enabled\n"); > - rc = -EBUSY; > - goto out; > + return -EBUSY; > } > if (cxled->cxld.id != port->hdm_end) { > dev_dbg(dev, "expected decoder%d.%d\n", port->id, > port->hdm_end); > - rc = -EBUSY; > - goto out; > + return -EBUSY; > } > + > devm_cxl_dpa_release(cxled); > - rc = 0; > -out: > - up_write(&cxl_dpa_rwsem); > - return rc; > + return 0; > } > > int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,
On Mon, Feb 17, 2025 at 10:48:25PM +0800, Li Ming wrote: > 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> > Signed-off-by: Li Ming <ming.li@zohomail.com> Reviewed-by: Alison Schofield <alison.schofield@intel.com> snip
diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c index 4a578092377e..874a791f8292 100644 --- a/drivers/cxl/core/hdm.c +++ b/drivers/cxl/core/hdm.c @@ -382,35 +382,27 @@ int cxl_dpa_free(struct cxl_endpoint_decoder *cxled) { struct cxl_port *port = cxled_to_port(cxled); struct device *dev = &cxled->cxld.dev; - int rc; - down_write(&cxl_dpa_rwsem); - if (!cxled->dpa_res) { - rc = 0; - goto out; - } + guard(rwsem_write)(&cxl_dpa_rwsem); + if (!cxled->dpa_res) + return 0; if (cxled->cxld.region) { dev_dbg(dev, "decoder assigned to: %s\n", dev_name(&cxled->cxld.region->dev)); - rc = -EBUSY; - goto out; + return -EBUSY; } if (cxled->cxld.flags & CXL_DECODER_F_ENABLE) { dev_dbg(dev, "decoder enabled\n"); - rc = -EBUSY; - goto out; + return -EBUSY; } if (cxled->cxld.id != port->hdm_end) { dev_dbg(dev, "expected decoder%d.%d\n", port->id, port->hdm_end); - rc = -EBUSY; - goto out; + return -EBUSY; } + devm_cxl_dpa_release(cxled); - rc = 0; -out: - up_write(&cxl_dpa_rwsem); - return rc; + return 0; } int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled,