Messages in this thread | ![/](/images/icornerl.gif) | | From | Prashant Malani <> | Date | Tue, 31 Jan 2023 10:17:14 -0800 | Subject | Re: [PATCH] platform/chrome: cros_typec_vdm: Fix VDO copy |
| |
Hi Tzung-Bi,
On Mon, Jan 30, 2023 at 7:49 PM Tzung-Bi Shih <tzungbi@kernel.org> wrote: > > On Fri, Jan 13, 2023 at 06:26:26PM +0000, Prashant Malani wrote: > > The usage of memcpy() affects the representation of the VDOs as they are > > copied to the EC Host Command buffer. Specifically, all higher order > > bits get dropped (for example: a VDO of 0x406 just gets copied as 0x6). > > memcpy() is byte-oriented; however, `vdo` is a pointer to u32. > > > Avoid this by explicitly copying each VDO in the array. The number of > > VDOs generated by alternate mode drivers in their VDMs is almost always > > just 1 (apart from the header) so this doesn't affect performance in a > > meaningful way). > > Although the patch has applied, I am wondering if the following would be a > better way to fix the issue: > > memcpy(&vdm_req.vdm_data[1], vdo, (cnt - 1) * sizeof(*vdo));
Yeah, that's right; I forgot that 'cnt' is "number of VDOs" and not "number of bytes" :S
As I mentioned, in a vast majority of cases, the number of VDOs is just 1, so I wouldn't bother and just leave this as it is (since there is no major benefit apart from saving 1 line).
| ![\](/images/icornerr.gif) |