ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
retval=cdev_add(&scull_cdev,dev,1);
if(retval)
{
cdev_del(&scull_cdev);
unregister_chrdev_region(dev, 1);
printk("<1> Error in cdev_add:");
return -EBUSY;
}
printk ("<1> scull_init was a Success and the major device number is %d \n", Major);
return 0;
}
static int device_read(struct file *filp,char *msgusr,int count,int *offp)
{
int i;
unsigned long ret;
The first error message is explained by the above code. You are asking sprintf to write to a string which has no storage allocated for it. The char pointer 'msg' is not initialized. Start by fixing that. I didn't look any further, so there may be other problems. This is not a problem specific to kernel/driver coding.
The sprintf issue is solved ..
The module is working fine except that it is not reading ..
If i try a cat /dev/scull,this is wat i get cat: /dev/scull: Bad address
if i check the /var/log/messages ,this is the message:
Nov 22 15:05:12 datacom kernel: Here we are Reading!!
Nov 22 15:05:14 datacom kernel: no of bytes read :4096<1> Error in reading !!
Here is the read function alone:
====================Read function alone ==================
static int device_read(struct file *filp,char *msgusr,int count,int *offp)
{
int i;
unsigned long ret;
I don't know what copy_to_user() does, but it appears to copy a buffer from kernel space to user space, of size 'count'. If so, then it looks like the second argument should just be 'msg_ptr' (Which you initialized to point at an information string in device_open() ). You seem to be having a bad char day.
It would be helpful to wrap your code listings in code tags to preserve formatting.
retval=cdev_add(&scull_cdev,dev,1);
if(retval)
{
cdev_del(&scull_cdev);
unregister_chrdev_region(dev, 1);
printk("<1> Error in cdev_add:");
return -EBUSY;
}
printk ("<1> scull_init was a Success and the major device number is %d \n", Major);
static ssize_t device_write (struct file *filp,char *msgusr,int count,int *offp)
{
int err,i=1;
i++;
printk("<1> i is :%d",i);
printk("<1> We are writing !!");
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.