Re: [PATCH] usb: renesas_usbhs: Use struct assignment instead of memcpy()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Greg,

On Tue, Jun 18, 2019 at 9:17 AM Greg KH <gregkh@xxxxxxxxxxxxxxxxxxx> wrote:
> 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@xxxxxxxxxxx>
> > ---
> >  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.

There are no checks that:
  - the source and destination pointers point to the same type,
  - the passed size matches the actual object size.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux