From patchwork Fri Mar 16 22:48:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 10290417 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 D6069602BD for ; Fri, 16 Mar 2018 22:48:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0C20290DA for ; Fri, 16 Mar 2018 22:48:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3516290DC; Fri, 16 Mar 2018 22:48:42 +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 98632290DA for ; Fri, 16 Mar 2018 22:48:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751982AbeCPWsk (ORCPT ); Fri, 16 Mar 2018 18:48:40 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:33908 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751969AbeCPWsj (ORCPT ); Fri, 16 Mar 2018 18:48:39 -0400 Received: by mail-qk0-f194.google.com with SMTP id z184so12759522qkc.1; Fri, 16 Mar 2018 15:48:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=re8SKRvbmxmjBoGhFNGu9EtCWfEDcjn/Xj7tMOpR83Y=; b=JOHOQkEw2O75ZjTj6v+cSomia2vQCn5Z+okktUrE91V+Y+sXohdvll65MWVZrlstlP VzSD2vD4ab5W2G9UVHamfFV/LXG4K9q/hhKNtDNryeImEoYD9BBeGIBVjsxYyJCniSmB 6q5s+MNWBxzqs+sNOdNUotJisKiKhmhuUfKk13yBG83xGZ35zi3mTgYfhxaBX8NhtGaa r1HYFVQFmyB/y6gpekWYVlDrgxzjrj64GjcCAEbdUGcjhMkFrxZzd8f79I3rw/aqwQB/ /j+9ewCXiFaqv6Qw8/bhTdmqzPcUoFa7IOOZGigAGrP0mD6GUYtC7pVrNiigeWdRitIr L6Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=re8SKRvbmxmjBoGhFNGu9EtCWfEDcjn/Xj7tMOpR83Y=; b=fqGdJjSNwf9VKIbw8hK2quis0wSQMFN6US5yW2DUr/beoNKLqSauQqAZgYje5DxRI4 RGlayOmfeCiAgMzoxTdmpU+gTJTASoCNyJkR0eoaVgB2VdUrMFtvkqbV7LiXAwJ/lzAb aJgHVqm2Pq/fwa4kneQGEzY6Gun4wcjOXKXPUnKgoiSHyICcX0dp8ZGv7g4Y54ml64B9 Dm8UlLRR66tVpLl8LFIOwcBAIwoelHaD7cI8Bu4wxdJhzOsbCO40TrZ/mPa1pePxOk2/ +XT7E/HGvoeqaXwNkZx5HauivwvOvKPSzCg4g1EQt1copcxoQsQbPbVc1eOpQxUZYIKA /llg== X-Gm-Message-State: AElRT7Fm4gMLZfgcmCVfXQNsNfnT3sSc11L/1MDI07+0vIK/3yhSdLB2 qMNK8qPJBBWemynK40xD41U= X-Google-Smtp-Source: AG47ELu6RWiEKdPHNoCngrSdKiq87xjz6cK5ncS4ffY0C/6oKmFH0lew5iokskuisdQp3kiHLONbgA== X-Received: by 10.55.170.67 with SMTP id t64mr5150265qke.54.1521240518911; Fri, 16 Mar 2018 15:48:38 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id d198sm5916185qkg.91.2018.03.16.15.48.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 16 Mar 2018 15:48:38 -0700 (PDT) Date: Fri, 16 Mar 2018 19:48:33 -0300 From: Rodrigo Siqueira 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 v2 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 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. This patch is an adaptation of the John Syne patches. Signed-off-by: Rodrigo Siqueira Signed-off-by: John Syne --- 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)