Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3411821rwa; Tue, 23 Aug 2022 04:27:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR69pc9tAOarz0wQBR42npdTmg4EcvImLpOwLK11K7nvTnglPin6GTkZ9gAXuezf3035eNUH X-Received: by 2002:a17:90b:2c06:b0:1fa:e636:105a with SMTP id rv6-20020a17090b2c0600b001fae636105amr2889481pjb.169.1661254077148; Tue, 23 Aug 2022 04:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254077; cv=none; d=google.com; s=arc-20160816; b=OKSm3GVCXEMt11XU2AytZryX+sTuU6ZlRzb15PrTSSivuu+wTlqtrHJOsOg2QFN2N7 XsbysdPnUTVfxFKiI8UXKiM5E+RXqeFFgfv2Ism+/qy80II08WGaT3+TLpM93NAz6nvw 3nzIo0uJnxnCtt651XdEIVLe0qA4/Qw2cR40xu8uzJxyyVEDYAXgRHloZ82kdJ4g7bBx a18NvQBQUfjrmp0+Bvp/fh0w7anycqV/6L+SFkQJFsGPD7uBHwi4zSzB9Q25feAuzfLg 6xtK8lR9a9Qa5RcN6vyBOCrDpOKmcWMBrLDb45jieOjj0+4uMf11Mc04YErtMutaYKVM JQAA== 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=WOv/KqNR/I2rnazIPsiCHufigyQIcoR9BEb4m8tzLzU=; b=M/9Tu0XwhVxGFpe+MsU76gnmjAL7CeOQQ7+7TPgfVMvwPRNEUrO6u6gG+LROgHPIbC tRawvJJ9cPAeN1vEzhIaLZgjDHsWJTiM0zoAlBNrXdYAc/u8bC7ygN9Cl9uVEZxF/y94 kZGLoyQbzWok/aGJBHoWvbUHcIs1sCpRVwz6CH1rcfVcZN/b22WD0SEZUQ/MYNfCuE1E bCBRQ33Dx+5ci2+NnwpZU81X+dXdZTfp63NMpyDrS03BTWU+UHEhZP1VT3nhL+vYMeKF G094SMMdmm/tmwPKOSUrbOqfYBzBBQMvs89CP4uU/SfuV9WwgfuszlAxbtofqqMFcXEl IoOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0KpY04kB; 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 c14-20020a170902d48e00b0016eef21566dsi16547534plg.198.2022.08.23.04.27.46; Tue, 23 Aug 2022 04:27:57 -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=0KpY04kB; 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 S1350186AbiHWJbw (ORCPT + 99 others); Tue, 23 Aug 2022 05:31:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350105AbiHWJ3u (ORCPT ); Tue, 23 Aug 2022 05:29:50 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B12C91D06; Tue, 23 Aug 2022 01:37:43 -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 D8472B81C5A; Tue, 23 Aug 2022 08:36:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20ADCC433C1; Tue, 23 Aug 2022 08:36:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243788; bh=/w7F+iipsaqlzfkd/2XvhEnRnAT6KKvkuj4hCLT0PrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0KpY04kBcobziMb2kHfSay8XgIUFnyGqMK0kd2utZMUE3J8fCkqRy2MbVfa6DkEvy U/9nMG9OcnASZI6mM+8nh23DOv46x7fMTyRsC2xmgC2wgW7NnbfjfRGDdicWVure7q eB6F7cXfHk70y4290UnQ3hvUvcKTyI5NE2VmM8Ug= 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.14 004/229] scsi: ufs: host: Hold reference returned by of_parse_phandle() Date: Tue, 23 Aug 2022 10:22:45 +0200 Message-Id: <20220823080053.430708004@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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 @@ -124,9 +124,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]; @@ -139,7 +150,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;