title: Static global variable and static local variable in driver function
body: <p>In one of my sample Linux kernel module, I have a variable <code>Device_Open</code> declared static outside all functions and a static variable <code>counter</code> declared inside a function <code>device_open</code>. Inside <code>device_open</code>, i increment both <code>Device_Open</code> and <code>counter</code>. The module is inserted without any errors into the kernel and i created a device file for my module /dev/chardev.</p>
  
  <p>I do <code>cat /dev/chardev</code>. What i can see is that <code>counter</code> gets incremented for each invocation of <code>cat /dev/chardev</code>, but <code>Device_Open</code> always remains 0. What is the reason for the difference in behavior related to incrementing the value of the variables ?</p>
  
  <p>Below is the code snippet for understanding</p>
  
  <pre><code>static int Device_Open = 0;
  
  static int device_open(struct inode *inode, struct file *file)
  {
      static int counter = 0;
  
      printk(KERN_INFO "Device_Open = %d", Device_Open);
      printk(KERN_INFO "counter = %d", counter);
  
      if (Device_Open)
          return -EBUSY;
  
      Device_Open++;
          counter++;
  
      try_module_get(THIS_MODULE);
  
      return SUCCESS;
  }
  </code></pre>