gpt4 book ai didi

c - 对齐陷阱: not handling instruction e1913f9f at [<80467364>]

转载 作者:行者123 更新时间:2023-11-30 18:36:35 25 4
gpt4 key购买 nike

当我在应用程序中使用我自己的 ioctl i2c 写入函数进行 i2c 写入时,我收到来自内核的“对齐陷阱:不处理指令”问题。

其实我自己写了一个摄像头驱动,有i2c读/写功能来控制摄像头(控制路径)。

这是我用来访问 i2c 进行写入的代码。

此问题是在应用程序中运行几次 i2c 写入或首次运行后出现的......因此,我们无法预测问题的发生。

我也见过这种情况,单次运行后,几分钟后就会出现这个问题。

我不知道可能是什么问题。顺便说一句,我以相同的方式有 i2c 读取功能,但没有任何“kmalloc”或内存分配/释放。而且它的工作没有任何问题。

在代码中,如果我注释掉“kfree(temp_buff)”,那么我不会遇到这个“对齐”陷阱问题,但不建议这样做,对吗?

谁能帮我解决这个问题吗?

    static s32 ioctl_i2cwrite(struct v4l2_int_device *s, struct v4l2_i2c *i2c_reg)
{
int j = 0, i = 0, ret = 0, reg_size_bkp = 0;
//Titus
int total_size = i2c_reg->count + i2c_reg->reg_size;
u8 i2c_w_buf [total_size];
char *temp_buff;


// int total_size = 3;
// u8 i2c_w_buf[3];


printk("Titus : i2c_write executed! %s : %d, total_size -> %d\n",__func__,__LINE__,total_size);


// temp_buff = kmalloc(i2c_reg->count * sizeof(char), GFP_KERNEL);
temp_buff = kmalloc(i2c_reg->count, GFP_KERNEL);
if(temp_buff == NULL){
printk("failed to allocate memory:\n");
return -1;
}

memset(temp_buff, 0, i2c_reg->count);
memcpy(temp_buff, i2c_reg->buffer, i2c_reg->count);
/*
ret = copy_from_user(temp_buff,i2c_reg->buffer,i2c_reg->count);
if(ret != 0)
{
pr_err("copy_from_user is failed... %s %d\n",__FILE__,__LINE__);
kfree(temp_buff);
return ret;
}
*/

/* Backup the size of register which needs to be read after filling the address buffer */
reg_size_bkp = i2c_reg->reg_size;
printk(" i2c_write: reg_size_bkp=%d i2c_reg->reg_size=%d %s\n",reg_size_bkp,i2c_reg->reg_size, __FILE__);


// Fill the address in buffer upto size of address want to write */
for(i = --i2c_reg->reg_size; i >= 0 ; i--,j++)
i2c_w_buf[i] = ((i2c_reg->reg >> (8*j)) & 0xFF);

/* Append the data value in the same buffer */
for(i = reg_size_bkp; i < (i2c_reg->count + reg_size_bkp) ; i++,temp_buff++)
i2c_w_buf[i] = *temp_buff;

ret = i2c_master_send(leonardo_data.i2c_client, i2c_w_buf, total_size );

//TODO: Titus: It leads to alignment trap issue.
kfree(temp_buff);


return ret;
}

