Skip to contentSkip to conversation

ata: Clean up hard coded array size calculation.

PATCH Applied Thiago Farina 5 participants 15 messages Nov 8, 2009 – Nov 20, 2009 libata

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ata: Clean up hard coded array size calculation.

Use ARRAY_SIZE macro of kernel api instead.

---
 drivers/ata/sata_mv.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/sata_mv.c +1 -1
index 6f5093b..a8a7be0 100644
@@ -2217,7 +2217,7 @@ static unsigned int mv_qc_issue_fis(struct ata_queued_cmd *qc)
 	int err = 0;
 
 	ata_tf_to_fis(&qc->tf, link->pmp, 1, (void *)fis);
-	err = mv_send_fis(ap, fis, sizeof(fis) / sizeof(fis[0]));
+	err = mv_send_fis(ap, fis, ARRAY_SIZE(fis));
 	if (err)
 		return err;
 
Signature · 1 line
1.6.5.2.150.g1b52a
#1 lore raw
Quoted 3 lines · Thiago Farina

Use ARRAY_SIZE macro of kernel api instead.

Quoted 21 lines

---
 drivers/ata/sata_mv.c |    2 +-

 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/sata_mv.c +1 -2
index 6f5093b..a8a7be0 100644
@@ -2217,7 +2217,7 @@ static unsigned int mv_qc_issue_fis(struct ata_queued_cmd *qc)
        int err = 0;
 
        ata_tf_to_fis(&qc->tf, link->pmp, 1, (void *)fis);
-       err = mv_send_fis(ap, fis, sizeof(fis) / sizeof(fis[0]));
+       err = mv_send_fis(ap, fis, ARRAY_SIZE(fis));
        if (err)
                return err;
 
--

1.6.5.2.150.g1b52a

#2 lore raw
In reply to Thiago Farina
Quoted 12 lines · Thiago Farina

Use ARRAY_SIZE macro of kernel api instead.

---
 drivers/ata/sata_mv.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/sata_mv.c +0 -0
index 6f5093b..a8a7be0 100644

drivers/ata/sata_mv.c static unsigned int mv_qc_issue_fis(struct ata_queued_cmd *qc) · line 2223

Quoted 8 lines
drivers/ata/sata_mv.c +1 -1
@@ -2217,7 +2217,7 @@ static unsigned int mv_qc_issue_fis(struct ata_queued_cmd *qc)
 	int err = 0;
 
 	ata_tf_to_fis(&qc->tf, link->pmp, 1, (void *)fis);
-	err = mv_send_fis(ap, fis, sizeof(fis) / sizeof(fis[0]));
+	err = mv_send_fis(ap, fis, ARRAY_SIZE(fis));
 	if (err)
 		return err;
 

..

What's the point of this ?

There is no "hardcoded array size" there to begin with, and using that silly macro obscures the actual calculation.

So now, instead of being able to verify correctness at a glance, I have to go off and research some silly macro and verify that it does the right thing.

Kind of like all of those "typedef structs" that are abhored around here.

-ml

#3 lore raw
Quoted 23 lines · On Tuesday 10 November 2009 06:00:19 Mark Lord wrote:
Quoted 20 lines · Thiago Farina

Use ARRAY_SIZE macro of kernel api instead.

---
 drivers/ata/sata_mv.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/sata_mv.c +1 -1
index 6f5093b..a8a7be0 100644
@@ -2217,7 +2217,7 @@ static unsigned int mv_qc_issue_fis(struct ata_queued_cmd *qc)
 	int err = 0;
 
 	ata_tf_to_fis(&qc->tf, link->pmp, 1, (void *)fis);
-	err = mv_send_fis(ap, fis, sizeof(fis) / sizeof(fis[0]));
+	err = mv_send_fis(ap, fis, ARRAY_SIZE(fis));
 	if (err)
 		return err;
 

..

Quoted 6 lines

What's the point of this ?

There is no "hardcoded array size" there to begin with, and using that silly macro obscures the actual calculation.

So now, instead of being able to verify correctness at a glance,

I kindly disagree here. ARRAY_SIZE makes code smaller and prevents subtle bugs in the more complex situations once you learn to always use it.

