Bug 7561
Summary: | gcc warnings with -Wpointer-arith when compiling modules | ||
---|---|---|---|
Product: | Other | Reporter: | Joerg Czeranski (jc) |
Component: | Other | Assignee: | other_other |
Status: | REJECTED INSUFFICIENT_DATA | ||
Severity: | low | CC: | adobriyan, protasnb |
Priority: | P2 | ||
Hardware: | i386 | ||
OS: | Linux | ||
Kernel Version: | 2.6.16, 2.6.16.32, 2.6.18.3 | Subsystem: | |
Regression: | --- | Bisected commit-id: | |
Attachments: | patch fixes warnings described in bug report |
Description
Joerg Czeranski
2006-11-21 06:33:05 UTC
Created attachment 9581 [details]
patch fixes warnings described in bug report
Could you, please, clarify buggy snippet? Such things could be in mainline, so someone could grep for them, instead of digging through noise which can be time consuming and not very productive. And 2.6.19 release is near. Alexey "really curious" Dobriyan The actual faulty code was this: struct sja1000_softc *sc_extra; ... sc_extra = sc->extra = kmalloc(sizeof *sc->extra, GFP_KERNEL); with sc->extra declared as void *. The correct code is: sc_extra = sc->extra = kmalloc(sizeof *sc_extra, GFP_KERNEL); Note the different argument to sizeof. The idiom p = kmalloc(sizeof *p, GFP_KERNEL); guarantees that the right size of memory is used or an error is reported. For the wrong code, the size was sizeof(void), because sc->extra has type void *, so it should have been rejected by the compiler as "sizeof of incomplete type" or something similar. Unfortunately, gcc without -Wpointer-arith treats void as char in most contexts, so sizeof(void) is 1. kmalloc() then allocates the smallest supported slab size, usually 32 bytes. This worked fine as long as struct sja1000_softc was small enough. When I added more fields to it, the module started overwriting random kernel data, whatever was allocated after that struct. I don't know whether there's an easy way to find such a bug with grep. If -Wpointer-arith is added, gcc 4.1.0 reports: warning: invalid application of 'sizeof' to a void type The easiest way might be to enable that warning, compile everything and grep for the warning in the output. I guess you're better off to send a patch to the kernel mailing list for this. Note that a bunch of new instances of that warning have been introduced since your last patch, so they'll also need fixing up. http://people.redhat.com/davej/kernels/Fedora/f8/RPMS.kernel/i586/build.log (There are build.log's for other archs in the parent dir too, which may have additional warnings). But as Roman mentioned, bringing this up on Linux-kernel is probably the best way forward. Has the patch ever been posted? If not, Joerg - can you please send it to the mailing list. Thanks. |