]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
w1: fix w1_send_slave dropping a slave id
authorDavid Fries <David@Fries.net>
Thu, 16 Jan 2014 04:29:12 +0000 (22:29 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Feb 2014 23:40:17 +0000 (15:40 -0800)
Previous logic,
if (avail > 8) {
store slave;
return;
}
send data; clear;

The logic error is, if there isn't space send the buffer and clear,
but the slave wasn't added to the now empty buffer loosing that slave
id.  It also should have been "if (avail >= 8)" because when it is 8,
there is space.

Instead, if there isn't space send and clear the buffer, then there is
always space for the slave id.

Signed-off-by: David Fries <David@Fries.net>
Cc: stable@vger.kernel.org
Acked-by: Evgeniy Polyakov <zbr@ioremap.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/w1/w1_netlink.c

index 40788c925d1c9b4d847e6572f5a8510ac402ac71..73705aff53cb776f076ddc09d41824695083843e 100644 (file)
@@ -54,28 +54,29 @@ static void w1_send_slave(struct w1_master *dev, u64 rn)
        struct w1_netlink_msg *hdr = (struct w1_netlink_msg *)(msg + 1);
        struct w1_netlink_cmd *cmd = (struct w1_netlink_cmd *)(hdr + 1);
        int avail;
+       u64 *data;
 
        /* update kernel slave list */
        w1_slave_found(dev, rn);
 
        avail = dev->priv_size - cmd->len;
 
-       if (avail > 8) {
-               u64 *data = (void *)(cmd + 1) + cmd->len;
+       if (avail < 8) {
+               msg->ack++;
+               cn_netlink_send(msg, 0, GFP_KERNEL);
 
-               *data = rn;
-               cmd->len += 8;
-               hdr->len += 8;
-               msg->len += 8;
-               return;
+               msg->len = sizeof(struct w1_netlink_msg) +
+                       sizeof(struct w1_netlink_cmd);
+               hdr->len = sizeof(struct w1_netlink_cmd);
+               cmd->len = 0;
        }
 
-       msg->ack++;
-       cn_netlink_send(msg, 0, GFP_KERNEL);
+       data = (void *)(cmd + 1) + cmd->len;
 
-       msg->len = sizeof(struct w1_netlink_msg) + sizeof(struct w1_netlink_cmd);
-       hdr->len = sizeof(struct w1_netlink_cmd);
-       cmd->len = 0;
+       *data = rn;
+       cmd->len += 8;
+       hdr->len += 8;
+       msg->len += 8;
 }
 
 static int w1_process_search_command(struct w1_master *dev, struct cn_msg *msg,