anton wilson wrote: > 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? My initial reaction is to add a lock for accessing and freeing the set of locks... a reader/writer lock perhaps. Then require a read lock before attempting to acquire a more specific lock. Then release the specific lock, followed by the read lock. The one that frees would grab the write lock. Is that what you were looking for? HTH, Eli --------------------. "If it ain't broke now, Eli Carter \ it will be soon." -- crypto-gram eli.carter(a)inet.com `------------------------------------------------- -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/