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 Sun, Sep 1, 2013 at 7:50 PM, Dan Carpenter <dan.carpenter@xxxxxxxxxx> wrote:
> On Sat, Aug 31, 2013 at 06:19:10PM -0400, Lidza Louina wrote:
>> This patch replaces all instances of "sizeof(struct"
>> with actual instances of the struct. For example
>> "sizeof(struct tty_struct" is replaced with
>> "sizeof(brd->SerialDriver.ttys".
>>
>
> This one is not right.

Is it wrong because it needs to be a pointer
to brd->SerialDriver.ttys? Or should it not be changed at all?

>> This patch affects driver.c, mgmt.c and tty.c.
>>
>
> Btw, you don't need to say this in the commit.

Alrighty

>> Signed-off-by: Lidza Louina <lidza.louina@xxxxxxxxx>
>> ---
>>  drivers/staging/dgnc/dgnc_driver.c |  2 +-
>>  drivers/staging/dgnc/dgnc_mgmt.c   |  2 +-
>>  drivers/staging/dgnc/dgnc_tty.c    | 28 ++++++++++++++--------------
>>  3 files changed, 16 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/staging/dgnc/dgnc_driver.c b/drivers/staging/dgnc/dgnc_driver.c
>> index 1e76f0c..9dee64c 100644
>> --- a/drivers/staging/dgnc/dgnc_driver.c
>> +++ b/drivers/staging/dgnc/dgnc_driver.c
>> @@ -499,7 +499,7 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
>>
>>       /* get the board structure and prep it */
>>       brd = dgnc_Board[dgnc_NumBoards] =
>> -     kzalloc(sizeof(struct board_t), GFP_KERNEL);
>> +     kzalloc(sizeof(brd), GFP_KERNEL);
>
> This should be "sizeof(*brd)".  The "brd" variable is a pointer (4 or
> 8 bytes) but we want the size of the struct it points to "*brd".  The
> same thing for the some of the others as well.

Okay, I can see why that would be here.

Basically sizeof function needs a pointer to the exact item that we
need the size of instead of a generic type.

Example:
if (copy_to_user(uarg, &buf, sizeof(buf))) {
becomes
if (copy_to_user(uarg, &buf, sizeof(*buf))) {

And:
memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
becomes
memcpy(&ch->ch_digi, &new_digi, sizeof(*ch->ch_digi));
_______________________________________________
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