From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 44C4A285050 for ; Wed, 6 May 2026 05:01:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778043683; cv=none; b=bLj29gfxRcLKCBjgkwiuQOb2E4AzfM/Hucp6fukq003xWM+I1Wv8nENR/tfZiVBuZqBoDCs0nqhMLSqZP1uOKjdMqeBAduKE2uWXRJ4PlZew3EuLqcvLfP6sMtPAzi9DslaZbKezLmroFd4g0ppkzvBT5mrlh56xyHiNQsMjC4s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778043683; c=relaxed/simple; bh=WHvjyHgD1TItrJGH0FkNazHavYPr4xyCEpQSkCRX/Xc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NM1GAkdFsbj7qlUO4gZtKtmR2uH4+Jo5OINk6+Zvjn7tPg+rwi7qmGRwbU3asMurNdqmV6l4/+jutD8VpqxbqZ9rDMNzWYFZG2IWmEHShIq3f28elWDXLbevEuEIqdUJlqgFvYKMOV0lX3SqNR3uBRKjMOUieDfFK+iFxfZPpwY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=GsFyOblt; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=gSc2K4fz; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="GsFyOblt"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="gSc2K4fz" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6463RJ602187468 for ; Wed, 6 May 2026 05:01:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=PiXhBeYotSE 4gHZOix5lHX+AUX2pHHBVag0+f6bRxcY=; b=GsFyObltNzTdzSvqk7fK4LUOjE6 G/OF8YhcbjY1YShm8FKH/dir5FZET4cED4DhIa25xGyFUi3rnRQTX2CHKuAVhLZ0 fuKZEvD3qCRXPUsa1pGeOgFWTKkAN7JnIccHmshXIt7mdsi0k/VrxBmW/33va9nl VB2xw7bXuBe4AiNTBadCAK+Ewgkq1xiIHB/gYCsIOP/X5cPlAWVsxwwIY5OLKtmu r/xYSEmM+kjWBxW6nJ8oCVARuBib1LqkYjuywlmGd4Zc1eCp5mx6OXxizVCZALb8 Qx3R6qOPKzDN9bd56f+kYaW0rkIY+fAQCZZ8xHs8oNE9RP30lGEkVPlxaqw== Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dygce3gaq-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 06 May 2026 05:01:21 +0000 (GMT) Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-c8247b55775so65292a12.3 for ; Tue, 05 May 2026 22:01:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1778043681; x=1778648481; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PiXhBeYotSE4gHZOix5lHX+AUX2pHHBVag0+f6bRxcY=; b=gSc2K4fz9ehKaYs3HVq9M0oeoeSxrgV2vxKrldNoH3/SWG0Hg6pP8NOggQmGu9bXkH 1aExhVZv4MBch9/r/a3BdmqB2ZW+4+EWxCcVYQYwG8R+wIPDAFF5DURTcYSTVPmC9K2d 9r7ENCxgw9uKwC1A74uo0xhNFH1fFfF8nrYFHR1eEsi4GdpCwhoWlxf1g1RRvWJ3DUTP VkZUrZRx+grUIKZX9hlam/Y9fFodzmmvGfDwhexE6FNYh9LiVSxnswH+c9lozq68NT/n tKRLu/oN5/4p90r4KDQ/e6CWSP61zw81H/46CIeMZY1fyGwc8POTdQJm7lKK8dzPHxW5 ajUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778043681; x=1778648481; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=PiXhBeYotSE4gHZOix5lHX+AUX2pHHBVag0+f6bRxcY=; b=Okzx0xsXyVv484BJuh2/N7RDiHZZvDt1tkIPprT/9zcIdIO0fIbz+n1thGEsFvHx7A lH9BI+M1yvxEpzzSGpuG08lCF0yhyrNt0YTxp/kHjWSzfPYRux3bvoMMF574SGJCn9/V L5ZkmtGwvvCKH6Agk/kY4YTFvyygVRrlyH6iv/72mLjqSx3fWCzponzY5cd+ToNSBdxg N7ww51wtwozT1y6Ucvs3dfgkNqsE5sJU/Ca5fowC2R4yOdcqiCmWQxX+KYOTmBAq7okC xeDhsqtyfIZAyfUcm/NzxOJKb8fukDz+86rzlZqqRLsRQHWGtaBR8K6HWx7bcaPoZ44t gM1Q== X-Gm-Message-State: AOJu0Yzwplg8jKSIFE2J4lJ09dgxQoTpE7jL8e43ZUVgAiNN9QWNnIg9 DeyKMg/kwKsNF/D/EgAPGxVsZziYpSU+O0QV9qENU1D2CbJ2iHdLMfy/J1yjegprNg+xQ2Sck2n XFgI1SKG4484glxjr8QqViZMGaNum7UZjKtDVgX3TRUoiNYvMZcckl0I4oDg5whTBt/L3/6HYJ9 E= X-Gm-Gg: AeBDieuaVk206YGgP2JFNkmQxySBQpobgKC9hI/L7+M949Zx3xBu7/O83VjZBCAgaCj Xk3gjYw49ocdasiBforwNwzbX0ORmPa9btju4snzKO1aOZDlAsGTVJ4abVnOidarmLdEG5Yahhx jkzp4nN+u9VZ64Gs5BjwZkeX2t3AHjRQke7WmWW61Nf49AUzN88X+6htA+YcBYuuFeYUKriHmN6 frS+KrYyT60IqQz9yKDMhNaKSusGo02VcVAGAqzovMl9VG6QkyQpMbQnG2r2v2JrH/lFNnosixg jWJek2skNVBOsPxdlox2KKTNrw1KpUhH+bqMj1Wga3fDOVMX1vEmd/ViVYfITqWLbohVYBYoAQc L2kr5BGQOkicZhShNuJY+JEBGy4jcRBiCnAjV1C49FbBqH3kyva2Itm7wguc= X-Received: by 2002:a05:6a00:a02:b0:82f:5051:f024 with SMTP id d2e1a72fcca58-83a5df484a2mr1768441b3a.27.1778043680484; Tue, 05 May 2026 22:01:20 -0700 (PDT) X-Received: by 2002:a05:6a00:a02:b0:82f:5051:f024 with SMTP id d2e1a72fcca58-83a5df484a2mr1768404b3a.27.1778043679849; Tue, 05 May 2026 22:01:19 -0700 (PDT) Received: from hu-mojha-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83967dbcfc0sm4891620b3a.42.2026.05.05.22.01.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 22:01:19 -0700 (PDT) From: Mukesh Ojha To: Bjorn Andersson , Konrad Dybcio , Mathieu Poirier Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, Mukesh Ojha Subject: [PATCH 2/5] remoteproc: use rsc_table_for_each_entry() in rproc_handle_resources() Date: Wed, 6 May 2026 10:31:04 +0530 Message-ID: <20260506050107.1985033-3-mukesh.ojha@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260506050107.1985033-1-mukesh.ojha@oss.qualcomm.com> References: <20260506050107.1985033-1-mukesh.ojha@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA2MDA0NiBTYWx0ZWRfX1WD3Kio/q2Zi GCQkfzvgx23tqsC7I0N3505vw7zzxofaDdnVocnedYnEn4Gpl2E6rZPsXap7w4heWSFsC9r2x3b pxoG1JdktoVJtqgB0oeZLE1d1nvbMRb17Wsc6oBAP9GrBvrF2ZX9HvmdcvjNqnmqya/3pyxa9d5 eqCKCH5mgjO6MECMknj+RM4aoyJ6NrPiFkPb5587eiM50iMApRHL8C8nlHU+MpSDjUFc7L/OnRO EgbMIOkvFf91jC8/vR7xkbSeu6GIZMEsdjk/gV7m9wZkKNRb6fwxmuQgnJoarvPlYYUVjSXUUpC /R7j+/bAdPsm2dY/0xRw1H1vXhNLnBWT6olT0yc10ht2kh456PqgeHZgOvjKF0EfRDx/tmPnfOK x7L74nbr10wycgL0n1hLFDO7WkKPAQAbIB0O52AxOGzhQtum3ecVixOjR5sg4Si3RdCu5N+FAlf EfYZosIz2aMqn2IlMGQ== X-Proofpoint-GUID: altZhB6Mja6yR1nYUU183MX5KKQ6T4Dc X-Proofpoint-ORIG-GUID: altZhB6Mja6yR1nYUU183MX5KKQ6T4Dc X-Authority-Analysis: v=2.4 cv=b6KCJNGx c=1 sm=1 tr=0 ts=69facb21 cx=c_pps a=Oh5Dbbf/trHjhBongsHeRQ==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=NGcC8JguVDcA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=EUspDBNiAAAA:8 a=xRbkGY9h9Oi8AtJRHVsA:9 a=_Vgx9l1VpLgwpw_dHYaR:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-05_02,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 adultscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 clxscore=1015 malwarescore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605060046 Replace the open-coded resource table iteration loop in rproc_handle_resources() with the rsc_table_for_each_entry() helper. The remoteproc-specific dispatch logic (vendor resource handling via rproc_handle_rsc(), RSC_LAST bounds check, handler table lookup) is moved into a local callback rproc_handle_rsc_entry(), keeping the iteration mechanics in one canonical place. The callback receives the payload offset within the table so that handlers which write back into the resource table (e.g. rproc_handle_carveout() recording a dynamically allocated address via rsc_offset) continue to work correctly. No functional change. Signed-off-by: Mukesh Ojha --- drivers/remoteproc/remoteproc_core.c | 81 +++++++++++++--------------- include/linux/rsc_table.h | 53 ++++++++++++++++++ 2 files changed, 91 insertions(+), 43 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index b087ed21858a..f003be006b1b 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1011,60 +1011,55 @@ static rproc_handle_resource_t rproc_loading_handlers[RSC_LAST] = { [RSC_VDEV] = rproc_handle_vdev, }; -/* handle firmware resource entries before booting the remote processor */ -static int rproc_handle_resources(struct rproc *rproc, - rproc_handle_resource_t handlers[RSC_LAST]) +struct rproc_rsc_cb_data { + struct rproc *rproc; + rproc_handle_resource_t *handlers; +}; + +static int rproc_handle_rsc_entry(u32 type, void *rsc, int offset, + int avail, void *data) { + struct rproc_rsc_cb_data *d = data; + struct rproc *rproc = d->rproc; struct device *dev = &rproc->dev; rproc_handle_resource_t handler; - int ret = 0, i; - - if (!rproc->table_ptr) - return 0; + int ret; - for (i = 0; i < rproc->table_ptr->num; i++) { - int offset = rproc->table_ptr->offset[i]; - struct fw_rsc_hdr *hdr = (void *)rproc->table_ptr + offset; - int avail = rproc->table_sz - offset - sizeof(*hdr); - void *rsc = (void *)hdr + sizeof(*hdr); + dev_dbg(dev, "rsc: type %d\n", type); - /* make sure table isn't truncated */ - if (avail < 0) { - dev_err(dev, "rsc table is truncated\n"); - return -EINVAL; - } - - dev_dbg(dev, "rsc: type %d\n", hdr->type); + if (type >= RSC_VENDOR_START && type <= RSC_VENDOR_END) { + ret = rproc_handle_rsc(rproc, type, rsc, offset, avail); + if (ret == RSC_HANDLED) + return 0; + if (ret < 0) + return ret; + dev_warn(dev, "unsupported vendor resource %d\n", type); + return 0; + } - if (hdr->type >= RSC_VENDOR_START && - hdr->type <= RSC_VENDOR_END) { - ret = rproc_handle_rsc(rproc, hdr->type, rsc, - offset + sizeof(*hdr), avail); - if (ret == RSC_HANDLED) - continue; - else if (ret < 0) - break; + if (type >= RSC_LAST) { + dev_warn(dev, "unsupported resource %d\n", type); + return 0; + } - dev_warn(dev, "unsupported vendor resource %d\n", - hdr->type); - continue; - } + handler = d->handlers[type]; + if (!handler) + return 0; - if (hdr->type >= RSC_LAST) { - dev_warn(dev, "unsupported resource %d\n", hdr->type); - continue; - } + return handler(rproc, rsc, offset, avail); +} - handler = handlers[hdr->type]; - if (!handler) - continue; +/* handle firmware resource entries before booting the remote processor */ +static int rproc_handle_resources(struct rproc *rproc, + rproc_handle_resource_t handlers[RSC_LAST]) +{ + struct rproc_rsc_cb_data d = { .rproc = rproc, .handlers = handlers }; - ret = handler(rproc, rsc, offset + sizeof(*hdr), avail); - if (ret) - break; - } + if (!rproc->table_ptr) + return 0; - return ret; + return rsc_table_for_each_entry(rproc->table_ptr, rproc->table_sz, + &rproc->dev, rproc_handle_rsc_entry, &d); } static int rproc_prepare_subdevices(struct rproc *rproc) diff --git a/include/linux/rsc_table.h b/include/linux/rsc_table.h index c32c8b6cd2a7..c6d6d553d8f1 100644 --- a/include/linux/rsc_table.h +++ b/include/linux/rsc_table.h @@ -303,4 +303,57 @@ struct fw_rsc_vdev { struct fw_rsc_vdev_vring vring[]; } __packed; +/** + * rsc_table_for_each_entry() - iterate over all entries in a resource table + * @table: pointer to the resource table + * @table_sz: total size of the table buffer in bytes + * @dev: device used for error logging + * @cb: callback invoked for each entry: + * @type - value from enum fw_resource_type + * @rsc - pointer to the entry payload (past struct fw_rsc_hdr) + * @offset - byte offset of the payload within the table; callers + * that write back into the table (e.g. to record a + * dynamically allocated address) use this to locate the + * entry for later update + * @avail - bytes available in the payload + * @data - caller-supplied private pointer + * Return 0 to continue iteration, non-zero to stop. + * @data: private pointer forwarded to @cb on every call + * + * Iterates over every resource entry in @table, performing the standard + * truncation check, and invokes @cb for each one. Iteration stops on the + * first non-zero return from @cb or on a malformed table. + * + * Returns 0 after a complete iteration, -EINVAL if the table is truncated, + * or the first non-zero value returned by @cb. + */ +static inline int rsc_table_for_each_entry(struct resource_table *table, + size_t table_sz, + struct device *dev, + int (*cb)(u32 type, void *rsc, + int offset, int avail, + void *data), + void *data) { + int i, ret; + + for (i = 0; i < table->num; i++) { + int offset = table->offset[i]; + struct fw_rsc_hdr *hdr = (void *)table + offset; + int avail = table_sz - offset - sizeof(*hdr); + int rsc_offset = offset + sizeof(*hdr); + void *rsc = (void *)hdr + sizeof(*hdr); + + if (avail < 0) { + dev_err(dev, "rsc table is truncated\n"); + return -EINVAL; + } + + ret = cb(hdr->type, rsc, rsc_offset, avail, data); + if (ret) + return ret; + } + + return 0; +} + #endif /* RSC_TABLE_H */ -- 2.53.0