EmbLogic's Blog

char driver problem…

 

 

The code during registration:-

scull_dev_ptr=kmalloc(NO_OF_DEVICES*sizeof(struct scull_dev),GFP_KERNEL);
memset(scull_dev_ptr,”,sizeof(struct scull_dev));
for(loopv=0;loopv<NO_OF_DEVICES;loopv++)
{
ldev=MKDEV(scull_major,scull_minor);
scull_minor=MINOR(ldev);
scull_dev_ptr[loopv].cdev_var.dev=ldev;
scull_dev_ptr[loopv].cdev_var.owner=THIS_MODULE;
cdev_init(&scull_dev_ptr[loopv].cdev_var,&fops);
ret_val_2=cdev_add(&scull_dev_ptr[loopv].cdev_var,ldev,1);
if(ret_val_2<0)
{
#ifdef DEBUG
printk(KERN_ERR “cdev_add failed”);
#endif
goto out;
}
scull_minor++;
#ifdef DEBUG
printk(KERN_INFO “minor=%d”,scull_minor);
#endif
}

The code during unregisteration:-

static void __exit cleanup_fun(void)
{
int loopv;
dev=MKDEV(scull_major,scull_minor);
printk(KERN_INFO “\nbegin: %s”,__func__);
for(loopv=0;loopv<NO_OF_DEVICES;LOOPV++)

cdev_del(&scull_dev_ptr[loopv].cdev_var);
kfree(scull_dev_ptr);
unregister_chrdev_region(dev,NO_OF_DEVICES);
#ifdef DEBUG
printk(KERN_INFO”bye for now”);

printk(KERN_INFO “name=%s,pid=%d”,current->comm,current->pid);
printk(KERN_INFO “end: %s\n”,__func__);
#endif
}

code works well..
-make (successful).
-it register my driver.(insmod successful).

-driver is present in (/proc/devices).
-rmmod also successful..

-driver is removed from(/proc/devices ).

But the problem is that “after rmmod & dmesg it leaves a message(10-15 lines)..
hw can these lines be removed ….
thegarbage lines are……
begin: initilization_fun
[ 4105.329806] major=247
[ 4105.329810] minor=1
[ 4105.329813] minor=2
[ 4105.329816] minor=3
[ 4105.329818] minor=4
[ 4105.329821] minor=5
[ 4105.329823] integer=11
[ 4105.329825] long integer=1111
[ 4105.329828] string=hello to the world of linux
[ 4105.329831] hello kernel
[ 4105.329833] name=insmod,4524
[ 4105.329836] end: initilization_fun
[ 4109.074416]
[ 4109.074418] begin: cleanup_fun
[ 4109.074430] ————[ cut here ]————
[ 4109.074441] WARNING: at lib/kobject.c:595 kobject_put+0×27/0x3c()
[ 4109.074445] Hardware name: System Product Name
[ 4109.074448] kobject: ‘(null)’ (ca22e574): is not initialized, yet kobject_put() is being called.
[ 4109.074452] Modules linked in: lkm(-) usb_storage fuse ebtable_nat ebtables ipt_MASQUERADE iptable_nat nf_nat bridge stp llc deflate zlib_deflate ctr camellia cast5 rmd160 crypto_null ccm serpent blowfish twofish twofish_common ecb xcbc cbc sha256_generic sha512_generic des_generic aes_i586 aes_generic ah6 ah4 esp6 esp4 xfrm4_mode_beet xfrm4_tunnel tunnel4 xfrm4_mode_tunnel xfrm4_mode_transport xfrm6_mode_transport xfrm6_mode_ro xfrm6_mode_beet xfrm6_mode_tunnel ipcomp ipcomp6 xfrm_ipcomp xfrm6_tunnel tunnel6 af_key sunrpc cpufreq_ondemand acpi_cpufreq mperf capi capifs kernelcapi ip6t_REJECT nf_conntrack_ipv6 ip6table_filter ip6_tables ipv6 vfat fat kvm_intel kvm uinput snd_hda_codec_realtek snd_hda_intel snd_hda_codec snd_hwdep snd_seq snd_seq_device i2c_i801 snd_pcm iTCO_wdt iTCO_vendor_support snd_timer snd soundcore snd_page_alloc ppdev parport_pc parport asus_atk0110 r8169 mii microcode i915 drm_kms_helper drm i2c_algo_bit i2c_core video output [last unloaded: lkm]
[ 4109.074568] Pid: 4532, comm: rmmod Tainted: G W 2.6.35.6-45.fc14.i686 #1
[ 4109.074572] Call Trace:
[ 4109.074581] [] warn_slowpath_common+0x6a/0x7f
[ 4109.074587] [] ? kobject_put+0×27/0x3c
[ 4109.074594] [] warn_slowpath_fmt+0x2b/0x2f
[ 4109.074599] [] kobject_put+0×27/0x3c
[ 4109.074606] [] cdev_del+0×22/0×25
[ 4109.074613] [] cleanup_fun+0×39/0x8f [lkm]
[ 4109.074619] [] sys_delete_module+0×181/0x1de
[ 4109.074627] [] ? audit_syscall_entry+0×116/0×138
[ 4109.074634] [] ? syscall_trace_enter+0×104/0×119
[ 4109.074641] [] syscall_call+0×7/0xb
[ 4109.074646] —[ end trace 6800ebedf54ef408 ]—
[ 4109.074649] bye for now
[ 4109.074652] name=rmmod,4532
[ 4109.074655] end: cleanup_fun

One Response to char driver problem…

  1. kamran says:

    //this part of the code is creating the trouble
    cdev_del(&scull_dev_ptr[loopv].cdev_var);
    kfree(scull_dev_ptr);
    unregister_chrdev_region(dev,NO_OF_DEVICES);

    The second argument is NO_OF_DEVICE, since
    NO_OF_DEVICE is set to some value say 3.
    You are doing that loopv times.

    Which will give you error.
    use unregister_chrdev_region without the for loop.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>