Haswell
Haswell

Reputation: 1652

Device driver without open method

I was wondering that is it mandatory to have a open release method for device driver's. The only job that open does is allocation of structures and putting them into file->priv_data, so that other methods can access.

So if I have all static allocations and do not care about things that happen upon unload, Is my "question" possible. What will happen upon user space open..Will I still get a file descriptor. and able to read write to the device file (read, write methods are implemented).

Upvotes: 0

Views: 77

Answers (1)

Federico
Federico

Reputation: 3902

Probably is the only job that open does in the example that you saw, is it possible. It depends from driver to driver, for simple drivers without special requirement on open/release (we are talking about char device I suppose) there are internal linux helpers.

Of course, what you suggest is possible, but ... keep in mind that it is a very bad design idea to use static declarations unless it is what you really want (and usually it isn't). For example, with static allocations, multiple instances of the device driver will share the same data.

Upvotes: 1

Related Questions