Received: by 10.213.65.68 with SMTP id h4csp3076511imn; Mon, 9 Apr 2018 14:00:34 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/dBaHLIBY19q4A5HLdWVlYGLv7+60VmgPo9DXzeuxy9kZmwmFkSun8QRzj3IaltCdZHVow X-Received: by 2002:a17:902:822:: with SMTP id 31-v6mr41320396plk.200.1523307634450; Mon, 09 Apr 2018 14:00:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523307634; cv=none; d=google.com; s=arc-20160816; b=pUQ+VYrldbkZbmr7Mu1MRdjGP4/yACJRgyJHudgM6WP4vmd7E7+XUQ3Pd2LdfDJGSR ZbHJYoecnIOS3pXDCAMMLCstxNy+RsGTLbhkJ4LO0DpSDnh3B7Vf3CcuYR5bWPlvGl6E UTDmfgBxQ1do0gYMezBH75ByHozsP29At0+R1DTZO8ObMQyE9cWy0y9BpDM4DsMTlvRc f8jqA029Wsp01pkUnLB9xP3zWvhnthspcmNOCRzatgBGSWrOX5ehARWF+OAiVxSurMcQ v0enRZWzdgvn0Xad4SkEIRv8KhheRLSeE839eNBUCNkQJxvGdiawnLtk21OVoB/ewwhR +LEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=qnbc27kLt4eIRPLzTHyku+EKlM4aUovnPs8aNskljtU=; b=C8wRe/FrcTQ4UDVF7REcGcyrhwype+2MEJiDwKerTLoaO5eSAvk2LBtiotB/0w6mg9 qvIvztgoVYjagRn+RPkh5BAlJvY1lAW7+kuvyUcdN/4VuTQtXWv2R8Y/uecXm1SVXsYg S4jczOkLsR5eUxaMGv8DcZxaD9pzuIkaC5doIPdXJ/s6ea+ji3FeAU3dSuMlK4waXGfa YH893ix1oqfImxNOcmpZu0bPsTfh+ahbbC7GlQ6Ol3EcUEvQKlB30gRGh/IImiJvEmir uwewC6Qj1Wfj0Q7CUYsBAJPQoYB2iHWfad1Bcs/oBLNAq1vt2LccVyTFFB5CINjRyWxu usMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Des73ZRV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w10si681622pgr.660.2018.04.09.13.59.56; Mon, 09 Apr 2018 14:00:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Des73ZRV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754366AbeDIU5B (ORCPT + 99 others); Mon, 9 Apr 2018 16:57:01 -0400 Received: from lelnx194.ext.ti.com ([198.47.27.80]:31846 "EHLO lelnx194.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754076AbeDIU47 (ORCPT ); Mon, 9 Apr 2018 16:56:59 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id w39Kurrt026658; Mon, 9 Apr 2018 15:56:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1523307413; bh=vAOZy/ciyAftTu+4d2GskwKB19RipV0E4I7H6IvPbHI=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=Des73ZRVG24dv5fyGl+a5EUFlX8Rq1nUi96MQ2pOgGmhm++U9X9QTNFlWJpd9WxlH zFu7vflX4905qJl9vrGAdJkegFiGCfG6FPP7xVaYQjVs33AKJvsFf6llnT1A8r61uh xsAW64etoaaXW5SaidiVEWd85g71QjaqKtWwVQ/U= Received: from DFLE114.ent.ti.com (dfle114.ent.ti.com [10.64.6.35]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w39KuriS015290; Mon, 9 Apr 2018 15:56:53 -0500 Received: from DFLE102.ent.ti.com (10.64.6.23) by DFLE114.ent.ti.com (10.64.6.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Mon, 9 Apr 2018 15:56:52 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE102.ent.ti.com (10.64.6.23) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Mon, 9 Apr 2018 15:56:52 -0500 Received: from [128.247.59.147] (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w39Kuq32031501; Mon, 9 Apr 2018 15:56:52 -0500 Subject: Re: [PATCH 1/2] i2c: sprd: Prevent i2c accesses after suspend is called To: Baolin Wang , CC: , , References: <99031524fa147e72451d26f54b24f36093c0d3fa.1523255712.git.baolin.wang@linaro.org> From: Grygorii Strashko Message-ID: <557074eb-e988-8ff5-bec0-c85bb9dcb8ec@ti.com> Date: Mon, 9 Apr 2018 15:56:52 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <99031524fa147e72451d26f54b24f36093c0d3fa.1523255712.git.baolin.wang@linaro.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/09/2018 01:40 AM, Baolin Wang wrote: > Add one flag to indicate if the i2c controller has been in suspend state, > which can prevent i2c accesses after i2c controller is suspended following > system suspend. This usually indicates some bigger problem - there should be no i2c access to the I2C driver once it's suspended. But if happens - it means suspend dependencies between drivers are broken or there some scheduling primitives are not disabled properly. (possible sources - kthreads, delayed works, timers or even threaded irqs) > > Signed-off-by: Baolin Wang > --- > drivers/i2c/busses/i2c-sprd.c | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/drivers/i2c/busses/i2c-sprd.c b/drivers/i2c/busses/i2c-sprd.c > index 25fcc3c..2fdad63 100644 > --- a/drivers/i2c/busses/i2c-sprd.c > +++ b/drivers/i2c/busses/i2c-sprd.c > @@ -86,6 +86,7 @@ struct sprd_i2c { > u32 count; > int irq; > int err; > + bool is_suspended; > }; > > static void sprd_i2c_set_count(struct sprd_i2c *i2c_dev, u32 count) > @@ -283,6 +284,9 @@ static int sprd_i2c_master_xfer(struct i2c_adapter *i2c_adap, > struct sprd_i2c *i2c_dev = i2c_adap->algo_data; > int im, ret; > > + if (i2c_dev->is_suspended) > + return -EBUSY; > + > ret = pm_runtime_get_sync(i2c_dev->dev); > if (ret < 0) > return ret; > @@ -586,11 +590,23 @@ static int sprd_i2c_remove(struct platform_device *pdev) > > static int __maybe_unused sprd_i2c_suspend_noirq(struct device *pdev) > { > + struct sprd_i2c *i2c_dev = dev_get_drvdata(pdev); > + > + i2c_lock_adapter(&i2c_dev->adap); > + i2c_dev->is_suspended = true; > + i2c_unlock_adapter(&i2c_dev->adap); > + > return pm_runtime_force_suspend(pdev); > } > > static int __maybe_unused sprd_i2c_resume_noirq(struct device *pdev) > { > + struct sprd_i2c *i2c_dev = dev_get_drvdata(pdev); > + > + i2c_lock_adapter(&i2c_dev->adap); > + i2c_dev->is_suspended = false; > + i2c_unlock_adapter(&i2c_dev->adap); > + > return pm_runtime_force_resume(pdev); > } > > -- regards, -grygorii