Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1943183imn; Mon, 1 Aug 2022 05:54:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ttsNQxtw6fyET6dKA45sH4RCQqXqRL8klPGpdVg5ej362ri9XRRm2ZK8L3RIFRy37RRH4M X-Received: by 2002:a17:906:ef8c:b0:72c:780c:6693 with SMTP id ze12-20020a170906ef8c00b0072c780c6693mr12322871ejb.196.1659358472152; Mon, 01 Aug 2022 05:54:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659358472; cv=none; d=google.com; s=arc-20160816; b=DWRu/FKTzRMyupb5FDJRTNmfwsd5TBRHs9flMq0r0ZeXzNNkxARQTzsQpn/QTsCNnf iwUCAOrq790OmlwX5tyZ1sTCdSxJyPsvovL/ubS91uiizX3teMuSMS8mIsOe+IJqLmGf /c6NLzHRHFcg3SgjvbiCnnLMt57YnfhSJpA1tvtUa7dslVY84rjBxDpLcwRr4j6x4SJH KmsJsK//C8OtMEwt+/Uq79TVlC3As1uvV0/ozLGyAJOC0lAUhtNwBOMIvrQxm2M8Mo3f 0c0LjVTk74k1S4uipE+wwvT+yknV0QUoUyqxnejEEB5dFy7P+hpB0xxVmt9Zk5tJjXgz BLRw== 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=H424U4yKepH56VgI3Lx/6CtdEUxadA7Lo0ASziR4IsU=; b=YrVI6NH1q5KhAe8h+JsMgy3TvhIpFPyJ1eHzuVujTF0FaQBmZ0gQ2PDCsq0xFaLV2o HHFpKUaQCbH/n1BiW+ckQnGMxBj4TQbfPapWXb2suTRwfdisANhpvKh2JUsrWPL0bz0R 6+1PzS46DTLMnRVh82S2v1EwPpOft7JJRbRaZv4ucqMAsnpY4htiq5iPJnxJ0uEJzsiO MSULljVHrkOAXUNmQajh1ktBVtsJ4xWls3wzc9ykDIexTxTMD/1At4PQGKfCpu7l0Tpy ZJ3fxzNFgAFlEFxMOYP1Jm56HBebJaHvJ3rcyFM4SRdi2cisslm+xSox2nYo7I9lXivG idcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Puob3fpM; 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 n22-20020a1709067b5600b007309383490esi1220408ejo.122.2022.08.01.05.54.07; Mon, 01 Aug 2022 05:54:32 -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=Puob3fpM; 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 S233188AbiHAMDs (ORCPT + 99 others); Mon, 1 Aug 2022 08:03:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233189AbiHAMAw (ORCPT ); Mon, 1 Aug 2022 08:00:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E306B4F655; Mon, 1 Aug 2022 04:53:14 -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 794F9B80E8F; Mon, 1 Aug 2022 11:53:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4470C433C1; Mon, 1 Aug 2022 11:53:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1659354792; bh=A4HOruPbbaKVIxq1nerFl1jW8NyTpVY694MfOQPQpO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Puob3fpMNznZXy07aSZuk5YC5OWnIdEcUVqeZLJJ1jTBgQ05R3KMfVjrUIcXbd1LI 5DdD2LMbtJKJh+xt7Va9dhwYj7xpqsN0WMqYAqfvEHje5PKfF1W6FbgIq49dzzloBJ qpGWNsfLrHXox6mi13BqFJtSgEn84W6QEOD3HqN4= 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.15 22/69] scsi: ufs: host: Hold reference returned by of_parse_phandle() Date: Mon, 1 Aug 2022 13:46:46 +0200 Message-Id: <20220801114135.418190782@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220801114134.468284027@linuxfoundation.org> References: <20220801114134.468284027@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) { char prop_name[MAX_PROP_SIZE]; struct ufs_vreg *vreg = NULL; @@ -121,7 +132,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;