public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Mike Frysinger <vapier.adi@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	uclinux-dist-devel@blackfin.uclinux.org,
	Michal Simek <monstr@monstr.eu>, Paul Mundt <lethal@linux-sh.org>
Subject: Re: [PATCH 05/17] Blackfin: convert to generic checksum code
Date: Tue, 23 Jun 2009 23:14:17 +0200	[thread overview]
Message-ID: <200906232314.18261.arnd@arndb.de> (raw)
In-Reply-To: <8bd0f97a0906190612n687cdbbt1e752997acb68e49@mail.gmail.com>

I missed your mail last week and only now stumbled over it after Linus
has pulled my tree.

On Friday 19 June 2009, Mike Frysinger wrote:
> >
> > sounds like a good idea.
> 
> how about the attached

Mostly good, but needs some improvements. At least it helped me
track down the last problem.

> > lib/checksum.c: Fix another endianess bug
> 
> hrm, still not quite :/
> 
> the attached test code shows failures in every case

When I tried running it on x86-64, it only showed failures for
numbers 1, 2 and 4. I fixed them with this patch:
---
lib/checksum: fix one more thinko

When do_csum gets unaligned data, we really need to treat
the first byte as an even byte, not an odd byte, because
we swap the two halves later.

Found by Mike's checksum-selftest module.

Reported-by: Mike Frysinger <vapier.adi@gmail.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

diff --git a/lib/checksum.c b/lib/checksum.c
index b08c2d0..0975087 100644
--- a/lib/checksum.c
+++ b/lib/checksum.c
@@ -57,9 +57,9 @@ static unsigned int do_csum(const unsigned char *buff, int len)
 	odd = 1 & (unsigned long) buff;
 	if (odd) {
 #ifdef __LITTLE_ENDIAN
-		result = *buff;
-#else
 		result += (*buff << 8);
+#else
+		result = *buff;
 #endif
 		len--;
 		buff++;
---

>extern unsigned short do_csum(const unsigned char *buff, int len);
>

do_csum is really an internal function. IMHO we should better check
csum_partial(), ip_fast_csum(), csum_fold(), csum_tcpudp_magic()
and ip_compute_csum(), or at least a subset of them.

>static unsigned char __initdata do_csum_data2[] = {
>        0x0d, 0x0a,
>};
>static unsigned char __initdata do_csum_data3[] = {
>        0xff, 0xfb, 0x01,
>};
> ...
>static struct do_csum_data __initdata do_csum_data[] = {
>        DO_CSUM_DATA(1, 0x0020),
>        DO_CSUM_DATA(2, 0xfc00),
>        DO_CSUM_DATA(3, 0x0a0d),
>        DO_CSUM_DATA(5, 0x7fc4),
>        DO_CSUM_DATA(7, 0x7597),
>        DO_CSUM_DATA(255, 0x4f96),
>};

You mixed up do_csum_data2 and do_csum_data3, so they will always
show up as incorrect. Also, the expected checksum is endian-dependent.
The test module should either be modified to expect 0xffff to be
returned in every case, or should use le16_to_cpu(0x0020) etc.

	Arnd <><

  reply	other threads:[~2009-06-23 21:16 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-14 12:01 [PATCH 00/17] Blackfin arch conversion to asm-generic Mike Frysinger
2009-06-14 12:01 ` [PATCH 01/17] Blackfin: use common test_bit() rather than __test_bit() Mike Frysinger
2009-06-14 12:01 ` [PATCH 02/17] Blackfin: pull in asm/io.h in ksyms for prototypes Mike Frysinger
2009-06-14 12:01 ` [PATCH 03/17] Blackfin: only build irqpanic.c when needed Mike Frysinger
2009-06-14 12:01 ` [PATCH 04/17] Blackfin: convert asm/ioctls.h to asm-generic/ioctls.h Mike Frysinger
2009-06-14 12:01 ` [PATCH 05/17] Blackfin: convert to generic checksum code Mike Frysinger
2009-06-15 11:04   ` Arnd Bergmann
2009-06-16 10:03     ` Mike Frysinger
2009-06-19  1:19     ` Mike Frysinger
2009-06-19  9:05       ` Arnd Bergmann
2009-06-19 10:42         ` Mike Frysinger
2009-06-19 12:33           ` Arnd Bergmann
2009-06-19 13:12             ` Mike Frysinger
2009-06-23 21:14               ` Arnd Bergmann [this message]
2009-06-23 21:53                 ` Mike Frysinger
2009-06-23 22:06                   ` Arnd Bergmann
2009-06-23 22:11                     ` Mike Frysinger
2009-09-19 19:08                 ` Mike Frysinger
2009-06-14 12:01 ` [PATCH 06/17] Blackfin: convert shm/sysv/ipc to asm-generic Mike Frysinger
2009-06-14 12:01 ` [PATCH 07/17] Blackfin: convert user/elf " Mike Frysinger
2009-06-14 12:01 ` [PATCH 08/17] Blackfin: convert socket/poll " Mike Frysinger
2009-06-14 12:01 ` [PATCH 09/17] Blackfin: convert simple headers " Mike Frysinger
2009-06-14 12:01 ` [PATCH 10/17] Blackfin: convert dma/pci " Mike Frysinger
2009-06-15 11:37   ` Arnd Bergmann
2009-06-16 10:00     ` Mike Frysinger
2009-06-14 12:01 ` [PATCH 11/17] Blackfin: convert termios " Mike Frysinger
2009-06-14 12:01 ` [PATCH 12/17] Blackfin: convert locking primitives " Mike Frysinger
2009-06-14 12:01 ` [PATCH 13/17] Blackfin: convert signal/mmap " Mike Frysinger
2009-06-14 12:01 ` [PATCH 14/17] Blackfin: convert irq/process " Mike Frysinger
2009-06-14 12:01 ` [PATCH 15/17] Blackfin: convert types " Mike Frysinger
2009-06-14 12:01 ` [PATCH 16/17] Blackfin: convert page/tlb " Mike Frysinger
2009-06-14 12:01 ` [PATCH 17/17] Blackfin: convert uaccess " Mike Frysinger
2009-06-15 11:42 ` [PATCH 00/17] Blackfin arch conversion " Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200906232314.18261.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=monstr@monstr.eu \
    --cc=uclinux-dist-devel@blackfin.uclinux.org \
    --cc=vapier.adi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox