From patchwork Sat Apr 1 17:54:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 746051 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vwQxF3kxSz9rxm for ; Sun, 2 Apr 2017 03:54:41 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="eUFaLVCk"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751932AbdDARyj (ORCPT ); Sat, 1 Apr 2017 13:54:39 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:32864 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751798AbdDARyi (ORCPT ); Sat, 1 Apr 2017 13:54:38 -0400 Received: by mail-pg0-f66.google.com with SMTP id 79so22758812pgf.0; Sat, 01 Apr 2017 10:54:38 -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:mime-version:content-disposition :user-agent; bh=4L/rmRYGaCrgmF7Gxdm2UkQYLKesuOUcwM03QevbCKY=; b=eUFaLVCksRSyxKAKiqoYkZB3oQM6/EE5noj55h+cqGh6yZ10IeOwUWyXs6eAQBkC45 7Bnpfbg/VfiE7HR3vUVYdDZbo599DDk5Nkh5fJhEdX2ZuXopVA66jm9zlrO3nd3RIfxs gR+r6GoWvmXzwAXsdDNH4QGbl0vLDnlBq1I+EzaLtmj0tZxhp+Wc/cYICnXzDR0lSAjq Gd3LoZAL7pbDkDVdsnrKVNZQyz2+9AXHU8K/XsG3/CXEoW5PDYA1M3bLwvKitKZRdp/m ZJLt4hpTavlHgjNSFpEr5wdnv9lwQiZQRUSEhSgRh33MilRmUeORD+jyxzw9E1KtqF44 tQvw== 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:mime-version :content-disposition:user-agent; bh=4L/rmRYGaCrgmF7Gxdm2UkQYLKesuOUcwM03QevbCKY=; b=ZtsMY8pfKJqLXXaLfqEqrxebeDNbOHD/aqgh9MZgDBnJiLBA7mZytm6qEIgetTheIZ NKzISFKJYtB9ExsesdsIgVDpNJ9bvizKCAyU6boXEEFlj78am/a3cbzknuNIdUTuO5T4 HXvxUVIaLXNtilg5pZgkix+N0RZVUdfXlEC0r/iV/or/wJi1qAU5iTtct4B7+ysv6Ge7 2xnknjvy6ZeX2jinbVbU3E7VLQAJwZfsr1C4O36gFaGPS9RgGran1EqA/cqrirju4W0K TWDpggw+rnY3m4EovANRL+9g5Ht0gaLMk+n8Ilu+isdoAXZztwh/hdHL2t3XCmEmYuOI 7Y2Q== X-Gm-Message-State: AFeK/H3izG3Y3z36Vjf8ZOmoHn5Gtcd/Qu3c1EcJPOqKpFA6JrLj78b/X7h24DhT8yjVNQ== X-Received: by 10.98.72.147 with SMTP id q19mr8559565pfi.253.1491069277790; Sat, 01 Apr 2017 10:54:37 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1311:6969:12b1:751a:a966]) by smtp.gmail.com with ESMTPSA id u75sm17229644pgc.31.2017.04.01.10.54.37 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sat, 01 Apr 2017 10:54:37 -0700 (PDT) Date: Sat, 1 Apr 2017 10:54:35 -0700 From: Dmitry Torokhov To: Wolfram Sang Cc: Jean Delvare , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] i2c: make sure i2c_master_send/recv return negative error codes Message-ID: <20170401175435.GA12354@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org There is theoretical possibility that i2c_master_send() and i2c_master_recv() may return non-negative result on error: we pass return values from i2c_xfer() unmodified to the caller, unless we transferred exactly 1 message. Let's ensure we always return negative on error. Signed-off-by: Dmitry Torokhov --- drivers/i2c/i2c-core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 6efeba42d10b..34b0482333f4 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -2835,7 +2835,10 @@ int i2c_master_send(const struct i2c_client *client, const void *buf, int count) * If everything went ok (i.e. 1 msg transmitted), return #bytes * transmitted, else error code. */ - return (ret == 1) ? count : ret; + if (likely(ret == 1)) + return count; + + return ret < 0 ? ret : -EIO; } EXPORT_SYMBOL(i2c_master_send); @@ -2865,7 +2868,10 @@ int i2c_master_recv(const struct i2c_client *client, void *buf, int count) * If everything went ok (i.e. 1 msg received), return #bytes received, * else error code. */ - return (ret == 1) ? count : ret; + if (likely(ret == 1)) + return count; + + return ret < 0 ? ret : -EIO; } EXPORT_SYMBOL(i2c_master_recv);