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 8331AC4345F for ; Wed, 1 May 2024 13:32:57 +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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ior2gPFVlEOyeV8FJQcXfdx4VXM0R/609sKh6Of53VM=; b=AVfRQuVzQTBIDxy4SrUK8YEMNw wJVONoZma/T/4ImofzZV0HbpHBO+urVKtBZllJVMRe+/DSCEahuCKCgX8SguAFmw28GPov5tnAmvr JJ90Q65Xr7hM/b7NBtCJzJtbD5xY+kmhX1hENNyrNiL51RhUpeIBAQ5W7OSyoCf5qw8iS729+6zvY hBSy9f8N3T6xz7VAip5069GdvkOVHp1blu9lZFiXTp2uzyHUKRHN0pKIvG5D4rL/WT5Lg3Wzzr2Nk AeLhUx5pkGzpEg5zbrbM0C+DaFH0r/PlUJyyqQ5AWxRdHQSo9CZe5ul0pq8MZKWUYKE+gaLfVoYCU edhioIog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2A4u-00000009gfp-2cCr; Wed, 01 May 2024 13:32:56 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2A4r-00000009ge1-3Li2 for linux-mediatek@lists.infradead.org; Wed, 01 May 2024 13:32:55 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-34d7b0dac54so459771f8f.0 for ; Wed, 01 May 2024 06:32:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714570370; x=1715175170; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ior2gPFVlEOyeV8FJQcXfdx4VXM0R/609sKh6Of53VM=; b=QXQFgiX0B6dtjeORXjynNw8zGdnw+BcZoDFX4HOiEJx0LE64vx895r5x4x9l93u/lK YoRV+ACJXi4kuIDSzwRvCeKjNTYl7Q7MrulVTqkH9jUyeJ/pAUH9VEJ+3QNjdhxGnsZW DbNZwYhFHlFD0ywgpt1iYqqed9xHjmvoIfYhTOtZwVkbRUDdkFNUhrU4KIFzZEWDOUye jEliuPyiQQLLHi8Z7O+7WDjrdawbrNniSzKeelX5Tm+wETUJb1wa4qfkNwbFD2GcTZk6 +07cFodpf5k536oofHZbVY6YwmyOLpKtumr9/f/VGWb+OPqScY9KyicVu2g/xc2vEPR0 /cSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714570370; x=1715175170; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ior2gPFVlEOyeV8FJQcXfdx4VXM0R/609sKh6Of53VM=; b=WXArY+qTa9JjWWWiUbHiFGlqcizx+721+aUy0FNZsTjrBzaJvcljsE/h5dYWrZ7eDu 4KifMiC52q2kxDMtDKaIdCD4ymYTN6SMNwqSbx64NY7JGip/D5uBqMf2ZmlQeHSwyrqO EezDShfYD62gsgFd2ET9DiNwb0SiWsaFA9erTzoc83NXXbJnk+kF528YHbhh0VO85sGu MrC9461ZlIFiqUQvNMCbLZyvGcxR/WRxxY3usLN5XwLBza2blnXmAJLk+2T/XnJ29AEA n1F/xsz6GNkYSETVZU8Y/ZlFeI1/wfJIu+DDTxpqN5GIhDHteJXluIqkexIw+g8YAlGI KwgQ== X-Forwarded-Encrypted: i=1; AJvYcCWCsJzlZnbbsQQmxsiobZP0Ffyy3FoLzrcdji3M0ZyHr1V1a6Fv+KuCpCT/9XHDVZqA+24EcCPYO3tzWlowulxQsqYvVbRO9camxIBXI5fbywbz X-Gm-Message-State: AOJu0Ywf57xVFd08jCok++BlFci/l3dabRY+0i3FAuKq1XlHMSSMf7tK I2CrJPW4e9NqARInBjsyNRP3v0x2kXe4uI/sjeo+80Ukf2aJ4OaS4oNy7xTuecI= X-Google-Smtp-Source: AGHT+IHuNu3c35RsAkvpJAfWqKVWQhv6Z4Ac0yjTjDmpBKt12bv5Zna3drXEkGYfHrENBoZl/SwOjw== X-Received: by 2002:a05:6000:24f:b0:34c:bf22:73f9 with SMTP id m15-20020a056000024f00b0034cbf2273f9mr2265612wrz.28.1714570369370; Wed, 01 May 2024 06:32:49 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id d4-20020adfe2c4000000b0034a3a0a753asm32876234wrj.100.2024.05.01.06.32.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 06:32:49 -0700 (PDT) Date: Wed, 1 May 2024 16:32:40 +0300 From: Dan Carpenter To: "Peng Fan (OSS)" Cc: Linus Walleij , Thierry Reding , Jonathan Hunter , Dvorkin Dmitry , Wells Lu , Maxime Coquelin , Alexandre Torgue , Emil Renner Berthing , Jianlong Huang , Hal Feng , Orson Zhai , Baolin Wang , Chunyan Zhang , Viresh Kumar , Shiraz Hashim , soc@kernel.org, Krzysztof Kozlowski , Sylwester Nawrocki , Alim Akhtar , Geert Uytterhoeven , Patrice Chotard , Heiko Stuebner , Damien Le Moal , Ludovic Desroches , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Dong Aisheng , Fabio Estevam , Shawn Guo , Jacky Bai , Pengutronix Kernel Team , Chester Lin , Matthias Brugger , Ghennadi Procopciuc , Sean Wang , Matthias Brugger , AngeloGioacchino Del Regno , Sascha Hauer , Andrew Jeffery , Joel Stanley , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-samsung-soc@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-riscv@lists.infradead.org, linux-mediatek@lists.infradead.org, imx@lists.linux.dev, linux-aspeed@lists.ozlabs.org, openbmc@lists.ozlabs.org, Peng Fan Subject: Re: [PATCH 01/21] pinctrl: ti: iodelay: Use scope based of_node_put() cleanups Message-ID: References: <20240501-pinctrl-cleanup-v1-0-797ceca46e5c@nxp.com> <20240501-pinctrl-cleanup-v1-1-797ceca46e5c@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240501-pinctrl-cleanup-v1-1-797ceca46e5c@nxp.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240501_063253_867914_75A713CA X-CRM114-Status: GOOD ( 19.49 ) X-BeenThere: linux-mediatek@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-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org On Wed, May 01, 2024 at 08:55:59PM +0800, Peng Fan (OSS) wrote: > @@ -879,16 +874,12 @@ static int ti_iodelay_probe(struct platform_device *pdev) > ret = pinctrl_register_and_init(&iod->desc, dev, iod, &iod->pctl); > if (ret) { > dev_err(dev, "Failed to register pinctrl\n"); > - goto exit_out; > + return ret; > } > > platform_set_drvdata(pdev, iod); > > return pinctrl_enable(iod->pctl); > - > -exit_out: > - of_node_put(np); > - return ret; > } This will call of_node_put() on the success path so it's a behavior change. The original code is buggy, it's supposed to call of_node_put() on the success path here or in ti_iodelay_remove(). If it's supposed to call of_node_put() here, then fine, this is bugfix but if it's supposed to call it in ti_iodelay_remove() then we need to save the pointer somewhere using no_free_ptr(). Probably saving ->np is the safest choice? The original code is already a little bit buggy because it doesn't check for pinctrl_enable() errors and cleanup. diff --git a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c index 040f2c46a868..f40a1476e4ff 100644 --- a/drivers/pinctrl/ti/pinctrl-ti-iodelay.c +++ b/drivers/pinctrl/ti/pinctrl-ti-iodelay.c @@ -156,6 +156,7 @@ struct ti_iodelay_device { const struct ti_iodelay_reg_data *reg_data; struct ti_iodelay_reg_values reg_init_conf_values; + struct device_node *np; }; /** @@ -884,7 +885,12 @@ static int ti_iodelay_probe(struct platform_device *pdev) platform_set_drvdata(pdev, iod); - return pinctrl_enable(iod->pctl); + ret = pinctrl_enable(iod->pctl); + if (ret) + goto exit_out; + + iod->np = no_free_ptr(np); + return 0; exit_out: of_node_put(np); @@ -903,6 +909,7 @@ static void ti_iodelay_remove(struct platform_device *pdev) pinctrl_unregister(iod->pctl); ti_iodelay_pinconf_deinit_dev(iod); + of_node_put(iod->np); /* Expect other allocations to be freed by devm */ }