Skip to contentSkip to conversation

linux/time.h: Remove dead code

PATCH New Marek Behún 2 participants 10 messages Oct 6, 2017 – Oct 17, 2017 1 message not in the archive

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

PATCH 1/4 linux/time.h: Remove dead code

Since
rem = ((long) *tim_p) % SECSPERDAY;
the second while cycle
while (rem >= SECSPERDAY)
is dead.

Reported-by Coverity (CID: 167334)
---
 include/linux/time.h | 5 -----
 1 file changed, 5 deletions(-)
include/linux/time.h +0 -5
index bf12b99d37..b8d298eb4d 100644
@@ -93,11 +93,6 @@ _DEFUN (localtime_r, (tim_p, res),
 	rem += SECSPERDAY;
 	--days;
     }
-    while (rem >= SECSPERDAY)
-    {
-	rem -= SECSPERDAY;
-	++days;
-    }
 
     /* compute hour, min, and sec */
     res->tm_hour = (int) (rem / SECSPERHOUR);
Signature · 1 line
2.13.6
#1 lore raw

PATCH 2/4 fs: btrfs: Fix usage of uninitialized variables

The variable res should be initialized to 0 in these functions, because if the searched key is not found, the variable is used uninitialized.

Reported-by Coverity (CID: 167335)
Reported-by Coverity (CID: 167336)
Reported-by Coverity (CID: 167337)
---
 fs/btrfs/chunk-map.c | 2 +-
 fs/btrfs/dir-item.c  | 2 +-
 fs/btrfs/inode.c     | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/chunk-map.c +1 -1
index 48407f3331..ce7330b1b7 100644
@@ -147,7 +147,7 @@ int btrfs_read_chunk_tree(void)
 	struct btrfs_path path;
 	struct btrfs_key key, *found_key;
 	struct btrfs_chunk *chunk;
-	int res;
+	int res = 0;
 
 	key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
 	key.type = BTRFS_CHUNK_ITEM_KEY;
