From mboxrd@z Thu Jan 1 00:00:00 1970 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 240EDC25B77 for ; Thu, 16 May 2024 14:42:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:CC:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tPFbyMbFLpYZTCE9Ttf0zxR5J8UpkdnMLum8x/rvEGM=; b=gGLGYYuhTtMVjK /RFb5EKlPZmlK1hAJAdz/HX6E+0WSHJhxng5QMJ5Wg04SWZMuvevj5Kw12WhjEvOipfg87rKp26p4 F3oFBd8s+D/Vw/4ub+snL6+w611nyvpysK3oqT34busjfrMI7/AfRnSkueCwhn4tvYeYqEbUH7L1z 1eMehNJKoSZLq7MSr6kSSauCshcSYH0Ja2GCpH9KE/ooqOmT7fYf3BsEBi0o047qGmoqck8WwEabe Kon/wI4Y7VujAxcpgQx/FUnOimsD+GuS17m+uuXDVmkMGOBG20TnFeeMuPiDntHI0z6qqWR/mxv3L Gx0J70KM7cM4NGKTUBIw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7cIn-00000005Bck-2vNg; Thu, 16 May 2024 14:41:49 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7cIk-00000005Bb2-0vtk for linux-arm-kernel@lists.infradead.org; Thu, 16 May 2024 14:41:48 +0000 Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4VgCPZ6fsGz6JB95; Thu, 16 May 2024 22:38:10 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id E7673140B35; Thu, 16 May 2024 22:41:33 +0800 (CST) Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 16 May 2024 15:41:32 +0100 Date: Thu, 16 May 2024 15:41:31 +0100 From: Jonathan Cameron To: Kousik Sanagavarapu CC: Nishanth Menon , Santosh Shilimkar , Julia Lawall , Shuah Khan , Javier Carrasco , , Subject: Re: [PATCH 1/3] soc: ti: pruss: do device_node auto cleanup Message-ID: <20240516154131.00007a8f@Huawei.com> In-Reply-To: <20240510071432.62913-2-five231003@gmail.com> References: <20240510071432.62913-1-five231003@gmail.com> <20240510071432.62913-2-five231003@gmail.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 X-Originating-IP: [10.202.227.76] X-ClientProxiedBy: lhrpeml100002.china.huawei.com (7.191.160.241) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240516_074146_645864_84D92EB5 X-CRM114-Status: GOOD ( 23.27 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, 10 May 2024 12:43:22 +0530 Kousik Sanagavarapu wrote: > Use scope based cleanup instead of manual of_node_put() calls, hence > simplifying the handling of error paths at various places. > > Suggested-by: Julia Lawall > Signed-off-by: Kousik Sanagavarapu > --- > drivers/soc/ti/pruss.c | 48 ++++++++++++++---------------------------- > 1 file changed, 16 insertions(+), 32 deletions(-) > > diff --git a/drivers/soc/ti/pruss.c b/drivers/soc/ti/pruss.c > index 24a42e0b645c..8f238d59eca9 100644 > --- a/drivers/soc/ti/pruss.c > +++ b/drivers/soc/ti/pruss.c > @@ -381,13 +381,13 @@ 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"); > + struct device_node *clks_np __free(device_node) = > + 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; > @@ -398,7 +398,7 @@ static int pruss_clk_init(struct pruss *pruss, struct device_node *cfg_node) > "coreclk-mux", clks_np); > if (ret) { > dev_err(dev, "failed to setup coreclk-mux\n"); > - goto put_clks_node; > + return ret; This driver would also benefit from use of dev_err_probe() for all cases like this that are called only from the probe() callback. return dev_err_probe(dev, ret, "failed to setup coreclk-mux\n2); Handles any deferred cases nicely, but in general simplifies code by making these printer error message and return cases a single line. > } > } > > @@ -406,13 +406,10 @@ static int pruss_clk_init(struct pruss *pruss, struct device_node *cfg_node) > clks_np); > if (ret) { > dev_err(dev, "failed to setup iepclk-mux\n"); > - goto put_clks_node; > + return ret; > } > > -put_clks_node: > - of_node_put(clks_np); > - > - return ret; > + return 0; > } > > static struct regmap_config regmap_conf = { > @@ -424,26 +421,22 @@ 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 (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); > @@ -455,16 +448,13 @@ static int pruss_cfg_of_init(struct device *dev, struct pruss *pruss) > 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; > + return PTR_ERR(pruss->cfg_regmap); > } > > ret = pruss_clk_init(pruss, child); > if (ret) > dev_err(dev, "pruss_clk_init failed, ret = %d\n", ret); > > -node_put: > - of_node_put(child); > return ret; > } > > @@ -472,7 +462,6 @@ 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; > @@ -494,7 +483,8 @@ static int pruss_probe(struct platform_device *pdev) > pruss->dev = dev; > mutex_init(&pruss->lock); > > - child = of_get_child_by_name(np, "memories"); > + struct device_node *child __free(device_node) = > + of_get_child_by_name(np, "memories"); In this case, the scope of the device_node being held is increased quite a bit. Whilst that shouldn't be a problem, it is a bit ugly. Perhaps factor this code out into another function similar to the ones above? Jonathan > if (!child) { > dev_err(dev, "%pOF is missing its 'memories' node\n", child); > return -ENODEV; > @@ -510,22 +500,17 @@ static int pruss_probe(struct platform_device *pdev) > > index = of_property_match_string(child, "reg-names", > mem_names[i]); > - if (index < 0) { > - of_node_put(child); > + if (index < 0) > return index; > - } > > - if (of_address_to_resource(child, index, &res)) { > - of_node_put(child); > + 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) { > 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; > @@ -535,7 +520,6 @@ static int pruss_probe(struct platform_device *pdev) > mem_names[i], &pruss->mem_regions[i].pa, > pruss->mem_regions[i].size, pruss->mem_regions[i].va); > } > - of_node_put(child); > > platform_set_drvdata(pdev, pruss); > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel