i think pointer can always be localized, as when then pointer is lost, the memory allocated is still always there, and moreover, the pointer is kept in a structure.   more likely is a compilation detected error:   when i compiled it tell me exactly which lines is not initialized:<div>
<br></div><div><div>  CC [M]  drivers/mymodule/mymem1.o</div><div>drivers/mymodule/mymem1.c: In function ‘mem_read’:</div><div>drivers/mymodule/mymem1.c:98: warning: ISO C90 forbids mixed declarations and code</div><div>drivers/mymodule/mymem1.c: In function ‘mem_write’:</div>
<div>drivers/mymodule/mymem1.c:125: warning: ISO C90 forbids mixed declarations and code</div><div>drivers/mymodule/mymem1.c: In function ‘module_initial’:</div><div>drivers/mymodule/mymem1.c:207: warning: ‘memory’ may be used uninitialized in this function</div>
</div><div><br></div><div>which is exactly the following:</div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><span class="Apple-style-span" style="border-collapse: separate;"><br>
</span></span></font></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">  memset(device, 0, sizeof(char) * map_size);</span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br>
</span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br></span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">  memory-&gt;device = device;================&gt; (memory is unitialized)</span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br>
</span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">correct?    sorry if i am wrong....</span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "> </span><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "> </span><br>
<br><div class="gmail_quote">On Sun, Feb 27, 2011 at 3:52 PM, Mulyadi Santosa <span dir="ltr">&lt;<a href="mailto:mulyadi.santosa@gmail.com">mulyadi.santosa@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Sun, Feb 27, 2011 at 11:57, Sameer Rahmani &lt;<a href="mailto:lxsameer@gmail.com">lxsameer@gmail.com</a>&gt; wrote:<br>
&gt; static int __init module_initial(void)<br>
&gt; {<br>
&gt;   dev_t dev;<br>
&gt;   int result;<br>
&gt;   struct memmap *memory;<br>
&gt;<br>
&gt;   if (major)<br>
&gt;     {<br>
&gt;       dev = MKDEV(major, minor);<br>
&gt;       result = register_chrdev_region(dev, 1, &quot;memchar&quot;);<br>
&gt;     }<br>
&gt;   else<br>
&gt;     {<br>
&gt;       result = alloc_chrdev_region(&amp;dev, minor, 1,<br>
&gt;                    &quot;memchar&quot;);<br>
&gt;       major = MAJOR(dev);<br>
&gt;<br>
&gt;     }<br>
&gt;   if (result &lt; 0)<br>
&gt;     {<br>
&gt;       printk (KERN_ALERT &quot;Cannot register major number.\n&quot;);<br>
&gt;       return result;<br>
&gt;     }<br>
&gt;<br>
&gt;   device = kmalloc(sizeof(char) * map_size, GFP_KERNEL);<br>
&gt;   if (! device)<br>
&gt;     {<br>
&gt;       printk (KERN_ALERT &quot;Allocating device failed.\n&quot;);<br>
&gt;       result = -ENOMEM;<br>
&gt;       goto fail;<br>
&gt;     }<br>
&gt;<br>
&gt;<br>
&gt;   memset(device, 0, sizeof(char) * map_size);<br>
&gt;<br>
&gt;   memory-&gt;device = device;<br>
&gt;   mem_setup_cdev(memory);<br>
&gt;<br>
&gt;<br>
&gt;   printk(KERN_ALERT &quot;Major: %d&quot;, major);<br>
&gt;   return 0;<br>
&gt;<br>
&gt;  fail:<br>
&gt;   module_cleanup();<br>
&gt;   return result;<br>
&gt; }<br>
<br>
</div></div>As you can see by yourself, you put many data structures as locals to<br>
module_init. So once module_init is thrashed, those variables/pointers<br>
also gone. Result? Easy to guess...lost reference :)<br>
<br>
--<br>
regards,<br>
<br>
Mulyadi Santosa<br>
Freelance Linux trainer and consultant<br>
<br>
blog: <a href="http://the-hydra.blogspot.com" target="_blank">the-hydra.blogspot.com</a><br>
training: <a href="http://mulyaditraining.blogspot.com" target="_blank">mulyaditraining.blogspot.com</a><br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Regards,<br>Peter Teoh<br>
</div>