fs/btrfs/dir-item.c +1 -1
index decf86eb53..970563404f 100644
@@ -93,7 +93,7 @@ int btrfs_readdir(const struct btrfs_root *root, u64 dir,
 	struct btrfs_path path;
 	struct btrfs_key key, *found_key;
 	struct btrfs_dir_item *item;
-	int res;
+	int res = 0;
 
 	key.objectid = dir;
 	key.type = BTRFS_DIR_INDEX_KEY;
fs/btrfs/inode.c +1 -1
index 0d3da28296..0af04278a3 100644
@@ -324,7 +324,7 @@ u64 btrfs_file_read(const struct btrfs_root *root, u64 inr, u64 offset,
 	struct btrfs_path path;
 	struct btrfs_key key;
 	struct btrfs_file_extent_item *extent;
-	int res;
+	int res = 0;
 	u64 rd, rd_all = -1ULL;
 
 	key.objectid = inr;
Signature · 1 line
2.13.6

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

PATCH 2/4 fs: btrfs: Fix usage of uninitialized variables

Quoted 5 lines · On Fri, 6 Oct 2017 06:54:34 -0700 "J. William Campbell"…

Hi Marek,
        If the searched key is not found, isn't it an error to use
the res value AT ALL? Setting it to 0 may cover up the warning, but the function shouldn't actually use it for anything. If it does, it is modifying an element that doesn't match the search key.

Hi Bill,

the res variable is just an indicator if an error occured. In these functions if no key is found, it is not an error (for example if no key is found in btrfs_readdir, it just means the directory is empty, which is not an error).

Marek

Quoted 3 lines

Best Regards,
Bill Campbell

#4 lore raw

PATCH 2/4 fs: btrfs: Fix usage of uninitialized variables

In reply to Marek Behún
Quoted 8 lines · Marek Behún

The variable res should be initialized to 0 in these functions, because if the searched key is not found, the variable is used uninitialized.

Reported-by Coverity (CID: 167335)
Reported-by Coverity (CID: 167336)
Reported-by Coverity (CID: 167337)

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171016/b2a6f7ad/attachment.sig>
#5 lore raw

PATCH 3/4 fs: btrfs: Fix printf length modifier

In reply to Marek Behún

Change %lu to %u. The compiler issues a warning otherwise.

---
 fs/btrfs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/super.c +1 -1
index 2529c2b3b6..706286ee2d 100644
@@ -147,7 +147,7 @@ static int btrfs_check_super(struct btrfs_super_block *sb)
 
 	if (sb->sys_chunk_array_size < sizeof(struct btrfs_key) +
 	    sizeof(struct btrfs_chunk)) {
-		printf("%s: system chunk array too small %u < %lu\n", __func__,
+		printf("%s: system chunk array too small %u < %u\n", __func__,
 		       sb->sys_chunk_array_size, (u32) sizeof(struct btrfs_key)
 		       + sizeof(struct btrfs_chunk));
 		ret = -1;
Signature · 1 line
2.13.6
#6 lore raw

PATCH 3/4 fs: btrfs: Fix printf length modifier

Hmm, this is weird. Tom's commit 6b7fd350

http://git.denx.de/?p=u-boot.git;a=commit;h=6b7fd350e85a97892a2cb066364797f3f3dcb9c9

forces %lu here, because the %u issued a warning.
But my compiler warns when %lu is used.
Maybe we should use PRIu32 instead...

...

Quoted 21 lines · On Fri, 6 Oct 2017 15:04:58 +0200 Marek Behún <[email protected]> wrote:

Change %lu to %u. The compiler issues a warning otherwise.

---
 fs/btrfs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/super.c +1 -1
index 2529c2b3b6..706286ee2d 100644
@@ -147,7 +147,7 @@ static int btrfs_check_super(struct
 btrfs_super_block *sb) 
 	if (sb->sys_chunk_array_size < sizeof(struct btrfs_key) +
 	    sizeof(struct btrfs_chunk)) {
-		printf("%s: system chunk array too small %u <
 %lu\n", __func__,
+		printf("%s: system chunk array too small %u < %u\n",
 __func__, sb->sys_chunk_array_size, (u32) sizeof(struct btrfs_key)
 		       + sizeof(struct btrfs_chunk));

ret = -1;

#7 lore raw

PATCH 3/4 fs: btrfs: Fix printf length modifier

Quoted 7 lines · Marek Behún

Hmm, this is weird. Tom's commit 6b7fd350

http://git.denx.de/?p=u-boot.git;a=commit;h=6b7fd350e85a97892a2cb066364797f3f3dcb9c9

forces %lu here, because the %u issued a warning.
But my compiler warns when %lu is used.
Maybe we should use PRIu32 instead...

Yes, oops :)

Quoted 32 lines

...

Quoted 20 lines · On Fri, 6 Oct 2017 15:04:58 +0200 Marek Behún <[email protected]> wrote:

Change %lu to %u. The compiler issues a warning otherwise.

---
 fs/btrfs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/super.c +1 -1
index 2529c2b3b6..706286ee2d 100644
@@ -147,7 +147,7 @@ static int btrfs_check_super(struct
 btrfs_super_block *sb) 
 	if (sb->sys_chunk_array_size < sizeof(struct btrfs_key) +
 	    sizeof(struct btrfs_chunk)) {
-		printf("%s: system chunk array too small %u <
 %lu\n", __func__,
+		printf("%s: system chunk array too small %u < %u\n",
 __func__, sb->sys_chunk_array_size, (u32) sizeof(struct btrfs_key)
 		       + sizeof(struct btrfs_chunk));
Quoted 1 line

ret = -1;

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171006/4cec6128/attachment.sig>
#8 lore raw

PATCH 4/4 fs: btrfs: Remove a foreign language note

In reply to Marek Behún

I accidentaly left a foreign language note in the code from development.

---
 fs/btrfs/inode.c | 1 -
 1 file changed, 1 deletion(-)
fs/btrfs/inode.c +0 -1
index 0af04278a3..f785b600fa 100644
@@ -210,7 +210,6 @@ static inline const char *skip_current_directories(const char *cur)
 	return cur;
 }
 
-/* inode.c, musi vratit aj root stromu kde sa inoda najde */
 u64 btrfs_lookup_path(struct btrfs_root *root, u64 inr, const char *path,
 		      u8 *type_p, struct btrfs_inode_item *inode_item_p,
 		      int symlink_limit)
Signature · 1 line
2.13.6
#9 lore raw

PATCH 4/4 fs: btrfs: Remove a foreign language note

Quoted 3 lines · Marek Behún

I accidentaly left a foreign language note in the code from development.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171016/71171784/attachment.sig>
#10 lore raw

PATCH 1/4 linux/time.h: Remove dead code

In reply to Marek Behún
Quoted 8 lines · Marek Behún

Since
rem = ((long) *tim_p) % SECSPERDAY;
the second while cycle
while (rem >= SECSPERDAY)
is dead.

Reported-by Coverity (CID: 167334)

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20171016/761c9f67/attachment.sig>