Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to miscdevice handling #58

Open
alexforencich opened this issue Mar 26, 2022 · 0 comments
Open

Improvements to miscdevice handling #58

alexforencich opened this issue Mar 26, 2022 · 0 comments

Comments

@alexforencich
Copy link

alexforencich commented Mar 26, 2022

When working on the Corundum device driver, I noticed a few things in the exanic kernel module that can be improved.

First, misc_dev.parent should be set to the device object before registering it. If you do that, then symlinks will be created in sysfs to cross-link the miscdevice and the PCIe device. This change is quite simple:

     exanic->misc_dev.name = exanic->name;
     exanic->misc_dev.fops = &exanic_fops;
+    exanic->misc_dev.parent = dev;
     err = misc_register(&exanic->misc_dev);

(looks like this needs to be done in two places, as there are two calls to misc_register)

Second, you can update exanic_get_sysfs_path to use that symlink to find the PCIe device from the miscdevice instead of one of the network interfaces by doing realpath on "/sys/class/misc/%s/device" with exanic->name. This could enable things like hot reset to work during firmware updates even if no network interfaces are registered.

Third, miscdevice already handles the find_by_minor stuff internally, and by default private_data points to the miscdevice struct. All you need to do to get a reference to the exanic struct is something like this in open, release, mmap, and ioctl:

struct miscdevice *miscdev = filp->private_data;
struct exanic *exanic = container_of(miscdev, struct exanic, misc_dev);

(and don't forget to leave filp->private_data alone in exanic_open)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant