title: linux device driver container_of macro when using arrays
body: <p>In one of the legacy device driver that I am using, I have a structure format as below - </p>
  
  <pre><code>struct inner_struct_containing_cdev {
     struct cdev cdev;
     ....
     ....
     /* more variables */
  };
  
  struct outer_struct {
      /* because I need 10 devices */
      struct inner_struct_containing_cdev inner[10];
      ....
      ....
      /* more variables which are common to all the 10 devices. */
  };
  </code></pre>
  
  <p>Now in my init_module I am calling <code>alloc_chrdev_region</code> and other allocation related calls. Now in my <code>open</code> file operation with signature <code>int open(struct inode *inode, struct file *filp)</code> I can get access to the cdev structure and hence the <code>inner_struct_containing_cdev</code>. But I would like to get the pointer to <code>outer_struct</code> instead. In the <code>open</code> call I don't know which array index of the <code>inner_struct_containing_cdev</code> struct I received a pointer to. 
  Is it possible to use <code>container_of</code> macro in such a case? Or need to re-design the structures?</p>
  
  <p>Currently I am handling the situation using a global variable. But this prevents me from having multiple instantiation.</p>