Commit 44c5027b authored by Samuel Holland's avatar Samuel Holland Committed by Martin K. Petersen

scsi: 3w-9xxx: Use flexible array members to avoid struct padding

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.

Link: https://lore.kernel.org/r/20210427235915.39211-2-samuel@sholland.orgSigned-off-by: default avatarSamuel Holland <samuel@sholland.org>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 0edca4fc
...@@ -676,7 +676,9 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long ...@@ -676,7 +676,9 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long
data_buffer_length_adjusted = (driver_command.buffer_length + 511) & ~511; data_buffer_length_adjusted = (driver_command.buffer_length + 511) & ~511;
/* Now allocate ioctl buf memory */ /* 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,
sizeof(TW_Ioctl_Buf_Apache) + data_buffer_length_adjusted,
&dma_handle, GFP_KERNEL);
if (!cpu_addr) { if (!cpu_addr) {
retval = TW_IOCTL_ERROR_OS_ENOMEM; retval = TW_IOCTL_ERROR_OS_ENOMEM;
goto out2; goto out2;
...@@ -685,7 +687,7 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long ...@@ -685,7 +687,7 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long
tw_ioctl = (TW_Ioctl_Buf_Apache *)cpu_addr; tw_ioctl = (TW_Ioctl_Buf_Apache *)cpu_addr;
/* Now copy down the entire ioctl */ /* 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, sizeof(TW_Ioctl_Buf_Apache) + driver_command.buffer_length))
goto out3; goto out3;
/* See which ioctl we are doing */ /* See which ioctl we are doing */
...@@ -867,11 +869,13 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long ...@@ -867,11 +869,13 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long
} }
/* Now copy the entire response to userspace */ /* Now copy the entire response to userspace */
if (copy_to_user(argp, tw_ioctl, sizeof(TW_Ioctl_Buf_Apache) + driver_command.buffer_length - 1) == 0) if (copy_to_user(argp, tw_ioctl, sizeof(TW_Ioctl_Buf_Apache) + driver_command.buffer_length) == 0)
retval = 0; retval = 0;
out3: out3:
/* Now free ioctl buf memory */ /* Now free ioctl buf memory */
dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_Ioctl_Buf_Apache) - 1, cpu_addr, dma_handle); dma_free_coherent(&tw_dev->tw_pci_dev->dev,
sizeof(TW_Ioctl_Buf_Apache) + data_buffer_length_adjusted,
cpu_addr, dma_handle);
out2: out2:
mutex_unlock(&tw_dev->ioctl_lock); mutex_unlock(&tw_dev->ioctl_lock);
out: out:
...@@ -1392,7 +1396,7 @@ static void twa_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_comm ...@@ -1392,7 +1396,7 @@ static void twa_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_comm
newcommand->request_id__lunl = newcommand->request_id__lunl =
cpu_to_le16(TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->request_id__lunl), request_id)); cpu_to_le16(TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->request_id__lunl), request_id));
if (length) { if (length) {
newcommand->sg_list[0].address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache) - 1); newcommand->sg_list[0].address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache));
newcommand->sg_list[0].length = cpu_to_le32(length); newcommand->sg_list[0].length = cpu_to_le32(length);
} }
newcommand->sgl_entries__lunh = newcommand->sgl_entries__lunh =
...@@ -1407,7 +1411,7 @@ static void twa_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_comm ...@@ -1407,7 +1411,7 @@ static void twa_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_comm
sgl = (TW_SG_Entry *)((u32 *)oldcommand+oldcommand->size - (sizeof(TW_SG_Entry)/4) + pae); sgl = (TW_SG_Entry *)((u32 *)oldcommand+oldcommand->size - (sizeof(TW_SG_Entry)/4) + pae);
else else
sgl = (TW_SG_Entry *)((u32 *)oldcommand+TW_SGL_OUT(oldcommand->opcode__sgloffset)); sgl = (TW_SG_Entry *)((u32 *)oldcommand+TW_SGL_OUT(oldcommand->opcode__sgloffset));
sgl->address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache) - 1); sgl->address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache));
sgl->length = cpu_to_le32(length); sgl->length = cpu_to_le32(length);
oldcommand->size += pae; oldcommand->size += pae;
......
...@@ -602,7 +602,7 @@ typedef struct TAG_TW_Ioctl_Apache { ...@@ -602,7 +602,7 @@ typedef struct TAG_TW_Ioctl_Apache {
TW_Ioctl_Driver_Command driver_command; TW_Ioctl_Driver_Command driver_command;
char padding[488]; char padding[488];
TW_Command_Full firmware_command; TW_Command_Full firmware_command;
char data_buffer[1]; char data_buffer[];
} TW_Ioctl_Buf_Apache; } TW_Ioctl_Buf_Apache;
/* Lock structure for ioctl get/release lock */ /* Lock structure for ioctl get/release lock */
...@@ -618,7 +618,7 @@ typedef struct { ...@@ -618,7 +618,7 @@ typedef struct {
unsigned short parameter_id; unsigned short parameter_id;
unsigned short parameter_size_bytes; unsigned short parameter_size_bytes;
unsigned short actual_parameter_size_bytes; unsigned short actual_parameter_size_bytes;
unsigned char data[1]; unsigned char data[];
} TW_Param_Apache, *PTW_Param_Apache; } TW_Param_Apache, *PTW_Param_Apache;
/* Response queue */ /* Response queue */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment