From patchwork Fri Dec 22 15:07:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 10130687 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 A228660318 for ; Fri, 22 Dec 2017 15:12:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3E5B29FB5 for ; Fri, 22 Dec 2017 15:12:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98B932A05A; Fri, 22 Dec 2017 15:12:50 +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 41E7E29FB5 for ; Fri, 22 Dec 2017 15:12:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756645AbdLVPMj (ORCPT ); Fri, 22 Dec 2017 10:12:39 -0500 Received: from esa1.microchip.iphmx.com ([68.232.147.91]:56578 "EHLO esa1.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756404AbdLVPKJ (ORCPT ); Fri, 22 Dec 2017 10:10:09 -0500 X-IronPort-AV: E=Sophos;i="5.45,441,1508828400"; d="scan'208";a="10402490" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 22 Dec 2017 08:10:09 -0700 Received: from eh-station.mchp-main.com (10.10.76.4) by chn-sv-exch07.mchp-main.com (10.10.76.108) with Microsoft SMTP Server id 14.3.352.0; Fri, 22 Dec 2017 08:10:07 -0700 From: Eugen Hristev To: , , , , , , , , , CC: Eugen Hristev Subject: [PATCH 07/14] iio: triggers: on pollfunc attach, complete iio_dev if NULL Date: Fri, 22 Dec 2017 17:07:14 +0200 Message-ID: <1513955241-10985-8-git-send-email-eugen.hristev@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513955241-10985-1-git-send-email-eugen.hristev@microchip.com> References: <1513955241-10985-1-git-send-email-eugen.hristev@microchip.com> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When attaching a pollfunc to a trigger, if the pollfunc does not have an associated iio_dev pointer, just use the private data iio_dev pointer from the trigger to fill in the poll func required iio_dev reference. Signed-off-by: Eugen Hristev --- drivers/iio/industrialio-trigger.c | 9 +++++++++ include/linux/iio/trigger_consumer.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c index 8565c92..ab180bd 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c @@ -272,6 +272,15 @@ int iio_trigger_attach_poll_func(struct iio_trigger *trig, bool notinuse = bitmap_empty(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER); + /* + * If we did not get a iio_dev in the poll func, attempt to + * obtain the trigger's owner's device struct + */ + if (!pf->indio_dev) + pf->indio_dev = iio_trigger_get_drvdata(trig); + if (!pf->indio_dev) + return -EINVAL; + /* Prevent the module from being removed whilst attached to a trigger */ __module_get(pf->indio_dev->driver_module); diff --git a/include/linux/iio/trigger_consumer.h b/include/linux/iio/trigger_consumer.h index aeefcdb..36e2a02 100644 --- a/include/linux/iio/trigger_consumer.h +++ b/include/linux/iio/trigger_consumer.h @@ -63,6 +63,8 @@ int iio_triggered_buffer_predisable(struct iio_dev *indio_dev); /* * Two functions for the uncommon case when we need to attach or detach * a specific pollfunc to and from a trigger + * If the pollfunc has a NULL iio_dev pointer, it will be filled from the + * trigger struct. */ int iio_trigger_attach_poll_func(struct iio_trigger *trig, struct iio_poll_func *pf);