]> www.infradead.org Git - users/willy/pagecache.git/commitdiff
cxl/memdev: cxl_memdev_ioctl() cleanup
authorLi Ming <ming.li@zohomail.com>
Fri, 21 Feb 2025 01:24:49 +0000 (09:24 +0800)
committerDave Jiang <dave.jiang@intel.com>
Fri, 14 Mar 2025 21:37:47 +0000 (14:37 -0700)
In cxl_memdev_ioctl(), the down_read(&cxl_memdev_rwsem) and
up_read(&cxl_memdev_rwsem) can be replaced by a
guard(rwsem_read)(&cxl_memdev_rwsem), it helps to remove the open-coded
up_read(&cxl_memdev_rwsem). Besides, the local var 'rc' can be also
removed to make the code more cleaner.

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-4-ming.li@zohomail.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
drivers/cxl/core/memdev.c

index 98c05426aa4a111274d1b81ef4d79078970e9088..6f90dcd626f992233e6bcb1a46d00d81531a4e5f 100644 (file)
@@ -668,15 +668,13 @@ static long cxl_memdev_ioctl(struct file *file, unsigned int cmd,
 {
        struct cxl_memdev *cxlmd = file->private_data;
        struct cxl_dev_state *cxlds;
-       int rc = -ENXIO;
 
-       down_read(&cxl_memdev_rwsem);
+       guard(rwsem_read)(&cxl_memdev_rwsem);
        cxlds = cxlmd->cxlds;
        if (cxlds && cxlds->type == CXL_DEVTYPE_CLASSMEM)
-               rc = __cxl_memdev_ioctl(cxlmd, cmd, arg);
-       up_read(&cxl_memdev_rwsem);
+               return __cxl_memdev_ioctl(cxlmd, cmd, arg);
 
-       return rc;
+       return -ENXIO;
 }
 
 static int cxl_memdev_open(struct inode *inode, struct file *file)