netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [cavium] weirdness in cnnic_alloc_aligned_dma()
@ 2015-12-12 18:41 Al Viro
  0 siblings, 0 replies; only message in thread
From: Al Viro @ 2015-12-12 18:41 UTC (permalink / raw)
  To: Raghu Vatsavayi; +Cc: David Miller, netdev

IMO
                ptr =
                    (void *)__get_free_pages(GFP_KERNEL,
                                             get_order(size));
                if ((unsigned long)ptr & 0x07) {
                        free_pages((unsigned long)ptr, get_order(size));
                        ptr = NULL;
                        /* Increment the size required if the first
                         * attempt failed.
                         */
                        if (!retries)
                                size += 7;
                }

in drivers/net/ethernet/cavium/liquidio/octeon_main.h:cnnic_alloc_aligned_dma()
takes defensive programming a bit too far - "if the page returned by
__get_free_pages() is not 64bit-aligned" is not going to trigger until
we start to support an architecture with page size lower than 8 bytes,
which is... unlikely.

Either this code takes paranoia to a truly impressive level, or something
else had been intended.  I tried to guess what that something might've
been, but it's hard to do without seeing the history prior to the
moment when it went into mainline.  The bit in the end is particularly
interesting:
        if ((unsigned long)ptr & 0x07)
                ptr = (void *)(((unsigned long)ptr + 7) & ~(7UL));
That - after having rejected such misaligned pointers.

Something's fishy in that code...

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-12-12 18:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-12 18:41 [cavium] weirdness in cnnic_alloc_aligned_dma() Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).