Re: Code problem

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

 



Heap Ho Tan (heaphotan@xxxxxxxxx) wrote:
> Hi,
> I have the following piece of code for some reason it
> kept crashing the kernel.
> 
> struct eventDest
> {
>   //Single lock for the whole data-structure
>   spinlock_t eventLock;
>   int eventID;
>   //declare a task list
>   int nb_process;
>   wait_queue_head_t queue;
>   struct list_head event_list;
> };
> 
> static spinlock_t event_lock;
> 
> int event_counter;
> 
> static LIST_HEAD(event_head);
> 
> int myeventopen()
> {
>   struct eventDest *event;
>   struct eventDest tmp;
>   spin_lock_irq(&event_lock);
>   event_counter=event_counter+1;
>   spin_unlock_irq(&event_lock);
> 
>   //printk("Ok up to here\n");
>   event=(struct eventDest *)kmalloc(sizeof(tmp),
> GFP_KERNEL);

I think you must test return of kmalloc() and don't deference a pointer
afterwards if error occured.

>   spin_lock_irq(&(event->eventLock));
>   event->eventID=event_counter;
>   //printk("Ok up to here 2\n");
>   event->nb_process=0;
>   list_add(&event_head, &(event->event_list));

Hey, event->list is not initialized ;-)
LIST_HEAD( event->event_list );

>   spin_unlock_irq(&(event->eventLock));
>   //printk("Ok up to here 3\n"); 
>   return event_counter;
> }
 
Have a good day.
-- 
Amicalement/Regards

Christophe Lucas - c.lucas@xxxxxxxxxxx - Registered User #271267

 * GNU/Linux developer/network administrator
 * Membre du RotomaLUG (LUG de la région Rouennaise)
   (http://www.rotomalug.org)
 * http://odie.mcom.fr/~clucas/

Attachment: signature.asc
Description: Digital signature


[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