Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5082189ybh; Wed, 7 Aug 2019 00:05:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxgkfZPyX8dfRO5Libdq92nH7aIvuwcLjepYVYZvc1BZazruWBXIQwATt9S1V7yHQCrtJ75 X-Received: by 2002:a62:187:: with SMTP id 129mr7929353pfb.128.1565161524371; Wed, 07 Aug 2019 00:05:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565161524; cv=none; d=google.com; s=arc-20160816; b=O5WbJ5K3QNMhYLpWwdql1c9ptf+qQunidADCdHim/kjUVN5UhwJvAVWzeuTs5IVneN 9HQUpE0YH8WqqNRE0HCDjCZ1DmO9onhc4CbWhNVjQAhzb1ht10Vg9mSIejgVGz++79+O Dj9CjLkKtSXT7ZjCLxH1fwaZXkYAdjSDJHjsppu2eLJ6mwGge8h7g+OXXgaupWuSO1wC lZmZpBuKcdDl4diFu5B36R7bDWXwuDNfHqPIolhDsLpRX9T+XbLHNhSOhK+jLr4hbmFz CG0ZKmmsodwtxzSYcgd+b+sDG3lWRD9FEgL87p0eBXCA2N+Yog+i6du7cXSPM2rfpk4/ ui2Q== 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:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ESF14Tj/Iz5q41yFZf19ms0Um+JiDKtApGa5yGw41/8=; b=FNE5xOALioTkgZwu3/27SYINLDlKNuotSmtlKyRJaI1wXVqa+9/FrCB8ZKNx9/enE0 kmZZM+ERZMsBqbb1fBluyqWMmrl23Dytw+eGssZyr3gGmagoQ6Ej8LdSljApH3lNwNKv DabCOHc3r5Zq2W5mVq/HYE1qC7qQUCV5/lr1MUWTnc7dGBGXBOWAjGREdV1egBu+H5W5 bW4WJPe7JWvUqyO2+j1DFsWwdqT+2+BnaOOyHErtRk36Qk+OPhD+IyE78raykL34a5Wi 5Z4h04RGQmfQxF8C73tXkeltTbXxHdYNN7QZqlZ2S8LFYesmcgHDaBR29q4Wg/Mm7Lrw 1dHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gncW6+eU; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j37si72908103plb.58.2019.08.07.00.05.06; Wed, 07 Aug 2019 00:05:24 -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=@gmail.com header.s=20161025 header.b=gncW6+eU; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727281AbfHGHEc (ORCPT + 99 others); Wed, 7 Aug 2019 03:04:32 -0400 Received: from mail-yb1-f195.google.com ([209.85.219.195]:44378 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727173AbfHGHEb (ORCPT ); Wed, 7 Aug 2019 03:04:31 -0400 Received: by mail-yb1-f195.google.com with SMTP id q203so733034ybg.11; Wed, 07 Aug 2019 00:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=ESF14Tj/Iz5q41yFZf19ms0Um+JiDKtApGa5yGw41/8=; b=gncW6+eU9mpF8r/ERuH+qecrfewjtuxt1iR6lwRBsa0/sgqMRTJgLXgSXizexNUPZA PiUh+rzf1sOxvnpDyRxEk162QXSsIszHrg15j3E5hT3/S05uckMK8pH2NFyDi2NwFiEf UdEI8WfWLCy71AFzmh3QMRIbFIrsaSX6SUeq6zeaDWwgB8tMBAjB1LypgMR5VBq5T0jn 0Palw89cRWLatrWR1toQUa3vc2S2STVoR7y/UEXDHoKM6HoFOeRzJCB1w90TmL27ql23 AANxYTMrbnVvu7ZwNzvAaT2C7DV+RuLOEkhRLdDfrOF/iMy7p92lwe4y3xomL0jAClEC dcqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=ESF14Tj/Iz5q41yFZf19ms0Um+JiDKtApGa5yGw41/8=; b=TZh3tMdjzyKblzF2ZLkGy/TcKkZnnkl5jeFCY8C/fGDM152Xe35UEvsn9U6ORgmNK7 FT0B7ed4c0Il57tYjDbMePWl10gk6lckSSH8q/qhescGPhhBpItyQ4V1LPDK8b/NjM9d Ip30SKkGpD+tSGakZ5158GiOeWvxkvLuqQQNWYwYvnMm0rkSXPoLfdlwG4LSTO3b4UuA /w57BoRzpU07sjLxGmTgt/TptdaY0GCHI5UjZI1ocC3JcUGTO3mdMWSebPNuiQNmb9ow gXrlF5viKwAvQ/AUPXb2CpK2Nnn7wcjCtS5emtXf2SuRe8VxAtCiCIbrLXm/hxZiJ64j gdFw== X-Gm-Message-State: APjAAAWy0zEdPA+85uxbCjsctjALfWdhPbBO4Z/NQkSolElb+QBSqBFn SPGFZpCailkRbdEmDoaJ4iJ24WFE1s0OYn0Uy4o= X-Received: by 2002:a25:4542:: with SMTP id s63mr4994355yba.395.1565161470670; Wed, 07 Aug 2019 00:04:30 -0700 (PDT) MIME-Version: 1.0 References: <20190805123134.23199-1-huangfq.daxian@gmail.com> <20190807065111.GA17104@localhost.localdomain> In-Reply-To: <20190807065111.GA17104@localhost.localdomain> From: Fuqian Huang Date: Wed, 7 Aug 2019 15:04:19 +0800 Message-ID: Subject: Re: [PATCH] i2c: avoid sleep in IRQ context To: "Adamski, Krzysztof (Nokia - PL/Wroclaw)" , linux-i2c@vger.kernel.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adamski, Krzysztof (Nokia - PL/Wroclaw) =E6=96=BC 2019=E5=B9=B48=E6=9C=887=E6=97=A5=E9=80=B1=E4=B8=89 =E4=B8=8B=E5= =8D=882:51=E5=AF=AB=E9=81=93=EF=BC=9A > > On Mon, Aug 05, 2019 at 08:31:34PM +0800, Fuqian Huang wrote: > >i2c_pxa_handler -> i2c_pxa_irq_txempty -> > >i2c_pxa_reset -> i2c_pxa_set_slave -> i2c_pxa_wait_slave > > > >As i2c_pxa_handler is an interrupt handler, it will finally > >calls i2c_pxa_wait_slave which calls msleep. > > > >Add in_interrupt check before msleep to avoid sleep > >in IRQ context. > > > >Signed-off-by: Fuqian Huang > >--- > > drivers/i2c/busses/i2c-pxa.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > >diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c > >index 2c3c3d6935c0..b35a0e8efcb2 100644 > >--- a/drivers/i2c/busses/i2c-pxa.c > >+++ b/drivers/i2c/busses/i2c-pxa.c > >@@ -443,6 +443,8 @@ static int i2c_pxa_wait_slave(struct pxa_i2c *i2c) > > > > show_state(i2c); > > > >+ if (in_interrupt()) > >+ return 0; > > Sleeping in irq context is not good indeed but if you just return here, > an error will be printed from i2c_pxa_set_slave() and cleanup of ICR > will be skipped. Is that ok? Sorry for this mistake. Maybe it should be changed to mdelay. And the new patch is like this: if (in_interrupt()) { mdelay(1); } else { msleep(1); } > > > while (time_before(jiffies, timeout)) { > > if (i2c_debug > 1) > > dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=3D%08x, ICR= =3D%08x, IBMR=3D%02x\n", >