From patchwork Wed Jul 3 06:55:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kousik Sanagavarapu X-Patchwork-Id: 13721467 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 2FB18C2BD09 for ; Wed, 3 Jul 2024 06:58:37 +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=g5IB8/nq6DlwhVNyviTWwBZ2x7h3P9W/CW2Qn6PLl7I=; b=jXIGyssFgqhC79xB816hIrU/AQ FM0ApEbzVEU9Z19JKLKdlSxNzS1A4yw1LCKLD405S3y+TxC7ricixi/atw6NzrpwZG+y/f1CTlNn/ 3iMc7tsLuzlQx3j3C1pPUlO2OavY6B0vR2nbGvB+76xfrK6Ywck5S18VzZyp2yWQ65uwrShRpsYNv Ls98JveqL/kIKh2Z9KpzmQp0YjwEx7bMSPpJGHQ8O4WV5Lj0OsGeSFgm2yrNYrD94BBxWfW5DXaa7 I3JZPsJR7IKHxm2k5MZFoB1ttos/pn8Zbcg7YgjrTlyBxLlyMnShjnbXbK/fgOYPWz07SfKoLT2SI l0rnyt+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOtwh-00000009Gcn-1xpr; Wed, 03 Jul 2024 06:58:27 +0000 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOtwQ-00000009GXe-2Egl for linux-arm-kernel@lists.infradead.org; Wed, 03 Jul 2024 06:58:11 +0000 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-725a7b0fc55so3077134a12.3 for ; Tue, 02 Jul 2024 23:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719989890; x=1720594690; 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=g5IB8/nq6DlwhVNyviTWwBZ2x7h3P9W/CW2Qn6PLl7I=; b=aF9FYSkHVMSbJW7UQcOVTxYIdOBiXirgGR+cYOcdT9oZuVsky+EKm2QxYHHTMb9xG0 e2+VleRxMqzVpesyg3F+P8EfOECBIGu+5BTT7HwGi4BLlQpGtWz8TQCRGvsPKb5I/OF5 dt8bJK2+Adox+deevXRXOx8Z6+XAk5388bjoDCnUQ76V4BfISzh0Th0NaRLkfcWwqiKU 7YBcsCnOELZfz2dCMH/j5eQp8aBHWXsI/HJ4ugvL1tdgJFnzACNaAjux/KO5VitGLg/f u4VSSIZALOHlOFGk7Tb5IFRo3MqIXibviHFAnfaSpwCi02C8rwv4CIfT1jOBBM5EtdZA k5ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719989890; x=1720594690; 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=g5IB8/nq6DlwhVNyviTWwBZ2x7h3P9W/CW2Qn6PLl7I=; b=GUBPekZa4tsw39tvmMFfH/5F3HkqoQnULkFRF4ajFM4ZFi4WJzDuO6T76bwSCYkg4t /cnbKVgV4KgCzkgWet8CwanXsQLpo/iAnhq1bPQCOjNWfxAm7LCCM4FumkNgkurbKArG EkQPVchyI7RTaLknXd00Gkkdz6U1V6Uvj9HpDEzY2tEIUl7lUUdivGwiPotdZsGDRou0 m8iuBb7CtPtZP0RMd6WgwfupInxDrDqQTCL6pgBP3mBfOdeKWPqC68AqtVxS7qA69U6j M71eWHxzNNKyz+5Jd1BZ7iKRHPSUyR0fqUM0Pw3aATkTj+HDh6EGsgn9f+d7QtxqPRRb tkMA== X-Forwarded-Encrypted: i=1; AJvYcCUd2EdmsTF3iVtGukkO4hbuGPue+Q8gw6r5uFqXSLcHcy10SgxnR7Cep2IWUwQKmpJMc1+IAendRd8BxN4GvgoWfN077eb0dpxd6bCV2jlXArXNF04= X-Gm-Message-State: AOJu0Yzu9HhTTugJKdXGN/SD7YSD07OmQaJ/XPFUJPqc9LHqMC72GlIw lEM/N1PDGm9mohSk0QZOsjr4H7um5N1Aigo+1ddi4dENkhcHVLUG X-Google-Smtp-Source: AGHT+IEY3rUCcx/kslsTq7Tjv7pevyUVOb+O1uxfTVwJ9nsCAKEHnyQPyUnwCmSJchrtKSBAnmdQ0A== X-Received: by 2002:a05:6a20:244c:b0:1be:c5c8:d1e2 with SMTP id adf61e73a8af0-1bef6198ccamr12807732637.35.1719989889627; Tue, 02 Jul 2024 23:58:09 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 23:58:09 -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 1/3] soc: ti: pruss: do device_node auto cleanup Date: Wed, 3 Jul 2024 12:25:26 +0530 Message-ID: <20240703065710.13786-2-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_235810_599266_E0DFBC8D X-CRM114-Status: GOOD ( 23.67 ) 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, hence simplifying the handling of error paths at various places. While at it, refactor the setup code for device node "memories", from pruss_probe() into a new function pruss_of_setup_memories(). It is worth noticing that this step is a direct consequence of trying to minimize the scope of the "struct device_node" pointer to make auto cleanup read more cleanly. Suggested-by: Julia Lawall Signed-off-by: Kousik Sanagavarapu --- drivers/soc/ti/pruss.c | 168 +++++++++++++++++++---------------------- 1 file changed, 78 insertions(+), 90 deletions(-) diff --git a/drivers/soc/ti/pruss.c b/drivers/soc/ti/pruss.c index 24a42e0b645c..9767d129a8ea 100644 --- a/drivers/soc/ti/pruss.c +++ b/drivers/soc/ti/pruss.c @@ -381,38 +381,82 @@ static int pruss_clk_mux_setup(struct pruss *pruss, struct clk *clk_mux, static int pruss_clk_init(struct pruss *pruss, struct device_node *cfg_node) { const struct pruss_private_data *data; - struct device_node *clks_np; struct device *dev = pruss->dev; int ret = 0; data = of_device_get_match_data(dev); - clks_np = of_get_child_by_name(cfg_node, "clocks"); - if (!clks_np) { - dev_err(dev, "%pOF is missing its 'clocks' node\n", cfg_node); - return -ENODEV; - } + struct device_node *clks_np __free(device_node) = + of_get_child_by_name(cfg_node, "clocks"); + if (!clks_np) + return dev_err_probe(dev, -ENODEV, + "%pOF is missing its 'clocks' node\n", cfg_node); if (data && data->has_core_mux_clock) { ret = pruss_clk_mux_setup(pruss, pruss->core_clk_mux, "coreclk-mux", clks_np); - if (ret) { - dev_err(dev, "failed to setup coreclk-mux\n"); - goto put_clks_node; - } + if (ret) + return dev_err_probe(dev, ret, + "failed to setup coreclk-mux\n"); } ret = pruss_clk_mux_setup(pruss, pruss->iep_clk_mux, "iepclk-mux", clks_np); - if (ret) { - dev_err(dev, "failed to setup iepclk-mux\n"); - goto put_clks_node; - } + if (ret) + return dev_err_probe(dev, ret, "failed to setup iepclk-mux\n"); -put_clks_node: - of_node_put(clks_np); + return 0; +} - return ret; +static int pruss_of_setup_memories(struct device *dev, struct pruss *pruss) +{ + struct device_node *np = dev_of_node(dev); + struct device_node *child __free(device_node) = + of_get_child_by_name(np, "memories"); + int i; + + if (!child) + return dev_err_probe(dev, -ENODEV, + "%pOF is missing its 'memories' node\n", + child); + + for (i = 0; i < PRUSS_MEM_MAX; i++) { + const struct pruss_private_data *data = + of_device_get_match_data(dev); + const char *mem_names[PRUSS_MEM_MAX] = + { "dram0", "dram1", "shrdram2" }; + struct resource res; + int index; + + /* + * On AM437x one of two PRUSS units don't contain Shared RAM, + * skip it + */ + if (data && data->has_no_sharedram && i == PRUSS_MEM_SHRD_RAM2) + continue; + + index = of_property_match_string(child, "reg-names", + mem_names[i]); + if (index < 0) + return index; + + if (of_address_to_resource(child, index, &res)) + return -EINVAL; + + pruss->mem_regions[i].va = devm_ioremap(dev, res.start, + resource_size(&res)); + if (!pruss->mem_regions[i].va) + return dev_err_probe(dev, -ENOMEM, + "failed to parse and map memory resource %d %s\n", + i, mem_names[i]); + pruss->mem_regions[i].pa = res.start; + pruss->mem_regions[i].size = resource_size(&res); + + dev_dbg(dev, "memory %8s: pa %pa size 0x%zx va %pK\n", + mem_names[i], &pruss->mem_regions[i].pa, + pruss->mem_regions[i].size, pruss->mem_regions[i].va); + } + return 0; } static struct regmap_config regmap_conf = { @@ -424,26 +468,21 @@ static struct regmap_config regmap_conf = { static int pruss_cfg_of_init(struct device *dev, struct pruss *pruss) { struct device_node *np = dev_of_node(dev); - struct device_node *child; + struct device_node *child __free(device_node) = + of_get_child_by_name(np, "cfg"); struct resource res; int ret; - child = of_get_child_by_name(np, "cfg"); - if (!child) { - dev_err(dev, "%pOF is missing its 'cfg' node\n", child); - return -ENODEV; - } + if (!child) + return dev_err_probe(dev, -ENODEV, + "%pOF is missing its 'cfg' node\n", child); - if (of_address_to_resource(child, 0, &res)) { - ret = -ENOMEM; - goto node_put; - } + if (of_address_to_resource(child, 0, &res)) + return -ENOMEM; pruss->cfg_base = devm_ioremap(dev, res.start, resource_size(&res)); - if (!pruss->cfg_base) { - ret = -ENOMEM; - goto node_put; - } + if (!pruss->cfg_base) + return -ENOMEM; regmap_conf.name = kasprintf(GFP_KERNEL, "%pOFn@%llx", child, (u64)res.start); @@ -452,34 +491,22 @@ static int pruss_cfg_of_init(struct device *dev, struct pruss *pruss) pruss->cfg_regmap = devm_regmap_init_mmio(dev, pruss->cfg_base, ®map_conf); kfree(regmap_conf.name); - if (IS_ERR(pruss->cfg_regmap)) { - dev_err(dev, "regmap_init_mmio failed for cfg, ret = %ld\n", - PTR_ERR(pruss->cfg_regmap)); - ret = PTR_ERR(pruss->cfg_regmap); - goto node_put; - } + if (IS_ERR(pruss->cfg_regmap)) + return dev_err_probe(dev, PTR_ERR(pruss->cfg_regmap), + "regmap_init_mmio failed for cfg\n"); ret = pruss_clk_init(pruss, child); if (ret) - dev_err(dev, "pruss_clk_init failed, ret = %d\n", ret); + return dev_err_probe(dev, ret, "pruss_clk_init failed\n"); -node_put: - of_node_put(child); return ret; } static int pruss_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct device_node *np = dev_of_node(dev); - struct device_node *child; struct pruss *pruss; - struct resource res; - int ret, i, index; - const struct pruss_private_data *data; - const char *mem_names[PRUSS_MEM_MAX] = { "dram0", "dram1", "shrdram2" }; - - data = of_device_get_match_data(&pdev->dev); + int ret; ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32)); if (ret) { @@ -494,48 +521,9 @@ static int pruss_probe(struct platform_device *pdev) pruss->dev = dev; mutex_init(&pruss->lock); - child = of_get_child_by_name(np, "memories"); - if (!child) { - dev_err(dev, "%pOF is missing its 'memories' node\n", child); - return -ENODEV; - } - - for (i = 0; i < PRUSS_MEM_MAX; i++) { - /* - * On AM437x one of two PRUSS units don't contain Shared RAM, - * skip it - */ - if (data && data->has_no_sharedram && i == PRUSS_MEM_SHRD_RAM2) - continue; - - index = of_property_match_string(child, "reg-names", - mem_names[i]); - if (index < 0) { - of_node_put(child); - return index; - } - - if (of_address_to_resource(child, index, &res)) { - of_node_put(child); - return -EINVAL; - } - - pruss->mem_regions[i].va = devm_ioremap(dev, res.start, - resource_size(&res)); - if (!pruss->mem_regions[i].va) { - dev_err(dev, "failed to parse and map memory resource %d %s\n", - i, mem_names[i]); - of_node_put(child); - return -ENOMEM; - } - pruss->mem_regions[i].pa = res.start; - pruss->mem_regions[i].size = resource_size(&res); - - dev_dbg(dev, "memory %8s: pa %pa size 0x%zx va %pK\n", - mem_names[i], &pruss->mem_regions[i].pa, - pruss->mem_regions[i].size, pruss->mem_regions[i].va); - } - of_node_put(child); + ret = pruss_of_setup_memories(dev, pruss); + if (ret < 0) + goto rpm_put; platform_set_drvdata(pdev, pruss); 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; From patchwork Wed Jul 3 06:55:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kousik Sanagavarapu X-Patchwork-Id: 13721469 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 90C59C30653 for ; Wed, 3 Jul 2024 06:58:56 +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=bxbxKt+yrBPNNKQZqw0DOsM2FX9GJEjPe3EATpJa3RU=; b=jOhoTiDEfBVurKfvv0eRogY941 50uqkO3dwKWw8NDHsoQCU9umjKf4wrarnqTBOzyG+kwpvPWp554qgmQeOxeoh1GVYhENzNQlQREBV muXS+vssEicPW09zcXtGV216aYebiJyWNZGX2QwOr6EkS+PV4JMJLeO3mu2T6Oax8Bi9fU/6VZoRf FEKK39zENhb26j2yctMqnIwoTtPkT0YecaCkOdAzNfLiHqcoSuiztKfglcDOb6C12SUHowofAnHP3 aSMJ0gUgswFG6avrQALiDFf0nz0PXR+eHYgqCrWpNG6F1a9vfWEa6wyVbwVjYixmaneqBmrqQptcR ggptbLjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOtx1-00000009Glh-3dms; Wed, 03 Jul 2024 06:58:47 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOtwb-00000009GbJ-2YUX for linux-arm-kernel@lists.infradead.org; Wed, 03 Jul 2024 06:58:23 +0000 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-2c97aceb6e4so175842a91.2 for ; Tue, 02 Jul 2024 23:58:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719989901; x=1720594701; 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=bxbxKt+yrBPNNKQZqw0DOsM2FX9GJEjPe3EATpJa3RU=; b=HI4pAqZKxDCYplVoaPbXaTj+PVrpWXzcFVdXRPGN5iKu1KZkQs91wgu8GHvN2JWffp MnCypNOdsYGYCsDtH6hRYhLBHyqKchI+H5keW1sNl4ZdX+S2Uxg17BwvgfQ9UCKPcomu Rvbsg9qTaMJsoivAIEIglBjYaJlFO3J4T2GJVyiorUrwTPykEfbUoQBIXA53Fky2MOr9 WMRNFt9+7CQS6NIolhVh3vckJ2d6IkHoEN7SBJ9hAO1EkyvCJXjTQfQBZPJYw+lXtUK3 /FK5JnbuRR5r4n3I9Y9ZfnvxysW2OGQnyrJR6nBmoebcxmS6BaljTMdrkapdwrB5X201 kl5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719989901; x=1720594701; 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=bxbxKt+yrBPNNKQZqw0DOsM2FX9GJEjPe3EATpJa3RU=; b=fNwCOKKqWfYsUEOQTWXw3MoKpyxoIS3XyfmDOVQyL1wLB+C6VsQUWtmBA1DqL7mHEv jTPRhT0qcSGlEEsrPrbB7e5mG0bV/AZXeXVod7+bvtCiEppe/xgokU8lNN1ZuYdILRRB zXP6CNFXJtUXapNl99ZUXjDjui+5v8B1Q9w2s2jAIwzT5R1adrmeeqjMXm+nLeCWXDE/ 1x6qzi+Yc4OU+TZsoNGVu1JEgzAzPzZYAp27oN5TJC3TtRlaS2jsp4RISjvuCp7ESauR h4J5BbSk9ppOtcHcWwgf/AjtAtIDQd1HTJYwH/mJ6Fm2ECl6Hu7n/r04dwO1vU628RAb kbnw== X-Forwarded-Encrypted: i=1; AJvYcCWA6e1zHWObuihcwpLnmR1jCSBxzpUeoQoGoKcrnd/BsJHFxiQGFevb8Iv19zkQJ6QaLEC7F0eB5j5sM1Ql2avYox9pyiw7AHAd4Jy+ha+tIV9WFLQ= X-Gm-Message-State: AOJu0YyVSEykuE4R3ivQL89ohNZ0RAbDLxQIAgIj5ZzKshERcHOR/X6Y WpmvgJpqyT/XqZVGTfH/EeNmdBVomMECwTCwo7ZrH/6CxrfPrfHF X-Google-Smtp-Source: AGHT+IHArs7mizExpBu5sv5B/RYD+ZEGUNrrOWSx56Hcy+SLKwJ5Kja6sljlxOWMSAWYm+qthagh5g== X-Received: by 2002:a17:90a:ec12:b0:2c8:880:776b with SMTP id 98e67ed59e1d1-2c93d71f509mr9257040a91.23.1719989900562; Tue, 02 Jul 2024 23:58:20 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 23:58:20 -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 3/3] soc: ti: pm33xx: do device_node auto cleanup Date: Wed, 3 Jul 2024 12:25:28 +0530 Message-ID: <20240703065710.13786-4-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_235821_673835_2880EDC5 X-CRM114-Status: GOOD ( 13.31 ) 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, hence simplifying the handling of error paths. Suggested-by: Julia Lawall Signed-off-by: Kousik Sanagavarapu --- drivers/soc/ti/pm33xx.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/soc/ti/pm33xx.c b/drivers/soc/ti/pm33xx.c index 8e983c3c4e03..40988c45ed00 100644 --- a/drivers/soc/ti/pm33xx.c +++ b/drivers/soc/ti/pm33xx.c @@ -383,10 +383,9 @@ static void am33xx_pm_free_sram(void) */ static int am33xx_pm_alloc_sram(void) { - struct device_node *np; - int ret = 0; + struct device_node *np __free(device_node) = + of_find_compatible_node(NULL, NULL, "ti,omap3-mpu"); - np = of_find_compatible_node(NULL, NULL, "ti,omap3-mpu"); if (!np) { np = of_find_compatible_node(NULL, NULL, "ti,omap4-mpu"); if (!np) { @@ -400,24 +399,21 @@ static int am33xx_pm_alloc_sram(void) if (!sram_pool) { dev_err(pm33xx_dev, "PM: %s: Unable to get sram pool for ocmcram\n", __func__); - ret = -ENODEV; - goto mpu_put_node; + return -ENODEV; } sram_pool_data = of_gen_pool_get(np, "pm-sram", 1); if (!sram_pool_data) { dev_err(pm33xx_dev, "PM: %s: Unable to get sram data pool for ocmcram\n", __func__); - ret = -ENODEV; - goto mpu_put_node; + return -ENODEV; } ocmcram_location = gen_pool_alloc(sram_pool, *pm_sram->do_wfi_sz); if (!ocmcram_location) { dev_err(pm33xx_dev, "PM: %s: Unable to allocate memory from ocmcram\n", __func__); - ret = -ENOMEM; - goto mpu_put_node; + return -ENOMEM; } ocmcram_location_data = gen_pool_alloc(sram_pool_data, @@ -425,12 +421,10 @@ static int am33xx_pm_alloc_sram(void) if (!ocmcram_location_data) { dev_err(pm33xx_dev, "PM: Unable to allocate memory from ocmcram\n"); gen_pool_free(sram_pool, ocmcram_location, *pm_sram->do_wfi_sz); - ret = -ENOMEM; + return -ENOMEM; } -mpu_put_node: - of_node_put(np); - return ret; + return 0; } static int am33xx_pm_rtc_setup(void)