Is DEFINE_SPINLOCK
preferable over spin_lock_init
? What are the advantages of the former over the latter, and what are the possible drawbacks?
If you have a static data structure, DEFINE_SPINLOCK lets you declare a spinlock variable and initialize it in one line. However for anything allocated at runtime, for example when a spinlock is embedded in a bigger structure, then you need to allocate the memory and then call spin_lock_init().
I guess I would say that I prefer DEFINE_SPINLOCK when it is possible to use it. The advantage is tiny (compile-time initialization vs. runtime initialization, a couple lines less of code) but there's no real drawback. As I mentioned above, it's often not possible to use DEFINE_SPINLOCK, though.