From patchwork Sun Aug 12 02:15:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 1309251 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 463BC3FCF6 for ; Sun, 12 Aug 2012 02:15:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754156Ab2HLCPt (ORCPT ); Sat, 11 Aug 2012 22:15:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39690 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753271Ab2HLCPs (ORCPT ); Sat, 11 Aug 2012 22:15:48 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q7C2FUOf008358 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 11 Aug 2012 22:15:31 -0400 Received: from [10.97.5.236] (vpn1-5-236.gru2.redhat.com [10.97.5.236]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q7C2FQQp002248 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 11 Aug 2012 22:15:28 -0400 Message-ID: <502711BE.4020701@redhat.com> Date: Sat, 11 Aug 2012 23:15:26 -0300 From: Mauro Carvalho Chehab User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120717 Thunderbird/14.0 MIME-Version: 1.0 To: Devin Heitmueller , Antti Palosaari CC: Linux Media Mailing List , Juergen Lock , hselasky@c2i.net Subject: Fwd: [PATCH, RFC] Fix DVB ioctls failing if frontend open/closed too fast References: <20120731222216.GA36603@triton8.kn-bremen.de> In-Reply-To: <20120731222216.GA36603@triton8.kn-bremen.de> X-Enigmail-Version: 1.4.3 X-Forwarded-Message-Id: <20120731222216.GA36603@triton8.kn-bremen.de> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Devin/Antti, As Juergen mentioned your help on this patch, do you mind helping reviewing and testing it? Touching on those semaphores can be very tricky, as anything wrong may cause a driver hangup. So, it is great to have more pair of eyes looking on it. While I didn't test the code (too busy trying to clean up my long queue - currently with still 200+ patches left), I did a careful review at the semaphore code there, and it seems this approach will work. At least, the first hunk looks perfect for me. The second hunk seems a little more worrying, as the dvb core might be waiting forever for a lock on a device that was already removed. In order to test it in practice, I think we need to remove an USB device by hand while tuning it, and see if the core will not lock the device forever. What do you think? Mauro -------- Mensagem original -------- Assunto: [PATCH, RFC] Fix DVB ioctls failing if frontend open/closed too fast Data: Wed, 1 Aug 2012 00:22:16 +0200 De: Juergen Lock Para: linux-media@vger.kernel.org CC: hselasky@c2i.net That likely fxes this MythTV ticket: http://code.mythtv.org/trac/ticket/10830 (which btw affects all usb tuners I tested as well, pctv452e, dib0700, af9015) pctv452e is still possibly broken with MythTV even after this fix; it does work with VDR here tho despite I2C errors. Reduced testcase: http://people.freebsd.org/~nox/tmp/ioctltst.c Thanx to devinheitmueller and crope from #linuxtv for helping with this fix! :) Signed-off-by: Juergen Lock --- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/drivers/media/dvb/dvb-core/dvb_frontend.c +++ b/drivers/media/dvb/dvb-core/dvb_frontend.c @@ -604,6 +604,7 @@ static int dvb_frontend_thread(void *dat enum dvbfe_algo algo; bool re_tune = false; + bool semheld = false; dprintk("%s\n", __func__); @@ -627,6 +628,8 @@ restart: if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) { /* got signal or quitting */ + if (!down_interruptible (&fepriv->sem)) + semheld = true; fepriv->exit = DVB_FE_NORMAL_EXIT; break; } @@ -742,6 +745,8 @@ restart: fepriv->exit = DVB_FE_NO_EXIT; mb(); + if (semheld) + up(&fepriv->sem); dvb_frontend_wakeup(fe); return 0; } @@ -1804,16 +1809,20 @@ static int dvb_frontend_ioctl(struct fil dprintk("%s (%d)\n", __func__, _IOC_NR(cmd)); - if (fepriv->exit != DVB_FE_NO_EXIT) + if (down_interruptible (&fepriv->sem)) + return -ERESTARTSYS; + + if (fepriv->exit != DVB_FE_NO_EXIT) { + up(&fepriv->sem); return -ENODEV; + } if ((file->f_flags & O_ACCMODE) == O_RDONLY && (_IOC_DIR(cmd) != _IOC_READ || cmd == FE_GET_EVENT || - cmd == FE_DISEQC_RECV_SLAVE_REPLY)) + cmd == FE_DISEQC_RECV_SLAVE_REPLY)) { + up(&fepriv->sem); return -EPERM; - - if (down_interruptible (&fepriv->sem)) - return -ERESTARTSYS; + } if ((cmd == FE_SET_PROPERTY) || (cmd == FE_GET_PROPERTY)) err = dvb_frontend_ioctl_properties(file, cmd, parg);