linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: linux-usb@vger.kernel.org, linux-renesas-soc@vger.kernel.org
Subject: Re: [PATCH] usb: renesas_usbhs: Use struct assignment instead of memcpy()
Date: Tue, 18 Jun 2019 07:59:15 +0200	[thread overview]
Message-ID: <20190618055915.GA5904@kroah.com> (raw)
In-Reply-To: <1560424728-13929-1-git-send-email-yoshihiro.shimoda.uh@renesas.com>

On Thu, Jun 13, 2019 at 08:18:48PM +0900, Yoshihiro Shimoda wrote:
> To avoid the error-proneness of calls to sizeof() in the memcpy,
> this patch uses struct assignment instead of memcpy.
> 
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> ---
>  This patch is based on Greg's linux-usb.git / usb-next branch.
>  Note that mod_host.c also has memcpy but we cannot use struct assignment
>  for it because the type of urb->setup_patcket is just "unsigned char *".
> 
>  drivers/usb/renesas_usbhs/common.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c
> index a501ea6..ebbe322 100644
> --- a/drivers/usb/renesas_usbhs/common.c
> +++ b/drivers/usb/renesas_usbhs/common.c
> @@ -651,9 +651,8 @@ static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev)
>  		return NULL;
>  
>  	dparam = &info->driver_param;
> -	memcpy(dparam, &data->param, sizeof(data->param));
> -	memcpy(&info->platform_callback, data->platform_callback,
> -	       sizeof(*data->platform_callback));
> +	*dparam = data->param;
> +	info->platform_callback = *data->platform_callback;

How are the original calls here "error-prone"?  Yes, the compiler will
end up calling memcpy somehow with this change, but it feels "wrong" to
hide a memory copy like this.

So are you _sure_ you want this change?

thanks,

greg k-h

  parent reply	other threads:[~2019-06-18  7:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-13 11:18 [PATCH] usb: renesas_usbhs: Use struct assignment instead of memcpy() Yoshihiro Shimoda
2019-06-17  8:40 ` Simon Horman
2019-06-18  5:59 ` Greg KH [this message]
2019-06-18  7:26   ` Geert Uytterhoeven
2019-06-18  8:42   ` Yoshihiro Shimoda

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=20190618055915.GA5904@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=yoshihiro.shimoda.uh@renesas.com \
    /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).