From patchwork Thu Apr 5 16:17:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Baptiste Maneyrol X-Patchwork-Id: 10324923 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 D34836032A for ; Thu, 5 Apr 2018 16:18:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C4A0528FD8 for ; Thu, 5 Apr 2018 16:18:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B94D628FF0; Thu, 5 Apr 2018 16:18:30 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 E768028FD8 for ; Thu, 5 Apr 2018 16:18:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752045AbeDEQSY (ORCPT ); Thu, 5 Apr 2018 12:18:24 -0400 Received: from mail-bn3nam01on0089.outbound.protection.outlook.com ([104.47.33.89]:63584 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751516AbeDEQRD (ORCPT ); Thu, 5 Apr 2018 12:17:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=invensense.onmicrosoft.com; s=selector1-invensense-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=smjEbxrJdZ2Mg/HI+b9dicRi9r4z7N7Gcqml64Y8+Qs=; b=mdSmCfFRdf60P4a3f3887TE7DOPjSYI0ZzWkTzC2qRdbkFw8C2l724/jeWFra8Lnm7dNVIxexIOQZWgVFgLMDQBWqrvIxu/WM6keztGDBqzDFqoNaSEhhMDhVyu/OuhR/nTbxFnDswWvzHOdOhS+CoRTmfcWJ1uWFv9BVWeX0o0= Received: from CY4PR1201MB0184.namprd12.prod.outlook.com (10.172.78.141) by CY4PR1201MB2471.namprd12.prod.outlook.com (10.172.116.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.631.10; Thu, 5 Apr 2018 16:17:00 +0000 Received: from CY4PR1201MB0184.namprd12.prod.outlook.com ([fe80::6cd9:f753:b84b:7f85]) by CY4PR1201MB0184.namprd12.prod.outlook.com ([fe80::6cd9:f753:b84b:7f85%13]) with mapi id 15.20.0631.015; Thu, 5 Apr 2018 16:17:00 +0000 From: Jean-Baptiste Maneyrol To: linux-iio Subject: [PATCH] iio: imu: inv_mpu6050: fix error path not turning chip back off Thread-Topic: [PATCH] iio: imu: inv_mpu6050: fix error path not turning chip back off Thread-Index: AQHTzPl+oj+eGneNw0aF/XVLYWM46w== Date: Thu, 5 Apr 2018 16:17:00 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=JManeyrol@invensense.com; x-originating-ip: [92.154.85.143] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; CY4PR1201MB2471; 7:7oETHgEB7rE0BwmQgZq+3JF8R12koj4ztz3KLiuOhozkMaatqPrUvaP35yxxbD3udNHZOl7Jx28dedGQAlg0OPHX/qrEYIY9BnCsVzxaTjmcED0jzApB3Yj8cHNo6MoocBjveVFHPPT0WrZD0VH7aUEqWCJO2tdL9dfJiX68iOtk3pq6kKAHCgBu8YGmdLCfD8IyCejIirwUBscSnk8FoIY1CmSVhmRr8zpCnvBvBtiQv1TK6be3bwY/KuaE3O41 x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 014998c1-d2e2-4b4f-f5d6-08d59b10a94e x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:CY4PR1201MB2471; x-ms-traffictypediagnostic: CY4PR1201MB2471: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(257004950022427); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(3231221)(944501327)(52105095)(6041310)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(6072148)(201708071742011); SRVR:CY4PR1201MB2471; BCL:0; PCL:0; RULEID:; SRVR:CY4PR1201MB2471; x-forefront-prvs: 06339BAE63 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(376002)(39850400004)(346002)(396003)(39380400002)(199004)(189003)(6436002)(186003)(99286004)(68736007)(478600001)(66066001)(3846002)(26005)(2900100001)(6116002)(1857600001)(6916009)(486006)(2906002)(3280700002)(316002)(5250100002)(3660700001)(86362001)(53936002)(72206003)(7736002)(106356001)(8676002)(5660300001)(33656002)(14454004)(80792005)(8936002)(6506007)(7696005)(476003)(97736004)(305945005)(9686003)(25786009)(81166006)(105586002)(55016002)(81156014)(102836004)(74316002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR1201MB2471; H:CY4PR1201MB0184.namprd12.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: invensense.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: UgqgbChtQUEh4TStxbHc+Cowdv22DXndgXVswl5cVu5We/ASVLoKI2Zeyb5P/DZZEZ6JE4jhVvoVPvArQ1eyM263/DJpUtZQOdkrc2xHWPY1N4Hat4fZ7CLMxSXrKjGXA0hQOI/IJo7rJ07fTlA51C8fSE+sUKfKTiINluRB2QPz0m9BJM5beDQiYuNaGJRDk+4iB48/ba0Jt+HbQb9sYIt6/plDOH9KoEE7pPfVFzuAmqo+ce0L7y1OurgpSepyQ+wRmD4HPKgQ8bur70KJrRtozvgrSIAsDemMHwBzm40PA91UU5XpDt4hKWR15YvX3CHfPh/ry84cYq4Ny4j+UtXQyC2jI8lJ/G6pACVk7swOihOsBtDAeBD8u73bhZGJMpSm2Yt3y2l0SUZlXMaf6fB/4Q59boK30NkPURNQvl4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: invensense.com X-MS-Exchange-CrossTenant-Network-Message-Id: 014998c1-d2e2-4b4f-f5d6-08d59b10a94e X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Apr 2018 16:17:00.4161 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 462b3b3b-e42b-47ea-801a-f1581aac892d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB2471 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 Some functions are turning the chip on and not back off in error path. With set_power function using a reference counter that would keep the chip on forever. Signed-off-by: Jean-Baptiste Maneyrol --- drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 12 ++++++++---- drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c | 25 ++++++++++++++++--------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c index 7d64be3..18c8866 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c @@ -262,27 +262,31 @@ static int inv_mpu6050_init_config(struct iio_dev *indio_dev) d = (INV_MPU6050_FSR_2000DPS << INV_MPU6050_GYRO_CONFIG_FSR_SHIFT); result = regmap_write(st->map, st->reg->gyro_config, d); if (result) - return result; + goto error_power_off; result = inv_mpu6050_set_lpf_regs(st, INV_MPU6050_FILTER_20HZ); if (result) - return result; + goto error_power_off; d = INV_MPU6050_ONE_K_HZ / INV_MPU6050_INIT_FIFO_RATE - 1; result = regmap_write(st->map, st->reg->sample_rate_div, d); if (result) - return result; + goto error_power_off; d = (INV_MPU6050_FS_02G << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT); result = regmap_write(st->map, st->reg->accl_config, d); if (result) - return result; + goto error_power_off; memcpy(&st->chip_config, hw_info[st->chip_type].config, sizeof(struct inv_mpu6050_chip_config)); result = inv_mpu6050_set_power_itg(st, false); return result; + +error_power_off: + inv_mpu6050_set_power_itg(st, false); + return result; } static int inv_mpu6050_sensor_set(struct inv_mpu6050_state *st, int reg, diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c index f963f9f..770b93a 100644 --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c @@ -53,45 +53,52 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable) result = inv_mpu6050_switch_engine(st, true, INV_MPU6050_BIT_PWR_GYRO_STBY); if (result) - return result; + goto error_power_off; } if (st->chip_config.accl_fifo_enable) { result = inv_mpu6050_switch_engine(st, true, INV_MPU6050_BIT_PWR_ACCL_STBY); if (result) - return result; + goto error_power_off; } result = inv_reset_fifo(indio_dev); if (result) - return result; + goto error_power_off; } else { result = regmap_write(st->map, st->reg->fifo_en, 0); if (result) - return result; + goto error_power_off; result = regmap_write(st->map, st->reg->int_enable, 0); if (result) - return result; + goto error_power_off; result = regmap_write(st->map, st->reg->user_ctrl, 0); if (result) - return result; + goto error_power_off; result = inv_mpu6050_switch_engine(st, false, INV_MPU6050_BIT_PWR_GYRO_STBY); if (result) - return result; + goto error_power_off; result = inv_mpu6050_switch_engine(st, false, INV_MPU6050_BIT_PWR_ACCL_STBY); if (result) - return result; + goto error_power_off; + result = inv_mpu6050_set_power_itg(st, false); if (result) - return result; + goto error_power_off; } return 0; + +error_power_off: + inv_mpu6050_switch_engine(st, false, INV_MPU6050_BIT_PWR_GYRO_STBY); + inv_mpu6050_switch_engine(st, false, INV_MPU6050_BIT_PWR_ACCL_STBY); + inv_mpu6050_set_power_itg(st, false); + return result; } /**