linux-usb-gadgets / libusbgx

C library encapsulating the Linux kernel USB gadget configfs userspace API functionality
GNU General Public License v2.0
216 stars 72 forks source link

Invalid attribute is set in multiple places because of incorrect MACRO #69

Closed wdl-crestron closed 1 year ago

wdl-crestron commented 1 year ago

Because macros are used in multiple places to initialize unnamed unions for example:

#define USBG_F_NET_ETHER_ADDR_TO_ATTR_VAL(WHAT)     \
    USBG_TO_UNION(usbg_f_net_attr_val, dev_addr, WHAT)

....

static inline int usbg_f_net_set_host_addr(usbg_f_net *nf,
                       const struct ether_addr *addr)
{
    return usbg_f_net_set_attr_val(nf, USBG_F_NET_HOST_ADDR,
                       USBG_F_NET_ETHER_ADDR_TO_ATTR_VAL(*addr));
}

this causes invalid attributes to be set, in this case dev_addr field is set to addr which, from function name, should set host_addr. This issue is present in multiple places.

This commit in https://github.com/linux-usb-gadgets/libusbgx/pull/68/commits/8221d20d2a0b2cf6ce180ad97ecb13821a3f30e0 removes problematic macros.

wdl-crestron commented 1 year ago

Incorrect issue report - because of union alignment members are overlapping so all should work. Still somewhat misleading.