在arc平台上的linux wifi驱动程序上未对齐的地址访问崩溃
作者:互联网
我在WIFI Marvell PCIe驱动程序的insmod上崩溃.
我在ARCH = arc OS = linux和little endian上运行WIFI驱动程序.
崩溃回溯表示未对齐的地址访问会导致崩溃.
我做了一些调查,发现了崩溃的地方,下面是代码片段.
case NullPktPeriod_i:
/** keep alive null data pkt interval in full power mode */
psnmp_mib->oid = wlan_cpu_to_le16((t_u16)NullPktPeriod_i);
if (cmd_action == HostCmd_ACT_GEN_SET) {
psnmp_mib->query_type =
wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
psnmp_mib->buf_size = wlan_cpu_to_le16(sizeof(t_u32));
ul_temp = *((t_u32 *)pdata_buf);
*((t_u32 *)(psnmp_mib->value)) =
wlan_cpu_to_le32((t_u32)ul_temp);
cmd->size += sizeof(t_u32);
}
break;
崩溃位于行*(((t_u32 *)(psnmp_mib-> value))= wlan_cpu_to_le32((t_u32)ul_temp);因为psnmp_mib->值是unsigned char,并且类型转换为unsigned long int.但是我们从pdata_buf分配的值是1个字节,只有ul_temp = *((t_u32 *)pdata_buf);.
奇怪的行为是,如果将ul_temp(无符号long int变量)初始化为零(任何值),并且如果运行,则看不到崩溃.但是PCI命令超时发生在获取get_hardware_spec命令时,内核挂起.
我没有解决此问题的线索.请提供一些输入以进一步进行操作.
打击是我的崩溃日志,
[ 29.920000] Path: (null)
[ 29.930000] CPU: 0 PID: 1047 Comm: kworker/u3:1 Tainted: P O 3.12.0 #103
[ 29.930000] Workqueue: MOAL_WORK_QUEUE woal_main_work_queue [pcie8xxx]
[ 29.940000] task: 9f0e02c0 ti: 9d192000 task.ti: 9d192000
[ 29.940000]
[ECR ]: 0x00230400 => Misaligned r/w from 0x9d451072
[ 29.950000] [EFA ]: 0x9d451072
[ 29.950000] [BLINK ]: wlan_prepare_cmd+0x1be/0x478 [mlan]
[ 29.950000] [ERET ]: wlan_ops_sta_prepare_cmd+0x1fe0/0x37dc [mlan]
[ 29.950000] [STAT32]: 0x00000a06 : E2 E1
[ 29.970000] BTA: 0x78571ccc SP: 0x9d193c34 FP: 0x00000000
[ 29.980000] LPS: 0x982de26c LPE: 0x982de270 LPC: 0x00000000
[ 29.980000] r00: 0x00000000 r01: 0x00000016 r02: 0x00000012
r03: 0x0000001e r04: 0x00000000 r05: 0x9d193cb4
r06: 0x9d451064 r07: 0x7857129c r08: 0xfffffffe
r09: 0x00000000 r10: 0x000004cf r11: 0x00000002
r12: 0x00000000
[ 29.990000]
[ 29.990000] Stack Trace:
请帮忙.
解决方法:
简单.做正确的事.一般情况下,将使用memcpy
:
t_u32 value = wlan_cpu_to_le32((t_u32)ul_temp);
memcpy(psnmp_mib->value, &value, sizeof (t_u32));
如0andriy所指出的,put_unaligned可以在这里使用:
put_unaligned(wlan_cpu_to_le32((t_u32)ul_temp), (t_u32*)psnmp_mib->value);
但是,这非常令人担忧,因为C标准确实声明behaviour is undefined when:
Conversion between two pointer types produces a result that is incorrectly aligned (07003).
因此,即使仅仅是强制转换(t_u32 *)的存在也可能导致编译器“意识到”指针psnmp_mib-> value始终与t_u32的对齐要求对齐.
未对齐访问-甚至将指针强制转换为未对齐结构-即使在“supposedly” allow unaligned access “everywhere”平台上也具有未定义的行为.
标签:linux-device-driver,wifi,c-3,linux 来源: https://codeday.me/bug/20191110/2015598.html