From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751713AbdL2RXn (ORCPT ); Fri, 29 Dec 2017 12:23:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:53076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751687AbdL2RXm (ORCPT ); Fri, 29 Dec 2017 12:23:42 -0500 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D67C02197D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=jic23@kernel.org Date: Fri, 29 Dec 2017 17:23:37 +0000 From: Jonathan Cameron To: Eugen Hristev Cc: , , , , , , , , Subject: Re: [PATCH 07/14] iio: triggers: on pollfunc attach, complete iio_dev if NULL Message-ID: <20171229172337.6226de69@archlinux> In-Reply-To: <1513955241-10985-8-git-send-email-eugen.hristev@microchip.com> References: <1513955241-10985-1-git-send-email-eugen.hristev@microchip.com> <1513955241-10985-8-git-send-email-eugen.hristev@microchip.com> X-Mailer: Claws Mail 3.15.1-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 22 Dec 2017 17:07:14 +0200 Eugen Hristev wrote: > 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 I'm yet to be convinced this is necessary rather than using a callback buffer. It's also decidedly unsafe as there is no particular reason in general to assume the private data is an iio_dev. > --- > 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); That isn't always valid. Triggers don't always have a iio_dev associated with them at all. > + 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);