wrapper device driver

Valdis.Kletnieks at vt.edu Valdis.Kletnieks at vt.edu
Mon Feb 2 17:02:36 EST 2015


On Mon, 02 Feb 2015 15:24:37 -0600, riya khanna said:
> Hi,
>
> I'm writing a device driver to to provide a wrapper device around a
> real device. Is it acceptable to do the following:
>
> wrapper_dev_open(flags) {
>    // do additional bookkeeping
>    real_dev_filp = filp_open(real_device_node_path, flags);
> }
>
> wrapper_dev_mmap(mmap_parameters) {
>    // do additional checks
>    return real_dev_filp->f_op->mmap(mmap_parameters);
> }
>
> wrapper_dev_ioctl(ioctl_parameters) {
>    // do additional checks
>    return real_dev_filp->f_op->ioctl(ioctl_parameters);
> }
>
> Is it safe to do something like this?

Probably not.  If you return a struct real_dev->f_op then any further
calls will vector through that structure, totally unseen to your wrapper,
which means you won't be able to provide whatever added-value extras the
wrapper is trying to do (in other words, your wrapper ends up not doing
anything).

The real fun starts when something calls real->f_op->close() out from
under you... :)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150202/204f6285/attachment.bin 


More information about the Kernelnewbies mailing list