I have posted a question earlier and I have confirmed that this is running in an infinite loop. However, I discovered that the infinite loop is happening inside kernel code. Specifically inside the kmalloc function. I know this is highly improbable, but I believe that this is the case.
The line of code that cause the infinite loop is in bold below and starts with buf =
If I comment this line out then it does not hang. If I uncomment it then it does. Further, more no print statements after that line are being printed and I have it surrounded by print statements.
KMALLOC is a macro defined as
# define KMALLOC(a,b) kmalloc((a),(b))
The last line being printed:
b0b0b0 4096
4096 being the size of buffer.
The get_buffer method is called quite a few times before the last time where it goes into an infinite loop. I am thinking there could be a memory leak or if memory is low this can happen?
An advice on how to tackle this issue would be greatly appreciated.
Thanks.
static inline struct buffer *get_buffer(void)
{
/* XXX: __get_free_page should be used. KMALLOC is for small stuff < PAGE_SIZE */
struct buffer *buf;
printk(KERN_EMERG " b0b0b0 %d\n", sizeof(struct buffer));
buf = KMALLOC(sizeof(struct buffer), GFP_KERNEL);
print_entry_location();
printk(KERN_EMERG " b1b1b1\n");
//if (buf) //i commented these out
//buf->ptr = buf->data + INIT_LOC; //i commented these out
printk(KERN_EMERG " b1b1b1\n");
print_exit_location();
return NULL; //i changed it to return null so the next function just exits
}
Additional info
struct buffer {
char *ptr;
char data[DATA_SIZE];
};
#define DATA_SIZE (PAGE_SIZE - sizeof(int))