Skip to contentSkip to conversation

staging/ozwpan: coding style ether_addr_copy

PATCH Joe Perches 2 participants 4 messages Mar 28, 2014 – Mar 30, 2014 6 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 20140312100132.GA18954@star

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

A message that is not in the archive (sent off-list or not yet received): 20140313012144.GD30138@star

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

A message that is not in the archive (sent off-list or not yet received): 20140313153911.GA17881@star

A message that is not in the archive (sent off-list or not yet received): 20140328111801.GD6991@mwanda

#6 lore raw

(adding Andrew Morton, David Miller and LKML to cc's)

Quoted 31 lines · Dan Carpenter
Quoted 21 lines · Jérôme Pinot
Quoted 1 line · Greg Kroah-Hartman

On Thu, Mar 13, 2014 at 10:21:44AM +0900, Jérôme Pinot wrote:

[...]

Quoted 4 lines
Quoted 4 lines
drivers/staging/ozwpan/ozcdev.c +0 -0
index 5de5981..10c0a96 100644
Quoted 8 lines

drivers/staging/ozwpan/ozcdev.c static int oz_set_active_pd(const u8 *addr) · line 220

Quoted 6 lines
drivers/staging/ozwpan/ozcdev.c +1 -1
@@ -217,7 +217,7 @@ static int oz_set_active_pd(const u8 *addr)
 	pd = oz_pd_find(addr);
 	if (pd) {
 		spin_lock_bh(&g_cdev.lock);
-		memcpy(g_cdev.active_addr, addr, ETH_ALEN);
+		ether_addr_copy(g_cdev.active_addr, addr);

Are you sure this will work?

No. But the ozwpan driver uses already ether_addr_equal which is not alignment-safe. As
https://www.kernel.org/doc/Documentation/unaligned-memory-access.txt
said:

Quoted 8 lines

"This alignment-unsafe function is still useful as it is a decent optimization for the cases when you can ensure alignment, which is true almost all of the time in ethernet networking context."

I expected the maintainer to confirm/infirm this. I'm just seeing that's actually Chris Kelly who did write this part of code, so I'm CC'ing him too.

Quoted 7 lines

It is aligned ok, but don't rely on the maintainer to fix your bugs. Don't send patches which you are not sure about.

Joe, this seems like a very bad warning message from checkpatch.pl because people will constantly send us patches over and over which introduce bugs and they rely on the maintainer to catch it every time. Can we get rid of the warning or move it under --strict or something?

Hi Dan.

Maybe.

The checkpatch message is:

"Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)"

My personal preference would be to add YA inline function for unaligned copies ether_addr_copy_unaligned for symmetry to ether_addr_equal_unaligned to etherdevice.h though.

Then the message could be changed to something like "Prefer ether_addr_copy[_unaligned] to memcpy(foo, bar, ETH_ALEN)"

Quoted 1 line

Do we have a mailing list yet for checkpatch issues?

No and I'm not going to advocate for one. I think the subscriber count would be about 4 people total.

You could add yourself to the checkpatch MAINTAINERS entry if you want to see more of the patches and discussions.

They are pretty rare.

#7 lore raw
Quoted 48 lines · Joe Perches

(adding Andrew Morton, David Miller and LKML to cc's)

Quoted 31 lines · Dan Carpenter
Quoted 21 lines · Jérôme Pinot
Quoted 1 line · Greg Kroah-Hartman

On Thu, Mar 13, 2014 at 10:21:44AM +0900, Jérôme Pinot wrote:

[...]

Quoted 4 lines
Quoted 4 lines
drivers/staging/ozwpan/ozcdev.c +0 -0
index 5de5981..10c0a96 100644
Quoted 8 lines

drivers/staging/ozwpan/ozcdev.c static int oz_set_active_pd(const u8 *addr) · line 220

Quoted 6 lines
drivers/staging/ozwpan/ozcdev.c +1 -1
@@ -217,7 +217,7 @@ static int oz_set_active_pd(const u8 *addr)
 	pd = oz_pd_find(addr);
 	if (pd) {
 		spin_lock_bh(&g_cdev.lock);
-		memcpy(g_cdev.active_addr, addr, ETH_ALEN);
+		ether_addr_copy(g_cdev.active_addr, addr);

Are you sure this will work?

No. But the ozwpan driver uses already ether_addr_equal which is not alignment-safe. As
https://www.kernel.org/doc/Documentation/unaligned-memory-access.txt
said:

Quoted 8 lines

"This alignment-unsafe function is still useful as it is a decent optimization for the cases when you can ensure alignment, which is true almost all of the time in ethernet networking context."

I expected the maintainer to confirm/infirm this. I'm just seeing that's actually Chris Kelly who did write this part of code, so I'm CC'ing him too.

Quoted 7 lines

It is aligned ok, but don't rely on the maintainer to fix your bugs. Don't send patches which you are not sure about.

Joe, this seems like a very bad warning message from checkpatch.pl because people will constantly send us patches over and over which introduce bugs and they rely on the maintainer to catch it every time. Can we get rid of the warning or move it under --strict or something?

Hi Dan.

Maybe.

The checkpatch message is:

Quoted 9 lines

"Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)"

My personal preference would be to add YA inline function for unaligned copies ether_addr_copy_unaligned for symmetry to ether_addr_equal_unaligned to etherdevice.h though.

Then the message could be changed to something like "Prefer ether_addr_copy[_unaligned] to memcpy(foo, bar, ETH_ALEN)"

Sure if we had a function which didn't introduce bugs then that would be great. As it is submitters ignore the alignment requirements and rely on us to catch bugs.

In Smatch, I constantly explain to people that I don't care about false positives because this is not GCC where you have to eliminate every warning. These days in the kernel we treat checkpatch.pl and GCC warnings the same so it sucks when they are something conditional.

regards,
dan carpenter

#8 lore raw
Quoted 2 lines · Dan Carpenter

These days in the kernel we treat checkpatch.pl and GCC warnings the same so it sucks when they are something conditional.

Treating checkpatch messages like gcc compilation warnings and failures has got to change.

There is _no way_ checkpatch can have no false positives.

#9 lore raw
Quoted 9 lines · Joe Perches
Quoted 2 lines · Dan Carpenter

These days in the kernel we treat checkpatch.pl and GCC warnings the same so it sucks when they are something conditional.

Treating checkpatch messages like gcc compilation warnings and failures has got to change.

There is _no way_ checkpatch can have no false positives.

We could argue back and forth, but for now lets just revert the ether_addr_copy() check because people ignore the alignement requirement and it just encourages people to introduce bugs.

regards,
dan carpenter