Strategies for accessing driver data from file operations!?

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

 



I was writing an spi driver, and taking a look into spidev.c, I see the the author
allocates a linked list to hold driver data instances. From open it iterates over
the list comparing two dev_t fields, one from current element on list other from
struct inode * parameter, here is the lines:

static int spidev_open(struct inode *inode, struct file *filp)
{
         struct spidev_data      *spidev;
         int                     status = -ENXIO;

         mutex_lock(&device_list_lock);

         list_for_each_entry(spidev, &device_list, device_entry) {
                 if (spidev->devt == inode->i_rdev) {
                         status = 0;
                         break;
                 }
         }
...

Now it set the filp->private data to its driver data, and on read and write file
operations he knows how to access is driver data,

I was looking for a simpler strategy, on my module I would have same devices on
distinct spi busses and chipselects, but it wouldn't go greater than 9 devices.

I need to access spi_device struct pointer for the right device from read and
write file operations.

Isn't there any path from struct file *filp to struct device *devp created
with device_create? I can't see it, but if is possible I can set device private
data from my probe function.

Cheers,

_______________________________________________
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