Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1417270 > unrolled thread

[PATCH 1/2] fuse: use list_first_entry_or_null

Started byGeliang Tang <geliangtang@gmail.com>
First post2016-06-08 12:50 +0200
Last post2016-06-08 12:50 +0200
Articles 2 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/2] fuse: use list_first_entry_or_null Geliang Tang <geliangtang@gmail.com> - 2016-06-08 12:50 +0200
    [PATCH 2/2] fuse: use list_first_entry Geliang Tang <geliangtang@gmail.com> - 2016-06-08 12:50 +0200

#1417270 — [PATCH 1/2] fuse: use list_first_entry_or_null

FromGeliang Tang <geliangtang@gmail.com>
Date2016-06-08 12:50 +0200
Subject[PATCH 1/2] fuse: use list_first_entry_or_null
Message-ID<rHJdD-7sQ-1@gated-at.bofh.it>
Use list_first_entry_or_null() instead of list_empty() and list_entry()
to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
 fs/fuse/dev.c  | 7 +++----
 fs/fuse/file.c | 9 ++++-----
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index cbece12..1432cf7 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1259,11 +1259,10 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,
 	if (!fiq->connected)
 		goto err_unlock;
 
-	if (!list_empty(&fiq->interrupts)) {
-		req = list_entry(fiq->interrupts.next, struct fuse_req,
-				 intr_entry);
+	req = list_first_entry_or_null(&fiq->interrupts, struct fuse_req,
+				       intr_entry);
+	if (req)
 		return fuse_read_interrupt(fiq, cs, nbytes, req);
-	}
 
 	if (forget_pending(fiq)) {
 		if (list_empty(&fiq->pending) || fiq->forget_batch-- > 0)
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 9154f86..c1d97a1 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1565,14 +1565,13 @@ static void fuse_writepage_end(struct fuse_conn *fc, struct fuse_req *req)
 static struct fuse_file *__fuse_write_file_get(struct fuse_conn *fc,
 					       struct fuse_inode *fi)
 {
-	struct fuse_file *ff = NULL;
+	struct fuse_file *ff;
 
 	spin_lock(&fc->lock);
-	if (!list_empty(&fi->write_files)) {
-		ff = list_entry(fi->write_files.next, struct fuse_file,
-				write_entry);
+	ff = list_first_entry_or_null(&fi->write_files, struct fuse_file,
+				      write_entry);
+	if (ff)
 		fuse_file_get(ff);
-	}
 	spin_unlock(&fc->lock);
 
 	return ff;
-- 
1.9.1

[toc] | [next] | [standalone]


#1417273 — [PATCH 2/2] fuse: use list_first_entry

FromGeliang Tang <geliangtang@gmail.com>
Date2016-06-08 12:50 +0200
Subject[PATCH 2/2] fuse: use list_first_entry
Message-ID<rHJdE-7sQ-13@gated-at.bofh.it>
In reply to#1417270
To make the intention clearer, use list_first_entry() instead of
list_entry().

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
 fs/fuse/dev.c  | 6 +++---
 fs/fuse/file.c | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 1432cf7..a766983 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -359,7 +359,7 @@ static void flush_bg_queue(struct fuse_conn *fc)
 		struct fuse_req *req;
 		struct fuse_iqueue *fiq = &fc->iq;
 
-		req = list_entry(fc->bg_queue.next, struct fuse_req, list);
+		req = list_first_entry(&fc->bg_queue, struct fuse_req, list);
 		list_del(&req->list);
 		fc->active_background++;
 		spin_lock(&fiq->waitq.lock);
@@ -1272,7 +1272,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,
 			fiq->forget_batch = 16;
 	}
 
-	req = list_entry(fiq->pending.next, struct fuse_req, list);
+	req = list_first_entry(&fiq->pending, struct fuse_req, list);
 	clear_bit(FR_PENDING, &req->flags);
 	list_del_init(&req->list);
 	spin_unlock(&fiq->waitq.lock);
@@ -2080,7 +2080,7 @@ static void end_requests(struct fuse_conn *fc, struct list_head *head)
 {
 	while (!list_empty(head)) {
 		struct fuse_req *req;
-		req = list_entry(head->next, struct fuse_req, list);
+		req = list_first_entry(head, struct fuse_req, list);
 		req->out.h.error = -ECONNABORTED;
 		clear_bit(FR_PENDING, &req->flags);
 		clear_bit(FR_SENT, &req->flags);
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index c1d97a1..07c00a4 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1509,7 +1509,8 @@ __acquires(fc->lock)
 	struct fuse_req *req;
 
 	while (fi->writectr >= 0 && !list_empty(&fi->queued_writes)) {
-		req = list_entry(fi->queued_writes.next, struct fuse_req, list);
+		req = list_first_entry(&fi->queued_writes, struct fuse_req,
+				       list);
 		list_del_init(&req->list);
 		fuse_send_writepage(fc, req, crop);
 	}
-- 
1.9.1

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web