From patchwork Wed Jul 3 06:55:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kousik Sanagavarapu X-Patchwork-Id: 13721468 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 D63FCC2BD09 for ; Wed, 3 Jul 2024 06:58:48 +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:References:In-Reply-To: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:List-Owner; bh=xzpdtG7l+61FZknCaY59u/tBtOIKZgOnyqq0sEG7wfc=; b=Xtesi1TcweaGsryANcTS1uYLqD z/HQMh1Holes/MgNDjvjSOFPSZGGDJRgUTFKcxC3nVRwLW6d3ZkGSuVGYVBKjkr9pFxJSbxkASYzu 8STDCWQ009csEM/E0C1+Si7qoEsuG258yot3zVa3CUoNzt9AJq5rnCfl8Kcga5qfj266/h1IW6bmu ElECPpdWxUgcg6gtI8tHHUhvU7bN4DcfS8UERK1pqfE/sK8DY6vC8oGOC2DIAi3Xgc9twxo80lrlf Mg7t+7ZB7o1SGd7qNuQVeskz0sNSChp8pQtemO2XuKe8antdumdaxTG3IdVbGpBnrDLwbO3pVQSpn dcRi1CWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOtwr-00000009GhR-2xif; Wed, 03 Jul 2024 06:58:37 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOtwW-00000009GYf-1N8I for linux-arm-kernel@lists.infradead.org; Wed, 03 Jul 2024 06:58:17 +0000 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2c8c6cc53c7so3477272a91.0 for ; Tue, 02 Jul 2024 23:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719989895; x=1720594695; darn=lists.infradead.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=xzpdtG7l+61FZknCaY59u/tBtOIKZgOnyqq0sEG7wfc=; b=PtbOHf5XRbtxYYh1cxdr5my4+ejazwArzivqKz+6oSDKSFLRoCfB8wKG7qN6CrrD/F 91HG/HgUHsSpUzIzlUkW01bv3CGrOafYQDYBk+H23cizuq85lGs4iRsvRBEE/0OFEiAw eOojtyRDCiJpJ4EENOxvOhzmUNu5k/BFjKU9kyEP4sz0zkGhpItZjA+KliuZezHYYMwA RX1erNCiCjVVZZmIKk0M/0UJKaJITN4rTvt3pmAQzI2+qq92BzuW5hqbhirX1Pd/PeFI rTZDzcg1fa6+R3H8T2aYlel5TICaKjFhIhE8x2jLuN6nxMSXW+KvAyVWHhhAqq5RscAW l2ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719989895; x=1720594695; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xzpdtG7l+61FZknCaY59u/tBtOIKZgOnyqq0sEG7wfc=; b=LEL9K4NQ9SbQ3v//AXgDeKMW7M/F9cnaHxkLjcUmz9xweL3/iCcr3i1YsJsE2yFlu4 lZL42NY8aM+ZaVW5fsEfauG96c5VJGS7lwUsOXc66aa2dcFFXsqfHb6UqiBHy8Jlm2Kf xfGT1uQN19x7U8RkqLLR0LesLrOCdlYftF85lOabn+xF11X+lc9jZ6wHkSYjUtUbZ9x+ wSf9gI1Gz3wpELZcHL5U6rapzVwhVJUAp73VWk7iATO7CFEPZDmzZTRICDJc7AS5Yj2W ig5cnMFkC9e4qiaU1FR/t3qObcN5Yw3HsZEd1yd/QT+LUfquodLinhwtS2ZtMBANafcn MoWQ== X-Forwarded-Encrypted: i=1; AJvYcCXuhk0Wa3Xrkd1Ct6bqNr4R09JA06o2/3iX7IfV124Q1tqBLFelJowMspsIjhNcE18Gw4O26SXhHoiDLFjw4qGGolIeWQYSaG0cRYUb3YzmNKNJYyk= X-Gm-Message-State: AOJu0Yx3s0LZ/EIRwENgGPXm06Een5v3p7vqrtRelq2ErV1RXSd1GKyt CqpO0hMkuG9R9mdzoL13OVTANPXuSBHH7mojtWnDBpfm8umvx5FW X-Google-Smtp-Source: AGHT+IFhTTaB1WupIMW6rfPpx8ReG1qfczZ5DxmoQdwGtfpjx5/6cHxOC3KlaEaxTWQ5ki3CPJyZXg== X-Received: by 2002:a17:90b:3a8b:b0:2c8:6308:ad78 with SMTP id 98e67ed59e1d1-2c93d7694abmr10642022a91.34.1719989895182; Tue, 02 Jul 2024 23:58:15 -0700 (PDT) Received: from kousik.local ([2405:201:c006:312d:258c:c06c:76e7:dba9]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91d3e818asm9973921a91.51.2024.07.02.23.58.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 23:58:14 -0700 (PDT) From: Kousik Sanagavarapu To: Julia Lawall , Nishanth Menon , Jonathan Cameron , Santosh Shilimkar , Nathan Chancellor Cc: Shuah Khan , Javier Carrasco , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Kousik Sanagavarapu Subject: [PATCH v2 2/3] soc: ti: knav_qmss_queue: do device_node auto cleanup Date: Wed, 3 Jul 2024 12:25:27 +0530 Message-ID: <20240703065710.13786-3-five231003@gmail.com> X-Mailer: git-send-email 2.45.2.561.g66ac6e4bcd In-Reply-To: <20240703065710.13786-1-five231003@gmail.com> References: <20240703065710.13786-1-five231003@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240702_235816_388993_D9075384 X-CRM114-Status: GOOD ( 19.06 ) 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 Use scope based cleanup, instead of manual of_node_put() calls, which automatically free()s "struct device_node". While at it, refactor the code from knav_queue_probe() into the seperate functions to make auto cleanup look more neat. Doing the cleanup this way has the advantage of reducing the chance of memory leaks in case we need to read from new OF nodes in the future when we probe. Suggested-by: Julia Lawall Signed-off-by: Kousik Sanagavarapu Reviewed-by: Jonathan Cameron --- drivers/soc/ti/knav_qmss_queue.c | 85 +++++++++++++++++--------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c index 06fb5505c22c..767b9c49ea93 100644 --- a/drivers/soc/ti/knav_qmss_queue.c +++ b/drivers/soc/ti/knav_qmss_queue.c @@ -1076,14 +1076,20 @@ static const char *knav_queue_find_name(struct device_node *node) } static int knav_queue_setup_regions(struct knav_device *kdev, - struct device_node *regions) + struct device_node *node) { struct device *dev = kdev->dev; + struct device_node *regions __free(device_node) = + of_get_child_by_name(node, "descriptor-regions"); struct knav_region *region; struct device_node *child; u32 temp[2]; int ret; + if (!regions) + return dev_err_probe(dev, -ENODEV, + "descriptor-regions not specified\n"); + for_each_child_of_node(regions, child) { region = devm_kzalloc(dev, sizeof(*region), GFP_KERNEL); if (!region) { @@ -1306,10 +1312,16 @@ static int knav_setup_queue_range(struct knav_device *kdev, } static int knav_setup_queue_pools(struct knav_device *kdev, - struct device_node *queue_pools) + struct device_node *node) { + struct device_node *queue_pools __free(device_node) = + of_get_child_by_name(node, "queue-pools"); struct device_node *type, *range; + if (!queue_pools) + return dev_err_probe(kdev->dev, -ENODEV, + "queue-pools not specified\n"); + for_each_child_of_node(queue_pools, type) { for_each_child_of_node(type, range) { /* return value ignored, we init the rest... */ @@ -1389,14 +1401,20 @@ static void __iomem *knav_queue_map_reg(struct knav_device *kdev, } static int knav_queue_init_qmgrs(struct knav_device *kdev, - struct device_node *qmgrs) + struct device_node *node) { struct device *dev = kdev->dev; + struct device_node *qmgrs __free(device_node) = + of_get_child_by_name(node, "qmgrs"); struct knav_qmgr_info *qmgr; struct device_node *child; u32 temp[2]; int ret; + if (!qmgrs) + return dev_err_probe(dev, -ENODEV, + "queue manager info not specified\n"); + for_each_child_of_node(qmgrs, child) { qmgr = devm_kzalloc(dev, sizeof(*qmgr), GFP_KERNEL); if (!qmgr) { @@ -1668,6 +1686,25 @@ static int knav_queue_start_pdsps(struct knav_device *kdev) return 0; } +static int knav_queue_setup_pdsps(struct knav_device *kdev, + struct device_node *node) +{ + struct device_node *pdsps __free(device_node) = + of_get_child_by_name(node, "pdsps"); + + if (pdsps) { + int ret; + + ret = knav_queue_init_pdsps(kdev, pdsps); + if (ret) + return ret; + ret = knav_queue_start_pdsps(kdev); + if (ret) + return ret; + } + return 0; +} + static inline struct knav_qmgr_info *knav_find_qmgr(unsigned id) { struct knav_qmgr_info *qmgr; @@ -1755,7 +1792,6 @@ MODULE_DEVICE_TABLE(of, keystone_qmss_of_match); static int knav_queue_probe(struct platform_device *pdev) { struct device_node *node = pdev->dev.of_node; - struct device_node *qmgrs, *queue_pools, *regions, *pdsps; struct device *dev = &pdev->dev; u32 temp[2]; int ret; @@ -1799,39 +1835,17 @@ static int knav_queue_probe(struct platform_device *pdev) kdev->num_queues = temp[1]; /* Initialize queue managers using device tree configuration */ - qmgrs = of_get_child_by_name(node, "qmgrs"); - if (!qmgrs) { - dev_err(dev, "queue manager info not specified\n"); - ret = -ENODEV; - goto err; - } - ret = knav_queue_init_qmgrs(kdev, qmgrs); - of_node_put(qmgrs); + ret = knav_queue_init_qmgrs(kdev, node); if (ret) goto err; /* get pdsp configuration values from device tree */ - pdsps = of_get_child_by_name(node, "pdsps"); - if (pdsps) { - ret = knav_queue_init_pdsps(kdev, pdsps); - if (ret) - goto err; - - ret = knav_queue_start_pdsps(kdev); - if (ret) - goto err; - } - of_node_put(pdsps); + ret = knav_queue_setup_pdsps(kdev, node); + if (ret) + goto err; /* get usable queue range values from device tree */ - queue_pools = of_get_child_by_name(node, "queue-pools"); - if (!queue_pools) { - dev_err(dev, "queue-pools not specified\n"); - ret = -ENODEV; - goto err; - } - ret = knav_setup_queue_pools(kdev, queue_pools); - of_node_put(queue_pools); + ret = knav_setup_queue_pools(kdev, node); if (ret) goto err; @@ -1853,14 +1867,7 @@ static int knav_queue_probe(struct platform_device *pdev) if (ret) goto err; - regions = of_get_child_by_name(node, "descriptor-regions"); - if (!regions) { - dev_err(dev, "descriptor-regions not specified\n"); - ret = -ENODEV; - goto err; - } - ret = knav_queue_setup_regions(kdev, regions); - of_node_put(regions); + ret = knav_queue_setup_regions(kdev, node); if (ret) goto err;