[PATCH] map-ram chip driver: 16-bit block transfer

Arnd Bergmann arnd at arndb.de
Fri Aug 11 12:42:56 PDT 2017


On Fri, Aug 11, 2017 at 7:57 PM, Sanjay Tandel
<sanjay.tandel at rockwellcollins.com> wrote:

>>>> +{
>>>> +     const unsigned char *t = to;
>>>> +
>>>> +     if (!(IS_ALIGNED((u32)from, sizeof(u16)))) {
>>>> +             from = (void __iomem *)ALIGN((u32)from, sizeof(u16))
>>>> +                                                     - sizeof(u16);
>>>> +             *(u8 *)t = (u8)((readw(from) & 0xff00) >> 8);
>>>> +             count--;
>>>> +             t++;
>>>> +             from += 2;
>>>> +     }
>>>> +     while (count >= 2) {
>>>> +             *(u16 *)t = readw(from);
>>>> +             count -= 2;
>>>> +             t += 2;
>>>> +             from += 2;
>>>> +     };
>>>> +     while (count > 0) {
>>>> +             *(u8 *)t = (u8)(readw(from) & 0x00ff);
>>>> +             count--;
>>>> +             t++;
>>>> +             from++;
>>>> +     }
>>>> +}
>>
>> This looks wrong on bit-endian kernels, which do a byte-swap
>> in readw. This is one of the few places that probably should use
>> __raw_readw().
>>
>
> Okay. will provide this change with fix-up patch.

On second thought, __raw_readw() can get combined into 32-bit
accesses on some architectures. If you want to be sure you use only
16-bit reads, then cpu_to_le32(readw_relaxed(from)) would be
the safer option.

      Arnd



More information about the linux-mtd mailing list