* [PATCH net-next-2.6] net: sock_bindtodevice() RCU-ification
@ 2009-11-04 22:36 Eric Dumazet
2009-11-06 5:08 ` David Miller
0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2009-11-04 22:36 UTC (permalink / raw)
To: David S. Miller; +Cc: Linux Netdev List
Avoid dev_hold()/dev_put() in sock_bindtodevice()
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
net/core/sock.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/net/core/sock.c b/net/core/sock.c
index 5a51512..38820ea 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -420,14 +420,16 @@ static int sock_bindtodevice(struct sock *sk, char __user *optval, int optlen)
if (devname[0] == '\0') {
index = 0;
} else {
- struct net_device *dev = dev_get_by_name(net, devname);
+ struct net_device *dev;
+ rcu_read_lock();
+ dev = dev_get_by_name_rcu(net, devname);
+ if (dev)
+ index = dev->ifindex;
+ rcu_read_unlock();
ret = -ENODEV;
if (!dev)
goto out;
-
- index = dev->ifindex;
- dev_put(dev);
}
lock_sock(sk);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next-2.6] net: sock_bindtodevice() RCU-ification
2009-11-04 22:36 [PATCH net-next-2.6] net: sock_bindtodevice() RCU-ification Eric Dumazet
@ 2009-11-06 5:08 ` David Miller
2009-11-06 6:39 ` David Miller
0 siblings, 1 reply; 5+ messages in thread
From: David Miller @ 2009-11-06 5:08 UTC (permalink / raw)
To: eric.dumazet; +Cc: netdev
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Wed, 04 Nov 2009 23:36:44 +0100
> Avoid dev_hold()/dev_put() in sock_bindtodevice()
>
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Applied to net-next-2.6, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next-2.6] net: sock_bindtodevice() RCU-ification
2009-11-06 5:08 ` David Miller
@ 2009-11-06 6:39 ` David Miller
2009-11-06 7:08 ` Eric Dumazet
0 siblings, 1 reply; 5+ messages in thread
From: David Miller @ 2009-11-06 6:39 UTC (permalink / raw)
To: eric.dumazet; +Cc: netdev
From: David Miller <davem@davemloft.net>
Date: Thu, 05 Nov 2009 21:08:30 -0800 (PST)
> From: Eric Dumazet <eric.dumazet@gmail.com>
> Date: Wed, 04 Nov 2009 23:36:44 +0100
>
>> Avoid dev_hold()/dev_put() in sock_bindtodevice()
>>
>> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
>
> Applied to net-next-2.6, thanks.
Eric I had to add the following patch to cure a build
warning after this, just FYI:
net: Fix build warning in sock_bindtodevice().
net/core/sock.c: In function 'sock_setsockopt':
net/core/sock.c:396: warning: 'index' may be used uninitialized in this function
net/core/sock.c:396: note: 'index' was declared here
GCC can't see that all paths initialize index, so just
set it to the default (0) and eliminate the specific
code block that handles the null device name string.
Signed-off-by: David S. Miller <davem@davemloft.net>
---
net/core/sock.c | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/net/core/sock.c b/net/core/sock.c
index 38820ea..76ff58d 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -417,9 +417,8 @@ static int sock_bindtodevice(struct sock *sk, char __user *optval, int optlen)
if (copy_from_user(devname, optval, optlen))
goto out;
- if (devname[0] == '\0') {
- index = 0;
- } else {
+ index = 0;
+ if (devname[0] != '\0') {
struct net_device *dev;
rcu_read_lock();
--
1.6.5.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next-2.6] net: sock_bindtodevice() RCU-ification
2009-11-06 6:39 ` David Miller
@ 2009-11-06 7:08 ` Eric Dumazet
2009-11-06 8:17 ` David Miller
0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2009-11-06 7:08 UTC (permalink / raw)
To: David Miller; +Cc: netdev
David Miller a écrit :
> From: David Miller <davem@davemloft.net>
> Date: Thu, 05 Nov 2009 21:08:30 -0800 (PST)
>
>> From: Eric Dumazet <eric.dumazet@gmail.com>
>> Date: Wed, 04 Nov 2009 23:36:44 +0100
>>
>>> Avoid dev_hold()/dev_put() in sock_bindtodevice()
>>>
>>> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
>> Applied to net-next-2.6, thanks.
>
> Eric I had to add the following patch to cure a build
> warning after this, just FYI:
>
> net: Fix build warning in sock_bindtodevice().
>
> net/core/sock.c: In function 'sock_setsockopt':
> net/core/sock.c:396: warning: 'index' may be used uninitialized in this function
> net/core/sock.c:396: note: 'index' was declared here
>
> GCC can't see that all paths initialize index, so just
> set it to the default (0) and eliminate the specific
> code block that handles the null device name string.
>
Thanks David, which gcc version are you using ?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next-2.6] net: sock_bindtodevice() RCU-ification
2009-11-06 7:08 ` Eric Dumazet
@ 2009-11-06 8:17 ` David Miller
0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2009-11-06 8:17 UTC (permalink / raw)
To: eric.dumazet; +Cc: netdev
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Fri, 06 Nov 2009 08:08:59 +0100
> Thanks David, which gcc version are you using ?
I'm using "gcc-4.2.4 (Ubuntu 4.2.4-1ubuntu3)" on sparc.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-11-06 8:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-04 22:36 [PATCH net-next-2.6] net: sock_bindtodevice() RCU-ification Eric Dumazet
2009-11-06 5:08 ` David Miller
2009-11-06 6:39 ` David Miller
2009-11-06 7:08 ` Eric Dumazet
2009-11-06 8:17 ` David Miller
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).