Re: [PATCH] net: core: datagram: tidy up copy functions a bit
From: Vito Caputo Date: Sat, 12 Oct 2019 04:55:09 -0700 > + if ((copy = min(start - offset, len)) > 0) { As Eric said, we try to avoid this very construct these days. I'm not applying this patch. Thank you.
Re: [PATCH] net: core: datagram: tidy up copy functions a bit
On 10/13/19 3:41 PM, Vito Caputo wrote: > I read it, thank you for your responses. > > Do you have any guidance to offer someone wanting to contribute with 1-2 > hours available per day? I don't want to cause a nuisance, but would > like to help where I can. My flawed assumption was that small, isolated > hygienic contributions without functionally changing anything would be > appropriate. I suggest you look at the syzkaller huge queue of bugs. You will learn more interesting stuff, and you will help the community in a more quantifiable way. https://syzkaller.appspot.com/upstream
Re: [PATCH] net: core: datagram: tidy up copy functions a bit
On Sun, Oct 13, 2019 at 01:17:18PM -0700, Eric Dumazet wrote: > > > On 10/13/19 1:01 PM, Vito Caputo wrote: > > On Sun, Oct 13, 2019 at 12:30:41PM -0700, Eric Dumazet wrote: > >> > >> > >> On 10/12/19 4:55 AM, Vito Caputo wrote: > >>> Eliminate some verbosity by using min() macro and consolidating some > >>> things, also fix inconsistent zero tests (! vs. == 0). > >>> > >>> Signed-off-by: Vito Caputo > >>> --- > >>> net/core/datagram.c | 44 ++-- > >>> 1 file changed, 14 insertions(+), 30 deletions(-) > >>> > >>> diff --git a/net/core/datagram.c b/net/core/datagram.c > >>> index 4cc8dc5db2b7..08d403f93952 100644 > >>> --- a/net/core/datagram.c > >>> +++ b/net/core/datagram.c > >>> @@ -413,13 +413,11 @@ static int __skb_datagram_iter(const struct sk_buff > >>> *skb, int offset, > >>> struct iov_iter *), void *data) > >>> { > >>> int start = skb_headlen(skb); > >>> - int i, copy = start - offset, start_off = offset, n; > >>> + int i, copy, start_off = offset, n; > >>> struct sk_buff *frag_iter; > >>> > >>> /* Copy header. */ > >>> - if (copy > 0) { > >>> - if (copy > len) > >>> - copy = len; > >>> + if ((copy = min(start - offset, len)) > 0) { > >> > >> No, we prefer not having this kind of construct anymore. > >> > >> This refactoring looks unnecessary code churn, making our future backports > >> not > >> clean cherry-picks. > >> > >> Simply making sure this patch does not bring a regression is very time > >> consuming. > > > > Should I not bother submitting patches for such cleanups? > > > > I submitted another, more trivial patch, is it also considered unnecessary > > churn: > > > > --- > > > > Author: Vito Caputo > > Date: Sat Oct 12 17:10:41 2019 -0700 > > > > net: core: skbuff: skb_checksum_setup() drop err > > > > Return directly from all switch cases, no point in storing in err. > > > > Signed-off-by: Vito Caputo > > > > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > > index f5f904f46893..c59b68a413b5 100644 > > --- a/net/core/skbuff.c > > +++ b/net/core/skbuff.c > > @@ -4888,23 +4888,14 @@ static int skb_checksum_setup_ipv6(struct sk_buff > > *skb, bool recalculate) > > */ > > int skb_checksum_setup(struct sk_buff *skb, bool recalculate) > > { > > - int err; > > - > > switch (skb->protocol) { > > case htons(ETH_P_IP): > > - err = skb_checksum_setup_ipv4(skb, recalculate); > > - break; > > - > > + return skb_checksum_setup_ipv4(skb, recalculate); > > case htons(ETH_P_IPV6): > > - err = skb_checksum_setup_ipv6(skb, recalculate); > > - break; > > - > > + return skb_checksum_setup_ipv6(skb, recalculate); > > default: > > - err = -EPROTO; > > - break; > > + return -EPROTO; > > } > > - > > - return err; > > } > > EXPORT_SYMBOL(skb_checksum_setup); > > > > --- > > > > Asking to calibrate my thresholds to yours, since I was planning to > > volunteer > > some time each evening to reading kernel code and submitting any obvious > > cleanups. > > > > This is not a cleanup. > > You prefer seeing the code written the way you did, but that is really a > matter of taste. > I respectfully disagree with your assertion. When the diff --stat shows more lines removed than added without harming readability, preferably improving readability, it's both a cleanup and not a debatable matter of taste. Having the quantifiable metric of fewer lines of code matters. > Think about backports of real bug fixes to stable kernels. > That's fair, but when the change is an isolated mechanical one in a single small function, as the one quoted above - is that really of any significant burden on backports? > Having these re-writes of code make things less easy for us really. > So in general we tend to leave the existing code style. > > I already replied to the other patch submission, please read > > https://marc.info/?l=linux-netdev=157099669227635=2 > I read it, thank you for your responses. Do you have any guidance to offer someone wanting to contribute with 1-2 hours available per day? I don't want to cause a nuisance, but would like to help where I can. My flawed assumption was that small, isolated hygienic contributions without functionally changing anything would be appropriate. Thanks, Vito Caputo
Re: [PATCH] net: core: datagram: tidy up copy functions a bit
On 10/13/19 1:01 PM, Vito Caputo wrote: > On Sun, Oct 13, 2019 at 12:30:41PM -0700, Eric Dumazet wrote: >> >> >> On 10/12/19 4:55 AM, Vito Caputo wrote: >>> Eliminate some verbosity by using min() macro and consolidating some >>> things, also fix inconsistent zero tests (! vs. == 0). >>> >>> Signed-off-by: Vito Caputo >>> --- >>> net/core/datagram.c | 44 ++-- >>> 1 file changed, 14 insertions(+), 30 deletions(-) >>> >>> diff --git a/net/core/datagram.c b/net/core/datagram.c >>> index 4cc8dc5db2b7..08d403f93952 100644 >>> --- a/net/core/datagram.c >>> +++ b/net/core/datagram.c >>> @@ -413,13 +413,11 @@ static int __skb_datagram_iter(const struct sk_buff >>> *skb, int offset, >>> struct iov_iter *), void *data) >>> { >>> int start = skb_headlen(skb); >>> - int i, copy = start - offset, start_off = offset, n; >>> + int i, copy, start_off = offset, n; >>> struct sk_buff *frag_iter; >>> >>> /* Copy header. */ >>> - if (copy > 0) { >>> - if (copy > len) >>> - copy = len; >>> + if ((copy = min(start - offset, len)) > 0) { >> >> No, we prefer not having this kind of construct anymore. >> >> This refactoring looks unnecessary code churn, making our future backports >> not >> clean cherry-picks. >> >> Simply making sure this patch does not bring a regression is very time >> consuming. > > Should I not bother submitting patches for such cleanups? > > I submitted another, more trivial patch, is it also considered unnecessary > churn: > > --- > > Author: Vito Caputo > Date: Sat Oct 12 17:10:41 2019 -0700 > > net: core: skbuff: skb_checksum_setup() drop err > > Return directly from all switch cases, no point in storing in err. > > Signed-off-by: Vito Caputo > > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > index f5f904f46893..c59b68a413b5 100644 > --- a/net/core/skbuff.c > +++ b/net/core/skbuff.c > @@ -4888,23 +4888,14 @@ static int skb_checksum_setup_ipv6(struct sk_buff > *skb, bool recalculate) > */ > int skb_checksum_setup(struct sk_buff *skb, bool recalculate) > { > - int err; > - > switch (skb->protocol) { > case htons(ETH_P_IP): > - err = skb_checksum_setup_ipv4(skb, recalculate); > - break; > - > + return skb_checksum_setup_ipv4(skb, recalculate); > case htons(ETH_P_IPV6): > - err = skb_checksum_setup_ipv6(skb, recalculate); > - break; > - > + return skb_checksum_setup_ipv6(skb, recalculate); > default: > - err = -EPROTO; > - break; > + return -EPROTO; > } > - > - return err; > } > EXPORT_SYMBOL(skb_checksum_setup); > > --- > > Asking to calibrate my thresholds to yours, since I was planning to volunteer > some time each evening to reading kernel code and submitting any obvious > cleanups. > This is not a cleanup. You prefer seeing the code written the way you did, but that is really a matter of taste. Think about backports of real bug fixes to stable kernels. Having these re-writes of code make things less easy for us really. So in general we tend to leave the existing code style. I already replied to the other patch submission, please read https://marc.info/?l=linux-netdev=157099669227635=2
Re: [PATCH] net: core: datagram: tidy up copy functions a bit
On Sun, Oct 13, 2019 at 12:30:41PM -0700, Eric Dumazet wrote: > > > On 10/12/19 4:55 AM, Vito Caputo wrote: > > Eliminate some verbosity by using min() macro and consolidating some > > things, also fix inconsistent zero tests (! vs. == 0). > > > > Signed-off-by: Vito Caputo > > --- > > net/core/datagram.c | 44 ++-- > > 1 file changed, 14 insertions(+), 30 deletions(-) > > > > diff --git a/net/core/datagram.c b/net/core/datagram.c > > index 4cc8dc5db2b7..08d403f93952 100644 > > --- a/net/core/datagram.c > > +++ b/net/core/datagram.c > > @@ -413,13 +413,11 @@ static int __skb_datagram_iter(const struct sk_buff > > *skb, int offset, > > struct iov_iter *), void *data) > > { > > int start = skb_headlen(skb); > > - int i, copy = start - offset, start_off = offset, n; > > + int i, copy, start_off = offset, n; > > struct sk_buff *frag_iter; > > > > /* Copy header. */ > > - if (copy > 0) { > > - if (copy > len) > > - copy = len; > > + if ((copy = min(start - offset, len)) > 0) { > > No, we prefer not having this kind of construct anymore. > > This refactoring looks unnecessary code churn, making our future backports not > clean cherry-picks. > > Simply making sure this patch does not bring a regression is very time > consuming. Should I not bother submitting patches for such cleanups? I submitted another, more trivial patch, is it also considered unnecessary churn: --- Author: Vito Caputo Date: Sat Oct 12 17:10:41 2019 -0700 net: core: skbuff: skb_checksum_setup() drop err Return directly from all switch cases, no point in storing in err. Signed-off-by: Vito Caputo diff --git a/net/core/skbuff.c b/net/core/skbuff.c index f5f904f46893..c59b68a413b5 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -4888,23 +4888,14 @@ static int skb_checksum_setup_ipv6(struct sk_buff *skb, bool recalculate) */ int skb_checksum_setup(struct sk_buff *skb, bool recalculate) { - int err; - switch (skb->protocol) { case htons(ETH_P_IP): - err = skb_checksum_setup_ipv4(skb, recalculate); - break; - + return skb_checksum_setup_ipv4(skb, recalculate); case htons(ETH_P_IPV6): - err = skb_checksum_setup_ipv6(skb, recalculate); - break; - + return skb_checksum_setup_ipv6(skb, recalculate); default: - err = -EPROTO; - break; + return -EPROTO; } - - return err; } EXPORT_SYMBOL(skb_checksum_setup); --- Asking to calibrate my thresholds to yours, since I was planning to volunteer some time each evening to reading kernel code and submitting any obvious cleanups. Thanks, Vito Caputo
Re: [PATCH] net: core: datagram: tidy up copy functions a bit
On 10/12/19 4:55 AM, Vito Caputo wrote: > Eliminate some verbosity by using min() macro and consolidating some > things, also fix inconsistent zero tests (! vs. == 0). > > Signed-off-by: Vito Caputo > --- > net/core/datagram.c | 44 ++-- > 1 file changed, 14 insertions(+), 30 deletions(-) > > diff --git a/net/core/datagram.c b/net/core/datagram.c > index 4cc8dc5db2b7..08d403f93952 100644 > --- a/net/core/datagram.c > +++ b/net/core/datagram.c > @@ -413,13 +413,11 @@ static int __skb_datagram_iter(const struct sk_buff > *skb, int offset, > struct iov_iter *), void *data) > { > int start = skb_headlen(skb); > - int i, copy = start - offset, start_off = offset, n; > + int i, copy, start_off = offset, n; > struct sk_buff *frag_iter; > > /* Copy header. */ > - if (copy > 0) { > - if (copy > len) > - copy = len; > + if ((copy = min(start - offset, len)) > 0) { No, we prefer not having this kind of construct anymore. This refactoring looks unnecessary code churn, making our future backports not clean cherry-picks. Simply making sure this patch does not bring a regression is very time consuming.