From patchwork Wed Jul 31 20:13:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 13749165 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 457DDC3DA7F for ; Wed, 31 Jul 2024 20:16:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=m/MCUJpgGLinqiGc9XcRSUQbxZSBkOSwuN4lOoEJTOA=; b=ABqixPvC+cn6V7c2ATg568sH+s V1gN4MCMjnz4leyCIxUOMbbRVNtaKj37hzgkdsEBXrurgOyZA2BuPHRy3zxrF5yM0dXh37jDqamCT PAgjVxwYDzwUcusGYgD4fWxT05nGm/wHYelvLc+5p3Seg7xv99HtMXiNMtJnz2AixFaWLpe5pQpif A7Oz564DVHZkDS3/Oas9yaHetxvDfQGwXLHOZxn3DSIIZWJfZvp/VbneJYv8HoLstUVxF1idjsEQs xVMAW0aDZcJuxwwNObRFW0Qj8YwyWyMB11ECSPcTNk+9AfhZjkOlTCu4CNziuqBjJ85x2PGZ8bKjX fINX/s4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZFjt-00000002QCz-39WL; Wed, 31 Jul 2024 20:16:01 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZFia-00000002PlN-0lhe for linux-arm-kernel@lists.infradead.org; Wed, 31 Jul 2024 20:14:41 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 4CEF6CE1831; Wed, 31 Jul 2024 20:14:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCBABC4AF0C; Wed, 31 Jul 2024 20:14:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722456878; bh=rs9OKvs3MRnvwNaZmqBZdZEDA/cG0O5dn7GKWEKIHpk=; h=From:To:Cc:Subject:Date:From; b=VWWXQTvVkuh0fARMRE9rCRbAybQnMtOqEsT5g5U2N5tIKHLlJgmsDV3sxFO7ZydRT w/bgoWOU51yXntaFiVjSJD0blXEgOEC1Us9eY3gAuzbwy9ujFME1wA9vf8NyF3aVfA VXuZyjpMs69KgZxIJeW6tV81RybpPKfNvaP/GU8TTx3T+lSV+voXdwQcD7rYeKPT6C AO9lg5zwbvnL4UQki1upXsya1H4m3Qc1sq9aKW4xnWCqwU8mJObEHqNXH+OUcIXY+s P5wPP1Zdlk7hr7U/WXqE/f9x+UJeV+8jfIH6UmFhJP+sn8zctTBy95F3f3MFvC66ke /zFWbndvLuHEQ== From: "Rob Herring (Arm)" To: Nishanth Menon , Santosh Shilimkar Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] soc: ti: knav: Use of_property_read_variable_u32_array() Date: Wed, 31 Jul 2024 14:13:58 -0600 Message-ID: <20240731201407.1838385-3-robh@kernel.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240731_131440_488491_92ED0F31 X-CRM114-Status: GOOD ( 12.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org There's no need to get the length of an DT array property before parsing the array. of_property_read_variable_u32_array() takes a minimum and maximum length and returns the actual length (or error code). This is part of a larger effort to remove callers of of_find_property() and similar functions. of_find_property() leaks the DT struct property and data pointers which is a problem for dynamically allocated nodes which may be freed. Signed-off-by: Rob Herring (Arm) --- drivers/soc/ti/knav_dma.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/drivers/soc/ti/knav_dma.c b/drivers/soc/ti/knav_dma.c index 6023006685fc..fb0746d8caad 100644 --- a/drivers/soc/ti/knav_dma.c +++ b/drivers/soc/ti/knav_dma.c @@ -602,7 +602,7 @@ static int dma_init(struct device_node *cloud, struct device_node *dma_node) unsigned max_tx_chan, max_rx_chan, max_rx_flow, max_tx_sched; struct device_node *node = dma_node; struct knav_dma_device *dma; - int ret, len, num_chan = 0; + int ret, num_chan = 0; resource_size_t size; u32 timeout; u32 i; @@ -615,25 +615,13 @@ static int dma_init(struct device_node *cloud, struct device_node *dma_node) INIT_LIST_HEAD(&dma->list); INIT_LIST_HEAD(&dma->chan_list); - if (!of_find_property(cloud, "ti,navigator-cloud-address", &len)) { - dev_err(kdev->dev, "unspecified navigator cloud addresses\n"); - return -ENODEV; - } - - dma->logical_queue_managers = len / sizeof(u32); - if (dma->logical_queue_managers > DMA_MAX_QMS) { - dev_warn(kdev->dev, "too many queue mgrs(>%d) rest ignored\n", - dma->logical_queue_managers); - dma->logical_queue_managers = DMA_MAX_QMS; - } - - ret = of_property_read_u32_array(cloud, "ti,navigator-cloud-address", - dma->qm_base_address, - dma->logical_queue_managers); - if (ret) { + ret = of_property_read_variable_u32_array(cloud, "ti,navigator-cloud-address", + dma->qm_base_address, 1, DMA_MAX_QMS); + if (ret < 0) { dev_err(kdev->dev, "invalid navigator cloud addresses\n"); return -ENODEV; } + dma->logical_queue_managers = ret; dma->reg_global = pktdma_get_regs(dma, node, 0, &size); if (IS_ERR(dma->reg_global))