Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1940026imn; Mon, 1 Aug 2022 05:50:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uAP6XFquu4GluxUDpbSxjZ+Ur8H1Z25sHZEyxF+UQG/k56PGjOmgEA2qNSwirYztHvp4uY X-Received: by 2002:a17:906:478b:b0:72b:5cd6:3f50 with SMTP id cw11-20020a170906478b00b0072b5cd63f50mr12961295ejc.514.1659358202088; Mon, 01 Aug 2022 05:50:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659358202; cv=none; d=google.com; s=arc-20160816; b=XSaCX1Je7nwGrsHwcNxyjrzk3hTr6sd62rKCx8kwhAPyNstvN3Id2P2jowMhVMLlq5 1nCma1NUOqPfOO7PCjHSmmtKhjIT97wSw6ikcJWpKmalWoEEF0CF83EkSoajW4cACV6f pOvo8aaz6AvtPdp/FZjz/Wc/JDlMhD7Wd7qvymLUSHY0PUFtjkUsZF0gIb1rogJcBbRi /Ohb50n8ZqOO9q2YTlYGqFTpKnVRctsaiiiK6UletqNbNmUjxzFeIGwhFgPspCwOKBaF uRQPkSMssJAU6KHkEXTF6qnbsE15N/3hetZt59xImUrV7Hzv2rtqC/pXEWdDGeIUCGJz V/xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=648DU8Uc93DmaJ/bfajG9qn1E0OudhMw4RqX0taaHn0=; b=Ytxa+P/kPHWEJSS6sIKM4DSvPWvvwur2eX+KQlv53RULqs6OyjXVkajEu5my/8AD9F TmFeejgUMrADake9f4H4uDqAiSgsPtcduL0F3r0vVQ+VHKtVrpUu9zgagGBL6WdQ6onU jMub4Nc6HtagquqSbkiPnF6k+ZBtMGzihxljgSTb4H5ac18KWoSzYdc8xEYyfQTSbpgp 44wue3FvLBbN21ULNpw9Q+2EPKp5UpbZMQN6GmynH1L6J1c+UDM5nEn/7C7AhzPsTEx9 ICe2NuyduRgpMaAWFsGkF+kfoSkdKgB5cf7EW2j5YS2uFgENmQNTtjRS8YN0e850jLMw Mn/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LpCN95gs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sd6-20020a1709076e0600b007304ac98b24si6199045ejc.754.2022.08.01.05.49.31; Mon, 01 Aug 2022 05:50:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LpCN95gs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231491AbiHALxL (ORCPT + 99 others); Mon, 1 Aug 2022 07:53:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231708AbiHALwh (ORCPT ); Mon, 1 Aug 2022 07:52:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A688422CF; Mon, 1 Aug 2022 04:49:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D4011B8116B; Mon, 1 Aug 2022 11:49:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BBB7C433D6; Mon, 1 Aug 2022 11:49:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1659354591; bh=Clqc8ivs8V+s/0FqC8Cc1hvDbi7dZvJI63M+KMCFpsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LpCN95gs8dC5Cn2ro4cq67cU8p8e6dQY47tEsFnX3IBquGGapdi1DWJAF8t6wPLdz 1XK/k7q/W5G57kOISpo95Y2RlXuZ+kJVijG5HIVbMX6mDYBI1tOxkIeK4HKC/jjGSH vIm1+nCD1utVPX0cxzGtkYVtqfxsnRexZeCxxo/k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Liang He , "Martin K. Petersen" Subject: [PATCH 5.10 16/65] scsi: ufs: host: Hold reference returned by of_parse_phandle() Date: Mon, 1 Aug 2022 13:46:33 +0200 Message-Id: <20220801114134.372823933@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220801114133.641770326@linuxfoundation.org> References: <20220801114133.641770326@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Liang He commit a3435afba87dc6cd83f5595e7607f3c40f93ef01 upstream. In ufshcd_populate_vreg(), we should hold the reference returned by of_parse_phandle() and then use it to call of_node_put() for refcount balance. Link: https://lore.kernel.org/r/20220719071529.1081166-1-windhl@126.com Fixes: aa4976130934 ("ufs: Add regulator enable support") Reviewed-by: Bart Van Assche Signed-off-by: Liang He Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/ufs/ufshcd-pltfrm.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- a/drivers/scsi/ufs/ufshcd-pltfrm.c +++ b/drivers/scsi/ufs/ufshcd-pltfrm.c @@ -107,9 +107,20 @@ out: return ret; } +static bool phandle_exists(const struct device_node *np, + const char *phandle_name, int index) +{ + struct device_node *parse_np = of_parse_phandle(np, phandle_name, index); + + if (parse_np) + of_node_put(parse_np); + + return parse_np != NULL; +} + #define MAX_PROP_SIZE 32 static int ufshcd_populate_vreg(struct device *dev, const char *name, - struct ufs_vreg **out_vreg) + struct ufs_vreg **out_vreg) { int ret = 0; char prop_name[MAX_PROP_SIZE]; @@ -122,7 +133,7 @@ static int ufshcd_populate_vreg(struct d } snprintf(prop_name, MAX_PROP_SIZE, "%s-supply", name); - if (!of_parse_phandle(np, prop_name, 0)) { + if (!phandle_exists(np, prop_name, 0)) { dev_info(dev, "%s: Unable to find %s regulator, assuming enabled\n", __func__, prop_name); goto out;