LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 03-08-2013, 04:43 AM   #1
_core
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Rep: Reputation: Disabled
Question Module with strange behavior


Hi,

i wrote a kernel-module for linux-kernel (3.X). So, ever when i'm loading the module for the first time, it works fine. when i remove it and load it again, i can't use it.

That module is a high-level-driver for the serial-port. i use inputattach to bind the module to a port. It also uses the input-subsystem to create a jsX and an eventX node. yes, it is an input-device-driver for the serial port .

here something from syslog:

first load + bind with inputattach
Code:
connect called
input: MyDevice as /devices/pnp0/00:0a/tty/ttyS0/serio0/input/input13
endbind port (kill inputattach)
Code:
disconnect called
bind again with inputattach
Code:
connect called
input: MyDevice as /devices/pnp0/00:0a/tty/ttyS0/serio1/input/input14
endbind port (kill inputattach)
Code:
disconnect called
bind again with inputattach
Code:
connect called
input: MyDevice as /devices/pnp0/00:0a/tty/ttyS0/serio2/input/input15
i can do so for hours.

now i remove the module (after killing inputattach) and load it again + bind with inputattach
Code:
connect called
input: MyDevice as /devices/pnp0/00:0a/tty/ttyS0/serio3/input/input16
disconnect called
so right after it calles the connect function, the disconnect function is called. but i have no idea why. it looks very strange to me that it works fine at the first time, but second, third, ... time it calles disconnect right after connect.

so has anyone of you an idea? i will post my code (it will be open source anyway), if you need it.


thanks!
 
Old 03-10-2013, 12:20 AM   #2
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
With out looking at the code my best guess is you are missing something in the disconnect part, it is not completely disconnecting, thus when the next connect is attempted it leads to immediate disconnect. But again that is just a guess.
 
Old 03-10-2013, 09:19 AM   #3
_core
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
OK,

here are my init, exit, connect and disconnect functions:

init and exit
Code:
static int __init xj_init(void)
{
	return serio_register_driver(&xj_drv);
}

static void __exit xj_exit(void)
{
	serio_unregister_driver(&xj_drv);
}
connect
Code:
static int xj_connect(struct serio* serio, struct serio_driver* drv)
{
	struct ser_drv_xj* xj;
	struct input_dev* input_dev;
	struct ff_device* ff;
	int err = -ENOMEM;
	int ff_effects = 1;
	
	xj = kzalloc(sizeof(struct ser_drv_xj), GFP_KERNEL);
	if (!xj)
		goto fail1;

	xj->serio = serio;
	serio_set_drvdata(serio, xj);
	err = serio_open(serio, drv);
	if (err)
		goto fail2;
	
	input_dev = input_allocate_device();
	if (!input_dev)
		goto fail3;

	xj->dev = input_dev;
	input_set_drvdata(input_dev, xj);	
	
	input_dev->name       = DEVICE_NAME;
	input_dev->id.bustype = BUS_RS232;
	input_dev->id.vendor  = SERIO_UNKNOWN;
	input_dev->id.product = 0x0001;
	input_dev->id.version = 0x0100;
	input_dev->dev.parent = &xj->serio->dev;
	input_dev->evbit[0]   = BIT_MASK(EV_ABS) | BIT_MASK(EV_FF_STATUS);
	
	input_set_abs_params(input_dev, ABS_WHEEL, SCALED_ANGLE_MIN, SCALED_ANGLE_MAX, 0, 0);
	set_bit(ABS_WHEEL, input_dev->ffbit);
	set_bit(FF_CONSTANT, input_dev->ffbit);
	err = input_ff_create(input_dev, ff_effects);
	if (err)
		goto fail4;
		
	ff		   = input_dev->ff;
	ff->erase  	   = xj_erase_effect;
	ff->upload 	   = xj_upload_effect;
	ff->set_gain 	   = xj_set_gain;
	ff->set_autocenter = xj_set_autocenter;
	ff->playback 	   = xj_playback;

	err = input_register_device(xj->dev);
	if (err)
		goto fail4;
		
	xj->endstop 	 = STEP_DEFAULT;
	xj->event        = kzalloc(sizeof(struct ff_event), GFP_KERNEL);
	xj->event->frame = kzalloc(sizeof(serial_protocol_frame_t), GFP_KERNEL);
	spin_lock_init(&(xj->event->lock));
        xj->event->last_update = jiffies_to_msecs(jiffies);
        xj->event->cycle = 100;
   
	return 0;
	
 fail4:	
	input_free_device(input_dev);
 fail3:	
	serio_close(serio);
 fail2:	
	serio_set_drvdata(serio, NULL);
	kfree(xj);
 fail1:
	return err;
}
disconnect
Code:
static void xj_disconnect(struct serio *serio)
{
	struct ser_drv_xj *xj;
    
	xj = serio_get_drvdata(serio);

	input_unregister_device(xj->dev);
	serio_close(serio);
	serio_set_drvdata(serio, NULL);
	kfree(xj);
}
and the fops for the serial interface:
Code:
static struct serio_device_id xj_serio_ids[] = {
	{
		.type	= SERIO_RS232,
		.proto	= SERIO_UNKNOWN,
		.id	= SERIO_ANY,
		.extra	= SERIO_ANY,
	},
	{ 0 }
};

MODULE_DEVICE_TABLE(serio, xj_serio_ids);

static struct serio_driver xj_drv = {
	.driver		= 
        {
            .name = DRIVER_NAME,
        },
	.description	= DRIVER_DESC,
	.id_table	= xj_serio_ids,
	.interrupt	= xj_interrupt,
	.connect	= xj_connect,
	.disconnect	= xj_disconnect,
        .write_wakeup   = xj_write_wakeup
};
thanks for your effort!
 
Old 03-11-2013, 12:11 AM   #4
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
The code looks ok.... try adding printks in connect and disconnect to figure out at which step is the disconnect being called.
 
Old 03-14-2013, 05:55 AM   #5
_core
LQ Newbie
 
Registered: Aug 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
I will do it today.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange Syslog behavior jackpal Linux - Networking 2 01-05-2007 02:33 PM
Strange behavior(??) in Samba! bigoli MEPIS 1 06-06-2005 12:43 PM
Very Strange Behavior raysr Mandriva 4 08-31-2004 03:06 PM
Strange Behavior andrewb758 Linux - Hardware 5 08-31-2003 03:42 PM
strange behavior abhijit Linux - General 3 07-10-2003 12:25 AM


All times are GMT -5. The time now is 09:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration