linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Samuel Holland <samuel@sholland.org>,
	Adam Radford <aradford@gmail.com>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Arnd Bergmann <arnd@arndb.de>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/3] scsi: 3w-9xxx: Use flexible array members to avoid struct padding
Date: Sat, 08 Aug 2020 19:37:57 -0700	[thread overview]
Message-ID: <cd3a39d4ef3da9968026549e285dea3ef4261795.camel@perches.com> (raw)
In-Reply-To: <20200809004727.53107-1-samuel@sholland.org>

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...



      parent reply	other threads:[~2020-08-09  2:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-09  0:47 [PATCH v3 1/3] scsi: 3w-9xxx: Use flexible array members to avoid struct padding Samuel Holland
2020-08-09  0:47 ` [PATCH v3 2/3] scsi: 3w-9xxx: Reduce scope of structure packing Samuel Holland
2020-08-09  0:47 ` [PATCH v3 3/3] scsi: 3w-9xxx: Fix endianness issues in command packets Samuel Holland
2020-08-09  2:37 ` Joe Perches [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cd3a39d4ef3da9968026549e285dea3ef4261795.camel@perches.com \
    --to=joe@perches.com \
    --cc=aradford@gmail.com \
    --cc=arnd@arndb.de \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=samuel@sholland.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).