[ Using ARRAY_SIZE you no longer have to verify anything and person
looking at the code (which not necessarily is the original author) immediately knows what was the author's intention. ]

Quoted 2 lines

I have to go off and research some silly macro and verify that it does the right thing.

You did it already and the macro name is quite descriptive so you may as well just ACK the patch now.. ;)

Signature · 1 line
Bartlomiej Zolnierkiewicz
#4 lore raw
Quoted 5 lines · Bartlomiej Zolnierkiewicz
Quoted 2 lines

I have to go off and research some silly macro and verify that it does the right thing.

You did it already and the macro name is quite descriptive so you may as well just ACK the patch now.. ;)

Indeed. We use the "silly macro" everywhere in the kernel for code clarity.

#5 lore raw
Quoted 8 lines · Pekka Enberg
Quoted 4 lines · Bartlomiej Zolnierkiewicz
Quoted 2 lines

I have to go off and research some silly macro and verify that it does the right thing.

You did it already and the macro name is quite descriptive so you may as well just ACK the patch now.. ;)

Indeed. We use the "silly macro" everywhere in the kernel for code clarity.

..

Looks like unnecessary churn and obfuscation to me.

-ml

#6 lore raw
Quoted 1 line · Mark Lord

Looks like unnecessary churn and obfuscation to me.

Obfuscation? Are you saying that just because you wrote this code? So what is the usage of a macro? I think you are having a defensive position here.

The macro is self-explanatory, ARRAY_SIZE, so the macro gives you the *size* of the array. You don't need to know how that is done, if you want, just go to the declaration of the macro.

#11 lore raw
In reply to Mark Lord
Quoted 24 lines · Mark Lord
Quoted 21 lines · Thiago Farina

Use ARRAY_SIZE macro of kernel api instead.

---
drivers/ata/sata_mv.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/sata_mv.c +1 -1
index 6f5093b..a8a7be0 100644
@@ -2217,7 +2217,7 @@ static unsigned int mv_qc_issue_fis(struct
 ata_queued_cmd *qc)
 int err = 0;
 
 ata_tf_to_fis(&qc->tf, link->pmp, 1, (void *)fis);
- err = mv_send_fis(ap, fis, sizeof(fis) / sizeof(fis[0]));
+ err = mv_send_fis(ap, fis, ARRAY_SIZE(fis));
 if (err)
 return err;

..

Quoted 8 lines

What's the point of this ?

There is no "hardcoded array size" there to begin with, and using that silly macro obscures the actual calculation.

So now, instead of being able to verify correctness at a glance, I have to go off and research some silly macro and verify that it does the right thing.

It is a standard cleanup for all kernel code, and it does make the code more readable to the casual reader / quick skimmer.

Jeff

#7 lore raw
In reply to Thiago Farina
Quoted 6 lines · Thiago Farina
Quoted 1 line · Mark Lord

Looks like unnecessary churn and obfuscation to me.

Obfuscation? Are you saying that just because you wrote this code? So what is the usage of a macro? I think you are having a defensive position here.

..

No, actually I believe Jeff wrote that particular line of code.

Cheers

#8 lore raw
Quoted 10 lines · Mark Lord
Quoted 6 lines · Thiago Farina
Quoted 1 line · Mark Lord

Looks like unnecessary churn and obfuscation to me.

Obfuscation? Are you saying that just because you wrote this code? So what is the usage of a macro? I think you are having a defensive position here.

..

No, actually I believe Jeff wrote that particular line of code.

You know, Linus actually invented a command for people who enjoy this game... ;)

git blame drivers/ata/sata_mv.c

shows each line of code, and metadata about each line such as commit id and author name.

Jeff

#9 lore raw
Quoted 16 lines · Jeff Garzik
Quoted 7 lines · Mark Lord
Quoted 5 lines · Thiago Farina
Quoted 2 lines · Mark Lord

Looks like unnecessary churn and obfuscation to me.

Quoted 7 lines
Quoted 3 lines

Obfuscation? Are you saying that just because you wrote this code? So what is the usage of a macro? I think you are having a defensive position here.

..

No, actually I believe Jeff wrote that particular line of code.

Quoted 7 lines

You know, Linus actually invented a command for people who enjoy this game...  ;)

       git blame drivers/ata/sata_mv.c

shows each line of code, and metadata about each line such as commit id and author name.

Sure, and I ran this command before saying that Mark wrote this code.

