From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753085AbcD1Qka (ORCPT ); Thu, 28 Apr 2016 12:40:30 -0400 Received: from mga03.intel.com ([134.134.136.65]:60702 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752319AbcD1Qk2 (ORCPT ); Thu, 28 Apr 2016 12:40:28 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,547,1455004800"; d="scan'208";a="942239729" From: Crestez Dan Leonard To: Jonathan Cameron , linux-iio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Daniel Baluta , Crestez Dan Leonard Subject: [RFC] iio: Release irq if set_trigger_state fails Date: Thu, 28 Apr 2016 19:40:22 +0300 Message-Id: <28d5b780aa8bd065492e0be1aa2f5c59a0cc0e16.1461861330.git.leonard.crestez@intel.com> X-Mailer: git-send-email 2.5.5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When attaching a pollfunc iio_trigger_attach_poll_func will allocate a virtual irq and call the driver's set_trigger_state function. Fix error handling to release the irq if set_trigger_state fails. Otherwise when using triggered buffers and the driver's set_trigger_state fails once then the buffer becomes unusable. It is not possible to handle this sort of error by calling iio_trigger_detach_poll_func externally somehow. That function should only be called if attach is successful. Signed-off-by: Crestez Dan Leonard --- I ran into this while adding some validation in driver's set_trigger_state function. It's much better to use buffer_ops->predisable for that kind of stuff but the iio core should still handle set_trigger_state errors correctly. drivers/iio/industrialio-trigger.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c index ae2806a..cf2be3e 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c @@ -214,18 +214,23 @@ static int iio_trigger_attach_poll_func(struct iio_trigger *trig, ret = request_threaded_irq(pf->irq, pf->h, pf->thread, pf->type, pf->name, pf); - if (ret < 0) { - module_put(pf->indio_dev->info->driver_module); - return ret; - } + if (ret < 0) + goto out_put_module; if (trig->ops && trig->ops->set_trigger_state && notinuse) { ret = trig->ops->set_trigger_state(trig, true); if (ret < 0) - module_put(pf->indio_dev->info->driver_module); + goto out_put_irq; } return ret; + +out_put_irq: + iio_trigger_put_irq(trig, pf->irq); + free_irq(pf->irq, pf); +out_put_module: + module_put(pf->indio_dev->info->driver_module); + return ret; } static int iio_trigger_detach_poll_func(struct iio_trigger *trig, -- 2.5.5