NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

re: kern/54486: athn driver panics on arm

The following reply was made to PR kern/54486; it has been noted by GNATS.

From: matthew green <>
Cc:,,, (Andreas Gustafsson)
Subject: re: kern/54486: athn driver panics on arm
Date: Sat, 24 Aug 2019 09:59:58 +1000

 >  Looks like gcc is optimizing the memcpy() call on line 2528 of
 >  src/sys/dev/usb/if_athn_usb.c into an unaligned 32-bit store:
 >                  txf = (struct ar_tx_frame *)&htc[1];
 >                  memset(txf, 0, sizeof(*txf));
 >                  txf->data_type = AR_HTC_NORMAL;
 >                  txf->node_idx = sta_index;
 >                  txf->vif_idx = 0;
 >                  txf->tid = tid;
 >  The fields at the beginning and end of *txf are being assigned to, so
 >  only the middle part really needs the memset()ting, and gcc apparently
 >  figures the way to do that is to store a 32-bit word of zeros there,
 >  at an unaligned address.
 >  I would not be surprised if this optimizaion is also breaking other
 >  parts of the arm kernel.  Does anyone know the right way to fix this?
 this looks similar to the problem worked around in if_axe.c:
 i forget the status of a real fix.  there's some issue with
 unaligned on v6/v7, IIRC.
 but i think this one is a code bug.
 the axe case has a structure with two uint16_t's in it, and
 assumes they will be 32 bit aligned.  that's wrong.
 however, in this case, struct ar_tx_frame has 4 x uint8_ts
 and then a uint32_t.
 that means the compiler is probably right to assume that a
 pointer to this structure will be aligned for uint32_t, so
 in this case, the compiler seems to be not wrong, and we 
 should fix the code.

Home | Main Index | Thread Index | Old Index