mirror of
https://github.com/corundum/corundum.git
synced 2025-01-30 08:32:52 +08:00
Use misc device properly
This commit is contained in:
parent
6edce8c984
commit
907bb68a99
@ -293,7 +293,6 @@ struct mqnic_priv {
|
||||
};
|
||||
|
||||
// mqnic_main.c
|
||||
extern struct mqnic_dev *mqnic_find_by_minor(unsigned minor);
|
||||
|
||||
// mqnic_dev.c
|
||||
extern const struct file_operations mqnic_fops;
|
||||
|
@ -34,24 +34,18 @@ either expressed or implied, of The Regents of the University of California.
|
||||
#include "mqnic.h"
|
||||
#include "mqnic_ioctl.h"
|
||||
|
||||
static int mqnic_open(struct inode *inode, struct file *filp)
|
||||
static int mqnic_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
struct mqnic_dev *mqnic;
|
||||
// struct miscdevice *miscdev = file->private_data;
|
||||
// struct mqnic_dev *mqnic = container_of(miscdev, struct mqnic_dev, misc_dev);
|
||||
|
||||
mqnic = mqnic_find_by_minor(iminor(inode));
|
||||
if (mqnic == NULL)
|
||||
{
|
||||
pr_err("Failed to locate mqnic for minor = %u.\n", iminor(inode));
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
filp->private_data = mqnic;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mqnic_release(struct inode *inode, struct file *filp)
|
||||
static int mqnic_release(struct inode *inode, struct file *file)
|
||||
{
|
||||
//struct mqnic_dev *mqnic = filp->private_data;
|
||||
// struct miscdevice *miscdev = file->private_data;
|
||||
// struct mqnic_dev *mqnic = container_of(miscdev, struct mqnic_dev, misc_dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -81,9 +75,10 @@ static int mqnic_map_registers(struct mqnic_dev *mqnic, struct vm_area_struct *v
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mqnic_mmap(struct file *filp, struct vm_area_struct *vma)
|
||||
static int mqnic_mmap(struct file *file, struct vm_area_struct *vma)
|
||||
{
|
||||
struct mqnic_dev *mqnic = filp->private_data;
|
||||
struct miscdevice *miscdev = file->private_data;
|
||||
struct mqnic_dev *mqnic = container_of(miscdev, struct mqnic_dev, misc_dev);
|
||||
int ret;
|
||||
|
||||
if (vma->vm_pgoff == 0)
|
||||
@ -102,9 +97,10 @@ fail_invalid_offset:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static long mqnic_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
||||
static long mqnic_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
struct mqnic_dev *mqnic = filp->private_data;
|
||||
struct miscdevice *miscdev = file->private_data;
|
||||
struct mqnic_dev *mqnic = container_of(miscdev, struct mqnic_dev, misc_dev);
|
||||
|
||||
if (_IOC_TYPE(cmd) != MQNIC_IOCTL_TYPE)
|
||||
return -ENOTTY;
|
||||
|
@ -80,24 +80,6 @@ static unsigned int mqnic_get_free_id(void)
|
||||
return id;
|
||||
}
|
||||
|
||||
struct mqnic_dev *mqnic_find_by_minor(unsigned minor)
|
||||
{
|
||||
struct mqnic_dev *mqnic;
|
||||
|
||||
spin_lock(&mqnic_devices_lock);
|
||||
|
||||
list_for_each_entry(mqnic, &mqnic_devices, dev_list_node)
|
||||
if (mqnic->misc_dev.minor == minor)
|
||||
goto done;
|
||||
|
||||
mqnic = NULL;
|
||||
|
||||
done:
|
||||
spin_unlock(&mqnic_devices_lock);
|
||||
|
||||
return mqnic;
|
||||
}
|
||||
|
||||
static irqreturn_t mqnic_interrupt(int irq, void *data)
|
||||
{
|
||||
struct mqnic_dev *mqnic = data;
|
||||
@ -150,8 +132,6 @@ static int mqnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||
mqnic->pdev = pdev;
|
||||
pci_set_drvdata(pdev, mqnic);
|
||||
|
||||
mqnic->misc_dev.minor = MISC_DYNAMIC_MINOR;
|
||||
|
||||
// assign ID and add to list
|
||||
spin_lock(&mqnic_devices_lock);
|
||||
mqnic->id = mqnic_get_free_id();
|
||||
@ -314,6 +294,7 @@ static int mqnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
|
||||
}
|
||||
}
|
||||
|
||||
mqnic->misc_dev.minor = MISC_DYNAMIC_MINOR;
|
||||
mqnic->misc_dev.name = mqnic->name;
|
||||
mqnic->misc_dev.fops = &mqnic_fops;
|
||||
mqnic->misc_dev.parent = dev;
|
||||
|
Loading…
x
Reference in New Issue
Block a user