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->device = device;================> (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"><<a href="mailto:mulyadi.santosa@gmail.com">mulyadi.santosa@gmail.com</a>></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 <<a href="mailto:lxsameer@gmail.com">lxsameer@gmail.com</a>> wrote:<br>
> static int __init module_initial(void)<br>
> {<br>
> dev_t dev;<br>
> int result;<br>
> struct memmap *memory;<br>
><br>
> if (major)<br>
> {<br>
> dev = MKDEV(major, minor);<br>
> result = register_chrdev_region(dev, 1, "memchar");<br>
> }<br>
> else<br>
> {<br>
> result = alloc_chrdev_region(&dev, minor, 1,<br>
> "memchar");<br>
> major = MAJOR(dev);<br>
><br>
> }<br>
> if (result < 0)<br>
> {<br>
> printk (KERN_ALERT "Cannot register major number.\n");<br>
> return result;<br>
> }<br>
><br>
> device = kmalloc(sizeof(char) * map_size, GFP_KERNEL);<br>
> if (! device)<br>
> {<br>
> printk (KERN_ALERT "Allocating device failed.\n");<br>
> result = -ENOMEM;<br>
> goto fail;<br>
> }<br>
><br>
><br>
> memset(device, 0, sizeof(char) * map_size);<br>
><br>
> memory->device = device;<br>
> mem_setup_cdev(memory);<br>
><br>
><br>
> printk(KERN_ALERT "Major: %d", major);<br>
> return 0;<br>
><br>
> fail:<br>
> module_cleanup();<br>
> return result;<br>
> }<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>