Skip to contentSkip to conversation

fs-udf: Adjustments for some function implementations

PATCH In review SF Markus Elfring 2 participants 5 messages Aug 15, 2017 – Aug 16, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover fs-udf: Adjustments for some function implementations

From: Markus Elfring <[email protected]>
Date: Tue, 15 Aug 2017 17:10:12 +0200

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
Delete an error message for a failed memory allocation in two functions Improve six size determinations
Adjust two checks for null pointers

 fs/udf/inode.c | 13 ++++---------
 fs/udf/namei.c |  2 +-
 fs/udf/super.c | 12 +++++-------
 3 files changed, 10 insertions(+), 17 deletions(-)
Signature · 1 line
2.14.0
#1 lore raw

PATCH 1/3 fs-udf: Delete an error message for a failed memory allocation in two functions

From: Markus Elfring <[email protected]>
Date: Tue, 15 Aug 2017 16:14:19 +0200

Omit an extra message for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

---
 fs/udf/inode.c | 7 +------
 fs/udf/super.c | 2 --
 2 files changed, 1 insertion(+), 8 deletions(-)
fs/udf/inode.c +1 -6
index 18fdb9d90812..7b50afc6e0c3 100644
@@ -1572,13 +1572,8 @@ static int udf_alloc_i_data(struct inode *inode, size_t size)
 {
 	struct udf_inode_info *iinfo = UDF_I(inode);
 	iinfo->i_ext.i_data = kmalloc(size, GFP_KERNEL);
-
-	if (!iinfo->i_ext.i_data) {
-		udf_err(inode->i_sb, "(ino %ld) no free memory\n",
-			inode->i_ino);
+	if (!iinfo->i_ext.i_data)
 		return -ENOMEM;
-	}
-
 	return 0;
 }
 
fs/udf/super.c +0 -2
index 462ac2e9258c..ca4b4274b524 100644
@@ -271,6 +271,4 @@ static int udf_sb_alloc_partition_maps(struct super_block *sb, u32 count)
 	if (!sbi->s_partmaps) {
-		udf_err(sb, "Unable to allocate space for %d partition maps\n",
-			count);
 		sbi->s_partitions = 0;
 		return -ENOMEM;
 	}
Signature · 1 line
2.14.0
#2 lore raw

PATCH 2/3 fs-udf: Improve six size determinations

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 15 Aug 2017 16:45:44 +0200

Replace the specification of data structures by variable references as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 fs/udf/inode.c | 6 +++---
 fs/udf/namei.c | 2 +-
 fs/udf/super.c | 5 ++---
 3 files changed, 6 insertions(+), 7 deletions(-)
fs/udf/inode.c +3 -3
index 7b50afc6e0c3..8dacf4f57414 100644
@@ -114,7 +114,7 @@ static void udf_update_extent_cache(struct inode *inode, loff_t estart,
 	__udf_clear_extent_cache(inode);
 	if (pos->bh)
 		get_bh(pos->bh);
-	memcpy(&iinfo->cached_extent.epos, pos, sizeof(struct extent_position));
+	memcpy(&iinfo->cached_extent.epos, pos, sizeof(*pos));
 	iinfo->cached_extent.lstart = estart;
 	switch (iinfo->i_alloc_type) {
 	case ICBTAG_FLAG_AD_SHORT:
@@ -1698,7 +1698,7 @@ static int udf_update_inode(struct inode *inode, int do_sync)
 			dsea->impUseLength = cpu_to_le32(sizeof(struct regid));
 		}
 		eid = (struct regid *)dsea->impUse;
-		memset(eid, 0, sizeof(struct regid));
+		memset(eid, 0, sizeof(*eid));
 		strcpy(eid->ident, UDF_ID_DEVELOPER);
 		eid->identSuffix[0] = UDF_OS_CLASS_UNIX;
 		eid->identSuffix[1] = UDF_OS_ID_LINUX;
@@ -1749,7 +1749,7 @@ static int udf_update_inode(struct inode *inode, int do_sync)
 		udf_time_to_disk_stamp(&efe->createTime, iinfo->i_crtime);
 		udf_time_to_disk_stamp(&efe->attrTime, inode->i_ctime);
 
-		memset(&(efe->impIdent), 0, sizeof(struct regid));
+		memset(&(efe->impIdent), 0, sizeof(efe->impIdent));
 		strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);
 		efe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
 		efe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
fs/udf/namei.c +1 -1
index 385ee89d5824..885198dfd9f8 100644
@@ -1184,7 +1184,7 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
 	 */
 	ncfi.fileVersionNum = ocfi.fileVersionNum;
 	ncfi.fileCharacteristics = ocfi.fileCharacteristics;
-	memcpy(&(ncfi.icb), &(ocfi.icb), sizeof(struct long_ad));
+	memcpy(&(ncfi.icb), &(ocfi.icb), sizeof(ocfi.icb));
 	udf_write_fi(new_dir, &ncfi, nfi, &nfibh, NULL, NULL);
 
 	/* The old fid may have moved - find it again */
fs/udf/super.c +2 -3
index ca4b4274b524..0dc7c2d9f0fa 100644
@@ -266,6 +266,5 @@ static int udf_sb_alloc_partition_maps(struct super_block *sb, u32 count)
 {
 	struct udf_sb_info *sbi = UDF_SB(sb);
 
-	sbi->s_partmaps = kcalloc(count, sizeof(struct udf_part_map),
-				  GFP_KERNEL);
+	sbi->s_partmaps = kcalloc(count, sizeof(*sbi->s_partmaps), GFP_KERNEL);
 	if (!sbi->s_partmaps) {
@@ -2097,7 +2096,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
 	uopt.fmode = UDF_INVALID_MODE;
 	uopt.dmode = UDF_INVALID_MODE;
 
-	sbi = kzalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
+	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
 	if (!sbi)
 		return -ENOMEM;
 
Signature · 1 line
2.14.0
#3 lore raw

PATCH 3/3 fs-udf: Adjust two checks for null pointers

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 15 Aug 2017 17:03:06 +0200
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script “checkpatch.pl” pointed information out like the following.

Comparison to NULL could be written !…

Thus fix affected source code places.

---
 fs/udf/super.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/udf/super.c +3 -2
index 0dc7c2d9f0fa..93c59630512b 100644
@@ -321,7 +321,8 @@ static void udf_sb_free_partitions(struct super_block *sb)
 {
 	struct udf_sb_info *sbi = UDF_SB(sb);
 	int i;
-	if (sbi->s_partmaps = NULL)
+
+	if (!sbi->s_partmaps)
 		return;
 	for (i = 0; i < sbi->s_partitions; i++)
 		udf_free_partition(&sbi->s_partmaps[i]);
@@ -1068,7 +1069,7 @@ static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
 	else
 		bitmap = vzalloc(size); /* TODO: get rid of vzalloc */
 
-	if (bitmap = NULL)
+	if (!bitmap)
 		return NULL;
 
 	bitmap->s_nr_groups = nr_groups;
Signature · 1 line
2.14.0