diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2018-05-03 20:06:14 +0200 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2018-05-03 20:06:14 +0200 |
commit | 77c090b85d2dc085dce3712d4a5faf8452531d58 (patch) | |
tree | 8943ec00fd7871df6fc12fad61dd31e2de13adc2 /char.c | |
parent | 391f8bee7ef5a2e92d24d73f0072915b7cb12b6b (diff) |
Store and use minor number
Diffstat (limited to 'char.c')
-rw-r--r-- | char.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -5,6 +5,7 @@ #include "linux/fs.h" #include "util.h" +#include "pci.h" #define DOOMDEV_COUNT 256 #define DOOMDEV_NAME "doom" @@ -32,13 +33,14 @@ struct file_operations doomdev_fops = { struct class *doom_class; -int new_doomdev(void) +int new_doomdev(struct pci_dev *dev) { int err = 0; int minor; dev_t devt; struct cdev *doom_cdev; struct device *doomdev; + struct doom_data *doom_data; if (next_minor >= DOOMDEV_COUNT) { return -ENOMEM; } @@ -51,6 +53,9 @@ int new_doomdev(void) doom_cdev->ops = &doomdev_fops; ORFAIL(cdev_add(doom_cdev, first, 1), error_add); minor = next_minor++; + doom_data = kmalloc(sizeof(*doom_data), GFP_KERNEL); + doom_data->minor = minor; + pci_set_drvdata(dev, doom_data); devt = MKDEV(major, minor); ORFAIL_PTR(device_create(doom_class, NULL, devt, NULL, "doom%d", minor), @@ -62,9 +67,12 @@ error_add: return err; } -void destroy_doomdev(void) +void destroy_doomdev(struct pci_dev *dev) { - device_destroy(doom_class, first); + struct doom_data *data; + data = pci_get_drvdata(dev); + device_destroy(doom_class, MKDEV(major, data->minor)); + kfree(data); } int char_init(void) |