Re: Practical character driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:

  CC [M]  drivers/mymodule/mymem1.o
drivers/mymodule/mymem1.c: In function ‘mem_read’:
drivers/mymodule/mymem1.c:98: warning: ISO C90 forbids mixed declarations and code
drivers/mymodule/mymem1.c: In function ‘mem_write’:
drivers/mymodule/mymem1.c:125: warning: ISO C90 forbids mixed declarations and code
drivers/mymodule/mymem1.c: In function ‘module_initial’:
drivers/mymodule/mymem1.c:207: warning: ‘memory’ may be used uninitialized in this function

which is exactly the following:

  memset(device, 0, sizeof(char) * map_size);

  memory->device = device;================> (memory is unitialized)

correct?    sorry if i am wrong....  

On Sun, Feb 27, 2011 at 3:52 PM, Mulyadi Santosa <mulyadi.santosa@xxxxxxxxx> wrote:
On Sun, Feb 27, 2011 at 11:57, Sameer Rahmani <lxsameer@xxxxxxxxx> wrote:
> static int __init module_initial(void)
> {
>   dev_t dev;
>   int result;
>   struct memmap *memory;
>
>   if (major)
>     {
>       dev = MKDEV(major, minor);
>       result = register_chrdev_region(dev, 1, "memchar");
>     }
>   else
>     {
>       result = alloc_chrdev_region(&dev, minor, 1,
>                    "memchar");
>       major = MAJOR(dev);
>
>     }
>   if (result < 0)
>     {
>       printk (KERN_ALERT "Cannot register major number.\n");
>       return result;
>     }
>
>   device = kmalloc(sizeof(char) * map_size, GFP_KERNEL);
>   if (! device)
>     {
>       printk (KERN_ALERT "Allocating device failed.\n");
>       result = -ENOMEM;
>       goto fail;
>     }
>
>
>   memset(device, 0, sizeof(char) * map_size);
>
>   memory->device = device;
>   mem_setup_cdev(memory);
>
>
>   printk(KERN_ALERT "Major: %d", major);
>   return 0;
>
>  fail:
>   module_cleanup();
>   return result;
> }

As you can see by yourself, you put many data structures as locals to
module_init. So once module_init is thrashed, those variables/pointers
also gone. Result? Easy to guess...lost reference :)

--
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



--
Regards,
Peter Teoh
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux