Re: [PATCH 2/4] Staging: rtl8712: Use ether_addr_equal() over memcmp()

From: punit vara
Date: Sun Oct 11 2015 - 07:12:18 EST


On Sun, Oct 11, 2015 at 6:07 AM, kbuild test robot <lkp@xxxxxxxxx> wrote:
> Hi Punit,
>
> [auto build test WARNING on v4.3-rc4 -- if it's inappropriate base, please ignore]
>
> reproduce:
> # apt-get install sparse
> make ARCH=x86_64 allmodconfig
> make C=1 CF=-D__CHECK_ENDIAN__
>
>
> sparse warnings: (new ones prefixed by >>)
>
> drivers/staging/rtl8712/rtl871x_ioctl_linux.c:227:15: sparse: cast to restricted __le16
>>> drivers/staging/rtl8712/rtl871x_ioctl_linux.c:2010:54: sparse: incorrect type in argument 2 (different base types)
> drivers/staging/rtl8712/rtl871x_ioctl_linux.c:2010:54: expected unsigned char const [usertype] *addr2
> drivers/staging/rtl8712/rtl871x_ioctl_linux.c:2010:54: got struct wlan_bssid_ex network
> drivers/staging/rtl8712/rtl871x_ioctl_linux.c: In function 'r871x_get_ap_info':
> drivers/staging/rtl8712/rtl871x_ioctl_linux.c:2010:32: error: incompatible type for argument 2 of 'ether_addr_equal'
> if (!ether_addr_equal(bssid, pnetwork->network)) {
> ^
> In file included from drivers/staging/rtl8712/osdep_service.h:39:0,
> from drivers/staging/rtl8712/rtl871x_ioctl_linux.c:32:
> include/linux/etherdevice.h:310:20: note: expected 'const u8 * {aka const unsigned char *}' but argument is of type 'struct wlan_bssid_ex'
> static inline bool ether_addr_equal(const u8 *addr1, const u8 *addr2)
> ^
>
> vim +2010 drivers/staging/rtl8712/rtl871x_ioctl_linux.c
>
> 1994 return -EINVAL;
> 1995 spin_lock_irqsave(&(pmlmepriv->scanned_queue.lock), irqL);
> 1996 phead = &queue->queue;
> 1997 plist = phead->next;
> 1998 while (1) {
> 1999 if (end_of_queue_search(phead, plist) == true)
> 2000 break;
> 2001 pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
> 2002 if (hwaddr_aton_i(data, bssid)) {
> 2003 netdev_info(dev, "r8712u: Invalid BSSID '%s'.\n",
> 2004 (u8 *)data);
> 2005 spin_unlock_irqrestore(&(pmlmepriv->scanned_queue.lock),
> 2006 irqL);
> 2007 return -EINVAL;
> 2008 }
> 2009 netdev_info(dev, "r8712u: BSSID:%pM\n", bssid);
>> 2010 if (!ether_addr_equal(bssid, pnetwork->network)) {
> 2011 /* BSSID match, then check if supporting wpa/wpa2 */
> 2012 pbuf = r8712_get_wpa_ie(&pnetwork->network.IEs[12],
> 2013 &wpa_ielen, pnetwork->network.IELength-12);
> 2014 if (pbuf && (wpa_ielen > 0)) {
> 2015 pdata->flags = 1;
> 2016 break;
> 2017 }
> 2018 pbuf = r8712_get_wpa2_ie(&pnetwork->network.IEs[12],
>
> ---
> 0-DAY kernel test infrastructure Open Source Technology Center
> https://lists.01.org/pipermail/kbuild-all Intel Corporation


That error is because I forgot MacAddress that I have already mention.
Julia I have used pahole as you suggested me
following are the two structure need to be consider for alignment.

struct iw_pmksa {
__u32 cmd; /* 0 4 */
struct sockaddr bssid; /* 4 16 */
__u8 pmkid[16]; /* 20 16 */

/* size: 36, cachelines: 1, members: 3 */
/* last cacheline: 36 bytes */
};

struct wlan_bssid_ex {
u32 Length; /* 0 4 */
unsigned char MacAddress[6]; /* 4 6 */
u8 Reserved[2]; /* 10 2 */
struct ndis_802_11_ssid Ssid; /* 12 36 */
u32 Privacy; /* 48 4 */
s32 Rssi; /* 52 4 */
enum NDIS_802_11_NETWORK_TYPE NetworkTypeInUse; /* 56 4 */
struct NDIS_802_11_CONFIGURATION Configuration; /* 60 32 */
/* --- cacheline 1 boundary (64 bytes) was 28 bytes ago --- */
enum NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode; /* 92 4 */
u8 rates[16]; /* 96 16 */
u32 IELength; /* 112 4 */
u8 IEs[768]; /* 116 768 */
/* --- cacheline 13 boundary (832 bytes) was 52 bytes ago --- */

/* size: 884, cachelines: 14, members: 12 */
/* last cacheline: 52 bytes */
};


As I understood both are not aligned to u16 so
ether_addr_equal_unaligned() should be used.

Here ether_addr_equal_unaligned() return true if both address are equal.

so here correct answer would be
if(ether_addr_equal_unaligned(bssid, pnetwork->network.MacAddress)) ??

If I am getting wrong any feedback are welcome otherwise I will
resend patch with correct modification.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/