Use __anon_inode_getfd instead of opencoding the logic using
get_unused_fd_flags + anon_inode_getfile.

Signed-off-by: Christoph Hellwig <h...@lst.de>
---
 drivers/gpio/gpiolib.c | 28 ++++------------------------
 1 file changed, 4 insertions(+), 24 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 40f2d7f69be26..cbcf47b1e6a40 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -736,21 +736,13 @@ static int linehandle_create(struct gpio_device *gdev, 
void __user *ip)
        i--;
        lh->numdescs = handlereq.lines;
 
-       fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC);
+       fd = __anon_inode_getfd("gpio-linehandle", &linehandle_fileops, lh,
+                       O_RDONLY | O_CLOEXEC, &file);
        if (fd < 0) {
                ret = fd;
                goto out_free_descs;
        }
 
-       file = anon_inode_getfile("gpio-linehandle",
-                                 &linehandle_fileops,
-                                 lh,
-                                 O_RDONLY | O_CLOEXEC);
-       if (IS_ERR(file)) {
-               ret = PTR_ERR(file);
-               goto out_put_unused_fd;
-       }
-
        handlereq.fd = fd;
        if (copy_to_user(ip, &handlereq, sizeof(handlereq))) {
                /*
@@ -769,8 +761,6 @@ static int linehandle_create(struct gpio_device *gdev, void 
__user *ip)
 
        return 0;
 
-out_put_unused_fd:
-       put_unused_fd(fd);
 out_free_descs:
        for (i = 0; i < count; i++)
                gpiod_free(lh->descs[i]);
@@ -1110,21 +1100,13 @@ static int lineevent_create(struct gpio_device *gdev, 
void __user *ip)
        if (ret)
                goto out_free_desc;
 
-       fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC);
+       fd = __anon_inode_getfd("gpio-event", &lineevent_fileops, le,
+                       O_RDONLY | O_CLOEXEC, &file);
        if (fd < 0) {
                ret = fd;
                goto out_free_irq;
        }
 
-       file = anon_inode_getfile("gpio-event",
-                                 &lineevent_fileops,
-                                 le,
-                                 O_RDONLY | O_CLOEXEC);
-       if (IS_ERR(file)) {
-               ret = PTR_ERR(file);
-               goto out_put_unused_fd;
-       }
-
        eventreq.fd = fd;
        if (copy_to_user(ip, &eventreq, sizeof(eventreq))) {
                /*
@@ -1140,8 +1122,6 @@ static int lineevent_create(struct gpio_device *gdev, 
void __user *ip)
 
        return 0;
 
-out_put_unused_fd:
-       put_unused_fd(fd);
 out_free_irq:
        free_irq(le->irq, le);
 out_free_desc:
-- 
2.26.2

Reply via email to