Bluetooth: Fix false-positive "uninitialized" compiler warning
authorJohan Hedberg <johan.hedberg@intel.com>
Wed, 3 Dec 2014 14:26:37 +0000 (16:26 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 3 Dec 2014 15:51:22 +0000 (16:51 +0100)
Some gcc versions don't seem to be able to properly track the flow of
the smp_cmd_pairing_random() function and end up causing the following
types of (false-positive) warnings:

 smp.c:1995:6: warning: ‘nb’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   err = smp_g2(smp->tfm_cmac, pkax, pkbx, na, nb, &passkey);
 smp.c:1995:6: warning: ‘na’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   err = smp_g2(smp->tfm_cmac, pkax, pkbx, na, nb, &passkey);
       ^
 smp.c:1995:6: warning: ‘pkbx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   err = smp_g2(smp->tfm_cmac, pkax, pkbx, na, nb, &passkey);
       ^
 smp.c:1995:6: warning: ‘pkax’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   err = smp_g2(smp->tfm_cmac, pkax, pkbx, na, nb, &passkey);

This patch fixes the issue by moving the pkax/pkbx and na/nb
initialization earlier in the function.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/smp.c

index 7435940456ee741ec5bd889f7d253a755491078d..96bf16dcd9e9382e2ed6add599b2a05d63233fba 100644 (file)
@@ -1947,6 +1947,18 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
        if (!test_bit(SMP_FLAG_SC, &smp->flags))
                return smp_random(smp);
 
+       if (hcon->out) {
+               pkax = smp->local_pk;
+               pkbx = smp->remote_pk;
+               na   = smp->prnd;
+               nb   = smp->rrnd;
+       } else {
+               pkax = smp->remote_pk;
+               pkbx = smp->local_pk;
+               na   = smp->rrnd;
+               nb   = smp->prnd;
+       }
+
        if (smp->method == REQ_OOB) {
                if (!hcon->out)
                        smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM,
@@ -1969,20 +1981,10 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
 
                if (memcmp(smp->pcnf, cfm, 16))
                        return SMP_CONFIRM_FAILED;
-
-               pkax = smp->local_pk;
-               pkbx = smp->remote_pk;
-               na   = smp->prnd;
-               nb   = smp->rrnd;
        } else {
                smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd),
                             smp->prnd);
                SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK);
-
-               pkax = smp->remote_pk;
-               pkbx = smp->local_pk;
-               na   = smp->rrnd;
-               nb   = smp->prnd;
        }
 
 mackey_and_ltk:
This page took 0.027159 seconds and 5 git commands to generate.