3.2.7 错误处理
#include <linux/err.h> char * collect_data(char *userbuffer) { char *buffer; /* ... */ buffer = kmalloc(100, GFP_KERNEL); if (!buffer) { /* Out of memory */ return ERR_PTR(-ENOMEM); } /* ... */ if (copy_from_user(buffer, userbuffer, 100)) { return ERR_PTR(-EFAULT); } /* ... */ return(buffer); } int my_function(char *userbuffer) { char *buf; /* ... */ buf = collect_data(userbuffer); if (IS_ERR(buf)) { printk("Error returned is %d!\n", PTR_ERR(buf)); } /* ... */ } |
http://www.cnblogs.com/snake-hand/p/3184709.html
时间: 2024-09-28 21:16:10