Received: by 10.192.165.156 with SMTP id m28csp1024510imm; Wed, 18 Apr 2018 02:40:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+nBiFyoNnjWMabb34NWPHM3ouX3XOJ1A9Nkh3nq2jvQOJvRoyuJDl9Suj5eXfk4UIiGnX3 X-Received: by 10.99.134.198 with SMTP id x189mr1200285pgd.274.1524044423483; Wed, 18 Apr 2018 02:40:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524044423; cv=none; d=google.com; s=arc-20160816; b=rvAJ3Osb+BZWyAA1DuGaZcIQqPnh+3Odq9rdTMQ1zd49aOyMZzNJYtMZ6qzg0TmoVG 8Rfs4THRR1dcDsaHKxuhb/xx6OiIW7oyvw02PSQdw5YIDwuLjybCXygY4ZWaYXhdwe99 sto/L+XRxLF+oN9PITYML8sFcqEt745wN7sYQlikmmriqlj0bopjApRxupnOQmqN2/Ja Hrk95PY7VZRH/8qE8/ZgZ//MB/HIZAJgwMhkKguDm4m437nxt5P1co7wgJnGnuBPbTcp VqWwYr7pRpiISbd33lmssqYeFoitWgQN/tOUdr5bgt/P0r1AiAGfYBrPg8feYScfSowo ZSMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=Cg8kLXaxDb7DbCVz/kNHaw9hkMGagdbiRBpjEW2EkYU=; b=dFW9fbG1YeYccVlaFJUPqrlrYs7sszBvwXjrTWLl7ZBVQs+pH3trt0guhjFcKXACLU kpUJ4wb5IQc/5ZBnzDMh8+YwqfCBWV3PtuAmjuK8FF/bl4opw65voL5H/IIGf+IRf2o+ LYddfg2BUtgcWorydVD+Lqf4yYSGRHU8vAW0rF5XmgZDbKGdvW3gBQWJ1B+AJYm4/sQA /lZeDCduiQOZpFQUHPfxmkHLEJlchMOIZPQsRgJ9GWvIWisz6pkHOoAMpPiO9wjiaM8h IDEsfFsI4Zk7+z9S8ZLCGQLXSAMMjcNrrT1Geu6Po6Fo1ooFOnih4SxV3RAxCnyQ9U6X D2TQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n6-v6si863399plp.386.2018.04.18.02.40.09; Wed, 18 Apr 2018 02:40:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753393AbeDRJha (ORCPT + 99 others); Wed, 18 Apr 2018 05:37:30 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:6745 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750983AbeDRJgO (ORCPT ); Wed, 18 Apr 2018 05:36:14 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id A8CEE3B38BBC0; Wed, 18 Apr 2018 17:35:59 +0800 (CST) Received: from localhost (10.202.226.43) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 18 Apr 2018 17:35:57 +0800 Date: Wed, 18 Apr 2018 10:35:48 +0100 From: Jonathan Cameron To: Dmitry Torokhov CC: Eugen Hristev , Jonathan Cameron , , , , , , , , , , Subject: Re: [PATCH v3 06/11] iio: inkern: add module put/get on iio dev module when requesting channels Message-ID: <20180418103548.000078b7@huawei.com> In-Reply-To: <20180417191906.GB67621@dtor-ws> References: <1523350677-27106-1-git-send-email-eugen.hristev@microchip.com> <1523350677-27106-7-git-send-email-eugen.hristev@microchip.com> <20180415203321.1aaaf91e@archlinux> <20180416235821.GF77055@dtor-ws> <67771f4c-d30c-4a28-2a9b-d5585186d60a@microchip.com> <20180417191906.GB67621@dtor-ws> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.31; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.43] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 17 Apr 2018 12:19:06 -0700 Dmitry Torokhov wrote: > Hi Eugen, > > On Tue, Apr 17, 2018 at 10:39:24AM +0300, Eugen Hristev wrote: > > > > > > On 17.04.2018 02:58, Dmitry Torokhov wrote: > > > On Sun, Apr 15, 2018 at 08:33:21PM +0100, Jonathan Cameron wrote: > > > > On Tue, 10 Apr 2018 11:57:52 +0300 > > > > Eugen Hristev wrote: > > > > > > > > > When requesting channels for a particular consumer device, > > > > > besides requesting the device (incrementing the reference counter), also > > > > > do it for the driver module of the iio dev. This will avoid the situation > > > > > where the producer IIO device can be removed and the consumer is still > > > > > present in the kernel. > > > > > > > > > > Signed-off-by: Eugen Hristev > > > > > --- > > > > > drivers/iio/inkern.c | 8 +++++++- > > > > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > > > > > > > diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c > > > > > index ec98790..68d9b87 100644 > > > > > --- a/drivers/iio/inkern.c > > > > > +++ b/drivers/iio/inkern.c > > > > > @@ -11,6 +11,7 @@ > > > > > #include > > > > > #include > > > > > #include > > > > > +#include > > > > > #include > > > > > #include "iio_core.h" > > > > > @@ -152,6 +153,7 @@ static int __of_iio_channel_get(struct iio_channel *channel, > > > > > if (index < 0) > > > > > goto err_put; > > > > > channel->channel = &indio_dev->channels[index]; > > > > > + try_module_get(channel->indio_dev->driver_module); > > > > > > > > And if it fails? (the module we are trying to get is going away...) > > > > > > > > We should try and handle it I think. Be it by just erroring out of here. > > > > > > Even more, this has nothing to do with modules. A device can go away for > > > any number of reasons (we unbind it manually via sysfs, we pull the USB > > > plug from the host in case it is USB-connected device, we unload I2C > > > adapter for the bus device resides on, we kick underlying PCI device) > > > and we should be able to handle this in some fashion. Handling errors > > > from reads and ignoring garbage is one of methods. > > > > > > FWIW this is a NACK from me. > > > > > > Thanks. > > Hello, > > > > This patch is actually a "best effort attempt" for the consumer driver > > (touch driver) to get a reference to the producer of the data (the IIO > > device), when it requests the specific channels. > > As of this moment, there is no attempt whatsoever for the consumer to have a > > reference on the producer driver. Thus, the producer can be removed at any > > time, and the consumer will fail ungraciously. > > This is the root of the issue. The consumer should be prepared to handle > errors from producer. > > > I can change the perspective from "best effort" to "mandatory" to get a > > reference to the producer, or you wish to stop trying to get any reference > > at all (remove this patch completely) ? > > You should take reference to the device itself (if it is not taken > already), so it does not disappear completely and you can continue using > IIO API to access it, and IIO API should be prepared to deal with "dead" > devices, but as I pointed in my other email, trying to pin the driver > is quite pointless as there are myriad other ways of device stopping > working besides module unloading. > > In any case, I think this problem is outside of the scope of this > patchset that adds a generic resistive touchscreen, so if you want to > continue working on this I'd recommend moving it into a separate series. > > Thanks. > Agreed, this one has come up a number of times before. Quite a lot of work got done by (IIRC) Lars Peter Clausen to stabilize things in various unexpected 'going away' events. Of course there may be paths we have added since that (it was years ago) that can cause trouble... Anyhow, separate issue as Dmitry says, let's deal with it separately. Jonathan