From patchwork Tue Jul 30 00:03:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 11064651 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1B811823 for ; Tue, 30 Jul 2019 00:11:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 943902842D for ; Tue, 30 Jul 2019 00:11:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 841532871E; Tue, 30 Jul 2019 00:11:10 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 1B8EE286EE for ; Tue, 30 Jul 2019 00:11:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728338AbfG3ALJ (ORCPT ); Mon, 29 Jul 2019 20:11:09 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:22604 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725925AbfG3ALJ (ORCPT ); Mon, 29 Jul 2019 20:11:09 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6U06x7h010217; Tue, 30 Jul 2019 02:11:02 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=STMicroelectronics; bh=6kvxeuBqh48iRzxAoiCa1EnnxeXN69Yrw0ZP/LgjKWw=; b=Wn5lMI7xKDWKlabsLg+zSO2mE5vn0YoBmNv0nuR1HdccWfzplXhzQi+kYT5C+kdUUYYg uYh2CAngDktQmMcE/ccWkLnd+gRAFR/VAEL+RxZbKy9pW2FiDzZLRs6kUt0PIlAsjMw6 8KpfbKSTXWIEePI3EWXu+77bBcAB0gXOcMWxSa/Uf5B/Hl0U4qEpGbgG0Jkx4ZCIWT0n n9WoWSGaJti8+ygZos3+AaPIiBV8wExad0STEZnls91xcL5AZAYYnffs8kmtS/Zz6xjk V0C/HdFjLchXtJIfyCVJVSG75FtVtIzZ7o7qQ5RZq15JzO8HYDx3D5/ouHsmIMlXqqTu GA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2u0br9sf9q-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 30 Jul 2019 02:11:02 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 66BE431; Tue, 30 Jul 2019 00:11:01 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag1node1.st.com [10.75.127.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4A7DC260C; Tue, 30 Jul 2019 00:11:01 +0000 (GMT) Received: from localhost (10.75.127.47) by SFHDAG1NODE1.st.com (10.75.127.1) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 30 Jul 2019 02:11:00 +0200 From: Denis Ciocca To: , CC: , Denis Ciocca Subject: [PATCH 1/4] iio:accel: preenable/postenable/predisable fixup for ST accel buffer Date: Mon, 29 Jul 2019 17:03:02 -0700 Message-ID: <20190730000305.30958-2-denis.ciocca@st.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190730000305.30958-1-denis.ciocca@st.com> References: <20190730000305.30958-1-denis.ciocca@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG5NODE1.st.com (10.75.127.13) To SFHDAG1NODE1.st.com (10.75.127.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-29_11:,, signatures=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 This patch is trying to cleanup for good the buffers operation functions. There is no need of using preenable, all can be done into postenable. Let's also rename the goto label using operation to perform and not where it fails. Signed-off-by: Denis Ciocca Reviewed-by: Alexandru Ardelean --- drivers/iio/accel/st_accel_buffer.c | 37 ++++++++++------------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c index 05f9aea431e2..81f89da125aa 100644 --- a/drivers/iio/accel/st_accel_buffer.c +++ b/drivers/iio/accel/st_accel_buffer.c @@ -29,56 +29,46 @@ int st_accel_trig_set_state(struct iio_trigger *trig, bool state) return st_sensors_set_dataready_irq(indio_dev, state); } -static int st_accel_buffer_preenable(struct iio_dev *indio_dev) -{ - return st_sensors_set_enable(indio_dev, true); -} - static int st_accel_buffer_postenable(struct iio_dev *indio_dev) { - int err; struct st_sensor_data *adata = iio_priv(indio_dev); + int err; adata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_DMA | GFP_KERNEL); - if (adata->buffer_data == NULL) { - err = -ENOMEM; - goto allocate_memory_error; - } + if (!adata->buffer_data) + return -ENOMEM; err = iio_triggered_buffer_postenable(indio_dev); if (err < 0) - goto st_accel_buffer_postenable_error; + goto st_accel_free_buffer; err = st_sensors_set_axis_enable(indio_dev, (u8)indio_dev->active_scan_mask[0]); if (err < 0) - goto st_sensors_set_axis_enable_error; + goto st_accel_buffer_predisable; - return err; + return st_sensors_set_enable(indio_dev, true); -st_sensors_set_axis_enable_error: +st_accel_buffer_predisable: iio_triggered_buffer_predisable(indio_dev); -st_accel_buffer_postenable_error: +st_accel_free_buffer: kfree(adata->buffer_data); -allocate_memory_error: return err; } static int st_accel_buffer_predisable(struct iio_dev *indio_dev) { - int err, err2; struct st_sensor_data *adata = iio_priv(indio_dev); - - err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS); - if (err < 0) - goto st_accel_buffer_predisable_error; + int err, err2; err = st_sensors_set_enable(indio_dev, false); if (err < 0) - goto st_accel_buffer_predisable_error; + goto st_accel_buffer_predisable; + + err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS); -st_accel_buffer_predisable_error: +st_accel_buffer_predisable: err2 = iio_triggered_buffer_predisable(indio_dev); if (!err) err = err2; @@ -88,7 +78,6 @@ static int st_accel_buffer_predisable(struct iio_dev *indio_dev) } static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = { - .preenable = &st_accel_buffer_preenable, .postenable = &st_accel_buffer_postenable, .predisable = &st_accel_buffer_predisable, }; From patchwork Tue Jul 30 00:03:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 11064655 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A6AF1398 for ; Tue, 30 Jul 2019 00:11:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE6B126CFF for ; Tue, 30 Jul 2019 00:11:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2F4828704; Tue, 30 Jul 2019 00:11:11 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 7F47428567 for ; Tue, 30 Jul 2019 00:11:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728472AbfG3ALK (ORCPT ); Mon, 29 Jul 2019 20:11:10 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:22600 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728406AbfG3ALK (ORCPT ); Mon, 29 Jul 2019 20:11:10 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6U074fn010239; Tue, 30 Jul 2019 02:11:04 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=STMicroelectronics; bh=YgA+Z47nykJeZngYkImyUvSnckPrpfYh6rVAul7UNgA=; b=zBK36dj4fX99Kcfkmvioub8aTC4UZ0nqYIzUyLdJvnNaHKMO7BRP/Yn7GJmRUKcaW7/I qYCR+Jxcmx0Nkbco3VqGXjYN0SuWPF+B0vg7zK4XLqzW2eMDqR9c7wTfNn0e0uIqA/iF B4VGToG8Mp4MU+4/Nq0bBGZv+whuK3JjMHaoKHIoIZv/ZXmsoeCwf2jSQ3zjV85VUfRv Dh/XIvFUr3SgNYZwjhYMLRW9M+mWtDp/Vf8+/tz6qFVyGrku5Q4LmSggzwsGH8jsYQ96 kPaQcaceLI+wQ0/VTWJMQnaEz0/fZslwSYwJg0jmYIe6pBFfwYG3viQ6w3hsJYvlLB09 og== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2u0br9sfa9-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 30 Jul 2019 02:11:04 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 1155D31; Tue, 30 Jul 2019 00:11:04 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag1node1.st.com [10.75.127.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id E675D260C; Tue, 30 Jul 2019 00:11:03 +0000 (GMT) Received: from localhost (10.75.127.48) by SFHDAG1NODE1.st.com (10.75.127.1) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 30 Jul 2019 02:11:03 +0200 From: Denis Ciocca To: , CC: , Denis Ciocca Subject: [PATCH 2/4] iio:gyro: preenable/postenable/predisable fixup for ST gyro buffer Date: Mon, 29 Jul 2019 17:03:03 -0700 Message-ID: <20190730000305.30958-3-denis.ciocca@st.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190730000305.30958-1-denis.ciocca@st.com> References: <20190730000305.30958-1-denis.ciocca@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG7NODE2.st.com (10.75.127.20) To SFHDAG1NODE1.st.com (10.75.127.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-29_11:,, signatures=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 This patch is trying to cleanup for good the buffers operation functions. There is no need of using preenable, all can be done into postenable. Let's also use logical sequence of operations as already done in accel driver. Finally also rename the goto label using operation to perform and not where it fails. Signed-off-by: Denis Ciocca Reviewed-by: Alexandru Ardelean --- drivers/iio/gyro/st_gyro_buffer.c | 45 +++++++++++++------------------ 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c index 21360681d4dd..be9f1fec2b5d 100644 --- a/drivers/iio/gyro/st_gyro_buffer.c +++ b/drivers/iio/gyro/st_gyro_buffer.c @@ -29,62 +29,55 @@ int st_gyro_trig_set_state(struct iio_trigger *trig, bool state) return st_sensors_set_dataready_irq(indio_dev, state); } -static int st_gyro_buffer_preenable(struct iio_dev *indio_dev) -{ - return st_sensors_set_enable(indio_dev, true); -} - static int st_gyro_buffer_postenable(struct iio_dev *indio_dev) { - int err; struct st_sensor_data *gdata = iio_priv(indio_dev); + int err; gdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_DMA | GFP_KERNEL); - if (gdata->buffer_data == NULL) { - err = -ENOMEM; - goto allocate_memory_error; - } + if (!gdata->buffer_data) + return -ENOMEM; - err = st_sensors_set_axis_enable(indio_dev, - (u8)indio_dev->active_scan_mask[0]); + err = iio_triggered_buffer_postenable(indio_dev); if (err < 0) - goto st_gyro_buffer_postenable_error; + goto st_gyro_free_buffer; - err = iio_triggered_buffer_postenable(indio_dev); + err = st_sensors_set_axis_enable(indio_dev, + (u8)indio_dev->active_scan_mask[0]); if (err < 0) - goto st_gyro_buffer_postenable_error; + goto st_gyro_buffer_predisable; - return err; + return st_sensors_set_enable(indio_dev, true); -st_gyro_buffer_postenable_error: +st_gyro_buffer_predisable: + iio_triggered_buffer_predisable(indio_dev); +st_gyro_free_buffer: kfree(gdata->buffer_data); -allocate_memory_error: return err; } static int st_gyro_buffer_predisable(struct iio_dev *indio_dev) { - int err; + int err, err2; struct st_sensor_data *gdata = iio_priv(indio_dev); - err = iio_triggered_buffer_predisable(indio_dev); + err = st_sensors_set_enable(indio_dev, false); if (err < 0) - goto st_gyro_buffer_predisable_error; + goto st_gyro_buffer_predisable; err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS); - if (err < 0) - goto st_gyro_buffer_predisable_error; - err = st_sensors_set_enable(indio_dev, false); +st_gyro_buffer_predisable: + err2 = iio_triggered_buffer_predisable(indio_dev); + if (!err) + err = err2; -st_gyro_buffer_predisable_error: kfree(gdata->buffer_data); return err; } static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = { - .preenable = &st_gyro_buffer_preenable, .postenable = &st_gyro_buffer_postenable, .predisable = &st_gyro_buffer_predisable, }; From patchwork Tue Jul 30 00:03:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 11064657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF5FE1398 for ; Tue, 30 Jul 2019 00:11:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C184E1FFCD for ; Tue, 30 Jul 2019 00:11:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B63AA286EE; Tue, 30 Jul 2019 00:11:15 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 5D8E52842D for ; Tue, 30 Jul 2019 00:11:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728652AbfG3ALP (ORCPT ); Mon, 29 Jul 2019 20:11:15 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:22620 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725925AbfG3ALO (ORCPT ); Mon, 29 Jul 2019 20:11:14 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6U06smI010177; Tue, 30 Jul 2019 02:11:07 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=STMicroelectronics; bh=kmtJhg39ytw8DOy7V99t6V1qw0Odkg5seTL+XtoS/PE=; b=OwQSSz+eVfuyHj1g9VfleddSj2YFgNTBIcfAeBYjVJlonnxGXNk7x5wf8E/GYSeRgT/M EJUxLcOLdXM0yMV9K4pxMjFWduutQmnDiRhbFw9XlxaT1pX06DA7kWxAVfdQyZTL5C55 bIt/xvFOv4KpZhkkjpheJSstSDdnmZDvawYHoPxr9daoRjlMXf/zPrWmyyK0MpiHl1Je ryr3ivuKLqie3s3AWdLB/J4cIVaFfOOEtqcI4GyUTSugO+lZcU4RVR3CzU7TSN8w+8OM QTnP+i14eq1bviHMZJbiDmUf1OvgEmSasnem4Xl1K6JzpKIKHxNonv1cJFujWtZ9h7gS nQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2u0br9sfak-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 30 Jul 2019 02:11:07 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A754531; Tue, 30 Jul 2019 00:11:06 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag1node1.st.com [10.75.127.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 9117A260C; Tue, 30 Jul 2019 00:11:06 +0000 (GMT) Received: from localhost (10.75.127.47) by SFHDAG1NODE1.st.com (10.75.127.1) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 30 Jul 2019 02:11:05 +0200 From: Denis Ciocca To: , CC: , Denis Ciocca Subject: [PATCH 3/4] iio:magn: preenable/postenable/predisable fixup for ST magn buffer Date: Mon, 29 Jul 2019 17:03:04 -0700 Message-ID: <20190730000305.30958-4-denis.ciocca@st.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190730000305.30958-1-denis.ciocca@st.com> References: <20190730000305.30958-1-denis.ciocca@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG4NODE2.st.com (10.75.127.11) To SFHDAG1NODE1.st.com (10.75.127.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-29_11:,, signatures=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 This patch is trying to cleanup for good the buffers operation functions. Let's rename the goto label using operation to perform and not where it fails. Signed-off-by: Denis Ciocca Reviewed-by: Alexandru Ardelean --- drivers/iio/magnetometer/st_magn_buffer.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c index 9dba93539a99..8d06643a042d 100644 --- a/drivers/iio/magnetometer/st_magn_buffer.c +++ b/drivers/iio/magnetometer/st_magn_buffer.c @@ -31,40 +31,36 @@ int st_magn_trig_set_state(struct iio_trigger *trig, bool state) static int st_magn_buffer_postenable(struct iio_dev *indio_dev) { - int err; struct st_sensor_data *mdata = iio_priv(indio_dev); + int err; mdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_DMA | GFP_KERNEL); - if (mdata->buffer_data == NULL) { - err = -ENOMEM; - goto allocate_memory_error; - } + if (!mdata->buffer_data) + return -ENOMEM; err = iio_triggered_buffer_postenable(indio_dev); if (err < 0) - goto st_magn_buffer_postenable_error; + goto st_magn_free_buffer; return st_sensors_set_enable(indio_dev, true); -st_magn_buffer_postenable_error: +st_magn_free_buffer: kfree(mdata->buffer_data); -allocate_memory_error: return err; } static int st_magn_buffer_predisable(struct iio_dev *indio_dev) { - int err; struct st_sensor_data *mdata = iio_priv(indio_dev); + int err, err2; err = st_sensors_set_enable(indio_dev, false); - if (err < 0) - goto st_magn_buffer_predisable_error; - err = iio_triggered_buffer_predisable(indio_dev); + err2 = iio_triggered_buffer_predisable(indio_dev); + if (!err) + err = err2; -st_magn_buffer_predisable_error: kfree(mdata->buffer_data); return err; } From patchwork Tue Jul 30 00:03:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis CIOCCA X-Patchwork-Id: 11064659 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 57AEE1399 for ; Tue, 30 Jul 2019 00:11:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4664C28567 for ; Tue, 30 Jul 2019 00:11:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AFD828704; Tue, 30 Jul 2019 00:11:17 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 D7FCF28699 for ; Tue, 30 Jul 2019 00:11:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725925AbfG3ALQ (ORCPT ); Mon, 29 Jul 2019 20:11:16 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:25172 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728406AbfG3ALQ (ORCPT ); Mon, 29 Jul 2019 20:11:16 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6U074fo010239; Tue, 30 Jul 2019 02:11:09 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=STMicroelectronics; bh=IXP1Nf32uMSQTte7apZ0rjwGna1PRwG0sK55r0BMTu4=; b=VWdN9puaI7D9h2D+WkJfU4ajSpGcxdM0wPM+jhF+CthEdO2CW/B9Qwu8Vza8WsQ25yVd JnsGRTlLFL5RBWWy5efnQJoDzPnGmYVqz4HHUDkGINoZachCqWE08EQpCzWRGmUtmUsx Pycw37nt1gqFZERPojwIEJf19XLJJ7xV9sfnr7smYoqrNFvcUKT01EAHFQxwhPnnxKJT o50Em42Izvnk08nXMAj9cwFMCHy2iLc+0UuERRNdlujzFs0IJ4PD3ASRIyV3UNOHXDmr tKQ+Bb+LgGKuqsCYECfLS4F3K9yKFNm8TjAu4O+nv5N8oYtxD18HGWJ6L2eRAUADDW1Q +w== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2u0br9sfb3-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 30 Jul 2019 02:11:09 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 46FF631; Tue, 30 Jul 2019 00:11:09 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag1node1.st.com [10.75.127.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 29860260C; Tue, 30 Jul 2019 00:11:09 +0000 (GMT) Received: from localhost (10.75.127.48) by SFHDAG1NODE1.st.com (10.75.127.1) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 30 Jul 2019 02:11:08 +0200 From: Denis Ciocca To: , CC: , Denis Ciocca Subject: [PATCH 4/4] iio:pressure: preenable/postenable/predisable fixup for ST press buffer Date: Mon, 29 Jul 2019 17:03:05 -0700 Message-ID: <20190730000305.30958-5-denis.ciocca@st.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190730000305.30958-1-denis.ciocca@st.com> References: <20190730000305.30958-1-denis.ciocca@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) To SFHDAG1NODE1.st.com (10.75.127.1) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-29_11:,, signatures=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 This patch is trying to cleanup for good the buffers operation functions. There is no need of using preenable, all can be done into postenable. Let's also use logical sequence of operations as already done in accel driver. Finally also rename the goto label using operation to perform and not where it fails. Signed-off-by: Denis Ciocca Reviewed-by: Alexandru Ardelean --- drivers/iio/pressure/st_pressure_buffer.c | 32 ++++++++--------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/drivers/iio/pressure/st_pressure_buffer.c b/drivers/iio/pressure/st_pressure_buffer.c index f21b630abaa0..54823cfcfab5 100644 --- a/drivers/iio/pressure/st_pressure_buffer.c +++ b/drivers/iio/pressure/st_pressure_buffer.c @@ -29,53 +29,43 @@ int st_press_trig_set_state(struct iio_trigger *trig, bool state) return st_sensors_set_dataready_irq(indio_dev, state); } -static int st_press_buffer_preenable(struct iio_dev *indio_dev) -{ - return st_sensors_set_enable(indio_dev, true); -} - static int st_press_buffer_postenable(struct iio_dev *indio_dev) { - int err; struct st_sensor_data *press_data = iio_priv(indio_dev); + int err; press_data->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_DMA | GFP_KERNEL); - if (press_data->buffer_data == NULL) { - err = -ENOMEM; - goto allocate_memory_error; - } + if (!press_data->buffer_data) + return -ENOMEM; err = iio_triggered_buffer_postenable(indio_dev); if (err < 0) - goto st_press_buffer_postenable_error; + goto st_press_free_buffer; - return err; + return st_sensors_set_enable(indio_dev, true); -st_press_buffer_postenable_error: +st_press_free_buffer: kfree(press_data->buffer_data); -allocate_memory_error: return err; } static int st_press_buffer_predisable(struct iio_dev *indio_dev) { - int err; struct st_sensor_data *press_data = iio_priv(indio_dev); - - err = iio_triggered_buffer_predisable(indio_dev); - if (err < 0) - goto st_press_buffer_predisable_error; + int err, err2; err = st_sensors_set_enable(indio_dev, false); -st_press_buffer_predisable_error: + err2 = iio_triggered_buffer_predisable(indio_dev); + if (!err) + err = err2; + kfree(press_data->buffer_data); return err; } static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = { - .preenable = &st_press_buffer_preenable, .postenable = &st_press_buffer_postenable, .predisable = &st_press_buffer_predisable, };