#10 lore raw
Quoted 14 lines · Thiago Farina
Quoted 13 lines · Jeff Garzik
Quoted 9 lines · Mark Lord
Quoted 5 lines · Thiago Farina
Quoted 1 line · Mark Lord

Looks like unnecessary churn and obfuscation to me.

Obfuscation? Are you saying that just because you wrote this code? So what is the usage of a macro? I think you are having a defensive position here.

..

No, actually I believe Jeff wrote that particular line of code.

You know, Linus actually invented a command for people who enjoy this game... ;)

Quoted 6 lines
Quoted 4 lines

git blame drivers/ata/sata_mv.c

shows each line of code, and metadata about each line such as commit id and author name.

Sure, and I ran this command before saying that Mark wrote this code.

..

I'm probably just the last chap to change the indentation on it. It really doesn't look like my style to me. ;)

There were two authors before me there, and that line looks like one of theirs. :)

Cheers

Applied
#12 lore raw
In reply to Thiago Farina
Quoted 12 lines · Thiago Farina

Use ARRAY_SIZE macro of kernel api instead.

---
  drivers/ata/sata_mv.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/sata_mv.c +0 -0
index 6f5093b..a8a7be0 100644

drivers/ata/sata_mv.c static unsigned int mv_qc_issue_fis(struct ata_queued_cmd *qc) · line 2221

Quoted 6 lines
drivers/ata/sata_mv.c +1 -1
@@ -2217,7 +2217,7 @@ static unsigned int mv_qc_issue_fis(struct ata_queued_cmd *qc)
  	int err = 0;
 
  	ata_tf_to_fis(&qc->tf, link->pmp, 1, (void *)fis);
-	err = mv_send_fis(ap, fis, sizeof(fis) / sizeof(fis[0]));
+	err = mv_send_fis(ap, fis, ARRAY_SIZE(fis));
  	if (err)

applied

#13 lore raw

Hi Jeff,

Quoted 17 lines · Jeff Garzik
Quoted 16 lines · Thiago Farina

Use ARRAY_SIZE macro of kernel api instead.

---
 drivers/ata/sata_mv.c |    2 +-

 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/sata_mv.c +0 -0
index 6f5093b..a8a7be0 100644
@@ -2217,7 +2217,7 @@ static unsigned int mv_qc_issue_fis(struct
 ata_queued_cmd *qc)
        int err = 0;
 
Quoted 6 lines

drivers/ata/sata_mv.c static unsigned int mv_qc_issue_fis(struct ata_queued_cmd *qc) · line 2221

Quoted 4 lines
drivers/ata/sata_mv.c +1 -1
        ata_tf_to_fis(&qc->tf, link->pmp, 1, (void *)fis);
-       err = mv_send_fis(ap, fis, sizeof(fis) / sizeof(fis[0]));
+       err = mv_send_fis(ap, fis, ARRAY_SIZE(fis));
        if (err)

applied

Was it applied to this tree
http://git.kernel.org/?p=linux/kernel/git/jgarzik/libata-dev.git?

#14 lore raw
Quoted 27 lines · Thiago Farina

Hi Jeff,

Quoted 17 lines · Jeff Garzik
Quoted 16 lines · Thiago Farina

Use ARRAY_SIZE macro of kernel api instead.

---
  drivers/ata/sata_mv.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
drivers/ata/sata_mv.c +0 -0
index 6f5093b..a8a7be0 100644
@@ -2217,7 +2217,7 @@ static unsigned int mv_qc_issue_fis(struct
 ata_queued_cmd *qc)
        int err = 0;
 
Quoted 6 lines

drivers/ata/sata_mv.c static unsigned int mv_qc_issue_fis(struct ata_queued_cmd *qc) · line 2221

Quoted 4 lines
drivers/ata/sata_mv.c +1 -1
        ata_tf_to_fis(&qc->tf, link->pmp, 1, (void *)fis);
-       err = mv_send_fis(ap, fis, sizeof(fis) / sizeof(fis[0]));
+       err = mv_send_fis(ap, fis, ARRAY_SIZE(fis));
        if (err)

applied

Quoted 2 lines

Was it applied to this tree
http://git.kernel.org/?p=linux/kernel/git/jgarzik/libata-dev.git?

Yes.

Jeff