diff mbox series

[1/1] fs: fat: remove superfluous assignments

Message ID 20210125231414.61516-1-xypron.glpk@gmx.de
State Accepted
Commit 84ca3055f0e6ae9c7d1434fac037bd6b8af1e8c9
Delegated to: Tom Rini
Headers show
Series [1/1] fs: fat: remove superfluous assignments | expand

Commit Message

Heinrich Schuchardt Jan. 25, 2021, 11:14 p.m. UTC
Do not assign a value to a variable if it is not used.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 fs/fat/fat.c       | 3 ++-
 fs/fat/fat_write.c | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)

--
2.29.2

Comments

Christian Gmeiner Jan. 26, 2021, 7:53 a.m. UTC | #1
Hi

Am Di., 26. Jan. 2021 um 00:14 Uhr schrieb Heinrich Schuchardt
<xypron.glpk@gmx.de>:
>
> 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.

>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  fs/fat/fat.c       | 3 ++-
>  fs/fat/fat_write.c | 6 +++---
>  2 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> index fb6ce094ac..ccba268f61 100644
> --- a/fs/fat/fat.c
> +++ b/fs/fat/fat.c
> @@ -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;
> diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
> index aae3a6a3d1..b43a27b205 100644
> --- a/fs/fat/fat_write.c
> +++ b/fs/fat/fat_write.c
> @@ -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;

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

>                 *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
>
Heinrich Schuchardt Jan. 26, 2021, 3:10 p.m. UTC | #2
On 26.01.21 08:53, Christian Gmeiner wrote:
> Hi
>
> Am Di., 26. Jan. 2021 um 00:14 Uhr schrieb Heinrich Schuchardt
> <xypron.glpk@gmx.de>:
>>
>> 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.

>
>>
>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>> ---
>>  fs/fat/fat.c       | 3 ++-
>>  fs/fat/fat_write.c | 6 +++---
>>  2 files changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
>> index fb6ce094ac..ccba268f61 100644
>> --- a/fs/fat/fat.c
>> +++ b/fs/fat/fat.c
>> @@ -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;
>> diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
>> index aae3a6a3d1..b43a27b205 100644
>> --- a/fs/fat/fat_write.c
>> +++ b/fs/fat/fat_write.c
>> @@ -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;
>
> 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

>
>>                 *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
>>
>
>
Tom Rini Jan. 30, 2021, 7:21 p.m. UTC | #3
On Tue, Jan 26, 2021 at 12:14:14AM +0100, Heinrich Schuchardt wrote:

> Do not assign a value to a variable if it is not used.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index fb6ce094ac..ccba268f61 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -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;
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index aae3a6a3d1..b43a27b205 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -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);