Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3324388rwa; Tue, 23 Aug 2022 02:51:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR54V/EQT3u+xTTaYVsa95dM/Mszl8/fr3cYqJ4jrZVRQJz5sj+KvuStd8vvFSXIb3bDFizS X-Received: by 2002:a05:6a00:80c:b0:536:a95a:f581 with SMTP id m12-20020a056a00080c00b00536a95af581mr8523977pfk.66.1661248314242; Tue, 23 Aug 2022 02:51:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248314; cv=none; d=google.com; s=arc-20160816; b=NDT241n2A3V2OSmPJP85X6GtidyRDgs3DBninQdb88W0++5AGNP+c9mgq6SE0FjWcq 0S08hKD/if01PqVym+0veD2+AA7HQ79yBB4oxwQZi+RE4IV7HP7l7UCxZv/kYt1jQNCv roJOTVPOzv5tt7f2/PgNJ78pGUR9tz7dTLPvTJ7gRltnuBlO507X8bzfSIAZqIwPz0lT 7n7beJ9uaR6qHXrhNDeA5Y4LYGwtKFaQbCTx1ZQlq+Eqsds0xncTwZAWvt9JPablu5/R LT4zLEgVgBHqm+KEzzR+LXr9BFAjcE7+ppXz+yyi6z2wbe3Y0iDp0IwBDGJMXEuK1WD4 tc9w== 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=hW2pEtOGO3ndGZWCB/8mpCfKbQsJankVugT2+7zJfHQ=; b=z7d+fy6MdqE4OBEu1d6X+lJb5QPsc1v4Z0arZs/S5o7LxPV2/sMOvCYfRxd6cn710B ZZovseGW9xN8RyLHJxYSNsxsBuvQ+yHdae9xnIrcTcYwGlT0Xr5plaVMdQeSO8cCaIGh I3rmux821LGAFKxbgCIty/zlOZ3bNSJajH7U8ACn5HXTH+unjnmF6Vp+Pwo7fMEHc5Y0 N5kpgBvU1DBFt3bSrjDmLIqthxtH3ObOY/E1aLyyuj+UwYtYb8vRe0ZGv9XzGZnIc7xq znl5LcfZaiNDnbcHs4ccqoAu2DeW//Sts+jLNCTfFRtfreg6MT+C3qqlUU4J/nzk3NAh Jfkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZsptSfGi; 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 m12-20020a170902bb8c00b001712cbdfa11si9185894pls.581.2022.08.23.02.51.43; Tue, 23 Aug 2022 02:51:54 -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=ZsptSfGi; 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 S242117AbiHWIMa (ORCPT + 99 others); Tue, 23 Aug 2022 04:12:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240165AbiHWIJs (ORCPT ); Tue, 23 Aug 2022 04:09:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A00EA67CBA; Tue, 23 Aug 2022 01:06:32 -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 dfw.source.kernel.org (Postfix) with ESMTPS id B43A8611A8; Tue, 23 Aug 2022 08:06:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B950BC433D6; Tue, 23 Aug 2022 08:06:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661241991; bh=iulYAl+pYZdrIyCxSiw/cLHIeTOyzhJvoonrV7c/uLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZsptSfGiBpNTHL58WPGHGXLBiqiof8mfXEaQZwEm2ECopsyNsJzjSt4SFDSwx6G+M 4Xrii4wlfq0lDW77V6R3AjQGDKDsHZ0VqLYFKgiNSil55AqzQGzJh9zZ6S4iv4u9/o H0Gt789eJ3Mw7vkhyIpWFjxKuHdZgdHe9E+ZnLok= 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 4.9 003/101] scsi: ufs: host: Hold reference returned by of_parse_phandle() Date: Tue, 23 Aug 2022 10:02:36 +0200 Message-Id: <20220823080034.726420269@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080034.579196046@linuxfoundation.org> References: <20220823080034.579196046@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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,T_SCC_BODY_TEXT_LINE 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 @@ -126,9 +126,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]; @@ -141,7 +152,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;