Solved How to alloc memory in Module for char devices?

Well I know this maybe a noob question. But I need ask because the last time I get kernel panic.

Usually when a develop C programs I use calloc or malloc for alloc memory for buffers

I developed one char device /dev/rdrand in it works well but it some slowly in comparation with the orginal random device /dev/random

https://github.com/albertobsd/rdrand/blob/master/rdrand.c

The last time I add some malloc function but at time to make I get some weird erros about malloc parameters. It is because makefile do reference to sys/malloc.h so how I can alloc dinamic memory for one use in the context of developing a Device module?

About my module is only for academic purposes, I just want compare the ouput between the fortuna random device and the Intel Secure Key RNG instrucction.

Regards
 
The last time I add some malloc function but at time to make I get some weird erros about malloc parameters.
Can you be more specific (i.e. post the errors)? Have you read malloc(9)? The kernel's malloc() has a different signature than the userland version and takes three parameters instead of only a size.
 
Can you be more specific (i.e. post the errors)? Have you read malloc(9)? The kernel's malloc() has a different signature than the userland version and takes three parameters instead of only a size.

Well, actually Im reading such malloc(9) man page. If the three parameters malloc is the only way to alloc memory in kernel module context So I'll have to learn to use it.

I will use the MALLOC_DEFINE macro to practice.
 
Back
Top