From patchwork Sun Mar 4 01:49:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Masney X-Patchwork-Id: 10257513 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 D966F6037F for ; Sun, 4 Mar 2018 01:56:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA037287A1 for ; Sun, 4 Mar 2018 01:56:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEA0E287A8; Sun, 4 Mar 2018 01:56:00 +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 540C0287A1 for ; Sun, 4 Mar 2018 01:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752361AbeCDBzW (ORCPT ); Sat, 3 Mar 2018 20:55:22 -0500 Received: from onstation.org ([52.200.56.107]:52882 "EHLO onstation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751961AbeCDBy5 (ORCPT ); Sat, 3 Mar 2018 20:54:57 -0500 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 DDC291AF3; Sun, 4 Mar 2018 01:49:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=onstation.org; s=default; t=1520128193; bh=zBO0Qx/IsjB2MXEErBntjUS3ZOQZU7agmdmw+gjNwFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T+EcX9Y96XN0CxOn5IejQd62n2ADqZl7t3N/bkFLUPOlo7E6W4DiNNJYI9x53QBQS qdTOZUIHsl0ERuqJKKtkp5hzNDbwUcf1BTziPwCfUwuFvU04ZkEZ+WVGg8M3ukx2wU 7fy28BldIJw7sEF6GWNOEhfBnHdAOBkRkIDfEQUU= 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, Jon.Brenner@ams.com Subject: [PATCH 06/12] staging: iio: tsl2x7x: correctly return errors in tsl2x7x_get_prox() Date: Sat, 3 Mar 2018 20:49:36 -0500 Message-Id: <20180304014942.18727-7-masneyb@onstation.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180304014942.18727-1-masneyb@onstation.org> References: <20180304014942.18727-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 Not all errors that occurred in tsl2x7x_get_prox() were correctly reported in the return value. This patch changes the error handling so that errors are now returned properly. Note that the ret variable is from the call to tsl2x7x_read_status(), and it already has the correct error check. The -EINVAL error code is for an unexpected value in the register. This patch also corrects an unnecessary word wrap in the call to le16_to_cpup() while changes are being made to this code. Signed-off-by: Brian Masney --- drivers/staging/iio/light/tsl2x7x.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 5c611250127f..cc209b64ed5a 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -489,16 +489,20 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev) case tmd2671: case tsl2771: case tmd2771: - if (!(ret & TSL2X7X_STA_ADC_VALID)) + if (!(ret & TSL2X7X_STA_ADC_VALID)) { + ret = -EINVAL; goto prox_poll_err; + } break; case tsl2572: case tsl2672: case tmd2672: case tsl2772: case tmd2772: - if (!(ret & TSL2X7X_STA_PRX_VALID)) + if (!(ret & TSL2X7X_STA_PRX_VALID)) { + ret = -EINVAL; goto prox_poll_err; + } break; } @@ -512,14 +516,13 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev) chdata[i] = ret; } - chip->prox_data = - le16_to_cpup((const __le16 *)&chdata[0]); + chip->prox_data = le16_to_cpup((const __le16 *)&chdata[0]); + ret = chip->prox_data; prox_poll_err: - mutex_unlock(&chip->prox_mutex); - return chip->prox_data; + return ret; } /**