Reputation: 1007
I was reviewing the following code in a linux kernel module :
static int proc_read_kernel(char *buffer, char **start, off_t offset, int length,int *eof, void *data)
{
int len=0;
struct mem_rw_t *mem= (struct mem_rw_t *)data;
switch(mem->flag)
{
From the above code it swiches to another function which has a length check as follows
static int func1(char *buffer, char **start, off_t offset, int length)
{
printk ("The value for len is %d\n\r",len);
printk ("The value for length is %d\n\r",length);
if(len > length)
goto list_finished;
The output of the above code looks as below. It looks like the len is going greater than length for the last value and proc read is not working properly:
The value for len is 0
The value for length is 3072
The value for len is 398
The value for length is 3072
The value for len is 796
The value for length is 3072
The value for len is 796
The value for length is 3072
The value for len is 1537
The value for length is 3072
The value for len is 1777
The value for length is 3072
The value for len is 1777
The value for length is 3072
The value for len is 2029
The value for length is 3072
The value for len is 2427
The value for length is 3072
The value for len is 3120
The value for length is 3072
<4>proc_file_read: Read count exceeded
Any suggestions to remove the above error ?
Upvotes: 0
Views: 439
Reputation: 16449
Based on what your comment says, I suggest that you look at linux/seq_file.h
.
The APIs it exports allow you to create a multi-line /proc entry, which isn't limited in size.
You'll need to provide a function that returns one line of data, and it would be called repeatedly by the I/S, with a new buffer each time. If each line doesn't exceed 3K (and it would be horribly unreadable if it does), it should be OK.
Upvotes: 1