[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <cd3a39d4ef3da9968026549e285dea3ef4261795.camel@perches.com>
Date: Sat, 08 Aug 2020 19:37:57 -0700
From: Joe Perches <joe@...ches.com>
To: Samuel Holland <samuel@...lland.org>,
Adam Radford <aradford@...il.com>,
"James E.J. Bottomley" <jejb@...ux.ibm.com>,
"Martin K. Petersen" <martin.petersen@...cle.com>,
Arnd Bergmann <arnd@...db.de>
Cc: linux-scsi@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 1/3] scsi: 3w-9xxx: Use flexible array members to
avoid struct padding
On Sat, 2020-08-08 at 19:47 -0500, Samuel Holland wrote:
> In preparation for removing the "#pragma pack(1)" from the driver, fix
> all instances where a trailing array member could be replaced by a
> flexible array member. Since a flexible array member has zero size, it
> introduces no padding, whether or not the struct is packed.
[]
> diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
[]
> @@ -676,7 +676,7 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long
> data_buffer_length_adjusted = (driver_command.buffer_length + 511) & ~511;
>
> /* Now allocate ioctl buf memory */
> - cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_Ioctl_Buf_Apache) - 1, &dma_handle, GFP_KERNEL);
> + cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted + sizeof(TW_Ioctl_Buf_Apache), &dma_handle, GFP_KERNEL);
Trivia:
It's perhaps more sensible to order the arguments with
the size of the struct first then the data length so
the argument is in the order of the expected content.
cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev,
sizeof(TW_Ioctl_Buf_Apache) + data_buffer_length_adjusted,
&dma_handle, GFP_KERNEL);
> @@ -685,7 +685,7 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long
> tw_ioctl = (TW_Ioctl_Buf_Apache *)cpu_addr;
>
> /* Now copy down the entire ioctl */
> - if (copy_from_user(tw_ioctl, argp, driver_command.buffer_length + sizeof(TW_Ioctl_Buf_Apache) - 1))
> + if (copy_from_user(tw_ioctl, argp, driver_command.buffer_length + sizeof(TW_Ioctl_Buf_Apache)))
if (copy_from_user(tw_ioctl, argp, sizeof(TW_Ioctl_Buf_Apache) + driver_command.buffer_length))
etc...
Powered by blists - more mailing lists