* [PATCH net-next 2/2] net: Eliminate duplicated codes by creating one new function in_dev_select_addr
@ 2017-03-07 14:51 fgao
2017-03-07 15:46 ` Sergei Shtylyov
0 siblings, 1 reply; 3+ messages in thread
From: fgao @ 2017-03-07 14:51 UTC (permalink / raw)
To: davem, kuznet, jmorris, kaber, netdev, gfree.wind; +Cc: Gao Feng
From: Gao Feng <fgao@ikuai8.com>
There are two duplicated loop codes which used to select right
address in current codes. Now eliminate these codes by creating
one new function in_dev_select_addr.
Signed-off-by: Gao Feng <fgao@ikuai8.com>
---
net/ipv4/devinet.c | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 1a9e550..d0964c5 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1191,6 +1191,19 @@ static int inet_gifconf(struct net_device *dev, char __user *buf, int len)
return done;
}
+static __be32 in_dev_select_addr(const struct in_device *in_dev,
+ int scope)
+{
+ for_primary_ifa(in_dev) {
+ if (ifa->ifa_scope != RT_SCOPE_LINK &&
+ ifa->ifa_scope <= scope) {
+ return ifa->ifa_local;
+ }
+ } endfor_ifa(in_dev);
+
+ return 0;
+}
+
__be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope)
{
__be32 addr = 0;
@@ -1229,13 +1242,9 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope)
if (dev) {
in_dev = __in_dev_get_rcu(dev);
if (in_dev) {
- for_primary_ifa(in_dev) {
- if (ifa->ifa_scope != RT_SCOPE_LINK &&
- ifa->ifa_scope <= scope) {
- addr = ifa->ifa_local;
- goto out_unlock;
- }
- } endfor_ifa(in_dev);
+ addr = in_dev_select_addr(in_dev, scope);
+ if (addr)
+ goto out_unlock;
}
}
@@ -1250,14 +1259,9 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope)
in_dev = __in_dev_get_rcu(dev);
if (!in_dev)
continue;
-
- for_primary_ifa(in_dev) {
- if (ifa->ifa_scope != RT_SCOPE_LINK &&
- ifa->ifa_scope <= scope) {
- addr = ifa->ifa_local;
- goto out_unlock;
- }
- } endfor_ifa(in_dev);
+ addr = in_dev_select_addr(in_dev, scope);
+ if (addr)
+ goto out_unlock;
}
}
out_unlock:
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next 2/2] net: Eliminate duplicated codes by creating one new function in_dev_select_addr
2017-03-07 14:51 [PATCH net-next 2/2] net: Eliminate duplicated codes by creating one new function in_dev_select_addr fgao
@ 2017-03-07 15:46 ` Sergei Shtylyov
2017-03-10 1:36 ` Feng Gao
0 siblings, 1 reply; 3+ messages in thread
From: Sergei Shtylyov @ 2017-03-07 15:46 UTC (permalink / raw)
To: fgao, davem, kuznet, jmorris, kaber, netdev, gfree.wind
Hello!
On 03/07/2017 05:51 PM, fgao@ikuai8.com wrote:
> From: Gao Feng <fgao@ikuai8.com>
>
> There are two duplicated loop codes which used to select right
Just "loops".
> address in current codes. Now eliminate these codes by creating
> one new function in_dev_select_addr.
>
> Signed-off-by: Gao Feng <fgao@ikuai8.com>
> ---
> net/ipv4/devinet.c | 34 +++++++++++++++++++---------------
> 1 file changed, 19 insertions(+), 15 deletions(-)
>
> diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
> index 1a9e550..d0964c5 100644
> --- a/net/ipv4/devinet.c
> +++ b/net/ipv4/devinet.c
> @@ -1191,6 +1191,19 @@ static int inet_gifconf(struct net_device *dev, char __user *buf, int len)
> return done;
> }
>
> +static __be32 in_dev_select_addr(const struct in_device *in_dev,
> + int scope)
> +{
> + for_primary_ifa(in_dev) {
> + if (ifa->ifa_scope != RT_SCOPE_LINK &&
> + ifa->ifa_scope <= scope) {
> + return ifa->ifa_local;
> + }
Could drop the useless {} here, while at it.
> + } endfor_ifa(in_dev);
> +
> + return 0;
> +}
> +
> __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope)
> {
> __be32 addr = 0;
[...]
MBR, Sergei
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next 2/2] net: Eliminate duplicated codes by creating one new function in_dev_select_addr
2017-03-07 15:46 ` Sergei Shtylyov
@ 2017-03-10 1:36 ` Feng Gao
0 siblings, 0 replies; 3+ messages in thread
From: Feng Gao @ 2017-03-10 1:36 UTC (permalink / raw)
To: Sergei Shtylyov
Cc: David S. Miller, kuznet, jmorris, Patrick McHardy,
Linux Kernel Network Developers
Hi Sergei,
On Tue, Mar 7, 2017 at 11:46 PM, Sergei Shtylyov
<sergei.shtylyov@cogentembedded.com> wrote:
> Hello!
>
> On 03/07/2017 05:51 PM, fgao@ikuai8.com wrote:
>
>> From: Gao Feng <fgao@ikuai8.com>
>>
>> There are two duplicated loop codes which used to select right
>
>
> Just "loops".
>
>> address in current codes. Now eliminate these codes by creating
>> one new function in_dev_select_addr.
>>
>> Signed-off-by: Gao Feng <fgao@ikuai8.com>
>> ---
>> net/ipv4/devinet.c | 34 +++++++++++++++++++---------------
>> 1 file changed, 19 insertions(+), 15 deletions(-)
>>
>> diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
>> index 1a9e550..d0964c5 100644
>> --- a/net/ipv4/devinet.c
>> +++ b/net/ipv4/devinet.c
>> @@ -1191,6 +1191,19 @@ static int inet_gifconf(struct net_device *dev,
>> char __user *buf, int len)
>> return done;
>> }
>>
>> +static __be32 in_dev_select_addr(const struct in_device *in_dev,
>> + int scope)
>> +{
>> + for_primary_ifa(in_dev) {
>> + if (ifa->ifa_scope != RT_SCOPE_LINK &&
>> + ifa->ifa_scope <= scope) {
>> + return ifa->ifa_local;
>> + }
>
>
> Could drop the useless {} here, while at it.
Thanks, I would correct it in v2 patch.
The checkpatch.pl ignores this issue when I checked this patch.
It seems one bug of checkpatch.pl
Regards
Feng
>
>> + } endfor_ifa(in_dev);
>> +
>> + return 0;
>> +}
>> +
>> __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int
>> scope)
>> {
>> __be32 addr = 0;
>
> [...]
>
> MBR, Sergei
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-03-10 1:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-07 14:51 [PATCH net-next 2/2] net: Eliminate duplicated codes by creating one new function in_dev_select_addr fgao
2017-03-07 15:46 ` Sergei Shtylyov
2017-03-10 1:36 ` Feng Gao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).