From patchwork Fri Mar 23 14:22:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 10304781 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 EDB2760384 for ; Fri, 23 Mar 2018 14:22:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC19128D84 for ; Fri, 23 Mar 2018 14:22:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D050228DF6; Fri, 23 Mar 2018 14:22:20 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 5326928D84 for ; Fri, 23 Mar 2018 14:22:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751847AbeCWOWT (ORCPT ); Fri, 23 Mar 2018 10:22:19 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:43664 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751682AbeCWOWS (ORCPT ); Fri, 23 Mar 2018 10:22:18 -0400 Received: by mail-qk0-f195.google.com with SMTP id g184so13036913qkd.10; Fri, 23 Mar 2018 07:22:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=PjUfM4tdQevx8QUni/mAnXHAGcwjz8uDpS/hbYCIxLE=; b=s2l8I2webWSpgYFpH/KQZ4dz9D4fzBhl4JCHiezmrEDqOxnTszoidQ/0g/Ao/dxDVz fGKmLRti545l9/lDbPxA9ZFbNI5NrInmQpVqYPKrV3TvUp4dfFDnROwcU1VlOU9X2bwW yrkNOxjWAsTgpvn1hIF+gLcm3/sJ8/fIQPqAdP5lnjlZr40cAkW3UapcxjYrKRt2jjVn eYTUydvlfrFCHKsSVGlO0lRGxvt/9VDy7arVCxciJybooKmBobPS3PSG1HBEqee8rbau ZZbHyPLX8qb75siv0RE1a3JnJLNNJXdfouclREKfPsYM69CdLJgyzJMcX0MstIeL6Ztt q3VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=PjUfM4tdQevx8QUni/mAnXHAGcwjz8uDpS/hbYCIxLE=; b=V3ItOsCTc9yoGBBQrJbvs/F6hv2WYJEW+GB6RbJvuvgFZGJ1GogR2P5U5NL+/w1kOb d+4oskwHBTkq+mQZV6denT0U0ey32GFrU0iPunYCMg48WmXAftJ7Cbp5Sv55rodv3ZJv wfcSePAv5WUxFZtS9Hwr2OuYbqxMqMW5DDDvaqSEjo3jBlT/zIRR8+nDccldpPlGmgT8 O0yKG/RoHajdHPkEgCNkKheqhFRx/axvMFcokRA6ZcRCY/1u5CytDe41jsYuIiJjSspF IW4b4s2od4jCWtl6MoXktgSydcMWo2s6bTx33VCV8rgoCRFiBr1IRLbN1Sytnsnr6CIL ubTg== X-Gm-Message-State: AElRT7EbCbWbk3WYs3MTKpxSiryHdYsNZtbnCUqBy10AQa9bXxEPtuWc 0wxVUQ32mf+oV7Cn/LE4wco= X-Google-Smtp-Source: AG47ELsaPQLTDXr01QtN0JjMe6/khvUarNlZV27ynMYqHoueKM36OghoF2SlZYhMmFyUMm/Ik8FC2Q== X-Received: by 10.55.91.4 with SMTP id p4mr40755208qkb.82.1521814937608; Fri, 23 Mar 2018 07:22:17 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id s47sm6673614qta.38.2018.03.23.07.22.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Mar 2018 07:22:16 -0700 (PDT) From: John Syne X-Google-Original-From: John Syne Date: Fri, 23 Mar 2018 11:22:10 -0300 To: John Syne , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Greg Kroah-Hartman , linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Barry Song <21cnbao@gmail.com> Cc: daniel.baluta@nxp.com, linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/8] staging:iio:ade7854: Fix error handling on read/write Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180223 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 Fixes: correctly handle errors on the read and write operation for I2C The original code does not correctly handle the error related to I2C read and write. This patch fixes the error handling related to all read/write functions for I2C. Signed-off-by: John Syne Signed-off-by: Rodrigo Siqueira --- Changes in v3: - Clarify authorship - Add Fixes tag in the commit message drivers/staging/iio/meter/ade7854-i2c.c | 24 ++++++++++++------------ drivers/staging/iio/meter/ade7854.c | 10 +++++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/staging/iio/meter/ade7854-i2c.c b/drivers/staging/iio/meter/ade7854-i2c.c index 317e4f0d8176..4437f1e33261 100644 --- a/drivers/staging/iio/meter/ade7854-i2c.c +++ b/drivers/staging/iio/meter/ade7854-i2c.c @@ -31,7 +31,7 @@ static int ade7854_i2c_write_reg_8(struct device *dev, ret = i2c_master_send(st->i2c, st->tx, 3); mutex_unlock(&st->buf_lock); - return ret; + return ret < 0 ? ret : 0; } static int ade7854_i2c_write_reg_16(struct device *dev, @@ -51,7 +51,7 @@ static int ade7854_i2c_write_reg_16(struct device *dev, ret = i2c_master_send(st->i2c, st->tx, 4); mutex_unlock(&st->buf_lock); - return ret; + return ret < 0 ? ret : 0; } static int ade7854_i2c_write_reg_24(struct device *dev, @@ -72,7 +72,7 @@ static int ade7854_i2c_write_reg_24(struct device *dev, ret = i2c_master_send(st->i2c, st->tx, 5); mutex_unlock(&st->buf_lock); - return ret; + return ret < 0 ? ret : 0; } static int ade7854_i2c_write_reg_32(struct device *dev, @@ -94,7 +94,7 @@ static int ade7854_i2c_write_reg_32(struct device *dev, ret = i2c_master_send(st->i2c, st->tx, 6); mutex_unlock(&st->buf_lock); - return ret; + return ret < 0 ? ret : 0; } static int ade7854_i2c_read_reg_8(struct device *dev, @@ -110,11 +110,11 @@ static int ade7854_i2c_read_reg_8(struct device *dev, st->tx[1] = reg_address & 0xFF; ret = i2c_master_send(st->i2c, st->tx, 2); - if (ret) + if (ret < 0) goto out; ret = i2c_master_recv(st->i2c, st->rx, 1); - if (ret) + if (ret < 0) goto out; *val = st->rx[0]; @@ -136,11 +136,11 @@ static int ade7854_i2c_read_reg_16(struct device *dev, st->tx[1] = reg_address & 0xFF; ret = i2c_master_send(st->i2c, st->tx, 2); - if (ret) + if (ret < 0) goto out; ret = i2c_master_recv(st->i2c, st->rx, 2); - if (ret) + if (ret < 0) goto out; *val = (st->rx[0] << 8) | st->rx[1]; @@ -162,11 +162,11 @@ static int ade7854_i2c_read_reg_24(struct device *dev, st->tx[1] = reg_address & 0xFF; ret = i2c_master_send(st->i2c, st->tx, 2); - if (ret) + if (ret < 0) goto out; ret = i2c_master_recv(st->i2c, st->rx, 3); - if (ret) + if (ret < 0) goto out; *val = (st->rx[0] << 16) | (st->rx[1] << 8) | st->rx[2]; @@ -188,11 +188,11 @@ static int ade7854_i2c_read_reg_32(struct device *dev, st->tx[1] = reg_address & 0xFF; ret = i2c_master_send(st->i2c, st->tx, 2); - if (ret) + if (ret < 0) goto out; ret = i2c_master_recv(st->i2c, st->rx, 3); - if (ret) + if (ret < 0) goto out; *val = (st->rx[0] << 24) | (st->rx[1] << 16) | diff --git a/drivers/staging/iio/meter/ade7854.c b/drivers/staging/iio/meter/ade7854.c index 90d07cdca4b8..0193ae3aae29 100644 --- a/drivers/staging/iio/meter/ade7854.c +++ b/drivers/staging/iio/meter/ade7854.c @@ -33,7 +33,7 @@ static ssize_t ade7854_read_8bit(struct device *dev, struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); ret = st->read_reg_8(dev, this_attr->address, &val); - if (ret) + if (ret < 0) return ret; return sprintf(buf, "%u\n", val); @@ -50,7 +50,7 @@ static ssize_t ade7854_read_16bit(struct device *dev, struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); ret = st->read_reg_16(dev, this_attr->address, &val); - if (ret) + if (ret < 0) return ret; return sprintf(buf, "%u\n", val); @@ -67,7 +67,7 @@ static ssize_t ade7854_read_24bit(struct device *dev, struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); ret = st->read_reg_24(dev, this_attr->address, &val); - if (ret) + if (ret < 0) return ret; return sprintf(buf, "%u\n", val); @@ -84,7 +84,7 @@ static ssize_t ade7854_read_32bit(struct device *dev, struct ade7854_state *st = iio_priv(indio_dev); ret = st->read_reg_32(dev, this_attr->address, &val); - if (ret) + if (ret < 0) return ret; return sprintf(buf, "%u\n", val); @@ -416,7 +416,7 @@ static int ade7854_set_irq(struct device *dev, bool enable) u32 irqen; ret = st->read_reg_32(dev, ADE7854_MASK0, &irqen); - if (ret) + if (ret < 0) return ret; if (enable)