From patchwork Thu Apr 25 14:19:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 1090867 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sang-engineering.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44qfTZ2Bd8z9sBp for ; Fri, 26 Apr 2019 00:20:02 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726891AbfDYOT7 (ORCPT ); Thu, 25 Apr 2019 10:19:59 -0400 Received: from sauhun.de ([88.99.104.3]:45574 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727188AbfDYOT7 (ORCPT ); Thu, 25 Apr 2019 10:19:59 -0400 Received: from localhost (p5486CE26.dip0.t-ipconnect.de [84.134.206.38]) by pokefinder.org (Postfix) with ESMTPSA id 3C4433E43BB; Thu, 25 Apr 2019 16:19:57 +0200 (CEST) From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: Peter Rosin , linux-renesas-soc@vger.kernel.org, Hans de Goede , Wolfram Sang Subject: [PATCH v2 2/2] i2c: core: apply 'is_suspended' check for SMBus, too Date: Thu, 25 Apr 2019 16:19:48 +0200 Message-Id: <20190425141948.29255-3-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190425141948.29255-1-wsa+renesas@sang-engineering.com> References: <20190425141948.29255-1-wsa+renesas@sang-engineering.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org We checked I2C calls, but not SMBus. Refactor the helper to an inline function and use it for both, I2C and SMBus. Fixes: 9ac6cb5fbb17 ("i2c: add suspended flag and accessors for i2c adapters") Reported-by: Peter Rosin Signed-off-by: Wolfram Sang Reviewed-by: Simon Horman --- drivers/i2c/i2c-core-base.c | 9 ++++----- drivers/i2c/i2c-core-smbus.c | 4 ++++ drivers/i2c/i2c-core.h | 11 +++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index f8e85983cb04..f7ae416f1e08 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1867,11 +1867,10 @@ int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) if (WARN_ON(!msgs || num < 1)) return -EINVAL; - if (test_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags)) { - if (!test_and_set_bit(I2C_ALF_SUSPEND_REPORTED, &adap->locked_flags)) - dev_WARN(&adap->dev, "Transfer while suspended\n"); - return -ESHUTDOWN; - } + + ret = __i2c_check_suspended(adap); + if (ret) + return ret; if (adap->quirks && i2c_check_for_quirks(adap, msgs, num)) return -EOPNOTSUPP; diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c index fdb0fb9fb9aa..788d42f2aad9 100644 --- a/drivers/i2c/i2c-core-smbus.c +++ b/drivers/i2c/i2c-core-smbus.c @@ -555,6 +555,10 @@ s32 __i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, int try; s32 res; + res = __i2c_check_suspended(adapter); + if (res) + return res; + /* If enabled, the following two tracepoints are conditional on * read_write and protocol. */ diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h index f9d0c417b5a5..c88cfef81343 100644 --- a/drivers/i2c/i2c-core.h +++ b/drivers/i2c/i2c-core.h @@ -54,6 +54,17 @@ static inline int __i2c_lock_bus_helper(struct i2c_adapter *adap) return ret; } +static inline int __i2c_check_suspended(struct i2c_adapter *adap) +{ + if (test_bit(I2C_ALF_IS_SUSPENDED, &adap->locked_flags)) { + if (!test_and_set_bit(I2C_ALF_SUSPEND_REPORTED, &adap->locked_flags)) + dev_WARN(&adap->dev, "Transfer while suspended\n"); + return -ESHUTDOWN; + } + + return 0; +} + #ifdef CONFIG_ACPI const struct acpi_device_id * i2c_acpi_match_device(const struct acpi_device_id *matches,