摄像头驱动用指针对成员变量赋值出现oops。。。
按照字符设备标准编写open(struct inode,struct video_device *v)后,
在用 struct s3c2440_cam *dev =(struct video_device *)v->priv; 后(这里的pirv指向全局变量cam), 用指针对dev的成员变量赋值时(如dev->width=1024)会出现oops,但是直接cam.width=1024就可以。
请问这是什么原因?如何解决?
内核版本 2.6.22.6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
奇怪的问题.
怀疑指针dev指向了错误的地方, 导致指针访问越界. 跟踪一下dev的值.
OOPS的信息是什么
Unable to handle kernel NULL pointer dereference at virtual address 0000027c
pgd = c39e0000
[0000027c] *pgd=306c5031, *pte=00000000, *ppte=00000000
Internal error: Oops: 817 [#1]
Modules linked in:
CPU: 0 Not tainted (2.6.22.6 #85)
PC is at s3c2440_cam_open+0x198/0x210
LR is at s3c2440_cam_open+0x17c/0x210
pc : [<c01d26c0>] lr : [<c01d26a4>] psr: 60000013
sp : c39bbe58 ip : 20000013 fp : c39bbe70
r10: c04c3000 r9 : c39ba000 r8 : 00000000
r7 : c384b88c r6 : 00000000 r5 : c03db5a0 r4 : c03db2ec
r3 : 00000280 r2 : c03db578 r1 : 00000000 r0 : 00000001
Flags: nZCv IRQs on FIQs on Mode SVC_32 Segment user
Control: c000717f Table: 339e0000 DAC: 00000015
Process test.o (pid: 799, stack limit = 0xc39ba25
Stack: (0xc39bbe58 to 0xc39bc000)
be40: c02d3690 c04b2b20
be60: c03daed4 c39bbe94 c39bbe74 c01cb334 c01d2538 c06acc20 c384b88c 00000000
be80: 00000000 c04b2b20 c39bbebc c39bbe98 c008e804 c01cb254 00000000 c04b2b20
bea0: c384b88c c008e6b8 c0487e20 c3849288 c39bbee4 c39bbec0 c008adc4 c008e6c8
bec0: c04b2b20 c39bbf04 00000003 ffffff9c c002d044 c04c3000 c39bbefc c39bbee8
bee0: c008aee0 c008acd4 00000000 00000000 c39bbf68 c39bbf00 c008af34 c008aebc
bf00: c39bbf04 c3849288 c0487e20 00000000 00000000 c39e1000 00000101 00000001
bf20: 00000000 c39ba000 c04952c8 c04952c0 ffffffe8 c04c3000 c39bbf68 c39bbf48
bf40: c008b0e8 c00a0bec 00000001 00000000 c04b2b20 00000000 bec4dd8c c39bbf94
bf60: c39bbf6c c008b270 c008af04 000085fc bec4dd84 0000888c 000088f0 00000005
bf80: c002d044 4013365c c39bbfa4 c39bbf98 c008b324 c008b22c 00000000 c39bbfa8
bfa0: c002cea0 c008b310 bec4dd84 0000888c 000089a0 00000000 bec4dd8c 00000000
bfc0: bec4dd84 0000888c 000088f0 00000001 000085fc 00000000 4013365c bec4dd58
bfe0: 00000000 bec4dcb4 0000266c 400c98e0 60000010 000089a0 00000000 00000000
Backtrace:
[<c01d2528>] (s3c2440_cam_open+0x0/0x210) from [<c01cb334>] (video_open+0xf0/0x)
r6:c03daed4 r5:c04b2b20 r4:c02d3690
[<c01cb244>] (video_open+0x0/0x17c) from [<c008e804>] (chrdev_open+0x14c/0x164)
r8:c04b2b20 r7:00000000 r6:00000000 r5:c384b88c r4:c06acc20
[<c008e6b8>] (chrdev_open+0x0/0x164) from [<c008adc4>] (__dentry_open+0x100/0x1)
r8:c3849288 r7:c0487e20 r6:c008e6b8 r5:c384b88c r4:c04b2b20
[<c008acc4>] (__dentry_open+0x0/0x1e from [<c008aee0>] (nameidata_to_filp+0x3)
[<c008aeac>] (nameidata_to_filp+0x0/0x4 from [<c008af34>] (do_filp_open+0x40/)
r4:00000000
[<c008aef4>] (do_filp_open+0x0/0x4 from [<c008b270>] (do_sys_open+0x54/0xe4)
r5:bec4dd8c r4:00000000
[<c008b21c>] (do_sys_open+0x0/0xe4) from [<c008b324>] (sys_open+0x24/0x2
[<c008b300>] (sys_open+0x0/0x2 from [<c002cea0>] (ret_fast_syscall+0x0/0x2c)
Code: e59f407c e3a01000 e3a00001 e3a03d0a (e586127c)
Segmentation fault
这是oops的信息
出错的位置是 dev->flag=0 这句,换成cam.flag就可以。。
意思原因貌似是dev没有指向cam
相关的代码
static int s3c2440_cam_open(struct inode *inode,struct video_device *v){
unsigned long flags;//irq state
struct s3c2440_camif *dev=(struct s3c2440_camif *)v->priv;
spin_lock_irqsave(&cam.lock,flags);
if(opened){
spin_unlock_irqrestore(&cam.lock,flags);
return -EBUSY;
}
spin_unlock_irqrestore(&cam.lock,flags);
cam_power(1);
cam_init();
dev->flag= 0;//cam.flag = 0;
cam.mode = 0;
cam.set_chg = 1;
cam_cfg.dev = dev;
cam_cfg.src_x = 640;
cam_cfg.src_y = 480;
cam_cfg.dst_x = 240;
cam_cfg.dst_y = 180;
cam_cfg.pre_x = 240;
cam_cfg.pre_y = 180;
cam_cfg.dst_fmt = 1;
cam_cfg.pre_fmt = 0;
cam_cfg.ycbcr = 0;
return 0;
}
static inline void config_camif_v4l(void){
cam.v.fops = &s3c2440_camif_fops;
cam.v.type = VID_TYPE_CAPTURE | VID_TYPE_SCALES; sprintf(cam.v.name,"%s","S3C2440_CAMIF";
cam.v.priv = &cam;
cam.v.type = VID_TYPE_CAPTURE | VID_TYPE_SCALES;
cam.v.release =v4l_release_back;
}
请问错误是在哪,如何解决?
dev初始化为cam时,打印一下。
出错前,再打印一下,看dev是否出错了。