Skip to contentSkip to conversation

fs: fat: remove superfluous assignments

PATCH New Heinrich Schuchardt 3 participants 4 messages Jan 25, 2021 – Jan 30, 2021 VFAT/FAT/msdos filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: fat: remove superfluous assignments

Do not assign a value to a variable if it is not used.

---
 fs/fat/fat.c       | 3 ++-
 fs/fat/fat_write.c | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)
fs/fat/fat.c +2 -1
index fb6ce094ac..ccba268f61 100644
@@ -248,7 +248,6 @@ static __u32 get_fatent(fsdata *mydata, __u32 entry)
 static int
 get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size)
 {
-	__u32 idx = 0;
 	__u32 startsect;
 	int ret;
 
@@ -277,6 +276,8 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size)
 			size -= mydata->sect_size;
 		}
 	} else {
+		__u32 idx;
+
 		idx = size / mydata->sect_size;
 		if (idx == 0)
 			ret = 0;
fs/fat/fat_write.c +3 -3
index aae3a6a3d1..b43a27b205 100644
@@ -573,7 +573,6 @@ static __u32 determine_fatent(fsdata *mydata, __u32 entry)
 static int
 set_sectors(fsdata *mydata, u32 startsect, u8 *buffer, u32 size)
 {
-	u32 nsects = 0;
 	int ret;
 
 	debug("startsect: %d\n", startsect);
@@ -595,6 +594,8 @@ set_sectors(fsdata *mydata, u32 startsect, u8 *buffer, u32 size)
 			size -= mydata->sect_size;
 		}
 	} else if (size >= mydata->sect_size) {
+		u32 nsects;
+
 		nsects = size / mydata->sect_size;
 		ret = disk_write(startsect, nsects, buffer);
 		if (ret != nsects) {
@@ -785,7 +786,6 @@ get_set_cluster(fsdata *mydata, __u32 clustnum, loff_t pos, __u8 *buffer,
 		}
 
 		size -= wsize;
-		buffer += wsize;
 		*gotsize += wsize;
 	}
 
@@ -1482,10 +1482,10 @@ static int delete_single_dentry(fat_itr *itr)
  */
 static int delete_long_name(fat_itr *itr)
 {
-	struct dir_entry *dent = itr->dent;
 	int seqn = itr->dent->nameext.name[0] & ~LAST_LONG_ENTRY_MASK;
 
 	while (seqn--) {
+		struct dir_entry *dent;
 		int ret;
 
 		ret = delete_single_dentry(itr);

--
2.29.2

#1 lore raw

PATCH 1/1 fs: fat: remove superfluous assignments

Hi

Am Di., 26. Jan. 2021 um 00:14 Uhr schrieb Heinrich Schuchardt <[email protected]>:

Quoted 2 lines

Do not assign a value to a variable if it is not used.

I am not very happy about this commit message tbo. What you are doing is reducing the scope
of variables.. so write this in your commit message.

Quoted 50 lines
---
 fs/fat/fat.c       | 3 ++-
 fs/fat/fat_write.c | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)
fs/fat/fat.c +2 -1
index fb6ce094ac..ccba268f61 100644
@@ -248,7 +248,6 @@ static __u32 get_fatent(fsdata *mydata, __u32 entry)
 static int
 get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size)
 {
-       __u32 idx = 0;
        __u32 startsect;
        int ret;
 
@@ -277,6 +276,8 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size)
                        size -= mydata->sect_size;
                }
        } else {
+               __u32 idx;
+
                idx = size / mydata->sect_size;
                if (idx == 0)
                        ret = 0;
fs/fat/fat_write.c +2 -1
index aae3a6a3d1..b43a27b205 100644
@@ -573,7 +573,6 @@ static __u32 determine_fatent(fsdata *mydata, __u32 entry)
 static int
 set_sectors(fsdata *mydata, u32 startsect, u8 *buffer, u32 size)
 {
-       u32 nsects = 0;
        int ret;
 
        debug("startsect: %d\n", startsect);
@@ -595,6 +594,8 @@ set_sectors(fsdata *mydata, u32 startsect, u8 *buffer, u32 size)
                        size -= mydata->sect_size;
                }
        } else if (size >= mydata->sect_size) {
+               u32 nsects;
+
                nsects = size / mydata->sect_size;
                ret = disk_write(startsect, nsects, buffer);
                if (ret != nsects) {

fs/fat/fat_write.c get_set_cluster(fsdata *mydata, __u32 clustnum, loff_t pos, __u8 *buffer, · line 788

Quoted 4 lines
fs/fat/fat_write.c +0 -1
@@ -785,7 +786,6 @@ get_set_cluster(fsdata *mydata, __u32 clustnum, loff_t pos, __u8 *buffer,
                }
 
                size -= wsize;
-               buffer += wsize;

That looks wrong when staring at it from my mail client.

Quoted 18 lines
fs/fat/fat_write.c +1 -2
                *gotsize += wsize;
        }
 
@@ -1482,10 +1482,10 @@ static int delete_single_dentry(fat_itr *itr)
  */
 static int delete_long_name(fat_itr *itr)
 {
-       struct dir_entry *dent = itr->dent;
        int seqn = itr->dent->nameext.name[0] & ~LAST_LONG_ENTRY_MASK;
 
        while (seqn--) {
+               struct dir_entry *dent;
                int ret;
 
                ret = delete_single_dentry(itr);
--

2.29.2

Signature · 5 lines
greets
--
Christian Gmeiner, MSc

https://christian-gmeiner.info/privacypolicy
#2 lore raw

PATCH 1/1 fs: fat: remove superfluous assignments

Quoted 10 lines · Christian Gmeiner

Hi

Am Di., 26. Jan. 2021 um 00:14 Uhr schrieb Heinrich Schuchardt <[email protected]>:

Quoted 2 lines

Do not assign a value to a variable if it is not used.

I am not very happy about this commit message tbo. What you are doing is reducing the scope
of variables.. so write this in your commit message.

Sure.

Quoted 53 lines
Quoted 53 lines
---
 fs/fat/fat.c       | 3 ++-
 fs/fat/fat_write.c | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)
fs/fat/fat.c +2 -1
index fb6ce094ac..ccba268f61 100644
@@ -248,7 +248,6 @@ static __u32 get_fatent(fsdata *mydata, __u32 entry)
 static int
 get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size)
 {
-       __u32 idx = 0;
        __u32 startsect;
        int ret;
 
@@ -277,6 +276,8 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size)
                        size -= mydata->sect_size;
                }
        } else {
+               __u32 idx;
+
                idx = size / mydata->sect_size;
                if (idx == 0)
                        ret = 0;
fs/fat/fat_write.c +2 -1
index aae3a6a3d1..b43a27b205 100644
@@ -573,7 +573,6 @@ static __u32 determine_fatent(fsdata *mydata, __u32 entry)
 static int
 set_sectors(fsdata *mydata, u32 startsect, u8 *buffer, u32 size)
 {
-       u32 nsects = 0;
        int ret;
 
        debug("startsect: %d\n", startsect);
@@ -595,6 +594,8 @@ set_sectors(fsdata *mydata, u32 startsect, u8 *buffer, u32 size)
                        size -= mydata->sect_size;
                }
        } else if (size >= mydata->sect_size) {
+               u32 nsects;
+
                nsects = size / mydata->sect_size;
                ret = disk_write(startsect, nsects, buffer);
                if (ret != nsects) {
@@ -785,7 +786,6 @@ get_set_cluster(fsdata *mydata, __u32 clustnum, loff_t pos, __u8 *buffer,
                }
 
Quoted 4 lines

fs/fat/fat_write.c get_set_cluster(fsdata *mydata, __u32 clustnum, loff_t pos, __u8 *buffer, · line 788

Quoted 2 lines
fs/fat/fat_write.c +0 -1
                size -= wsize;
-               buffer += wsize;

That looks wrong when staring at it from my mail client.

This is the last time buffer is accessed before return. Why do you think it is wrong?

Best regards

Heinrich

Quoted 21 lines
Quoted 19 lines
fs/fat/fat_write.c +1 -2
                *gotsize += wsize;
        }
 
@@ -1482,10 +1482,10 @@ static int delete_single_dentry(fat_itr *itr)
  */
 static int delete_long_name(fat_itr *itr)
 {
-       struct dir_entry *dent = itr->dent;
        int seqn = itr->dent->nameext.name[0] & ~LAST_LONG_ENTRY_MASK;
 
        while (seqn--) {
+               struct dir_entry *dent;
                int ret;
 
                ret = delete_single_dentry(itr);
--

2.29.2

#3 lore raw

PATCH 1/1 fs: fat: remove superfluous assignments

In reply to Heinrich Schuchardt
Quoted 3 lines · Heinrich Schuchardt

Do not assign a value to a variable if it is not used.

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: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210130/0dd3a803/attachment.sig>