lkml.org 
[lkml]   [2021]   [Mar]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Subject[PATCH 3/4] cxl/mem: Do not rely on device_add() side effects for dev_set_name() failures
    From
    Date
    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 failure.

    Fixes: b39cb1052a5c ("cxl/mem: Register CXL memX devices")
    Reported-by: Jason Gunthorpe <jgg@nvidia.com>
    Signed-off-by: Dan Williams <dan.j.williams@intel.com>
    ---
    drivers/cxl/mem.c | 6 ++++--
    1 file changed, 4 insertions(+), 2 deletions(-)

    diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c
    index e53d573ae4ab..d615f183520c 100644
    --- a/drivers/cxl/mem.c
    +++ b/drivers/cxl/mem.c
    @@ -1204,12 +1204,14 @@ static int cxl_mem_add_memdev(struct cxl_mem *cxlm)
    dev->bus = &cxl_bus_type;
    dev->devt = MKDEV(cxl_mem_major, cxlmd->id);
    dev->type = &cxl_memdev_type;
    - dev_set_name(dev, "mem%d", cxlmd->id);

    cdev = &cxlmd->cdev;
    cdev_init(cdev, &cxl_memdev_fops);

    - rc = cdev_device_add(cdev, dev);
    + rc = dev_set_name(dev, "mem%d", cxlmd->id);
    + if (rc == 0)
    + rc = cdev_device_add(cdev, dev);
    +
    if (rc) {
    percpu_ref_kill(&cxlmd->ops_active);
    put_device(dev);
    \
     
     \ /
      Last update: 2021-03-24 22:03    [W:2.682 / U:0.136 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site