From c5e184effc52f4bbaa100a917fbba0a64716e091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Sat, 1 Jan 2011 20:31:27 +0100 Subject: [PATCH] Remove IFDHCreateChannel() counter constrain This fixes unloading the driver handled as USB bundle pcscd plug-in. pcsc-lite-1.6.6 creates channels above 0xF. The driver did not increment the counter in this case leading to Listenet thread not desctruted on complement IFDHCloseChannel() call. PCSC daemon then dlclosed() the plug-in, umapping the code effectively and causing SEGFAULT after resuming USB scan in Listenet thread. I don't know whether this change is compatible with serial reader interface Athena tried to mimic to pcsc-lite. E.g. multiple device hanling can be broken. --- ifdhandler.c | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ifdhandler.c b/ifdhandler.c index 22486e6..0b24ec8 100644 --- a/ifdhandler.c +++ b/ifdhandler.c @@ -76,8 +76,7 @@ RESPONSECODE IFDHCreateChannel ( DWORD Lun, DWORD Channel ) { syslog(LOG_INFO, "==============================================\n"); #endif - if (Channel >= 0x1 && Channel <= 0xF) - createChannelCounter++; + createChannelCounter++; if (!listenerStarted) { pthread_create(&listenetThread, NULL, Listener, &readerData); @@ -117,6 +116,16 @@ RESPONSECODE IFDHCloseChannel ( DWORD Lun ) { #endif createChannelCounter--; + + if (createChannelCounter < 0) { +#ifdef ASE_DEBUG + syslog(LOG_INFO, "ASE IIIe USB Reader : " + "unballanced IFDH{Create,Close}Channel() invocations detected. " + "Bug in PCSC daemon?\n"); +#endif + createChannelCounter = 0; + } + if (createChannelCounter == 0) { #ifdef ASE_DEBUG syslog(LOG_INFO, "ASE IIIe USB Reader : killing listener\n"); -- 1.7.3.4