On Thu, Jun 25, 2015 at 11:40:15AM -0500, Andrew Gabbasov wrote:
> spi_map_buf() processes mapping of vmalloc-ed buffers in a special way,
> making mapping of every page separately. However, if the buffer is not
> aligned to page boundary (e.g. sub-array in a vmalloc-ed array), it
> fills the scatter table with page-size unaligned pieces, that cross
> page boundaries. This is incorrect and can, for example, cause memory
> corruption and various crashes when working with ubifs on spi-nor chips.

The caller is supposed to be providing us with aligned memory here.
However it could be helpful to do this so...

> -     const int sgs = DIV_ROUND_UP(len, desc_len);
> +     const int sgs = DIV_ROUND_UP(vmalloced_buf ?
> +                                     len + offset_in_page(buf) : len,
> +                                  desc_len);

No, please write this legibly without the ternery operator.

Attachment: signature.asc
Description: Digital signature

Reply via email to