root@imx6:/# root@imx6:/# Alignment trap: not handling instruction e1913f9f at [<80467364>] Unhandled fault: alignment exception (0x001) at 0x9e383d41 Internal error: : 1 [#1] PREEMPT SMP ARM Modules linked in: ov5642_camera mxc_v4l2_capture ipu_bg_overlay_sdc ipu_still ipu_prp_enc ipu_csi_enc adv7180_tvin ipu_fg_overlay_sdc v4l2_int_device gpio_keys usb_f_ecm g_ether usb_f_rndis u_ether libcomposite CPU: 1 PID: 935 Comm: Xorg Not tainted 3.14.52-svn99 #2 task: a8ace3c0 ti: a8d38000 task.ti: a8d38000 PC is at gckOS_AtomIncrement+0x1c/0x48 LR is at gckVIDMEM_NODE_Allocate+0x100/0x13c pc : [<80467368>] lr : [<8047b810>] psr: a00f0013 sp : a8d39c50 ip : a8d39c60 fp : a8d39c5c r10: 00000006 r9 : a8ec7e80 r8 : 00000009 r7 : a8846700 r6 : 00000000 r5 : a8846300 r4 : 9e383240 r3 : 00000000 r2 : a8d39c6c r1 : 9e383d41 r0 : a8846300 Flags: NzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user Control: 10c5387d Table: 3840404a DAC: 00000015 Process Xorg (pid: 935, stack limit = 0xa8d38238) Stack: (0xa8d39c50 to 0xa8d3a000) 9c40:
a8d39c9c a8d39c60 8047b810 80467358 9c60: 800dd984 9e383240 00000000 a8ec7e80 a868c540 00000009 00000007 00000002 9c80: 00000006 00000001 a8846700 00004000 a8d39cfc a8d39ca0 8046ecfc 8047b71c 9ca0: a8d39ccc a8d39cb0 800ddb1c 80052c24 a8819a00 000003a7 00004000 a8d39db8 9cc0: 000000cc a8b37cc0 a8ec7e80 00000000 a8b37eb4 ffffffff 00000000 a8d39d88 9ce0: a8846700 00000000 a8d38000 00000001 a8d39d5c a8d39d00 80471768 8046ea34 9d00: 00000040 00000006 00000003 a8d39dbc 00000000 00100100 00000000 00000000 9d20: 00000000 000003a7 a8b37eb4 00000000 ffffffff 00000000 a8844600 a8de7540 9d40: a8d38000 00007530 a8104338 7e8f38f8 a8d39ef4 a8d39d60 8046d848 80470d9c

