Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Bluetooth: Fix false-positive "uninitialized" compiler warning

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>

authored by

Johan Hedberg and committed by
Marcel Holtmann
580039e8 7f376cd6

+12 -10
+12 -10
net/bluetooth/smp.c
··· 1947 1947 if (!test_bit(SMP_FLAG_SC, &smp->flags)) 1948 1948 return smp_random(smp); 1949 1949 1950 + if (hcon->out) { 1951 + pkax = smp->local_pk; 1952 + pkbx = smp->remote_pk; 1953 + na = smp->prnd; 1954 + nb = smp->rrnd; 1955 + } else { 1956 + pkax = smp->remote_pk; 1957 + pkbx = smp->local_pk; 1958 + na = smp->rrnd; 1959 + nb = smp->prnd; 1960 + } 1961 + 1950 1962 if (smp->method == REQ_OOB) { 1951 1963 if (!hcon->out) 1952 1964 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, ··· 1981 1969 1982 1970 if (memcmp(smp->pcnf, cfm, 16)) 1983 1971 return SMP_CONFIRM_FAILED; 1984 - 1985 - pkax = smp->local_pk; 1986 - pkbx = smp->remote_pk; 1987 - na = smp->prnd; 1988 - nb = smp->rrnd; 1989 1972 } else { 1990 1973 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), 1991 1974 smp->prnd); 1992 1975 SMP_ALLOW_CMD(smp, SMP_CMD_DHKEY_CHECK); 1993 - 1994 - pkax = smp->remote_pk; 1995 - pkbx = smp->local_pk; 1996 - na = smp->rrnd; 1997 - nb = smp->prnd; 1998 1976 } 1999 1977 2000 1978 mackey_and_ltk: