On Sun, 19 Mar 2000, Alan Cox wrote:

> Spot the problem
> 
> 
>       np = (void *)(((long)kmalloc(sizeof(*np), GFP_KERNEL) + 31) & ~31);

The old method was to put the padding at the end of the private structure with
code like
    int pad0, pad1;           /* Pad for alignment. */

That ran into the problem of people not understanding the comment and adding
new structure element after this.

The pci-skeleton driver and many others use

        {       /* Make certain elements e.g. descriptor lists are aligned. */
                void *mem = kmalloc(sizeof(*np) + PRIV_ALIGN, GFP_KERNEL);
                if ( ! mem) {
                        ....
                }
                dev->priv = np = (void *)(((long)mem + PRIV_ALIGN) & ~PRIV_ALIGN);
                memset(np, 0, sizeof(*np));
                np->priv_addr = mem;
        }

> and later
> 
>       kfree(dev->priv);

This must be
     kfree(dev->priv_addr)

> So all the existing drivers are not remotely back compatible anyway, they
> are broken in the case of a misaligned return and have been for a long time.
> Some of the other drivers 'solve' the problem by simply forgetting to free
> the buffer.

This was a bug in some of the drivers, but has since been fixed.  Well, at
least in my versions, which have been explicitly rejected because they
contain backwards-compatibility code..

Donald Becker
Scyld Computing Corporation, [EMAIL PROTECTED]

-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]

Reply via email to