Dave Jiang wrote: > Converting nvdimm_bus_lock/unlock to guard() to clean up usage > of gotos for error handling and avoid future mistakes of missed > unlock on error paths. > > Link: https://lore.kernel.org/linux-cxl/[email protected]/ > Suggested-by: Jonathan Cameron <[email protected]> > Signed-off-by: Dave Jiang <[email protected]> > --- > Ira, up to you if you want to take this cleanup. > --- [..] > diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c > index 0ccf4a9e523a..d2c2d71e7fe0 100644 > --- a/drivers/nvdimm/bus.c > +++ b/drivers/nvdimm/bus.c > @@ -1177,15 +1175,15 @@ static int __nd_ioctl(struct nvdimm_bus *nvdimm_bus, > struct nvdimm *nvdimm, > goto out; > } > > - device_lock(dev); > - nvdimm_bus_lock(dev); > + guard(device)(dev); > + guard(nvdimm_bus)(dev); > rc = nd_cmd_clear_to_send(nvdimm_bus, nvdimm, func, buf); > if (rc) > - goto out_unlock; > + goto out; > > rc = nd_desc->ndctl(nd_desc, nvdimm, cmd, buf, buf_len, &cmd_rc); > if (rc < 0) > - goto out_unlock; > + goto out; > > if (!nvdimm && cmd == ND_CMD_CLEAR_ERROR && cmd_rc >= 0) { > struct nd_cmd_clear_error *clear_err = buf; [..] > diff --git a/drivers/nvdimm/dimm.c b/drivers/nvdimm/dimm.c > index 91d9163ee303..2018458a3dba 100644 > --- a/drivers/nvdimm/dimm.c > +++ b/drivers/nvdimm/dimm.c > @@ -95,13 +95,13 @@ static int nvdimm_probe(struct device *dev) > > dev_dbg(dev, "config data size: %d\n", ndd->nsarea.config_size); > > - nvdimm_bus_lock(dev); > - if (ndd->ns_current >= 0) { > - rc = nd_label_reserve_dpa(ndd); > - if (rc == 0) > - nvdimm_set_labeling(dev); > + scoped_guard(nvdimm_bus, dev) { > + if (ndd->ns_current >= 0) { > + rc = nd_label_reserve_dpa(ndd); > + if (rc == 0) > + nvdimm_set_labeling(dev); > + } > } > - nvdimm_bus_unlock(dev); > > if (rc) > goto err; [.. trim the hunks that successfully eliminated goto ..]
My litmus test for scoped-based-cleanup conversions is whether *all* of the gotos are removed in a converted function. So either fully convert all error unwind in a function to scope-based, or none of it. Do not leave people to reason about potentially jumping through scopes with goto.
