From patchwork Fri May 4 02:53:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Masney X-Patchwork-Id: 10379749 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 18A1960327 for ; Fri, 4 May 2018 02:56:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04C0F2923B for ; Fri, 4 May 2018 02:56:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECD6129243; Fri, 4 May 2018 02:56:35 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable 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 4EEB32923B for ; Fri, 4 May 2018 02:56:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751278AbeEDC4W (ORCPT ); Thu, 3 May 2018 22:56:22 -0400 Received: from onstation.org ([52.200.56.107]:45156 "EHLO onstation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751269AbeEDCx2 (ORCPT ); Thu, 3 May 2018 22:53:28 -0400 Received: from xilitla.hsd1.wv.comcast.net (c-98-236-77-125.hsd1.wv.comcast.net [98.236.77.125]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: masneyb) by onstation.org (Postfix) with ESMTPSA id 8E0FC96C; Fri, 4 May 2018 02:53:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=onstation.org; s=default; t=1525402407; bh=j+bD70d5RX/hQy6U2ZFqygEX/pikUFTcftlfILScwtY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IfZ6S2dTEz7ANpwCdd6rZczQEMqi9/MRX6d5SP2oU9MsJV1XbOFtw/rCjePCcj1xN 6hEzI0G7g1eDYqyYph2gpchx9E3jiMTnC6UtxM8RRtS1B9IMG59CaS+lb3daqctCzP vJ+8b2Wi0ExNg0HkrhuWxZ7yETe76/lUW+pIUAnM= From: Brian Masney To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, linux-kernel@vger.kernel.org, drew.paterson@ams.com Subject: [PATCH v2 03/11] staging: iio: tsl2x7x: don't setup event handlers if interrupts are not configured Date: Thu, 3 May 2018 22:53:11 -0400 Message-Id: <20180504025319.28953-4-masneyb@onstation.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180504025319.28953-1-masneyb@onstation.org> References: <20180504025319.28953-1-masneyb@onstation.org> 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 The driver would expose to userspace the events directory even if the interrupts were not configured. This patch changes the driver so that the events directory is not exposed to user space if interrupts are not configured. This patch also corrects the indentation of the chan_table_elements and info structure members. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 130 +++++++++++++++++++++++++++++++----- 1 file changed, 112 insertions(+), 18 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index b4d77f65ca12..7e8db5178a2c 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -134,8 +134,9 @@ struct tsl2x7x_als_info { struct tsl2x7x_chip_info { int chan_table_elements; - struct iio_chan_spec channel[4]; - const struct iio_info *info; + struct iio_chan_spec channel_with_events[4]; + struct iio_chan_spec channel_without_events[4]; + const struct iio_info *info; }; struct tsl2X7X_chip { @@ -1447,7 +1448,7 @@ static const struct iio_event_spec tsl2x7x_events[] = { static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = { [ALS] = { - .channel = { + .channel_with_events = { { .type = IIO_LIGHT, .indexed = 1, @@ -1469,11 +1470,31 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = { .channel = 1, }, }, - .chan_table_elements = 3, - .info = &tsl2X7X_device_info[ALS], + .channel_without_events = { + { + .type = IIO_LIGHT, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + }, { + .type = IIO_INTENSITY, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_INT_TIME) | + BIT(IIO_CHAN_INFO_CALIBSCALE) | + BIT(IIO_CHAN_INFO_CALIBBIAS), + }, { + .type = IIO_INTENSITY, + .indexed = 1, + .channel = 1, + }, + }, + .chan_table_elements = 3, + .info = &tsl2X7X_device_info[ALS], }, [PRX] = { - .channel = { + .channel_with_events = { { .type = IIO_PROXIMITY, .indexed = 1, @@ -1483,11 +1504,19 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = { .num_event_specs = ARRAY_SIZE(tsl2x7x_events), }, }, - .chan_table_elements = 1, - .info = &tsl2X7X_device_info[PRX], + .channel_without_events = { + { + .type = IIO_PROXIMITY, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + }, + }, + .chan_table_elements = 1, + .info = &tsl2X7X_device_info[PRX], }, [ALSPRX] = { - .channel = { + .channel_with_events = { { .type = IIO_LIGHT, .indexed = 1, @@ -1517,11 +1546,37 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = { .num_event_specs = ARRAY_SIZE(tsl2x7x_events), }, }, - .chan_table_elements = 4, - .info = &tsl2X7X_device_info[ALSPRX], + .channel_without_events = { + { + .type = IIO_LIGHT, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + }, { + .type = IIO_INTENSITY, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_INT_TIME) | + BIT(IIO_CHAN_INFO_CALIBSCALE) | + BIT(IIO_CHAN_INFO_CALIBBIAS), + }, { + .type = IIO_INTENSITY, + .indexed = 1, + .channel = 1, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + }, { + .type = IIO_PROXIMITY, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + }, + }, + .chan_table_elements = 4, + .info = &tsl2X7X_device_info[ALSPRX], }, [PRX2] = { - .channel = { + .channel_with_events = { { .type = IIO_PROXIMITY, .indexed = 1, @@ -1532,11 +1587,20 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = { .num_event_specs = ARRAY_SIZE(tsl2x7x_events), }, }, - .chan_table_elements = 1, - .info = &tsl2X7X_device_info[PRX2], + .channel_without_events = { + { + .type = IIO_PROXIMITY, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_CALIBSCALE), + }, + }, + .chan_table_elements = 1, + .info = &tsl2X7X_device_info[PRX2], }, [ALSPRX2] = { - .channel = { + .channel_with_events = { { .type = IIO_LIGHT, .indexed = 1, @@ -1567,8 +1631,35 @@ static const struct tsl2x7x_chip_info tsl2x7x_chip_info_tbl[] = { .num_event_specs = ARRAY_SIZE(tsl2x7x_events), }, }, - .chan_table_elements = 4, - .info = &tsl2X7X_device_info[ALSPRX2], + .channel_without_events = { + { + .type = IIO_LIGHT, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), + }, { + .type = IIO_INTENSITY, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_INT_TIME) | + BIT(IIO_CHAN_INFO_CALIBSCALE) | + BIT(IIO_CHAN_INFO_CALIBBIAS), + }, { + .type = IIO_INTENSITY, + .indexed = 1, + .channel = 1, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + }, { + .type = IIO_PROXIMITY, + .indexed = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_CALIBSCALE), + }, + }, + .chan_table_elements = 4, + .info = &tsl2X7X_device_info[ALSPRX2], }, }; @@ -1620,10 +1711,11 @@ static int tsl2x7x_probe(struct i2c_client *clientp, indio_dev->dev.parent = &clientp->dev; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->name = chip->client->name; - indio_dev->channels = chip->chip_info->channel; indio_dev->num_channels = chip->chip_info->chan_table_elements; if (clientp->irq) { + indio_dev->channels = chip->chip_info->channel_with_events; + ret = devm_request_threaded_irq(&clientp->dev, clientp->irq, NULL, &tsl2x7x_event_handler, @@ -1636,6 +1728,8 @@ static int tsl2x7x_probe(struct i2c_client *clientp, "%s: irq request failed\n", __func__); return ret; } + } else { + indio_dev->channels = chip->chip_info->channel_without_events; } tsl2x7x_defaults(chip);