Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6267262rwb; Tue, 9 Aug 2022 12:04:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR6+4vQIvHPEx4kaQpf0Z8W9hPzucNquMACLa8c5lpmhw6oAaDnZUMlYBEBVhV2xjEEfll39 X-Received: by 2002:a17:902:ca05:b0:16d:cf59:2aff with SMTP id w5-20020a170902ca0500b0016dcf592affmr24920789pld.105.1660071893757; Tue, 09 Aug 2022 12:04:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660071893; cv=none; d=google.com; s=arc-20160816; b=QIL1pwVvk7oP/imlwzOLcQYwxpK+S30nJOf65Xls/GfmMx1+/9dFNHDlnmHF66d9Bo GwQStBncl6xhk0ZeclBTXwvQwuUHnfVWb4C9Um1JRGRpow82CJazFJURkKrThD672bRg dc0/+uNlW7MNifKxfZA/16l2y9oBIj0+zU30hyeGSHBNMIU9jnzxQt/3tjTVGk6V2xB/ xJ2K4aQ/UtN4N9a96Ry3hbO/nKAI/dn/pmnPnqwsp1K7gglPTnA9DtMa7LqiH1DO0t4U ZMTQr9X24wxHsCE+uqkCeA00S1NrUCDS1aNZNBOT9/dPL5jcmOBBBv0bzpW2L+dLGa2I 8XXQ== 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=ZR5H4FKbWOVrSvzb8pHsKGNspuuIAtjjf43qb2JVyODbjAQw7LdcjSybGwfYIZwQMc egWFCOuAzfQQxn/di+jYiriOTM7i2+4NeCYh3gJ20Gm0Z1mrALBe+jpNV36M0vzAwL9Z ukxmOI8KSFh/X2G1p8T/JgJTplzhZ4ytUDlnn7hORHhYTO1t8irxm9W3UUr76yeie21d 19r+LUDy7joQZRTmuiK+1xCCta7BAy+/vfdnEgSsbLhDB883b8Yg3jTyJUUR4CZQWmYU s4Laa95tD+3sFI+1sEQNg3/Fm8dZiYPghPlWjB9t3iwTTjptMxUl5L1KO8vzwc5FD1VC ZNlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pIVJXLUg; 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 v30-20020a63b95e000000b0041d8ca10b57si7496419pgo.223.2022.08.09.12.04.40; Tue, 09 Aug 2022 12:04:53 -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=pIVJXLUg; 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 S245331AbiHISE1 (ORCPT + 99 others); Tue, 9 Aug 2022 14:04:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344471AbiHISD2 (ORCPT ); Tue, 9 Aug 2022 14:03:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44CA92656D; Tue, 9 Aug 2022 11:01: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 dfw.source.kernel.org (Postfix) with ESMTPS id D0ACD61058; Tue, 9 Aug 2022 18:01:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48688C4347C; Tue, 9 Aug 2022 18:01:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660068113; bh=/w7F+iipsaqlzfkd/2XvhEnRnAT6KKvkuj4hCLT0PrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pIVJXLUgoTdDUNIIjSq1IqBE0CuXvw1SX+joAUGdvvRM00uO7ffyW3m8qM1usMG9o gxs4gP08ALbt/d4SD0MjVAdRYgeOkqaa+qfVSQXcphBIzgrgxF2G+W2UmcXZS2hw75 /bkbgvoV2IAHlcKzHV72Acw0cPI7dmY7EZFcjoW8= 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.19 09/32] scsi: ufs: host: Hold reference returned by of_parse_phandle() Date: Tue, 9 Aug 2022 20:00:00 +0200 Message-Id: <20220809175513.392199843@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220809175513.082573955@linuxfoundation.org> References: <20220809175513.082573955@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,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;