From patchwork Wed Aug 3 11:00:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 9261015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 434136048B for ; Wed, 3 Aug 2016 11:01:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34E4328579 for ; Wed, 3 Aug 2016 11:01:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2807028580; Wed, 3 Aug 2016 11:01:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2328028579 for ; Wed, 3 Aug 2016 11:01:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757474AbcHCLBa (ORCPT ); Wed, 3 Aug 2016 07:01:30 -0400 Received: from lb2-smtp-cloud2.xs4all.net ([194.109.24.25]:49263 "EHLO lb2-smtp-cloud2.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757772AbcHCLBZ (ORCPT ); Wed, 3 Aug 2016 07:01:25 -0400 Received: from tschai.lan ([90.149.38.145]) by smtp-cloud2.xs4all.net with ESMTP id Sb0l1t00437uBN201b0o3o; Wed, 03 Aug 2016 13:00:49 +0200 Received: from [192.168.1.137] (marune.xs4all.nl [80.101.105.217]) by tschai.lan (Postfix) with ESMTPSA id D071F18015A; Wed, 3 Aug 2016 13:00:44 +0200 (CEST) To: linux-input Cc: Dmitry Torokhov , "linux-media@vger.kernel.org" From: Hans Verkuil Subject: [PATCHv2] serio: add hangup support Message-ID: <0d959a01-e698-0178-af89-5925469f95ab@xs4all.nl> Date: Wed, 3 Aug 2016 13:00:44 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.2.0 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The Pulse-Eight USB CEC adapter is a usb device that shows up as a ttyACM0 device. It requires that you run inputattach in order to communicate with it via serio. This all works well, but it would be nice to have a udev rule to automatically start inputattach. That too works OK, but the problem comes when the USB device is unplugged: the tty hangup is never handled by the serio framework so the inputattach utility never exits and you have to kill it manually. By adding this hangup callback the inputattach utility now properly exits as soon as the USB device is unplugged. The udev rule I used on my Debian sid system is: SUBSYSTEM=="tty", KERNEL=="ttyACM[0-9]*", ATTRS{idVendor}=="2548", ATTRS{idProduct}=="1002", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}+="pulse8-cec-inputattach@%k.service" And pulse8-cec-inputattach@%k.service is as follows: --- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html =============================================================== [Unit] Description=inputattach for pulse8-cec device on %I [Service] Type=simple ExecStart=/usr/local/bin/inputattach --pulse8-cec /dev/%I KillMode=process =============================================================== Signed-off-by: Hans Verkuil Tested-by: Hans Verkuil --- Change since the original RFC patch: don't call close() from the hangup() function, instead only set the DEAD flag in hangup() instead of in close(). --- diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c index 9c927d3..4045e95 100644 --- a/drivers/input/serio/serport.c +++ b/drivers/input/serio/serport.c @@ -71,7 +71,6 @@ static void serport_serio_close(struct serio *serio) spin_lock_irqsave(&serport->lock, flags); clear_bit(SERPORT_ACTIVE, &serport->flags); - set_bit(SERPORT_DEAD, &serport->flags); spin_unlock_irqrestore(&serport->lock, flags); wake_up_interruptible(&serport->wait); @@ -248,6 +247,19 @@ static long serport_ldisc_compat_ioctl(struct tty_struct *tty, } #endif +static int serport_ldisc_hangup(struct tty_struct * tty) +{ + struct serport *serport = (struct serport *) tty->disc_data; + unsigned long flags; + + spin_lock_irqsave(&serport->lock, flags); + set_bit(SERPORT_DEAD, &serport->flags); + spin_unlock_irqrestore(&serport->lock, flags); + + wake_up_interruptible(&serport->wait); + return 0; +} + static void serport_ldisc_write_wakeup(struct tty_struct * tty) { struct serport *serport = (struct serport *) tty->disc_data; @@ -274,6 +286,7 @@ static struct tty_ldisc_ops serport_ldisc = { .compat_ioctl = serport_ldisc_compat_ioctl, #endif .receive_buf = serport_ldisc_receive, + .hangup = serport_ldisc_hangup, .write_wakeup = serport_ldisc_write_wakeup };