Driver Development Misuse Pointer error: Unable to handle kernel NULL pointer dereference in virtual address

Source: Internet
Author: User
Tags tainted
Preface

Today, the error caused by the misuse of the pointer in the drive development: Unable to handle kernel NULL pointer dereference in virtual address xxxxxxxx. This error is what I encountered when I used DMA for the LCD driver, and the error caused by referencing an empty pointer when allocating the memory used for the DMA transfer. The error printing information is as follows:

[72.820000] Unable to handle kernel NULL pointer dereference in virtual Address 00000000 [72.820000] PGD = c0004000 [72.820000] [00000000] *pgd=00000000 [72.830000] Internal error:oops:817 [#1] ARM [72.830000] Modules linked In : Disp_tft (o) sec_mmap (o) [72.830000] cpu:0 tainted:g O (3.6.5 #55) [72.830000] PC is at __memzero+0   x4c/0x80 [72.830000] LR is at 0x0 [72.830000] PC: [<c0167a0c>] LR: [<00000000>] psr:00000113 [ 72.830000] SP:C0407DB4 ip:00000000 FP:C0407DCC [72.830000] r10:00000140 r9:00200000 r8:000000f0 [72 .830000] r7:dfcd0000 r6:de2c0000 r5:00000000 r4:00000001 [72.830000] r3:00000000 r2:00000000-R1:FFFF Ffd0 r0:00000000 [72.830000] FLAGS:NZCV IRQs on Fiqs on Mode svc_32 ISA ARM Segment kernel [72.830000] Cont rol:10c53c7d table:7f1cc059 dac:00000015 [72.830000] Process swapper (pid:0, stack limit = 0xc04062e8) [72.830 Stack: (0XC0407DB4To 0xc0408000) ... [72.830000] BackTrace: [72.830000] [<c0172c68>] (sg_init_table+0x0/0x38) from [<bf020324>] (lcd_flash_t imer+0x144/0x340 [Disp_tft]) [72.830000] R5:de81a0d4 r4:de240340 [72.830000] [<bf0201e0>] (lcd_flash_timer+0x 0/0x340 [Disp_tft]) from [<c0057e60>] (RUN_TIMER_SOFTIRQ+0X134/0X1D4) [72.830000] [<c0057d2c>] (Run_timer  _SOFTIRQ+0X0/0X1D4) from [<c005236c>] (__do_softirq+0xa4/0x164) [72.830000] r8:c046f6c0 r7:00000100-r6:c0406000 r5:c046f708 r4:00000001 [72.830000] [<c00522c8>] (__do_softirq+0x0/0x164) from [<c00527bc>] (irq_exit+0x4 8/0x94) [72.830000] [<c0052774>] (irq_exit+0x0/0x94) from [<c000ed10>] (handle_irq+0x6c/0x8c) [72.830000 ] [<c000eca4>] (handle_irq+0x0/0x8c) from [<c0008530>] (gic_handle_irq+0x40/0x58)

Later, Baidu a bit, found that the cause of this error mainly has the following points:

1. Driver developer references an empty pointer while writing driver, causing the kernel's paging mechanism to not map the pointer to a physical address, and the processor issues a page error to the operating system. If the address is invalid, the kernel cannot "page into" the missing address; It (often) produces a oops if this occurs when the processor is in administrative mode;

2. Check the kernel options for driving dependencies, you may have left a key kernel option not selected; solution

In most cases, this error occurs because the driver references an invalid pointer (or a null pointer). This will require you to navigate to the wrong place through a step-by-step print Debug or error message printed through the kernel, and then modify it. Case Show

In order to illustrate how to solve such problems, the author presents an example of sitting in the first place, which is easy for readers to understand. For ease of understanding, the author simplifies the code:

1. For example, add the following two snippets of code to the initialization function of a driver:

static int __init disp_init (void)
{
     int *ptr = NULL;
     *ptr = 0x123456;
     
     ...........
}

The following error occurs when the driver is loaded:

[101.650000] Unable to handle kernel NULL pointer dereference in virtual Address 00000000 [101.66000 0] PGD = de0ac000 [101.660000] [00000000] *pgd=7f21e831, *pte=00000000, *ppte=00000000 [101.660000] Internal Error:oo ps:817 [#1] ARM [101.660000] Modules linked In:disp_tft (o+) prn_ltp02245 (o) ope_gpio_tft (o) Buzz (o) sec_mmap (o) [last UNLOADED:DISP_TFT] [101.660000] cpu:0 tainted:g O (3.6.5 #56) [101.660000] PC is at disp_init+0x28/0x 818 [DISP_TFT] [101.660000] LR is at do_one_initcall+0x9c/0x16c [101.660000] PC: [<bf07d028>] LR: [<c000 8658>] psr:60000013 [101.660000] sp:de2bfe58 ip:de2bfeb0 fp:de2bfeac [101.660000] r10:bf07d000 r9:0 0000000 r8:00000001 [101.660000] r7:debd1080 r6:bf079fe8 r5:00000000 r4:bf07a0e0 [101.660000] r3:00123 456 r2:00000000 r1:00000fff r0:18045000 
[  101.660000] BackTrace: 
[  101.660000] [<bf07d000>] (disp_init+0x0/0x818 [Disp_tft]) from [< C0008658>] (do_one_initcall+0x9c/0x16c)
[  101.660000]  r8:00000001 r7:debd1080 R6:bf079fe8 r5:0 0000000 r4:bf079fa0
[  101.660000] [<c00085bc>] (do_one_initcall+0x0/0x16c) from [<c0078968>] ( SYS_INIT_MODULE+0X1590/0X171C)
[  101.660000] [<c00773d8>] (sys_init_module+0x0/0x171c) from [< C000DE20>] (ret_fast_syscall+0x0/0x30)
[  

With the above error message, we can navigate to the function where the error occurred, using a null pointer in Disp_init ().

about how to drive debugging according to the Oops information in Linux please read the following blog carefully:

http://blog.csdn.net/kangear/article/details/8217329

(Disclaimer: Blogs are quoted from others)

The above blog details how to troubleshoot errors caused by using invalid pointers in drive development based on error messages printed by the kernel. The author has also made reference to this blog before it dawned. So, I also stand on the shoulders of giants to learn AH.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.