cxl/mem: Do not rely on device_add() side effects for dev_set_name() failures
authorDan Williams <dan.j.williams@intel.com>
Thu, 1 Apr 2021 14:33:25 +0000 (07:33 -0700)
committerDan Williams <dan.j.williams@intel.com>
Tue, 6 Apr 2021 18:41:30 +0000 (11:41 -0700)
commit1c3333a28d4532cfc37d4d25bfc76654a0c76643
tree67fd629f9d6b50214644239e585e84fddacda935
parent5877515912cc4f0d67071b7cee15076ebef24708
cxl/mem: Do not rely on device_add() side effects for dev_set_name() failures

While device_add() will happen to catch dev_set_name() failures it is a
broken pattern to follow given that the core may try to fall back to a
different name.

Add explicit checking for dev_set_name() failures to be cleaned up by
put_device(). Skip cdev_device_add() and proceed directly to
put_device() if the name set fails.

This type of bug is easier to see if 'alloc' is split from 'add'
operations that require put_device() on failure. So cxl_memdev_alloc()
is split out as a result.

Fixes: b39cb1052a5c ("cxl/mem: Register CXL memX devices")
Reported-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/161728760514.2474381.1163928273337158134.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/cxl/mem.c