Skip to contentSkip to conversation

fixed some coding style issues

PATCH New Dong Fang 1 participant 5 messages Jul 30, 2013 – Aug 5, 2013

Subsystems (3)
lore
Share & tools
lore

Dong Fang

author
#0 lore raw

PATCH v2 1/1 fixed some coding style issues

i fixed some coding style issues and use list_for_each_entry() for list traversing in this patchs

---
[PATCH 1/3] vfs: fixed some CamelCase coding style issue [PATCH 2/3] fs/fuse: use list_for_each_entry() for list traversing [PATCH 3/3] fs/vfs: use list_for_each_entry() for list traversing

author
#1 lore raw

PATCH 1/3 vfs: fixed some CamelCase coding style issue

---
 fs/binfmt_misc.c |   39 ++++++++++++++++++++-------------------
 1 files changed, 20 insertions(+), 19 deletions(-)
fs/binfmt_misc.c +20 -19
index 1c740e1..e02b857 100644
@@ -45,7 +45,7 @@ enum {Enabled, Magic};
 #define MISC_FMT_OPEN_BINARY (1<<30)
 #define MISC_FMT_CREDENTIALS (1<<29)
 
-typedef struct {
+struct bm_node {
 	struct list_head list;
 	unsigned long flags;		/* type, status, etc. */
 	int offset;			/* offset of magic */
@@ -55,7 +55,7 @@ typedef struct {
 	char *interpreter;		/* filename of interpreter */
 	char *name;
 	struct dentry *dentry;
-} Node;
+};
 
 static DEFINE_RWLOCK(entries_lock);
 static struct file_system_type bm_fs_type;
@@ -67,13 +67,13 @@ static int entry_count;
  * if we do, return the node, else NULL
  * locking is done in load_misc_binary
  */
-static Node *check_file(struct linux_binprm *bprm)
+static struct bm_node *check_file(struct linux_binprm *bprm)
 {
+	struct bm_node *e;
 	char *p = strrchr(bprm->interp, '.');
-	struct list_head *l;
 
-	list_for_each(l, &entries) {
-		Node *e = list_entry(l, Node, list);
+
+	list_for_each_entry(e, &entries, list) {
 		char *s;
 		int j;
 
@@ -107,7 +107,7 @@ static Node *check_file(struct linux_binprm *bprm)
  */
 static int load_misc_binary(struct linux_binprm *bprm)
 {
-	Node *fmt;
+	struct bm_node *fmt;
 	struct file * interp_file = NULL;
 	char iname[BINPRM_BUF_SIZE];
 	const char *iname_addr = iname;
@@ -235,7 +235,7 @@ static char *scanarg(char *s, char del)
 	return s;
 }
 
-static char * check_special_flags (char * sfs, Node * e)
+static char *check_special_flags(char *sfs, struct bm_node *e)
 {
 	char * p = sfs;
 	int cont = 1;
@@ -270,9 +270,9 @@ static char * check_special_flags (char * sfs, Node * e)
  * ':name:type:offset:magic:mask:interpreter:flags'
  * where the ':' is the IFS, that can be chosen with the first char
  */
-static Node *create_entry(const char __user *buffer, size_t count)
+static struct bm_node *create_entry(const char __user *buffer, size_t count)
 {
-	Node *e;
+	struct bm_node *e;
 	int memsize, err;
 	char *buf, *p;
 	char del;
@@ -283,14 +283,14 @@ static Node *create_entry(const char __user *buffer, size_t count)
 		goto out;
 
 	err = -ENOMEM;
-	memsize = sizeof(Node) + count + 8;
+	memsize = sizeof(struct bm_node) + count + 8;
 	e = kmalloc(memsize, GFP_USER);
 	if (!e)
 		goto out;
 
-	p = buf = (char *)e + sizeof(Node);
+	p = buf = (char *)e + sizeof(*e);
 
-	memset(e, 0, sizeof(Node));
+	memset(e, 0, sizeof(*e));
 	if (copy_from_user(buf, buffer, count))
 		goto Efault;
 
@@ -415,7 +415,7 @@ static int parse_command(const char __user *buffer, size_t count)
 
 /* generic stuff */
 
-static void entry_status(Node *e, char *page)
+static void entry_status(struct bm_node *e, char *page)
 {
 	char *dp;
 	char *status = "disabled";
@@ -490,7 +490,7 @@ static void bm_evict_inode(struct inode *inode)
 	kfree(inode->i_private);
 }
 
-static void kill_node(Node *e)
+static void kill_node(struct bm_node *e)
 {
 	struct dentry *dentry;
 
@@ -515,7 +515,7 @@ static void kill_node(Node *e)
 static ssize_t
 bm_entry_read(struct file * file, char __user * buf, size_t nbytes, loff_t *ppos)
 {
-	Node *e = file_inode(file)->i_private;
+	struct bm_node *e = file_inode(file)->i_private;
 	ssize_t res;
 	char *page;
 
@@ -534,7 +534,7 @@ static ssize_t bm_entry_write(struct file *file, const char __user *buffer,
 				size_t count, loff_t *ppos)
 {
 	struct dentry *root;
-	Node *e = file_inode(file)->i_private;
+	struct bm_node *e = file_inode(file)->i_private;
 	int res = parse_command(buffer, count);
 
 	switch (res) {
@@ -566,7 +566,7 @@ static const struct file_operations bm_entry_operations = {
 static ssize_t bm_register_write(struct file *file, const char __user *buffer,
 			       size_t count, loff_t *ppos)
 {
-	Node *e;
+	struct bm_node *e;
 	struct inode *inode;
 	struct dentry *root, *dentry;
 	struct super_block *sb = file->f_path.dentry->d_sb;
@@ -652,7 +652,8 @@ static ssize_t bm_status_write(struct file * file, const char __user * buffer,
 			mutex_lock(&root->d_inode->i_mutex);
 
 			while (!list_empty(&entries))
-				kill_node(list_entry(entries.next, Node, list));
+				kill_node(list_entry(entries.next,
+						     struct bm_node, list));
 
 			mutex_unlock(&root->d_inode->i_mutex);
 			dput(root);
Signature · 1 line
1.7.1
author
#2 lore raw

Re: [PATCH 1/3] vfs: fixed some CamelCase coding style issue

Quoted 139 lines · Dong Fang
---
  fs/binfmt_misc.c |   39 ++++++++++++++++++++-------------------
  1 files changed, 20 insertions(+), 19 deletions(-)
fs/binfmt_misc.c +18 -18
index 1c740e1..e02b857 100644
@@ -45,7 +45,7 @@ enum {Enabled, Magic};
  #define MISC_FMT_OPEN_BINARY (1<<30)
  #define MISC_FMT_CREDENTIALS (1<<29)
 
-typedef struct {
+struct bm_node {
  	struct list_head list;
  	unsigned long flags;		/* type, status, etc. */
  	int offset;			/* offset of magic */
@@ -55,7 +55,7 @@ typedef struct {
  	char *interpreter;		/* filename of interpreter */
  	char *name;
  	struct dentry *dentry;
-} Node;
+};
 
  static DEFINE_RWLOCK(entries_lock);
  static struct file_system_type bm_fs_type;
@@ -67,13 +67,13 @@ static int entry_count;
   * if we do, return the node, else NULL
   * locking is done in load_misc_binary
   */
-static Node *check_file(struct linux_binprm *bprm)
+static struct bm_node *check_file(struct linux_binprm *bprm)
  {
+	struct bm_node *e;
  	char *p = strrchr(bprm->interp, '.');
-	struct list_head *l;
 
-	list_for_each(l, &entries) {
-		Node *e = list_entry(l, Node, list);
+
+	list_for_each_entry(e, &entries, list) {
  		char *s;
  		int j;
 
@@ -107,7 +107,7 @@ static Node *check_file(struct linux_binprm *bprm)
   */
  static int load_misc_binary(struct linux_binprm *bprm)
  {
-	Node *fmt;
+	struct bm_node *fmt;
  	struct file * interp_file = NULL;
  	char iname[BINPRM_BUF_SIZE];
  	const char *iname_addr = iname;
@@ -235,7 +235,7 @@ static char *scanarg(char *s, char del)
  	return s;
  }
 
-static char * check_special_flags (char * sfs, Node * e)
+static char *check_special_flags(char *sfs, struct bm_node *e)
  {
  	char * p = sfs;
  	int cont = 1;
@@ -270,9 +270,9 @@ static char * check_special_flags (char * sfs, Node * e)
   * ':name:type:offset:magic:mask:interpreter:flags'
   * where the ':' is the IFS, that can be chosen with the first char
   */
-static Node *create_entry(const char __user *buffer, size_t count)
+static struct bm_node *create_entry(const char __user *buffer, size_t count)
  {
-	Node *e;
+	struct bm_node *e;
  	int memsize, err;
  	char *buf, *p;
  	char del;
@@ -283,14 +283,14 @@ static Node *create_entry(const char __user *buffer, size_t count)
  		goto out;
 
  	err = -ENOMEM;
-	memsize = sizeof(Node) + count + 8;
+	memsize = sizeof(struct bm_node) + count + 8;
  	e = kmalloc(memsize, GFP_USER);
  	if (!e)
  		goto out;
 
-	p = buf = (char *)e + sizeof(Node);
+	p = buf = (char *)e + sizeof(*e);
 
-	memset(e, 0, sizeof(Node));
+	memset(e, 0, sizeof(*e));
  	if (copy_from_user(buf, buffer, count))
  		goto Efault;
 
@@ -415,7 +415,7 @@ static int parse_command(const char __user *buffer, size_t count)
 
  /* generic stuff */
 
-static void entry_status(Node *e, char *page)
+static void entry_status(struct bm_node *e, char *page)
  {
  	char *dp;
  	char *status = "disabled";
@@ -490,7 +490,7 @@ static void bm_evict_inode(struct inode *inode)
  	kfree(inode->i_private);
  }
 
-static void kill_node(Node *e)
+static void kill_node(struct bm_node *e)
  {
  	struct dentry *dentry;
 
@@ -515,7 +515,7 @@ static void kill_node(Node *e)
  static ssize_t
  bm_entry_read(struct file * file, char __user * buf, size_t nbytes, loff_t *ppos)
  {
-	Node *e = file_inode(file)->i_private;
+	struct bm_node *e = file_inode(file)->i_private;
  	ssize_t res;
  	char *page;
 
@@ -534,7 +534,7 @@ static ssize_t bm_entry_write(struct file *file, const char __user *buffer,
  				size_t count, loff_t *ppos)
  {
  	struct dentry *root;
-	Node *e = file_inode(file)->i_private;
+	struct bm_node *e = file_inode(file)->i_private;
  	int res = parse_command(buffer, count);
 
  	switch (res) {
@@ -566,7 +566,7 @@ static const struct file_operations bm_entry_operations = {
  static ssize_t bm_register_write(struct file *file, const char __user *buffer,
  			       size_t count, loff_t *ppos)
  {
-	Node *e;
+	struct bm_node *e;
  	struct inode *inode;
  	struct dentry *root, *dentry;
  	struct super_block *sb = file->f_path.dentry->d_sb;

fs/binfmt_misc.c static ssize_t bm_status_write(struct file * file, const char __user * buffer, · line 659

Quoted 9 lines
fs/binfmt_misc.c +2 -1
@@ -652,7 +652,8 @@ static ssize_t bm_status_write(struct file * file, const char __user * buffer,
  			mutex_lock(&root->d_inode->i_mutex);
 
  			while (!list_empty(&entries))
-				kill_node(list_entry(entries.next, Node, list));
+				kill_node(list_entry(entries.next,
+						     struct bm_node, list));
 
  			mutex_unlock(&root->d_inode->i_mutex);
  			dput(root);

can anyone give me some suggestion? dan?

author
#3 lore raw

PATCH 2/3 fs/fuse: use list_for_each_entry() for list traversing

In reply to Dong Fang
---
 fs/fuse/dev.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
fs/fuse/dev.c +2 -4
index 1d55f94..ef74ad5 100644
@@ -1765,11 +1765,9 @@ static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
 /* Look up request on processing list by unique ID */
 static struct fuse_req *request_find(struct fuse_conn *fc, u64 unique)
 {
-	struct list_head *entry;
+	struct fuse_req *req;
 
-	list_for_each(entry, &fc->processing) {
-		struct fuse_req *req;
-		req = list_entry(entry, struct fuse_req, list);
+	list_for_each_entry(req, &fc->processing, list) {
 		if (req->in.h.unique == unique || req->intr_unique == unique)
 			return req;
 	}
Signature · 1 line
1.7.1
author
#4 lore raw

PATCH 3/3 fs/vfs: use list_for_each_entry() for list traversing

In reply to Dong Fang
---
 fs/binfmt_elf.c       |   22 ++++++++--------------
 fs/binfmt_elf_fdpic.c |   34 +++++++++++++---------------------
 fs/dcookies.c         |   27 ++++++++++-----------------
 fs/mbcache.c          |    6 +++---
 4 files changed, 34 insertions(+), 55 deletions(-)
fs/binfmt_elf.c +8 -14
index 100edcc..22b9245 100644
@@ -1867,10 +1867,8 @@ static int fill_note_info(struct elfhdr *elf, int phdrs,
 			list_add(&ets->list, &info->thread_list);
 		}
 
-		list_for_each(t, &info->thread_list) {
+		list_for_each_entry(ets, &info->thread_list, list) {
 			int sz;
-
-			ets = list_entry(t, struct elf_thread_status, list);
 			sz = elf_dump_thread_status(siginfo->si_signo, ets);
 			info->thread_status_size += sz;
 		}
@@ -1933,19 +1931,16 @@ static int write_note_info(struct elf_note_info *info,
 			   struct file *file, loff_t *foffset)
 {
 	int i;
-	struct list_head *t;
+	struct elf_thread_status *ets;
 
 	for (i = 0; i < info->numnote; i++)
 		if (!writenote(info->notes + i, file, foffset))
 			return 0;
 
 	/* write out the thread status notes section */
-	list_for_each(t, &info->thread_list) {
-		struct elf_thread_status *tmp =
-				list_entry(t, struct elf_thread_status, list);
-
-		for (i = 0; i < tmp->num_notes; i++)
-			if (!writenote(&tmp->notes[i], file, foffset))
+	list_for_each_entry(ets, &info->thread_list, list) {
+		for (i = 0; i < ets->num_notes; i++)
+			if (!writenote(&ets->notes[i], file, foffset))
 				return 0;
 	}
 
@@ -1954,10 +1949,9 @@ static int write_note_info(struct elf_note_info *info,
 
 static void free_note_info(struct elf_note_info *info)
 {
-	while (!list_empty(&info->thread_list)) {
-		struct list_head *tmp = info->thread_list.next;
-		list_del(tmp);
-		kfree(list_entry(tmp, struct elf_thread_status, list));
+	struct elf_thread_status *ets, *tmp;
+	list_for_each_entry_safe(ets, tmp, &info->thread_list, list) {
+		kfree(ets);
 	}
 
 	/* Free data allocated by fill_files_note(): */
fs/binfmt_elf_fdpic.c +13 -21
index c166f32..2d00655 100644
@@ -1595,7 +1595,6 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
 	struct elf_prstatus *prstatus = NULL;	/* NT_PRSTATUS */
 	struct elf_prpsinfo *psinfo = NULL;	/* NT_PRPSINFO */
  	LIST_HEAD(thread_list);
- 	struct list_head *t;
 	elf_fpregset_t *fpu = NULL;
 #ifdef ELF_CORE_COPY_XFPREGS
 	elf_fpxregset_t *xfpu = NULL;
@@ -1604,6 +1603,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
 	elf_addr_t *auxv;
 	struct elf_phdr *phdr4note = NULL;
 	struct elf_shdr *shdr4extnum = NULL;
+	struct elf_thread_status *ets, *tmp;
 	Elf_Half e_phnum;
 	elf_addr_t e_shoff;
 
@@ -1643,24 +1643,21 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
 
 	if (cprm->siginfo->si_signo) {
 		struct core_thread *ct;
-		struct elf_thread_status *tmp;
 
 		for (ct = current->mm->core_state->dumper.next;
 						ct; ct = ct->next) {
-			tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
-			if (!tmp)
+			ets = kzalloc(sizeof(*ets), GFP_KERNEL);
+			if (!ets)
 				goto cleanup;
 
-			tmp->thread = ct->task;
-			list_add(&tmp->list, &thread_list);
+			ets->thread = ct->task;
+			list_add(&ets->list, &thread_list);
 		}
 
-		list_for_each(t, &thread_list) {
-			struct elf_thread_status *tmp;
+		list_for_each_entry(ets, &thread_list, list) {
 			int sz;
-
-			tmp = list_entry(t, struct elf_thread_status, list);
-			sz = elf_dump_thread_status(cprm->siginfo->si_signo, tmp);
+			sz = elf_dump_thread_status(cprm->siginfo->si_signo,
+						    ets);
 			thread_status_size += sz;
 		}
 	}
@@ -1800,12 +1797,9 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
 			goto end_coredump;
 
 	/* write out the thread status notes section */
-	list_for_each(t, &thread_list) {
-		struct elf_thread_status *tmp =
-				list_entry(t, struct elf_thread_status, list);
-
-		for (i = 0; i < tmp->num_notes; i++)
-			if (!writenote(&tmp->notes[i], cprm->file, &foffset))
+	list_for_each_entry(ets, &thread_list, list) {
+		for (i = 0; i < ets->num_notes; i++)
+			if (!writenote(&ets->notes[i], cprm->file, &foffset))
 				goto end_coredump;
 	}
 
@@ -1838,10 +1832,8 @@ end_coredump:
 	set_fs(fs);
 
 cleanup:
-	while (!list_empty(&thread_list)) {
-		struct list_head *tmp = thread_list.next;
-		list_del(tmp);
-		kfree(list_entry(tmp, struct elf_thread_status, list));
+	list_for_each_entry_safe(ets, tmp, &thread_list, list) {
+		kfree(ets);
 	}
 	kfree(phdr4note);
 	kfree(elf);
fs/dcookies.c +10 -17
index ab5954b..f1af239 100644
@@ -64,22 +64,18 @@ static size_t dcookie_hash(unsigned long dcookie)
 
 static struct dcookie_struct * find_dcookie(unsigned long dcookie)
 {
-	struct dcookie_struct *found = NULL;
-	struct dcookie_struct * dcs;
-	struct list_head * pos;
-	struct list_head * list;
+	struct dcookie_struct *dcs;
+	struct list_head *head;
 
-	list = dcookie_hashtable + dcookie_hash(dcookie);
+	head = dcookie_hashtable + dcookie_hash(dcookie);
 
-	list_for_each(pos, list) {
-		dcs = list_entry(pos, struct dcookie_struct, hash_list);
+	list_for_each_entry(dcs, head, hash_list) {
 		if (dcookie_value(dcs) == dcookie) {
-			found = dcs;
-			break;
+			return dcs;
 		}
 	}
 
-	return found;
+	return NULL;
 }
 
 
@@ -283,16 +279,13 @@ static void free_dcookie(struct dcookie_struct * dcs)
 
 static void dcookie_exit(void)
 {
-	struct list_head * list;
-	struct list_head * pos;
-	struct list_head * pos2;
-	struct dcookie_struct * dcs;
+	struct list_head *head;
+	struct dcookie_struct *dcs, *tmp;
 	size_t i;
 
 	for (i = 0; i < hash_size; ++i) {
-		list = dcookie_hashtable + i;
-		list_for_each_safe(pos, pos2, list) {
-			dcs = list_entry(pos, struct dcookie_struct, hash_list);
+		head = dcookie_hashtable + i;
+		list_for_each_entry_safe(dcs, tmp, head, hash_list) {
 			list_del(&dcs->hash_list);
 			free_dcookie(dcs);
 		}
fs/mbcache.c +3 -3
index 8c32ef3..ae7d9de 100644
@@ -458,14 +458,14 @@ mb_cache_entry_get(struct mb_cache *cache, struct block_device *bdev,
 		   sector_t block)
 {
 	unsigned int bucket;
-	struct list_head *l;
+	struct list_head *head;
 	struct mb_cache_entry *ce;
 
 	bucket = hash_long((unsigned long)bdev + (block & 0xffffffff),
 			   cache->c_bucket_bits);
 	spin_lock(&mb_cache_spinlock);
-	list_for_each(l, &cache->c_block_hash[bucket]) {
-		ce = list_entry(l, struct mb_cache_entry, e_block_list);
+	head = &cache->c_block_hash[bucket];
+	list_for_each_entry(ce, head, e_block_list) {
 		if (ce->e_bdev == bdev && ce->e_block == block) {
 			DEFINE_WAIT(wait);
 
Signature · 1 line
1.7.1