# SPI wrong readDataSizePtr value

**URL:** <https://forum.legato.io/t/spi-wrong-readdatasizeptr-value/4169>\
**Category:** Legato Application Framework\
**Created:** [March 8, 2019, 6:06pm UTC](https://forum.legato.io/t/spi-wrong-readdatasizeptr-value/4169 "2019-03-08T18:06:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheGod](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/thegod/32/252_2.png) [@TheGod](https://forum.legato.io/u/TheGod)\
**Post date:** [March 8, 2019, 6:06pm UTC](https://forum.legato.io/t/spi-wrong-readdatasizeptr-value/4169/1 "2019-03-08T18:06:40Z")

</div>

readDataSizePtr should inform how many bytes was read. But system always returns original value. Problem is in functions le\_spi\_ReadHD, le\_spi\_WriteReadFD, le\_spi\_WriteReadHD.  
Example:

> ```
> uint8_t Data[40];
> size_t S = NUM_ARRAY_MEMBERS(Data);
> Res = le_spi_ReadHD(SPIHandle, Data, &S);
> if(Res == LE_OK)
> {
> char Str[10];
> sprintf(Str, "%d", S);
> LE_INFO(Str);
> //S value is always 40 does not matter if system receives 2,3,10 or 20 bytes, S is incorrect 
> //and it is always 40. 
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![JayM2M](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@JayM2M](https://forum.legato.io/u/JayM2M)\
**Post date:** [March 22, 2019, 4:00pm UTC](https://forum.legato.io/t/spi-wrong-readdatasizeptr-value/4169/2 "2019-03-22T16:00:22Z")

</div>

Hi

I don’t have SPI hardware available to test but from Legato SPI library code review, it seems that `readDataLength` is not updated in `le_spiLib_ReadHD()` function:

> <https://github.com/legatoproject/legato-af/blob/bb8645bba0743e9d946a30784c560b5e1fa6db6a/components/spiLibrary/le_spiLibrary.c#L321>

I guess we should add the following line before “`result = LE_OK;`”:

> `*readDataLength = transferResult;`

Could try to rebuild Legato with this mod?

Jay
