UBIFS: fix minor stylistic issues
Subsystems (2)
PATCH 3/4 UBIFS: do not read flash unnecessarily
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
This fix makes the 'dbg_check_old_index()' function return immediately if debugging is disabled, instead of executing incorrect 'goto out' which causes UBIFS to:
1. Allocate memory
2. Read the flash
On every commit. OK, we do not commit that often, but it is still silly to do unneeded I/O anyway.
Credits to coverity for spotting this silly issue.
--- fs/ubifs/commit.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/ubifs/commit.c +1 -1
@@ -577,7 +577,7 @@ int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot)size_t sz;if (!(ubifs_chk_flags &UBIFS_CHK_OLD_IDX )) - goto out; +return 0 ;INIT_LIST_HEAD (&list);
Signature · 1 line
1.7.2.3
PATCH 4/4 UBIFS: fix oops on error path in read_pnode
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Thanks to coverity which spotted that UBIFS will oops if 'kmalloc()' in 'read_pnode()' fails and we dereference a NULL 'pnode' pointer when we 'goto out'.
--- fs/ubifs/lpt.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
fs/ubifs/lpt.c +3 -4
@@ -1270,10 +1270,9 @@ static int read_pnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip) lnum = branch->lnum; offs = branch->offs; pnode =kzalloc (sizeof (struct ubifs_pnode ),GFP_NOFS ); -if (!pnode) { - err = -ENOMEM ; - goto out; - } +if (!pnode) +return -ENOMEM ; +if (lnum ==0 ) {/* * This pnode was not written which just means that the LEB
Signature · 1 line
1.7.2.3
PATCH 2/4 UBIFS: use __packed instead of __attribute__((packed))
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
There was an attempt to standartize various "__attribute__" and other macros in order to have potentially portable and more consistent code, see commit 82ddcb040570411fc2d421d96b3e69711c670328.
Note, that commit refers Rober Love's blog post, but the URL is broken, the valid URL is:
http://blog.rlove.org/2005/10/with-little-help-from-your-compiler.html
Moreover, nowadays checkpatch.pl warns about using __attribute__((packed)):
"WARNING: __packed is preferred over __attribute__((packed))"
It is not a big deal for UBIFS to use __packed, so let's do it.
--- fs/ubifs/ubifs-media.h | 28 ++++++++++++++-------------- 1 files changed, 14 insertions(+), 14 deletions(-)
fs/ubifs/ubifs-media.h +14 -14
@@ -434,7 +434,7 @@ struct ubifs_ch {__u8 node_type;__u8 group_type;__u8 padding[2 ]; -} __attribute__ ((packed)); +} __packed;/** * union ubifs_dev_desc - device node descriptor.
@@ -448,7 +448,7 @@ struct ubifs_ch {union ubifs_dev_desc {__le32 new;__le64 huge; -} __attribute__ ((packed)); +} __packed;/** * struct ubifs_ino_node - inode node.
@@ -509,7 +509,7 @@ struct ubifs_ino_node {__le16 compr_type;__u8 padding2[26 ];/* Watch 'zero_ino_node_unused()' if changing! */ __u8 data[]; -} __attribute__ ((packed)); +} __packed;/** * struct ubifs_dent_node - directory entry node.
@@ -534,7 +534,7 @@ struct ubifs_dent_node {__le16 nlen;__u8 padding2[4 ];/* Watch 'zero_dent_node_unused()' if changing! */ __u8 name[]; -} __attribute__ ((packed)); +} __packed;/** * struct ubifs_data_node - data node.
@@ -555,7 +555,7 @@ struct ubifs_data_node {__le16 compr_type;__u8 padding[2 ];/* Watch 'zero_data_node_unused()' if changing! */ __u8 data[]; -} __attribute__ ((packed)); +} __packed;/** * struct ubifs_trun_node - truncation node.
@@ -575,7 +575,7 @@ struct ubifs_trun_node {__u8 padding[12 ];/* Watch 'zero_trun_node_unused()' if changing! */ __le64 old_size;__le64 new_size; -} __attribute__ ((packed)); +} __packed;/** * struct ubifs_pad_node - padding node.
@@ -586,7 +586,7 @@ struct ubifs_trun_node {struct ubifs_pad_node {struct ubifs_ch ch;__le32 pad_len; -} __attribute__ ((packed)); +} __packed;/** * struct ubifs_sb_node - superblock node.
@@ -644,7 +644,7 @@ struct ubifs_sb_node {__u8 uuid[16 ];__le32 ro_compat_version;__u8 padding2[3968 ]; -} __attribute__ ((packed)); +} __packed;/** * struct ubifs_mst_node - master node.
@@ -711,7 +711,7 @@ struct ubifs_mst_node {__le32 idx_lebs;__le32 leb_cnt;__u8 padding[344 ]; -} __attribute__ ((packed)); +} __packed;/** * struct ubifs_ref_node - logical eraseblock reference node.
@@ -727,7 +727,7 @@ struct ubifs_ref_node {__le32 offs;__le32 jhead;__u8 padding[28 ]; -} __attribute__ ((packed)); +} __packed;/** * struct ubifs_branch - key/reference/length branch
@@ -741,7 +741,7 @@ struct ubifs_branch {__le32 offs;__le32 len;__u8 key[]; -} __attribute__ ((packed)); +} __packed;/** * struct ubifs_idx_node - indexing node.
@@ -755,7 +755,7 @@ struct ubifs_idx_node {__le16 child_cnt;__le16 level;__u8 branches[]; -} __attribute__ ((packed)); +} __packed;/** * struct ubifs_cs_node - commit start node.
@@ -765,7 +765,7 @@ struct ubifs_idx_node {struct ubifs_cs_node {struct ubifs_ch ch;__le64 cmt_no; -} __attribute__ ((packed)); +} __packed;/** * struct ubifs_orph_node - orphan node.
@@ -777,6 +777,6 @@ struct ubifs_orph_node {struct ubifs_ch ch;__le64 cmt_no; __le64 inos[]; -} __attribute__ ((packed)); +} __packed;#endif /* __UBIFS_MEDIA_H__ */
Signature · 1 line
1.7.2.3
PATCH 1/4 UBIFS: fix minor stylistic issues
From: Artem Bityutskiy <[email protected]>
Fix several minor stylistic issues:
* lines longer than 80 characters
* space before closing parenthesis ')'
* spaces in the indentations
--- fs/ubifs/debug.c | 3 ++- fs/ubifs/file.c | 17 +++++++++-------- fs/ubifs/io.c | 4 ++-- fs/ubifs/lpt_commit.c | 2 +- fs/ubifs/orphan.c | 3 ++- fs/ubifs/super.c | 4 ++-- fs/ubifs/tnc.c | 10 +++++----- fs/ubifs/ubifs.h | 6 +++--- 8 files changed, 26 insertions(+), 23 deletions(-)
fs/ubifs/debug.c +2 -1
@@ -2390,7 +2390,8 @@ int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head) hashb =key_block (c, &sb->key);if (hasha > hashb) { -ubifs_err ("larger hash %u goes before %u" , hasha, hashb); +ubifs_err ("larger hash %u goes before %u" , + hasha, hashb); goto error_dump; } }
fs/ubifs/file.c +9 -8
@@ -971,11 +971,11 @@ static int do_writepage(struct page *page, int len)* the page locked, and it locks @ui_mutex. However, write-back does take inode * @i_mutex, which means other VFS operations may be run on this inode at the * same time. And the problematic one is truncation to smaller size, from where -* we have to call 'truncate_setsize()', which first changes @inode->i_size, then -* drops the truncated pages. And while dropping the pages, it takes the page -* lock. This means that 'do_truncation()' cannot call 'truncate_setsize()' with -* @ui_mutex locked, because it would deadlock with 'ubifs_writepage()'. This -* means that @inode->i_size is changed while @ui_mutex is unlocked. +* we have to call 'truncate_setsize()', which first changes @inode->i_size, +* then drops the truncated pages. And while dropping the pages, it takes the +* page lock. This means that 'do_truncation()' cannot call 'truncate_setsize()' +* with @ui_mutex locked, because it would deadlock with 'ubifs_writepage()'. +* This means that @inode->i_size is changed while @ui_mutex is unlocked. * * XXX(truncate): with the new truncate sequence this is not true anymore, * and the calls to truncate_setsize can be move around freely. They should
@@ -1429,10 +1429,11 @@ static int ubifs_releasepage(struct page *page, gfp_t unused_gfp_flags) }/* -* mmap()d file has taken write protection fault and is being made -* writable. UBIFS must ensure page is budgeted for. +* mmap()d file has taken write protection fault and is being made writable. +* UBIFS must ensure page is budgeted for. */ -static int ubifs_vm_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf) +static int ubifs_vm_page_mkwrite (struct vm_area_struct *vma, +struct vm_fault *vmf) {struct page *page = vmf->page;struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
fs/ubifs/io.c +2 -2
@@ -393,7 +393,7 @@ int ubifs_wbuf_sync_nolock(struct ubifs_wbuf *wbuf)ubifs_assert (wbuf->size % c->min_io_size ==0 );ubifs_assert (!c->ro_media && !c->ro_mount);if (c->leb_size - wbuf->offs >= c->max_write_size) -ubifs_assert (!((wbuf->offs + wbuf->size) % c->max_write_size )); +ubifs_assert (!((wbuf->offs + wbuf->size) % c->max_write_size));if (c->ro_error)return -EROFS ;
@@ -588,7 +588,7 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len)ubifs_assert (mutex_is_locked (&wbuf->io_mutex));ubifs_assert (!c->ro_media && !c->ro_mount);if (c->leb_size - wbuf->offs >= c->max_write_size) -ubifs_assert (!((wbuf->offs + wbuf->size) % c->max_write_size )); +ubifs_assert (!((wbuf->offs + wbuf->size) % c->max_write_size));if (c->leb_size - wbuf->offs - wbuf->used < aligned_len) { err = -ENOSPC ;
fs/ubifs/lpt_commit.c +1 -1
@@ -586,7 +586,7 @@ static struct ubifs_pnode *next_pnode_to_dirty(struct ubifs_info *c,if (nnode->nbranch[iip].lnum)break ; } - }while (iip >=UBIFS_LPT_FANOUT ); + }while (iip >=UBIFS_LPT_FANOUT );/* Go right */ nnode =ubifs_get_nnode (c, nnode, iip);
fs/ubifs/orphan.c +2 -1
@@ -673,7 +673,8 @@ static int kill_orphans(struct ubifs_info *c) sleb =ubifs_scan (c, lnum,0 , c->sbuf,1 );if (IS_ERR (sleb)) {if (PTR_ERR (sleb) == -EUCLEAN ) - sleb =ubifs_recover_leb (c, lnum,0 , c->sbuf,0 ); + sleb =ubifs_recover_leb (c, lnum,0 , + c->sbuf,0 );if (IS_ERR (sleb)) { err =PTR_ERR (sleb);break ;
fs/ubifs/super.c +2 -2
@@ -1144,7 +1144,7 @@ static int check_free_space(struct ubifs_info *c) {ubifs_assert (c->dark_wm >0 );if (c->lst.total_free + c->lst.total_dirty < c->dark_wm) { -ubifs_err ("insufficient free space to mount in read/write mode" ); +ubifs_err ("insufficient free space to mount in R/W mode" );dbg_dump_budg (c);dbg_dump_lprops (c);return -ENOSPC ;
@@ -1456,7 +1456,7 @@ static int mount_ubifs(struct ubifs_info *c)dbg_msg ("node sizes: ref %zu, cmt. start %zu, orph %zu" ,UBIFS_REF_NODE_SZ ,UBIFS_CS_NODE_SZ ,UBIFS_ORPH_NODE_SZ );dbg_msg ("max. node sizes: data %zu, inode %zu dentry %zu, idx %d" , -UBIFS_MAX_DATA_NODE_SZ ,UBIFS_MAX_INO_NODE_SZ , +UBIFS_MAX_DATA_NODE_SZ ,UBIFS_MAX_INO_NODE_SZ ,UBIFS_MAX_DENT_NODE_SZ ,ubifs_idx_node_sz (c, c->fanout));dbg_msg ("dead watermark: %d" , c->dead_wm);dbg_msg ("dark watermark: %d" , c->dark_wm);
fs/ubifs/tnc.c +5 -5
@@ -2557,11 +2557,11 @@ int ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key,if (err) {/* Ensure the znode is dirtied */ if (znode->cnext || !ubifs_zn_dirty (znode)) { - znode =dirty_cow_bottom_up (c, znode); -if (IS_ERR (znode)) { - err =PTR_ERR (znode); - goto out_unlock; - } + znode =dirty_cow_bottom_up (c, znode); +if (IS_ERR (znode)) { + err =PTR_ERR (znode); + goto out_unlock; + } } err =tnc_delete (c, znode, n); }
fs/ubifs/ubifs.h +3 -3
@@ -389,9 +389,9 @@ struct ubifs_gced_idx_leb {* The @ui_size is a "shadow" variable for @inode->i_size and UBIFS uses * @ui_size instead of @inode->i_size. The reason for this is that UBIFS cannot * make sure @inode->i_size is always changed under @ui_mutex, because it -* cannot call 'truncate_setsize()' with @ui_mutex locked, because it would deadlock -* with 'ubifs_writepage()' (see file.c). All the other inode fields are -* changed under @ui_mutex, so they do not need "shadow" fields. Note, one +* cannot call 'truncate_setsize()' with @ui_mutex locked, because it would +* deadlock with 'ubifs_writepage()' (see file.c). All the other inode fields +* are changed under @ui_mutex, so they do not need "shadow" fields. Note, one * could consider to rework locking and base it on "shadow" fields. */ struct ubifs_inode {
Signature · 1 line
1.7.2.3