[PATCH net-next v2] net/core: fix wrong return value in __splice_segment

Pengtao He posted 1 patch 2 months, 1 week ago
There is a newer version of this series
net/core/skbuff.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH net-next v2] net/core: fix wrong return value in __splice_segment
Posted by Pengtao He 2 months, 1 week ago
Return true immediately when the last segment is processed,
avoid to walking once more in the frags loop.

Signed-off-by: Pengtao He <hept.hept.hept@gmail.com>
---
v2->v1:
Correct the commit message and target tree.
v1:
https://lore.kernel.org/netdev/20250723063119.24059-1-hept.hept.hept@gmail.com/
---
 net/core/skbuff.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index ee0274417948..cc3339ab829a 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3114,6 +3114,9 @@ static bool __splice_segment(struct page *page, unsigned int poff,
 		*len -= flen;
 	} while (*len && plen);
 
+	if (!*len)
+		return true;
+
 	return false;
 }
 
-- 
2.49.0
Re: [PATCH net-next v2] net/core: fix wrong return value in __splice_segment
Posted by Eric Dumazet 2 months, 1 week ago
On Thu, Jul 24, 2025 at 3:29 AM Pengtao He <hept.hept.hept@gmail.com> wrote:
>
> Return true immediately when the last segment is processed,
> avoid to walking once more in the frags loop.
>
> Signed-off-by: Pengtao He <hept.hept.hept@gmail.com>
> ---
> v2->v1:
> Correct the commit message and target tree.
> v1:
> https://lore.kernel.org/netdev/20250723063119.24059-1-hept.hept.hept@gmail.com/
> ---
>  net/core/skbuff.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index ee0274417948..cc3339ab829a 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -3114,6 +3114,9 @@ static bool __splice_segment(struct page *page, unsigned int poff,
>                 *len -= flen;
>         } while (*len && plen);
>
> +       if (!*len)
> +               return true;
> +
>         return false;
>  }
>

Condition is evaluated twice. What about this instead ?

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index ee0274417948e0eb121792a400a0455884c92e56..23b776cd98796cf8eb4d19868a0506423226914d
100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3112,7 +3112,9 @@ static bool __splice_segment(struct page *page,
unsigned int poff,
                poff += flen;
                plen -= flen;
                *len -= flen;
-       } while (*len && plen);
+               if (!*len)
+                       return true;
+       } while (plen);

        return false;
 }
Re: [PATCH net-next v2] net/core: fix wrong return value in __splice_segment
Posted by Pengtao He 2 months, 1 week ago
> >
> > Return true immediately when the last segment is processed,
> > avoid to walking once more in the frags loop.
> >
> > Signed-off-by: Pengtao He <hept.hept.hept@gmail.com>
> > ---
> > v2->v1:
> > Correct the commit message and target tree.
> > v1:
> > https://lore.kernel.org/netdev/20250723063119.24059-1-hept.hept.hept@gmai=
> l.com/
> > ---
> >  net/core/skbuff.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> > index ee0274417948..cc3339ab829a 100644
> > --- a/net/core/skbuff.c
> > +++ b/net/core/skbuff.c
> > @@ -3114,6 +3114,9 @@ static bool __splice_segment(struct page *page, uns=
> igned int poff,
> >                 *len -=3D flen;
> >         } while (*len && plen);
> >
> > +       if (!*len)
> > +               return true;
> > +
> >         return false;
> >  }
> >
> 
> Condition is evaluated twice. What about this instead ?
> 
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index ee0274417948e0eb121792a400a0455884c92e56..23b776cd98796cf8eb4d19868a0=
> 506423226914d
> 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -3112,7 +3112,9 @@ static bool __splice_segment(struct page *page,
> unsigned int poff,
>                 poff +=3D flen;
>                 plen -=3D flen;
>                 *len -=3D flen;
> -       } while (*len && plen);
> +               if (!*len)
> +                       return true;
> +       } while (plen);
> 
>         return false;
>  }
> 
Ok, this is better.

Thanks.