From: Eric Dumazet <dada1@cosmosbay.com>
To: Jiri Pirko <jpirko@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Linux Netdev List <netdev@vger.kernel.org>,
Jay Vosburgh <fubar@us.ibm.com>
Subject: Re: [PATCH] bonding: bond_slave_info_query() fix
Date: Thu, 23 Apr 2009 15:39:04 +0200 [thread overview]
Message-ID: <49F06F78.4030601@cosmosbay.com> (raw)
In-Reply-To: <20090423121121.GG29268@psychotron.englab.brq.redhat.com>
Jiri Pirko a écrit :
> Thu, Apr 23, 2009 at 01:24:07PM CEST, dada1@cosmosbay.com wrote:
>> bond_slave_info_query() should keep a read lock while accessing slave info,
>> or risk accessing stale data and corruption.
>>
>> Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
>>
>> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
>> index 63369b6..66697db 100644
>> --- a/drivers/net/bonding/bond_main.c
>> +++ b/drivers/net/bonding/bond_main.c
>> @@ -2213,33 +2213,27 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in
>> {
>> struct bonding *bond = netdev_priv(bond_dev);
>> struct slave *slave;
>> - int i, found = 0;
>> + int i, ret = -ENODEV;
>>
>> - if (info->slave_id < 0) {
>> + if (info->slave_id < 0)
>> return -ENODEV;
>
> You can return ret; here since -ENODEV is there, but I don't know if it isn't
> against policy. Patch looks good anyway.
>
Yes, we can just delete this extra test, since requested slave_id wont
be found anyway if negative.
Thanks
[PATCH] bonding: bond_slave_info_query() fix
bond_slave_info_query() should keep a read lock while accessing slave info,
or risk accessing stale data and corruption.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 63369b6..67515b7 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -2213,33 +2213,24 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in
{
struct bonding *bond = netdev_priv(bond_dev);
struct slave *slave;
- int i, found = 0;
-
- if (info->slave_id < 0) {
- return -ENODEV;
- }
+ int i, res = -ENODEV;
read_lock(&bond->lock);
bond_for_each_slave(bond, slave, i) {
if (i == (int)info->slave_id) {
- found = 1;
+ res = 0;
+ strcpy(info->slave_name, slave->dev->name);
+ info->link = slave->link;
+ info->state = slave->state;
+ info->link_failure_count = slave->link_failure_count;
break;
}
}
read_unlock(&bond->lock);
- if (found) {
- strcpy(info->slave_name, slave->dev->name);
- info->link = slave->link;
- info->state = slave->state;
- info->link_failure_count = slave->link_failure_count;
- } else {
- return -ENODEV;
- }
-
- return 0;
+ return res;
}
/*-------------------------------- Monitoring -------------------------------*/
next prev parent reply other threads:[~2009-04-23 13:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-23 11:24 [PATCH] bonding: bond_slave_info_query() fix Eric Dumazet
2009-04-23 12:11 ` Jiri Pirko
2009-04-23 13:39 ` Eric Dumazet [this message]
2009-04-23 14:51 ` Jay Vosburgh
2009-05-01 22:17 ` David Miller
2009-05-01 22:16 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49F06F78.4030601@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=davem@davemloft.net \
--cc=fubar@us.ibm.com \
--cc=jpirko@redhat.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.