RE: information between kernel and device driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If you want to define the variable in kernel and use it in your driver,
that variable should be exported, so that modules (like ur driver) can
use it.

Another thing is, never define a variable in header file, as header file
will be included by number of .c files, so compiler will give "Multiple
Definition" error. If a variable is going to be referred in number of .c
files, the best practice is to define it in one .c file (it can be
memory.c for your case, as you mentioned in your last mail) and declare
the same variable in header file as extern. Now include this header file
in all .c file where you want to refer that variable.

Declaration of variable as extern, do not allocate a memory to variable.
It is just a compiler directive statement, which tells the compiler that
the variable has been defined in some other .c file so no need to give
an error on finding reference to that variable.

In your case, you can do following:

	memory.c:
	int bitmap = 0;
	EXPORT_SYMBOL(bitmap);

	something.h:
	extern int bitmap;

	your_driver.c
	#include <something.h>
	/*Any manipulation of bitmap*/
	Bitmap += 1;


I hope thing work like this, if I am wrong somewhere please correct me.

Regards,
Gaurav



-----Original Message-----
From: kernelnewbies-bounce@xxxxxxxxxxxx
[mailto:kernelnewbies-bounce@xxxxxxxxxxxx] On Behalf Of Cristina Rivera
Sent: Sunday, July 25, 2004 8:18 PM
To: kernelnewbies@xxxxxxxxxxxx
Subject: information between kernel and device driver

Hi there,

3rd stage of my fight with the kernel.

Problem: I have a char device which has to use information of a kernel 
variable (created for me) called bitmapped, this variable has to be used
by 
the kernel to get information from user, I have thought about defining
this 
variable in a header file for including it in the kernel, but...if my
driver 
has to use it, can I define this variable in the code of my driver as
extern 
if it's only defined at memory.c, for example?

Which is the best way for defining this variable at the kernel and use
it 
from either the kernel or the user?

_________________________________________________________________
Descarga gratis la Barra de Herramientas de MSN 
http://www.msn.es/usuario/busqueda/barra?XAPID=2031&DI=1055&SU=http%3A//
www.hotmail.com&HL=LINKTAG1OPENINGTEXT_MSNBH


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux