From patchwork Wed Mar 27 21:12:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 1067437 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 44V11v5p60z9sQt for ; Thu, 28 Mar 2019 08:13:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726176AbfC0VNV (ORCPT ); Wed, 27 Mar 2019 17:13:21 -0400 Received: from sauhun.de ([88.99.104.3]:38958 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726059AbfC0VNV (ORCPT ); Wed, 27 Mar 2019 17:13:21 -0400 Received: from localhost (p5486CE6B.dip0.t-ipconnect.de [84.134.206.107]) by pokefinder.org (Postfix) with ESMTPSA id E72342E35A2; Wed, 27 Mar 2019 22:13:18 +0100 (CET) From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Frederic Weisbecker , Peter Zijlstra , Ingo Molnar , Wolfram Sang Subject: [RFC PATCH] i2c: remove use of in_atomic() Date: Wed, 27 Mar 2019 22:12:56 +0100 Message-Id: <20190327211256.17232-1-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Commit cea443a81c9c ("i2c: Support i2c_transfer in atomic contexts") added in_atomic() to the I2C core. However, the use of in_atomic() outside of core kernel code is discouraged and was already[1] when this code was added in early 2008. The above commit was a preparation for b7a3670131c7 ("i2c-pxa: Add polling transfer"). Its commit message says explicitly it was added "for cases where I2C transactions have to occur at times interrups are disabled". So, the intention was 'disabled interrupts'. This matches the use cases for atomic I2C transfers I have seen so far: very late communication (mostly to a PMIC) to powerdown or reboot the system. For those cases, interrupts are disabled then. It doesn't seem that in_atomic() adds value. Note that only ~10 out of ~120 bus master drivers support atomic transfers, mostly by polling always when no irq is supplied. A generic I2C client driver cannot assume support for atomic transfers. This is currently a platform-dependent corner case. The I2C core will soon gain an extra callback into bus drivers especially for atomic transfers to make them more generic. The code deciding which transfer to use (atomic/non-atomic) should mimic the behaviour which locking to use (trylock/lock). Because I don't want to add more in_atomic() to the I2C core, this patch simply removes it. [1] https://lwn.net/Articles/274695/ Signed-off-by: Wolfram Sang --- So, I had to dive into this in_atomic() topic and this is what I concluded. I don't see any reasonable constellation where this could cause a regression, but I am all open for missing something and being pointed to it. This is why the patch is RFC. I'd really welcome comments. Thanks! drivers/i2c/i2c-core-base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 38af18645133..943bebeec3ed 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1946,7 +1946,7 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) * one (discarding status on the second message) or errno * (discarding status on the first one). */ - if (in_atomic() || irqs_disabled()) { + if (irqs_disabled()) { ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT); if (!ret) /* I2C activity is ongoing. */