From nobody Tue Oct 7 03:47:41 2025 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67C762E62D0; Tue, 15 Jul 2025 13:26:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752585980; cv=pass; b=NYkI0pJD6yZU9mLNWjRnAFda1x4Q6dyowWdcv3iWj4K9I+TUjolR/gLSAZlS8bPOtVfJ9EKksBgz66sxk1RRmr+beJcWn6a8aGgkCXzsAaIMxjXFhnwhQOEi7DEnI5FwThoD8wDdBrWfapOsIeVW8RncFSVDFBsZ2pU1kza7mQc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752585980; c=relaxed/simple; bh=M8j7JAndjW76gZkMNx9GjJJXm+NYfmI5q0z6lnV/IuI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ClFjXx4hpQrT9+UV97h9592MyPhD8R6G2rUSV+SZ2l6Jt3ztH63QwSdosqp2687QR2ziEPVN7SF+a7Vp+N2XKK3vJZRtjHqq5rzq2YFT+6wP4tPs5NNAd/B8iuNwoKKwbsiZdHWtbJpO5SJb07G/CedusUWrEUgdq/Ip8zSbxL0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=usama.anjum@collabora.com header.b=OgQCcXgz; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=usama.anjum@collabora.com header.b="OgQCcXgz" ARC-Seal: i=1; a=rsa-sha256; t=1752585926; cv=none; d=zohomail.com; s=zohoarc; b=ZdQxCDeWOHLEFuTlFqIixHgGjtzZ3Z9TLntiH3HWyPuPUbOhtv4uI5u+RDYgCEMMreis9h/DZWtZugtu1P2nhtmSrjbXgZVAaM4GJaWSir32zUpgxKmYrMqh2FClXXaYdm6cHqK92kkc4VojsYLAib6GvzTn/mTyRTYYcx7JeZE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752585926; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=yOrcLOG6tjcTjNDL4YHJ2yUTrv14txmB+F3Ap51joxo=; b=PCUDKkJMbeHOvJw34GnomgTc4I8mySfgqK1EY6Tgf/ijFgRhapFs92BDJEjz4NEphtHSIcio8vUx0WxUFrzPE0E5Lc4+5JNiRqTtMsG13qElqoHPjPtZblHYOR7nhLD11466cYS+gXHCRJIiYN/FJdgnKOtUihvha315RRvMQvk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1752585926; s=zohomail; d=collabora.com; i=usama.anjum@collabora.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=yOrcLOG6tjcTjNDL4YHJ2yUTrv14txmB+F3Ap51joxo=; b=OgQCcXgzCF37pcPDWJSJ2V3IqI7BfXU55+a6qazyknVajfRCbWZ+s6zocxnF3o6U 8zOwgTVGkGZrEvU+Kvim4P4FEsQoK+JNJ1NnxmvIL/Oey8d2eDqY5tWk9Qp8qrGtAYl Hd/PUDbkG7d6zm5F+BU7c1ZA3HUmHoHQnzhJx8nY= Received: by mx.zohomail.com with SMTPS id 1752585925284460.38188208462543; Tue, 15 Jul 2025 06:25:25 -0700 (PDT) From: Muhammad Usama Anjum To: Manivannan Sadhasivam , Jeff Hugo , Muhammad Usama Anjum , Youssef Samir , Matthew Leung , Alexander Wilhelm , Kunwu Chan , Krishna Chaitanya Chundru , Jacek Lawrynowicz , Yan Zhen , Sujeev Dias , Greg Kroah-Hartman , Siddartha Mohanadoss , mhi@lists.linux.dev, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: kernel@collabora.com, stable@vger.kernel.org Subject: [PATCH v2 2/3] bus: mhi: host: keep bhie buffer through suspend cycle Date: Tue, 15 Jul 2025 18:25:08 +0500 Message-Id: <20250715132509.2643305-3-usama.anjum@collabora.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250715132509.2643305-1-usama.anjum@collabora.com> References: <20250715132509.2643305-1-usama.anjum@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" When there is memory pressure, at resume time dma_alloc_coherent() returns error which in turn fails the loading of the firmware and hence the driver crashes. Fix it by allocating only once and then reuse the same allocated memory. As we'll allocate this memory only once, this memory will stays allocated. Fixes: f88f1d0998ea ("bus: mhi: host: Add a policy to enable image transfer= via BHIe in PBL") Cc: Krishna Chaitanya Chundru Cc: stable@vger.kernel.org Signed-off-by: Muhammad Usama Anjum --- Changes since v1: - Added in v2 --- drivers/bus/mhi/host/boot.c | 19 ++++++++++++------- drivers/bus/mhi/host/init.c | 5 +++++ include/linux/mhi.h | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/bus/mhi/host/boot.c b/drivers/bus/mhi/host/boot.c index 9fc983bc12d49..9f35ce9d670e7 100644 --- a/drivers/bus/mhi/host/boot.c +++ b/drivers/bus/mhi/host/boot.c @@ -478,17 +478,22 @@ static int mhi_load_image_bhi(struct mhi_controller *= mhi_cntrl, const u8 *fw_dat =20 static int mhi_load_image_bhie(struct mhi_controller *mhi_cntrl, const u8 = *fw_data, size_t size) { - struct image_info *image; + struct image_info **image =3D &mhi_cntrl->bhie_image; int ret; =20 - ret =3D mhi_alloc_bhie_table(mhi_cntrl, &image, size); - if (ret) - return ret; + if (!(*image)) { + ret =3D mhi_alloc_bhie_table(mhi_cntrl, image, size); + if (ret) + return ret; =20 - mhi_firmware_copy_bhie(mhi_cntrl, fw_data, size, image); + mhi_firmware_copy_bhie(mhi_cntrl, fw_data, size, *image); + } =20 - ret =3D mhi_fw_load_bhie(mhi_cntrl, &image->mhi_buf[image->entries - 1]); - mhi_free_bhie_table(mhi_cntrl, image); + ret =3D mhi_fw_load_bhie(mhi_cntrl, &(*image)->mhi_buf[(*image)->entries = - 1]); + if (ret) { + mhi_free_bhie_table(mhi_cntrl, *image); + *image =3D NULL; + } =20 return ret; } diff --git a/drivers/bus/mhi/host/init.c b/drivers/bus/mhi/host/init.c index 2e0f18c939e68..46ed0ae2ac285 100644 --- a/drivers/bus/mhi/host/init.c +++ b/drivers/bus/mhi/host/init.c @@ -1228,6 +1228,11 @@ void mhi_unprepare_after_power_down(struct mhi_contr= oller *mhi_cntrl) mhi_cntrl->rddm_image =3D NULL; } =20 + if (mhi_cntrl->bhie_image) { + mhi_free_bhie_table(mhi_cntrl, mhi_cntrl->bhie_image); + mhi_cntrl->bhie_image =3D NULL; + } + if (mhi_cntrl->bhi_image) { mhi_free_bhi_buffer(mhi_cntrl, mhi_cntrl->bhi_image); mhi_cntrl->bhi_image =3D NULL; diff --git a/include/linux/mhi.h b/include/linux/mhi.h index 593012f779d97..77986cd66fda3 100644 --- a/include/linux/mhi.h +++ b/include/linux/mhi.h @@ -391,6 +391,7 @@ struct mhi_controller { size_t reg_len; struct image_info *fbc_image; struct image_info *rddm_image; + struct image_info *bhie_image; struct image_info *bhi_image; struct mhi_chan *mhi_chan; struct list_head lpm_chans; --=20 2.39.5