Re: spinlock protection on data question

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

 



On Wednesday 07 August 2002 10:57 pm, Sumit Agarwal wrote:
> I dont know the context of the problem.
>
> If there is no lock for the above structure, try using the
> usage or
> count field to know, if the data is in use.
>
> If you want more details, can you repost the question?


I have a array of data that is used globally and an array of locks to protect 
them.

struct context_data data[10];
spinlock_t locks[10];


The problem I'm having is that to find out which spinlock to use to lock any 
struct in that array, I have to first access the data like this:

num = mydata->num;
spin_lock_irqaave( &locks[num], &flags);


but one of my driver functions frees that same data:

static void disconnect_rasid(struct usb_device *dev, void *drv_context)
{
   num = ((context_data *) drv_context)->num;
   spin_lock_irqaave( &locks[num], &flags);

   kfree(drv_context);

   /* ....  */

}

so i think that any other function that uses that data is going to have 
problems if it is called at the same time as disconnect because, before it 
can lock the data structure, it has to access the data structure to find out 
where in the array of locks the spinlock is .. . if disconnect has freed that 
data structure, it no longer exists and you're accessing a null pointer.

Any suggestions?


Anton 
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[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