Re: [patch] wireless: at76c50x: allocating too much data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 21 Apr 2012, Dan Carpenter wrote:

On Fri, Apr 20, 2012 at 09:14:44PM +0300, Kalle Valo wrote:
Dan Carpenter <dan.carpenter@xxxxxxxxxx> writes:

On Fri, Apr 20, 2012 at 06:57:00PM +1000, Julian Calaby wrote:
-       struct mib_local *m = kmalloc(sizeof(struct mib_phy), GFP_KERNEL);
+       struct mib_local *m = kmalloc(sizeof(struct mib_local), GFP_KERNEL);

Would it be better practice to use sizeof(*m)?


That was my temptation as well...  But I decided to make it match
with the surrounding code.  I'm happy to resend if people want.

IMHO sizeof(*m) is better and I tend to use it.

Related to this: I have a bad habit of sometimes dropping '*' from
sizeof()? Is there a tool which could spot that?


That's what I was working on for Smatch when I sent this patch.

The odd thing is that I can't find any bugs like this in the kernel.
If sizeof(foo) is less than sizeof(*foo), which is probably the
normal case, then these get caught early on in testing.

Still I think people must have done manual audits as well...  It
feels too clean to be natural.

Looking for x = ... sizeof(x) ... I get 9 reports. In most cases it looks like sizeof(x) is coincidentally the same as the size that is wanted. Two cases that look like they could have some noticible effect are:

arch/xtensa/platforms/iss/network.c, line 789
drivers/block/cciss.c, line 4211

I will send patches for those two.

julia

[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux