Re: register_chrdev_region

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

 



I am using kernel 2.6.11-1.1369_FC4.
and trying out register_chrdev_region() in a module as explained in book
Linux Device Drivers(LDD3) by rubini.
In that book It is given that to obtain one or more device numbers to
work with we hav to use  register_chrdev_region
and i am trying to use that fun as follows.But i am unable to get the
desired result.And i am getting segmentation fault.
Will you please tell me wht is wrong with my code?





#ifndef __KERNEL__
	#define __KERNEL__
#endif

#ifndef MODULE
	#define MODULE
#endif

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>

MODULE_AUTHOR("RAJA");
MODULE_DESCRIPTION("SCULL DEVICE 1");
MODULE_LICENSE("GPL");

#define DEVICE_NAME "scull"
#define NO_OF_DEVICES_REQUIRED 5
dev_t devNo;
static int __init init_module1(void);
static void __exit exit_module1(void);

static int __init init_module1()
{
	printk("Entered Into init function for module1");
	int result = register_chrdev_region(0,NO_OF_DEVICES_REQUIRED,DEVICE_NAME);
	if(result)
		printk("Unable To Create Region\n");
	else
		printk("Region Created\n");
	devNo = MKDEV(0,0);
	printk("Exited From init function for module1");
	return 0;
}

static void __exit exit_module1()
{
	printk("Entered Into Exit function for module1");
	unregister_chrdev_region(devNo,NO_OF_DEVICES_REQUIRED);
	printk("Exited From Exit function for module1");
}

module_init(init_module1);
module_exit(exit_module1);








On Mon, 2005-09-26 at 01:33 -0400, Hemant Mohapatra wrote:
> On 9/26/05, raja <vnagaraju@xxxxxxxxxxxx> wrote:
> 
> > Will you please tell me wht is wrong with
> > me.
> 
> Much. Right now, I'll settle for just "You don't do your homework well
> at all and hop around here asking things that are essentially
> _textbook_ knowledge."
> 
> To help you out a little more, let me give you a few examples:
> 
> "I cannot seem to use foo_bar() function, Please help me" - bad question.
> 
> "I am using kernel-<insert version> and trying out foo_bar() in a
> module as explained in book <insert book name here>. After doing what
> the book says, I am still getting foo-bar error <insert error log
> snippet here>. What is going wrong?" - better question.
> 
> Hope it helps.
> ./h
> --
> Operating Systems and Computer Architecture Research  - University of Cincinnati
> http://www.ececs.uc.edu/~mohapth


--
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