9d60: 00000000 00000000 7e8f3970 00000000 00000140 00000000 7e8f3970 00000000 9d80: 00000140 00000000 00000007 00000002 00000000 00000000 00000000 00000000 9da0: 00000000 00000000 00004000 00000040 00000006 00000003 00000001 00000000 9dc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 7e8f39d8 9de0: 00000000 76fa4000 76f6e6fd 76f9899c 00000017 76e4ff10 00001000 ffffffff 9e00: fffffff0 783b79f0 00001000 00000000 00000000 7e8f39ec 00000001 7e8f3a10 root@imx6:/# 9e20: 00000000 00000000 00000020 76f674a3 00000000 00000002 00000000 76fab554 9e40: 7835f998 76b89000 00000009 76fb018c 76fb018c 76fb018c 76fb018c 76fb018c 9e60: 78153960 00000000 78382c70 765746b3 00000000 00000000 00000000 00000000 9e80: 00000000 00000000 00000000 76b894e8 7e8f3ae4 00000044 7e8f3ad0 00000028 9ea0: 0000001a 783fac14 00000000 76afbe9d 00000000 00000000 00000040 7e8f3ae4 9ec0: 780d6228 766ce63c a8d39ef4 a82f4780 a82f4780 00007530 7e8f38f8 a8104338 9ee0: a8d38000 7e8f38f8 a8d39f7c a8d39ef8 800f26fc 8046d728 8004e090 8004dcb8 9f00: a8d39f1c a8d39f10 7e8f3a10 7e8f39f4 00000000 00000129 8000eae4 a63ed680 9f20: 7e8f39f4 00000000 00000129 8000eae4 a8d38000 00000000 a8d39f94 a8d39f48 9f40: 80507e24 805067b4 00000000 00000001 7e8f3c48 a82f4780 a82f4780 00007530 9f60: 7e8f38f8 00000009 a8d38000 00000000 a8d39fa4 a8d39f80 800f2c50 800f2688 9f80: 780d6228 00002710 766f2548 00007530 00000036 8000eae4 00000000 a8d39fa8 9fa0: 8000e960 800f2c20 00002710 766f2548 00000009 00007530 7e8f38f8 780d6228 9fc0: 00002710 766f2548 00007530 00000036 00000028 0000001a 783fac14 00000000 9fe0: 766e7550 7e8f38e4 766cf9d8 76b342b6 800f0030 00000009 3bf58811 3bf58c11 Backtrace: [<8046734c>] (gckOS_AtomIncrement) from [<8047b810>] (gckVIDMEM_NODE_Allocate+0x100/0x13c) [<8047b710>] (gckVIDMEM_NODE_Allocate) from [<8046ecfc>] (gckKERNEL_AllocateLinearMemory+0x2d4/0x338) r10:00004000 r9:a8846700 r8:00000001 r7:00000006 r6:00000002 r5:00000007 r4:00000009 [<8046ea28>] (gckKERNEL_AllocateLinearMemory) from [<80471768>] (gckKERNEL_Dispatch+0x9d8/0x1080) r10:00000001 r9:a8d38000 r8:00000000 r7:a8846700 r6:a8d39d88 r5:00000000 r4:ffffffff [<80470d90>] (gckKERNEL_Dispatch) from [<8046d848>] (drv_ioctl+0x12c/0x2b8) r10:7e8f38f8 r8:a8104338 r7:00007530 r6:a8d38000 r5:a8de7540 r4:a8844600 [<8046d71c>] (drv_ioctl) from [<800f26fc>] (do_vfs_ioctl+0x80/0x598) r10:7e8f38f8 r9:a8d38000 r8:a8104338 r7:7e8f38f8 r6:00007530 r5:a82f4780 r4:a82f4780 [<800f267c>] (do_vfs_ioctl) from [<800f2c50>] (SyS_ioctl+0x3c/0x60) r10:00000000 r9:a8d38000 r8:00000009 r7:7e8f38f8 r6:00007530 r5:a82f4780 r4:a82f4780 [<800f2c14>] (SyS_ioctl) from [<8000e960>] (ret_fast_syscall+0x0/0x38) r8:8000eae4 r7:00000036 r6:00007530 r5:766f2548 r4:00002710 r3:780d6228 Code: e3510000 0a00000a f57ff05b e1913f9f (e2833001) ---[ end trace 095d3b4029173c21 ]--- ------------[ cut here ]------------ Kernel BUG at 800dda80 [verbose debug info unavailable] Internal error: Oops - BUG: 0 [#2] PREEMPT SMP ARM Modules linked in: ov5642_camera mxc_v4l2_capture ipu_bg_overlay_sdc ipu_stillCPU: 2 PID: 754 Comm: NetworkManager Tainted: G D 3.14.52-svn99 #2 task: a8349300 ti: a8526000 task.ti: a8526000 PC is at kfree+0x18c/0x198 LR is at inotify_free_event+0x10/0x14 pc : [<800dda80>] lr : [<8011db68>]
psr: 40010013 sp : a8527e80 ip : 80934240 fp : a8527eb4 r10: 00000800 r9 : a8bea6c8 r8 : a8526000 r7 : abb1e000 r6 : 7e8e4124 r5 : 9e380000 r4 : 00000020 r3 : 00000000 r2 : ab757000 r1 : 00000000 r0 : 00000000 Flags: nZcv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user Control: 10c5387d Table: 3866404a DAC: 00000015 Process NetworkManager (pid: 754, stack limit = 0xa8526238) Stack: (0xa8527e80 to 0xa8528000) 7e80: 800f34e0 0001352e 8005de80 00000020 00000005 7e8e4124 a8bea6c0 a8526000 7ea0: a8bea6c8 00000800 a8527ec4 a8527eb8 8011db68 800dd900 a8527ed4 a8527ec8 7ec0: 8011bec4 8011db64 a8527f44 a8527ed8 8011e168 8011bea0 a8527f44 7e8e4134 7ee0: 00000010 a8bea780 7e8e4124 a8bea6e8 a8527f44 00000001 00000080 00000282 7f00: 00000010 00000000 a8349300 8006657c a8527f10 a8527f10 a8d8f600 a8bea780 7f20: 00000800 7e8e4124 a8527f78 00000800 a8526000 7e8e4124 a8527f74 a8527f48 7f40: 800e2e64 8011df5c 800fc0a4 800fc024 00000000 00000000 a8bea781 a8bea780 7f60: 00000800 7e8e4124 a8527fa4 a8527f78 800e303c 800e2dd8 00000000 00000000 7f80: 7e8e411c 0000000a 7e8e4124 00000003 8000eae4 00000000 00000000 a8527fa8 7fa0: 8000e960 800e3004 7e8e411c 0000000a 0000000a 7e8e4124 00000800 00000000 7fc0: 7e8e411c 0000000a 7e8e4124 00000003 004cc0b0 76bdc5b8 004dcdd8 0005a195 7fe0: 00000000 7e8e4110 76a99619 76a99620 80010030 0000000a 3bf5e821 3bf5ec21 Backtrace: [<800dd8f4>] (kfree) from [<8011db68>] (inotify_free_event+0x10/0x14) r10:00000800 r9:a8bea6c8 r8:a8526000 r7:a8bea6c0 r6:7e8e4124 r5:00000005 r4:00000020 [<8011db58>] (inotify_free_event) from [<8011bec4>] (fsnotify_destroy_event+0x30/0x34) [<8011be94>] (fsnotify_destroy_event) from [<8011e168>] (inotify_read+0x218/0x2f8) [<8011df50>] (inotify_read) from [<800e2e64>] (vfs_read+0x98/0x138) r10:7e8e4124 r9:a8526000 r8:00000800 r7:a8527f78 r6:7e8e4124 r5:00000800 r4:a8bea780 [<800e2dcc>] (vfs_read) from [<800e303c>] (SyS_read+0x44/0x90) r10:7e8e4124 r8:00000800 r7:a8bea780 r6:a8bea781 r5:00000000 r4:00000000 [<800e2ff8>] (SyS_read) from [<8000e960>] (ret_fast_syscall+0x0/0x38) r10:00000000 r8:8000eae4 r7:00000003 r6:7e8e4124 r5:0000000a r4:7e8e411c Code: e7923283 e3130902 11a07001 eaffffb0 (e7f001f2) ---[ end trace 095d3b4029173c22 ]--- power_down_callback: ipu0/csi0 ipu_prp_enc ipu_csi_enc adv7180_tvin ipu_fg_overlay_sdc v4l2_int_device gpio_keys usb_f_ecm g_ether usb_f_rndis u_ether libcomposite mxc_sdc_fb fb.20: 1280x720 h_sync,r,l: 40,110,220 v_sync,l,u: 5,5,20 pixclock=74250000 Hz imx-ipuv3 2800000.ipu: try ipu internal clk imx-ipuv3 2800000.ipu: disp=0, pixel_clk=74250000 74250000 parent=74250000 div=1 mxc_sdc_fb fb.20: 1280x720 h_sync,r,l: 40,110,220 v_sync,l,u: 5,5,20 pixclock=74250000 Hz imx-ipuv3 2800000.ipu: try ipu internal clk imx-ipuv3 2800000.ipu: disp=0, pixel_clk=74250000 74250000 parent=74250000 div=1 mxc_sdc_fb fb.20: 1280x720 h_sync,r,l: 40,110,220 v_sync,l,u: 5,5,20 pixclock=74250000 Hz imx-ipuv3 2800000.ipu: try ipu internal clk imx-ipuv3 2800000.ipu: disp=0, pixel_clk=74250000 74250000 parent=74250000 div=1 mxc_sdc_fb fb.20: 1280x720 h_sync,r,l: 40,110,220 v_sync,l,u: 5,5,20 pixclock=74250000 Hz imx-ipuv3 2800000.ipu: try ipu internal clk imx-ipuv3 2800000.ipu: disp=0, pixel_clk=74250000 74250000 parent=74250000 div=1 Unable to handle kernel paging request at virtual address 0024d8ac pgd = a9390000 [0024d8ac] *pgd=00000000

问候,
泰特斯·S.

最佳答案

for(i = reg_size_bkp; i < (i2c_reg->count + reg_size_bkp) ; i++,temp_buff++)

在这一行中,您将递增 temp_buff 指针,因此您将丢失分配的内存的起始地址。当您使用 free() 时,您将释放一些字符对齐的随机地址,不一定是单词对齐的,我猜这就是引发对齐错误的原因。您需要将 malloc() 返回的相同地址传递给 free()

关于c - 对齐陷阱: not handling instruction e1913f9f at [<80467364>],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40498963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com