mm/iob: Support neg offset in iob_clone

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
Zhe Weng 2023-02-07 20:00:59 +08:00 committed by Petro Karashchenko
parent fb861c0a29
commit cd1decf4a5
2 changed files with 7 additions and 7 deletions

View File

@ -476,8 +476,8 @@ int iob_clone(FAR struct iob_s *iob1, FAR struct iob_s *iob2,
****************************************************************************/
int iob_clone_partial(FAR struct iob_s *iob1, unsigned int len,
unsigned int offset1, FAR struct iob_s *iob2,
unsigned int offset2, bool throttled, bool block);
int offset1, FAR struct iob_s *iob2,
int offset2, bool throttled, bool block);
/****************************************************************************
* Name: iob_concat

View File

@ -109,8 +109,8 @@ static int iob_next(FAR struct iob_s *iob, bool throttled, bool block)
****************************************************************************/
int iob_clone_partial(FAR struct iob_s *iob1, unsigned int len,
unsigned int offset1, FAR struct iob_s *iob2,
unsigned int offset2, bool throttled, bool block)
int offset1, FAR struct iob_s *iob2,
int offset2, bool throttled, bool block)
{
FAR uint8_t *src;
FAR uint8_t *dest;
@ -129,7 +129,7 @@ int iob_clone_partial(FAR struct iob_s *iob1, unsigned int len,
* the list, Skip I/O buffer containing the data offset.
*/
while (iob1 != NULL && offset1 >= iob1->io_len)
while (iob1 != NULL && (int)(offset1 - iob1->io_len) >= 0)
{
offset1 -= iob1->io_len;
iob1 = iob1->io_flink;
@ -195,7 +195,7 @@ int iob_clone_partial(FAR struct iob_s *iob1, unsigned int len,
/* Have we taken all of the data from the source I/O buffer? */
if (offset1 >= iob1->io_len)
if ((int)(offset1 - iob1->io_len) >= 0)
{
/* Skip over empty entries in the chain (there should not be any
* but just to be safe).
@ -218,7 +218,7 @@ int iob_clone_partial(FAR struct iob_s *iob1, unsigned int len,
* transferred?
*/
if (offset2 >= (CONFIG_IOB_BUFSIZE - iob2->io_offset) &&
if ((int)(offset2 + iob2->io_offset - CONFIG_IOB_BUFSIZE) >= 0 &&
iob1 != NULL)
{
ret = iob_next(iob2, throttled, block);