Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751507AbdLSQSi (ORCPT ); Tue, 19 Dec 2017 11:18:38 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:48243 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750892AbdLSQSg (ORCPT ); Tue, 19 Dec 2017 11:18:36 -0500 From: Fabien DESSENNE To: Jia-Ju Bai , "mchehab@kernel.org" , Benjamin GAIGNARD , "hverkuil@xs4all.nl" CC: "linux-media@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH V3 1/2] bdisp: Fix a possible sleep-in-atomic bug in bdisp_hw_reset Thread-Topic: [PATCH V3 1/2] bdisp: Fix a possible sleep-in-atomic bug in bdisp_hw_reset Thread-Index: AQHTeND05xJk8ccvdUKoQ4CXY5gWnaNKx54A Date: Tue, 19 Dec 2017 16:18:30 +0000 Message-ID: References: <1513691849-6378-1-git-send-email-baijiaju1990@gmail.com> In-Reply-To: <1513691849-6378-1-git-send-email-baijiaju1990@gmail.com> Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.75.127.44] Content-Type: text/plain; charset="utf-8" Content-ID: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-12-19_08:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by nfs id vBJGIgN0010779 Content-Length: 3157 Lines: 118 Hi, It's almost good! You have to fix these checkpatch Warning/Check: WARNING: Block comments use a trailing */ on a separate line #36: FILE: drivers/media/platform/sti/bdisp/bdisp-hw.c:383: +     * needing any delays */ CHECK: Alignment should match open parenthesis #38: FILE: drivers/media/platform/sti/bdisp/bdisp-hw.c:385: +    if (readl_poll_timeout_atomic(bdisp->regs + BLT_STA1, tmp, +        (tmp & BLT_STA1_IDLE), POLL_RST_DELAY_MS, From kernel documentation in the "Posting patches" chapter: "You should always run patches through scripts/checkpatch.pl and address the complaints it comes up with." And, please use the --strict option Thanks for your understanding. BR Fabien On 19/12/17 14:57, Jia-Ju Bai wrote: > The driver may sleep under a spinlock. > The function call path is: > bdisp_device_run (acquire the spinlock) > bdisp_hw_reset > msleep --> may sleep > > To fix it, readl_poll_timeout_atomic is used to replace msleep. > > This bug is found by my static analysis tool(DSAC) and > checked by my code review. > > Signed-off-by: Jia-Ju Bai > --- > drivers/media/platform/sti/bdisp/bdisp-hw.c | 23 ++++++++++++----------- > 1 file changed, 12 insertions(+), 11 deletions(-) > > diff --git a/drivers/media/platform/sti/bdisp/bdisp-hw.c b/drivers/media/platform/sti/bdisp/bdisp-hw.c > index b7892f3..b63d9c9 100644 > --- a/drivers/media/platform/sti/bdisp/bdisp-hw.c > +++ b/drivers/media/platform/sti/bdisp/bdisp-hw.c > @@ -4,7 +4,7 @@ > * License terms: GNU General Public License (GPL), version 2 > */ > > -#include > +#include > > #include "bdisp.h" > #include "bdisp-filter.h" > @@ -15,7 +15,7 @@ > > /* Reset & boot poll config */ > #define POLL_RST_MAX 50 > -#define POLL_RST_DELAY_MS 20 > +#define POLL_RST_DELAY_US 20000 > > enum bdisp_target_plan { > BDISP_RGB, > @@ -366,7 +366,7 @@ struct bdisp_filter_addr { > */ > int bdisp_hw_reset(struct bdisp_dev *bdisp) > { > - unsigned int i; > + u32 tmp; > > dev_dbg(bdisp->dev, "%s\n", __func__); > > @@ -378,16 +378,17 @@ int bdisp_hw_reset(struct bdisp_dev *bdisp) > bdisp->regs + BLT_CTL); > writel(0, bdisp->regs + BLT_CTL); > > - /* Wait for reset done */ > - for (i = 0; i < POLL_RST_MAX; i++) { > - if (readl(bdisp->regs + BLT_STA1) & BLT_STA1_IDLE) > - break; > - msleep(POLL_RST_DELAY_MS); > - } > - if (i == POLL_RST_MAX) > + /* Wait for reset done. > + * Despite the large timeout, most of the time the reset happens without > + * needing any delays */ shall be + * needing any delays + */ > + if (readl_poll_timeout_atomic(bdisp->regs + BLT_STA1, tmp, > + (tmp & BLT_STA1_IDLE), POLL_RST_DELAY_US, > + POLL_RST_DELAY_US * POLL_RST_MAX)) { shall be: + if (readl_poll_timeout_atomic(bdisp->regs + BLT_STA1, tmp, + tmp & BLT_STA1_IDLE, POLL_RST_DELAY_US, + POLL_RST_DELAY_US * POLL_RST_MAX)) { > dev_err(bdisp->dev, "Reset timeout\n"); > + return -EAGAIN; > + } > > - return (i == POLL_RST_MAX) ? -EAGAIN : 0; > + return 0; > } > > /**