Re: [PATCH 02/12] staging: dgnc: replaces generic struct from sizeof calls

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

 



On Tue, Sep 03, 2013 at 01:26:05PM -0400, Lidza Louina wrote:
> And:
> memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
> becomes
> memcpy(&ch->ch_digi, &new_digi, sizeof(*ch->ch_digi));

Nope.  "ch->ch_digi" is not a pointer so this will generate a compile
error.  That one should be:

	memcpy(&ch->ch_digi, &new_digi, sizeof(ch->ch_digi));

The theory of this sizeof() style is that the relationship between
the sizeof() and the variable is clear immediately.  If it's (struct
foo) then you maybe have to look up that it's the correct struct.  In
reality those bugs are very rare though.  (I have audited the kernel
for these).

Smatch would have found some of these bugs I think...

git://repo.or.cz/smatch.git
cd smatch
make
cd ~/kernel/src/
~/smatch/smatch_scripts/kchecker drivers/staging/dgnc/dgnc_tty.c

Smatch also gives you Sparse for free:

~/smatch/smatch_scripts/kchecker --sparse drivers/staging/dgnc/dgnc_tty.c

The Smatch version of Sparse might be a little out of date...

regards,
dan carpenter
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux