Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp336609imn; Fri, 29 Jul 2022 08:19:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tYC54zco6bulUN/xNBRd8qOty5YPKEsve9Pv3JXbCmSPxik98FWMKozPVNGxf1v7an815V X-Received: by 2002:a05:6402:348f:b0:43c:2919:cfb5 with SMTP id v15-20020a056402348f00b0043c2919cfb5mr3984463edc.326.1659107968631; Fri, 29 Jul 2022 08:19:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659107968; cv=none; d=google.com; s=arc-20160816; b=Su4W9Zad+b+o34tCBezeAGfO1KXhVD1OpdRVOlGdEhmV2D5IojUAyp0PvTOJCPfSO/ W8IHuPVcNknBNUpSlWQGBpCDMqotnB4nVrMhPwDpIIjkK//EBTT9WLcfnAYxam6rulrI 6XUX+9zsAC4jJjmRvsf3P4aEfvi2Unu/9k6ESKwFQojUtCn/6X4+vB+iD1x05T1gdtBW Vky4ixXM7YMt+fJ1e7FEYpcVFAVO2wTKKM2hPM02ttAgUkac+VP1UMMV/bWUKLCSi+vh Ccyv4KtV9VG0vNaNqP9lKtAbn5SjVcIUNQ4yrXb728I3PMCU1BqBMmOADU45Cnk8vcLm Y+OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ojlVOlrrmV+wt1KMhrby2To+4h/iOYYCL1Egvk1oDWE=; b=Bc6PAvLxJSdOWmAmaad/vkirlvcR3BK8iroRti1pxydLEMYUm96uJH/QG9gzeRtjX/ VyKQHwX9rWVbWquqzYfqS97ihh+bcREtwbGLWaj9HOnnhRoNs6g+EKVmt2mGwsj+uS1w /IwroPu3J+zPEtoTse0dKwGxlA3Ni5PRMusa2CtjBmHlj4mhq6fkDpWtjiHVtS5MenbK 0oYNPgZmzndT5yk7bUm1EDR5b84J/xA8vGEQuUx/PolFNLL9fDHBdQtvPvY108vTl8WS sDAllNvVycKh6EgAgr0wgm2d2wWNbHTcnw3ipaGLJL9BxOOZHLMAiWZrQx/BpQEKLKyL CaMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=thrMeuuK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w24-20020a17090652d800b0072b4f140c57si3622077ejn.592.2022.07.29.08.19.04; Fri, 29 Jul 2022 08:19:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=thrMeuuK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237053AbiG2O0S (ORCPT + 99 others); Fri, 29 Jul 2022 10:26:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237056AbiG2O0R (ORCPT ); Fri, 29 Jul 2022 10:26:17 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E94DC42ACA; Fri, 29 Jul 2022 07:26:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 5EEBBCE29C0; Fri, 29 Jul 2022 14:26:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40456C433B5; Fri, 29 Jul 2022 14:26:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659104772; bh=+uMoBAWIxMSyXxcObfO5cph22nMVTb/iovwbfOaC60I=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=thrMeuuK2VSrxm0ruqnTHhY8+hQZ4zpezH9G8rUOteC7blIg1D/tpQ2cfpPLhfRWE DLyGP04+rju95e1Y5YIEjnQIVfMco+HTxdfUhU14PFmtQQh1g047x3kh0OD4f6GwrG v9meh8C0T+sXUGmTl6+0qTbj6Q16GfWq/O4OhHZgMLklA8wGnx89N6RwGza6azMDJJ pITNu7roK4QkuvIEuWJtaGAcxoUzho3Ee9weqB/uyMy0OvWXRpA0F0mNYyk2TDvzN2 Orfsr/0dJKcaRTJ1Ng3LwCtnvza8H6A9Iali8xH/wW6+//gl8L/8HlZHFEPI3KJLfd Nk9WijSbKcf4g== Date: Fri, 29 Jul 2022 19:56:05 +0530 From: Manivannan Sadhasivam To: Qiang Yu Cc: quic_hemantk@quicinc.com, loic.poulain@linaro.org, quic_jhugo@quicinc.com, mhi@lists.linux.dev, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, quic_cang@quicinc.com Subject: Re: [PATCH v3 1/1] bus: mhi: host: Fix up null pointer access in mhi_irq_handler Message-ID: <20220729142605.GB9937@thinkpad> References: <1658459838-30802-1-git-send-email-quic_qianyu@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1658459838-30802-1-git-send-email-quic_qianyu@quicinc.com> X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 22, 2022 at 11:17:18AM +0800, Qiang Yu wrote: > The irq handler for a shared IRQ ought to be prepared for running > even now it's being freed. So let's check the pointer used by > mhi_irq_handler to avoid null pointer access since it is probably > released before freeing IRQ. > > Signed-off-by: Qiang Yu Applied to mhi-next! This patch is targeted for v5.20-rcS. Thanks, Mani > --- > v2->v3: add comments > v1->v2: change dev_err to dev_dbg > > drivers/bus/mhi/host/main.c | 19 ++++++++++++++++--- > 1 file changed, 16 insertions(+), 3 deletions(-) > > diff --git a/drivers/bus/mhi/host/main.c b/drivers/bus/mhi/host/main.c > index f3aef77a..df0fbfe 100644 > --- a/drivers/bus/mhi/host/main.c > +++ b/drivers/bus/mhi/host/main.c > @@ -430,12 +430,25 @@ irqreturn_t mhi_irq_handler(int irq_number, void *dev) > { > struct mhi_event *mhi_event = dev; > struct mhi_controller *mhi_cntrl = mhi_event->mhi_cntrl; > - struct mhi_event_ctxt *er_ctxt = > - &mhi_cntrl->mhi_ctxt->er_ctxt[mhi_event->er_index]; > + struct mhi_event_ctxt *er_ctxt; > struct mhi_ring *ev_ring = &mhi_event->ring; > - dma_addr_t ptr = le64_to_cpu(er_ctxt->rp); > + dma_addr_t ptr; > void *dev_rp; > > + /* > + * If CONFIG_DEBUG_SHIRQ is set, the IRQ handler will get invoked during __free_irq() > + * and by that time mhi_ctxt() would've freed. So check for the existence of mhi_ctxt > + * before handling the IRQs. > + */ > + if (!mhi_cntrl->mhi_ctxt) { > + dev_dbg(&mhi_cntrl->mhi_dev->dev, > + "mhi_ctxt has been freed\n"); > + return IRQ_HANDLED; > + } > + > + er_ctxt = &mhi_cntrl->mhi_ctxt->er_ctxt[mhi_event->er_index]; > + ptr = le64_to_cpu(er_ctxt->rp); > + > if (!is_valid_ring_ptr(ev_ring, ptr)) { > dev_err(&mhi_cntrl->mhi_dev->dev, > "Event ring rp points outside of the event ring\n"); > -- > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project. > -- மணிவண்ணன் சதாசிவம்