fs-qnx6: Adjustments for qnx6_mmi_fill_super()
Subsystems (2)
cover fs-qnx6: Adjustments for qnx6_mmi_fill_super()
From: Markus Elfring <[email protected]>
Date: Wed, 16 Aug 2017 18:08:02 +0200
Two update suggestions were taken into account
from static source code analysis.
Markus Elfring (2):
Delete an error message for a failed memory allocation Less checks in qnx6_mmi_fill_super() after error detection
fs/qnx6/super_mmi.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-)
Signature · 1 line
2.14.0
PATCH 1/2 fs-qnx6: Delete an error message for a failed memory allocation in qnx6_mmi_fill_super()
From: Markus Elfring <[email protected]>
Date: Wed, 16 Aug 2017 17:07:26 +0200
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
--- fs/qnx6/super_mmi.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/qnx6/super_mmi.c +1 -3
@@ -100,10 +100,8 @@ struct qnx6_super_block *qnx6_mmi_fill_super(struct super_block *s, int silent) } qsb =kmalloc (sizeof (*qsb),GFP_KERNEL ); -if (!qsb) { -pr_err ("unable to allocate memory.\n" ); +if (!qsb) goto out; - }if (fs64_to_cpu (sbi, sb1->sb_serial) >fs64_to_cpu (sbi, sb2->sb_serial)) {
Signature · 1 line
2.14.0
PATCH 2/2 fs-qnx6: Less checks in qnx6_mmi_fill_super() after error detection
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 16 Aug 2017 18:00:24 +0200
Two pointer checks could be repeated by the qnx6_mmi_fill_super() function during error handling even if the relevant properties can be determined for the involved variables before by source code analysis.
* Adjust jump targets so that extra checks can be omitted at the end.
* Delete an initialisation for the variables "bh2" and "qsb" which became unnecessary with this refactoring.
--- fs/qnx6/super_mmi.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)
fs/qnx6/super_mmi.c +15 -16
@@ -34,9 +34,9 @@ static void qnx6_mmi_copy_sb(struct qnx6_super_block *qsb,struct qnx6_super_block *qnx6_mmi_fill_super (struct super_block *s,int silent) { -struct buffer_head *bh1, *bh2 =NULL ; +struct buffer_head *bh1, *bh2;struct qnx6_mmi_super_block *sb1, *sb2; -struct qnx6_super_block *qsb =NULL ; +struct qnx6_super_block *qsb;struct qnx6_sb_info *sbi;__u64 offset;
@@ -52,7 +52,7 @@ struct qnx6_super_block *qnx6_mmi_fill_super(struct super_block *s, int silent)if (fs32_to_cpu (sbi, sb1->sb_magic) !=QNX6_SUPER_MAGIC ) {if (!silent) {pr_err ("wrong signature (magic) in superblock #1.\n" ); - goto out; + goto brelse_first; } }
@@ -60,7 +60,7 @@ struct qnx6_super_block *qnx6_mmi_fill_super(struct super_block *s, int silent) if (fs32_to_cpu(sbi, sb1->sb_checksum) ! crc32_be(0, (char *)(bh1->b_data + 8), 504)) {pr_err ("superblock #1 checksum error\n" ); - goto out; + goto brelse_first; }/* calculate second superblock blocknumber */
@@ -70,38 +70,38 @@ struct qnx6_super_block *qnx6_mmi_fill_super(struct super_block *s, int silent)/* set new blocksize */ if (!sb_set_blocksize (s,fs32_to_cpu (sbi, sb1->sb_blocksize))) {pr_err ("unable to set blocksize\n" ); - goto out; + goto brelse_first; }/* blocksize invalidates bh - pull it back in */ brelse (bh1); bh1 =sb_bread (s,0 );if (!bh1) - goto out; + goto exit; sb1 = (struct qnx6_mmi_super_block *)bh1->b_data;/* read second superblock */ bh2 =sb_bread (s, offset);if (!bh2) {pr_err ("unable to read the second superblock\n" ); - goto out; + goto brelse_first; } sb2 = (struct qnx6_mmi_super_block *)bh2->b_data;if (fs32_to_cpu (sbi, sb2->sb_magic) !=QNX6_SUPER_MAGIC ) {if (!silent)pr_err ("wrong signature (magic) in superblock #2.\n" ); - goto out; + goto brelse_second; }/* checksum check - start at byte 8 and end at byte 512 */ if (fs32_to_cpu (sbi, sb2->sb_checksum) !=crc32_be (0 , (char *)(bh2->b_data +8 ),504 )) {pr_err ("superblock #1 checksum error\n" ); - goto out; + goto brelse_second; } qsb =kmalloc (sizeof (*qsb),GFP_KERNEL );if (!qsb) - goto out; + goto brelse_second;if (fs64_to_cpu (sbi, sb1->sb_serial) >fs64_to_cpu (sbi, sb2->sb_serial)) {
@@ -136,11 +136,10 @@ struct qnx6_super_block *qnx6_mmi_fill_super(struct super_block *s, int silent)/* success */ return sbi->sb; - -out: -if (bh1 !=NULL ) -brelse (bh1); -if (bh2 !=NULL ) -brelse (bh2); +brelse_second: +brelse (bh2); +brelse_first: +brelse (bh1); +exit:return NULL ; }
Signature · 1 line
2.14.0