Originally Posted by syg00
More likely you need to rethink your design.
Indeed, you do.
If a piece of software is designed to run as a loadable (and therefore, also un
loadable) module, then by definition it is not "endless." It runs in response to some set of stimuli ... both those coming from whatever it's supposed to be responding-to and doing, and
those that signal that the module is being unloaded. When that indication is received, the module must quickly terminate its affairs in an orderly fashion (or indicate that it refuses to be unloaded at this time). Existing source-code for USB drivers is an excellent source of reference here. (Never bother to "re-invent the wheel of knowledge" when writing kernel code: there's an abundance of tested source-code at your fingertips, to copy from, adapt and use.)
Let me please stress this point:
Find something of known-good quality that already exists
and copy its basic design faithfully. (For example, IIRC there is a "generic USB driver template" out there someplace.) Refer to the current
source-code libraries of the Linux that you are actually targeting, not merely to books, because the internal implementation of Linux has evolved considerably over time. "Use the Source, Luke!"