kernel module compile error in c.

  • Thread starter KürÅŸat ÖNSÖZ
  • Start date
K

Kürşat ÖNSÖZ

Hi guys,
I try compile kernel module in c but I get this error.

make -C /lib/modules/3.5.0-17-generic/build M=/home/kursat/Desktop/dev-uyg/2 modules
make[1]: Entering directory `/usr/src/linux-headers-3.5.0-17-generic'
CC [M] /home/kursat/Desktop/dev-uyg/2/mehmet.o
/home/kursat/Desktop/dev-uyg/2/mehmet.c: In function ‘mehmet_read’:
/home/kursat/Desktop/dev-uyg/2/mehmet.c:20:35: error: parameter name omitted
make[2]: *** [/home/kursat/Desktop/dev-uyg/2/mehmet.o] Error 1
make[1]: *** [_module_/home/kursat/Desktop/dev-uyg/2] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.5.0-17-generic'
make: *** [all] Error 2





my makefile :

obj-m += mehmet.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean





my source code is :

#ifndef __KERNEL__
#define __KERNEL__
#define MODULE
#define LINUX
#endif

#include <linux/module.h>
#include <linux/version.h>
#include <linux/fs.h>

static ssize_t mehmet_read (struct file *, char * ,size_t,loff_t *);
static ssize_t mehmet_write (struct file *, const char *, size_t, loff_t *);

static struct file_operations mehmet_fops = {
read : mehmet_read,
write : mehmet_write,

};

static ssize_t mehmet_read(struct file *, char * buf,size_t count, loff_t *ppos)
{
return 0;
}

static ssize_t mehmet_write (struct file * file, const char * buf, size_t size, loff_t * ppos)
{
return size;
}


int init_module(void)
{
int i = 0;
i = register_chrdev(222,"mehmet",&mehmet_fops);
if(i<0)
return i;
return 0;
}

void cleanup_module (void)
{
unregister_chrdev (222, "mehmet");
}
 
J

Joe Pfeiffer

Kürşat ÖNSÖZ said:
/home/kursat/Desktop/dev-uyg/2/mehmet.c: In function ‘mehmet_read’:
/home/kursat/Desktop/dev-uyg/2/mehmet.c:20:35: error: parameter name omitted

static ssize_t mehmet_read(struct file *, char * buf,size_t count, loff_t *ppos)

What is the name of the struct file * parameter in mehmet_read()?
 
J

Jorgen Grahn

What is the name of the struct file * parameter in mehmet_read()?

Yeah -- when defining a function you have to name all the parameters,
even if you don't intend to use them.

I would have preferred if it meant "on purpose I'm not using this
parameter", like it does in C++. It's no big deal in the finished
program, but it's useful in the early stages of development (e.g.
where kursat seems to be).

/Jorgen
 
A

ais523

Jorgen said:
Yeah -- when defining a function you have to name all the parameters,
even if you don't intend to use them.

I would have preferred if it meant "on purpose I'm not using this
parameter", like it does in C++. It's no big deal in the finished
program, but it's useful in the early stages of development (e.g.
where kursat seems to be).

There is actually an idiom for "I'm not using this parameter on purpose"
which many compilers/delinters/maintenance programmers understand: you
write a statement that consists entirely of that parameter, cast to
void. This is perfectly conforming C, and one which many implementations
will interpret as having an effect on diagnostics (they can do that,
because the standard does not require a diagnostic for an unused
parameter).

Sadly, some older delinters will complain about the statement with no
effect when you do this.
 
J

Jorgen Grahn

There is actually an idiom for "I'm not using this parameter on purpose"
which many compilers/delinters/maintenance programmers understand: you
write a statement that consists entirely of that parameter, cast to
void.

True. It's more annoying than the C++ solution though, in that it
doesn't /ensure/ that it's unused. In C89 you also have to place it
after the variable declarations.

By the way, since the context is Linux kernel code, there may be local
conventions which should be followed. Maybe they have an UNUSED(var)
macro or something.
This is perfectly conforming C, and one which many implementations
will interpret as having an effect on diagnostics (they can do that,
because the standard does not require a diagnostic for an unused
parameter).

Well, it's not unused if you say (void)foo ... and a compiler doesn't
have to warn about useless statements either.

/Jorgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top