2

I'm writing a Linux kernel module, which is builtin to kernel image. The module's init function, i.e. module_init(myinit), is thus called during boot. Inside myinit, I need to do a SHA1 hash operation. However, the function crypto_alloc_hash("sha1", 0, CRYPTO_ALG_ASYNC); returns -2. My guess is that myinit is called before crypto library's init function, so the SHA1 algorithm has not been registered yet.

I then tried to use late_initcall instead of module_init. It worked. I think it's ugly. What if the crypto module is also using late_initcall? How many modules are there and how many init levels are enough?

Is there a better way to do it? E.g. by specifying module dependency, or, wait for an event that signifies completion of crypto library loading.

Wu Yongzheng
  • 1,707
  • 17
  • 23
  • `How many modules are there and how many init levels are enough?` - [This answer](http://stackoverflow.com/a/11111014/3440745) enumerates init levels. – Tsyvarev Nov 12 '15 at 10:53
  • @Tsyvarev, I know. What I meant was the number of levels is far less than the number of modules, so it's not a good solution to the module dependency problem. – Wu Yongzheng Nov 12 '15 at 11:04
  • If you know this, what is a reason to **ask this again**? Please, leave only those questions in your post, which you **want to be answered**. For other facts please use declarative sentences, like you do in the comment. (The question post itself is OK, but it is better to save us from **guessing** what you actually want.) – Tsyvarev Nov 12 '15 at 11:17
  • @Tsyvarev, Sorry, it's a bit ambiguous. – Wu Yongzheng Nov 13 '15 at 01:17

0 Answers0