From patchwork Wed Aug 14 19:58:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13763898 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6C281AED23 for ; Wed, 14 Aug 2024 19:58:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723665511; cv=none; b=jZLXbJaKINUDyHcUkuAKoBd0dDNGpPn6Lmwcag+ot0sXF4VMEyTrYGcLX+u7ZtajU3SGqP4+py5iDDzxS7SPYlxFFzWXqV+0pZY/7V2MFAX7hUTySHXUxCmCPnO4WRRU6wOUSUIxyyvW8lRf/KZAnhHIGr4S4IOa/KtkjJ5Fgns= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723665511; c=relaxed/simple; bh=v6yCN++aTWIn2HL04PVf4IrdFZo3E5raTygn8B9Fh9k=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=HmHo+CufyL3xy6/iJOlIPCO8VY+xYSBLcu6ng2MSR2aXDI6Cp8Gn3uxSqRS90ODmyohZDn3cw9h0Bja2XdQPPE0F12Ne/D18zRmkgI5l26RMWMPHIXg8e1rxFJXdCoEqhtPKmDY2f9Wj3UH3/B0JoggNET8Gr+XL/GfNWjNrq6A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Hgmn2X+m; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Hgmn2X+m" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4281c164408so1019595e9.1 for ; Wed, 14 Aug 2024 12:58:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723665508; x=1724270308; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/4hCGRVnEuxwiy7oU4DBiRNiiuMGKwjKKo5OtTueCic=; b=Hgmn2X+mgImXg7PDDf71MjzTpzcRO8nSqKN3eXuP1Jfz0NA8MIzG3wyT4Y302KKNGU Yo5/lSjjaCqwMCF27bdvPHheNnh0T0YJsQNlEWfNjxiXY/oKtP2jM6ikFOVjxfCiLqKi xjyZY7PnRT6bi3CpRvsrpFs+v4EZGvPqpNA+WmDoo7tUynKnoyn32z+XLZv+2R/MR/dm AKrD4jvuFUX5K5PUaQdtM3yI0KCNkkxI04/C3OdqtBIfgE34GU5i/nDYBs7mEjHn6yGf w5t9cqjjpEcMuZlBgVzXMvKNUEv+uW19MwnlnfEGv9M/PhdFbiGX5mArzgE+G61bd5rM 7RBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723665508; x=1724270308; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/4hCGRVnEuxwiy7oU4DBiRNiiuMGKwjKKo5OtTueCic=; b=lQrwUBU36UOS0VtlT58af/tTUBLgfxB/tGzo+Hp0k60l/MsrFxvyNqF+nUz3P6mRZI g7UKcLjgu1V1w88hO6BBP+YDweZ/fYTHxlT+fL2htAZRfp51CWOo3wSl9jX7ZPxJyQGK gH/t/H/VYixPUJWR6rANtcsJgn36FK8Zoy/e+D7hcGnM/mm4ju2CSeBbbd3BxyOTplPh 2jTR1YqPCW3nmdLgCc3EK0QTBxESbuQAOOv+fhQN5EJtLH/ULpbSsYWsh96F0V+dn1pF TbvAgwfcAnhK6Vfo71bM4lihtKzzvqN1DMzU4nns+nBu5NKsRA1sg/LZwwJsung4IZ2i U6dg== X-Forwarded-Encrypted: i=1; AJvYcCUgAyHT2cbE96eTuq2zUcmplej6kEgNrqvh73z+o3mNvws6N0Q7sIh7iMslaBY3+wJWj1JDSyvd0P/MphNGPgDgCao6VUXTCvE= X-Gm-Message-State: AOJu0YxJQLmv3HrwsP++g0euM+/jDh/6PQQ9Qtg6KoybCuAqY5d3rgws r/UEnhk+rZerZQxKoK9gNhJcAC4jhxAkZtrpfjLz1gfCWzV8O9c+z6UXCy53Yl4= X-Google-Smtp-Source: AGHT+IE3BzsR7UafBAgIAWRDl6haElUv/rAMn14EgEbQx6m7ZWfdFr9PhRc5eYrYxjkWsVukGaOw0w== X-Received: by 2002:a05:6000:2a7:b0:368:319c:9a77 with SMTP id ffacd0b85a97d-37177783998mr2835327f8f.29.1723665507702; Wed, 14 Aug 2024 12:58:27 -0700 (PDT) Received: from krzk-bin.. ([178.197.215.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36e4cfeef76sm13482263f8f.59.2024.08.14.12.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 12:58:27 -0700 (PDT) From: Krzysztof Kozlowski To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH 1/3] thermal: of: Fix OF node leak in thermal_of_trips_init() error path Date: Wed, 14 Aug 2024 21:58:21 +0200 Message-ID: <20240814195823.437597-1-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Terminating for_each_child_of_node() loop requires dropping OF node reference, so bailing out after thermal_of_populate_trip() error misses this. Solve the OF node reference leak with scoped for_each_child_of_node_scoped(). Fixes: d0c75fa2c17f ("thermal/of: Initialize trip points separately") Cc: Signed-off-by: Krzysztof Kozlowski Reviewed-by: Chen-Yu Tsai Reviewed-by: Daniel Lezcano --- drivers/thermal/thermal_of.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index aa34b6e82e26..30f8d6e70484 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -125,7 +125,7 @@ static int thermal_of_populate_trip(struct device_node *np, static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *ntrips) { struct thermal_trip *tt; - struct device_node *trips, *trip; + struct device_node *trips; int ret, count; trips = of_get_child_by_name(np, "trips"); @@ -150,7 +150,7 @@ static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *n *ntrips = count; count = 0; - for_each_child_of_node(trips, trip) { + for_each_child_of_node_scoped(trips, trip) { ret = thermal_of_populate_trip(trip, &tt[count++]); if (ret) goto out_kfree; From patchwork Wed Aug 14 19:58:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13763899 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A2951BF30F for ; Wed, 14 Aug 2024 19:58:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723665512; cv=none; b=bTrWQMEXVjeMZncxWKjLJPtHMPyjqk4ZwIcWPFLEmhc2ebxqpluGAVqc+DoMKHVkJ+yw4rdITn5N1Hqwendm4MHQ6UuJIyTZjvdhr4VscmaHgh2U35WJWoqUK5+YjLUrpnv68XRgiQUZysNDstmoNldFnfsdVCGI88aDwuAUcig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723665512; c=relaxed/simple; bh=DrwiAoxoyEqBFQNKyiASdBbPbGDrpRDECmNJiSspMII=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QnQNmxojoCilEvGuXSV9p5vryTjOnJPsECmWGroeL3eeuJM0OWUXAoTLdirc/NItuXpRKMh8/Jw1SrwwD5kmd1Y2tPThXNu3m1u9HWkBKw4daQTTBpDAQNsFljGkSothGnZQtadMyufaUKBilsIlqq5SB2BxiZzOB/Q315bwvds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=lo/7IS+e; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="lo/7IS+e" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-3687ea0521cso160527f8f.1 for ; Wed, 14 Aug 2024 12:58:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723665509; x=1724270309; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Cb257pBqZhP6UYLMmFTbQ8fmxgCfB52QrCQL5eJC8t4=; b=lo/7IS+ey3auZSvDTSEb9NhSRN8yGfx0CVjtG4SKmKZ8W6r6XQNu5suG7g6u3/CrwW 5/HIGUctPpX8SKRjxLSGAF3FWYfbQzGCy+vFpll9WchS7tdOrYU5/fJsbA0rqxNrPLXM C5PI6BVuITA/chhTXiBmjBEaKmEpJKsDA2CYrQGpUwQ3VdVxEcJu5vGmP4PWBK3OcVa0 TEvL3iU76aMx7QvmJ++zdnv+xlFrrUtjwusZowOSAOTDYIh/4cgX9tjCkXl6GX5KFAtt lruq7iZE3BgY3zO3Mq1Urct5Hj094ZXY5yXgI/ls3mbd2CPR1bhVvPlwyHHiUqC39Xb2 /eYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723665509; x=1724270309; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cb257pBqZhP6UYLMmFTbQ8fmxgCfB52QrCQL5eJC8t4=; b=E3pyCVaZwV/PsN3sXLPKje1gyPr4Y9BrvVfYvj/mfwMPCZncAIMickJvGBFrkQ8Q9r Kb6BJxcjvFvSwp/0nl++VexwSuXew6XBKic1L5P3hNezbYS7huvegI6sRnFBnAQHdXhT 0pFVW6Bgz8nO6B6Fv32QwZGkAl1R+Z9OkboeigGzyW9IkUT6l2vqHrtYaQRTfly/0crq CvDX98G68XfQsAIlWqFUy5iQ1aXDLKCWjI8ECq5Mh+147HKo6vEEvbSm1Pdw/wZu6mA0 S8E5jwiG7PTqfmxjI2RyvMXMH63jgAONPT5NYT0ZXRsZLwHXuAWxjVD6phHttUOizkp6 Yscg== X-Forwarded-Encrypted: i=1; AJvYcCW9KTBw70xmSHhDBJnUK9GweiVtvNQy6AtWyhYaEYkaaAO1HEt5KwBRgcrW7GEilU9L8sAP9EN/YWF2afMg/tXD/tHD0vjLIJw= X-Gm-Message-State: AOJu0YyrYuJ+LlfSF039d+lbmzfTLESnAzqZG475rw57o5Qtcb6EXpId HYLdRxU1dXqGty0HVxW7HsNVZ8Do6VI7Q85mi1C2j0tSS9K4Anrh2gbyLr61uRY= X-Google-Smtp-Source: AGHT+IG88V2hU+EgJ7Lr0puPbxnLdAZ2m99QYLzaH5h8aG7w+H+SP6z/ChwWFYdSv8IxFj+SArDOkg== X-Received: by 2002:a5d:4ad0:0:b0:368:6606:bd01 with SMTP id ffacd0b85a97d-371777fe399mr3092052f8f.55.1723665509278; Wed, 14 Aug 2024 12:58:29 -0700 (PDT) Received: from krzk-bin.. ([178.197.215.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36e4cfeef76sm13482263f8f.59.2024.08.14.12.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 12:58:28 -0700 (PDT) From: Krzysztof Kozlowski To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH 2/3] thermal: of: Fix OF node leak in thermal_of_zone_register() Date: Wed, 14 Aug 2024 21:58:22 +0200 Message-ID: <20240814195823.437597-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240814195823.437597-1-krzysztof.kozlowski@linaro.org> References: <20240814195823.437597-1-krzysztof.kozlowski@linaro.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 thermal_of_zone_register() calls of_thermal_zone_find() which will iterate over OF nodes with for_each_available_child_of_node() to find matching thermal zone node. When it finds such, it exits the loop and returns the node. Prematurely ending for_each_available_child_of_node() loops requires dropping OF node reference, thus success of of_thermal_zone_find() means that caller must drop the reference. Fixes: 3fd6d6e2b4e8 ("thermal/of: Rework the thermal device tree initialization") Cc: Signed-off-by: Krzysztof Kozlowski Reviewed-by: Chen-Yu Tsai Reviewed-by: Daniel Lezcano --- drivers/thermal/thermal_of.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 30f8d6e70484..b08a9b64718d 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -491,7 +491,8 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * trips = thermal_of_trips_init(np, &ntrips); if (IS_ERR(trips)) { pr_err("Failed to find trip points for %pOFn id=%d\n", sensor, id); - return ERR_CAST(trips); + ret = PTR_ERR(trips); + goto out_of_node_put; } ret = thermal_of_monitor_init(np, &delay, &pdelay); @@ -519,6 +520,7 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * goto out_kfree_trips; } + of_node_put(np); kfree(trips); ret = thermal_zone_device_enable(tz); @@ -533,6 +535,8 @@ static struct thermal_zone_device *thermal_of_zone_register(struct device_node * out_kfree_trips: kfree(trips); +out_of_node_put: + of_node_put(np); return ERR_PTR(ret); } From patchwork Wed Aug 14 19:58:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13763900 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 768C31C0DC7 for ; Wed, 14 Aug 2024 19:58:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723665514; cv=none; b=X8jgzpp/Ga9FQkAUuhLO+mId4Pc7fqE4gAWNFYjrG1LJESDgw3spl/0pFWi7lJT/sqKhzeY2ko2J9LG1va9wmXRmLy/FNK2lcjz0JPIWwTjYd1kw70srfCM1P0ZKTnqipk6T+JHzH8wDeidNhSlx8wxp7gAo6SWGLDWNwT3bBQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723665514; c=relaxed/simple; bh=mMyEb0aqCda54qwh073Rn7++7QwzrUQlVi0xlbd0UY0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tC4XdYJzi4MMEcEnHrwrX6JZ+DdopxHweNX6i+huPNgRUJOU/VYwiqx72tqK8DCf2dsp7kFvS5dnKlmEJ/Lb+dvUlammFTq5tTVgzp3LPMI/rRMK9JelLMVVpn3n4p0U9AGchKvTq/fTlL6mzk319Unk8YFvHzRXzD6Cs6aNGdQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=tBxC7puM; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="tBxC7puM" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-428e0d184b4so954755e9.2 for ; Wed, 14 Aug 2024 12:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723665511; x=1724270311; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=x+R8NVOLOXBT5QSEMY/JOLRg5p8mbpf+sRpuYCIgm3Y=; b=tBxC7puMlYOz8w2NNpp9C87Gsbku3Mdq0tyD2HlAmMYYlP637LtAxLzTz+iDAPLNEw ACf20Ts84Pv6Rh+9JhFCmT881YFCKcTqvTqMrdMpJTt6G+j839buwMlYu08GAKCB7pct pt/ssg9aLYPbtwI710WOzfbvuAtPvNizIMXNraJVxOmOL8pVJApwquxSssFKm6e4gney G1p6nzgfdJjoM9ll0hBdF4yowPCUY3p+ZKb8pQ+OkntysvybmHuLA8CTkxAHv8QozEkX 1x0z8vZDTizs4LWrK19rLXnTMJPuvdbOi1C/rlgaAPtgh1ykxmjCaCVeu3wtZGNzjPsA +MIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723665511; x=1724270311; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x+R8NVOLOXBT5QSEMY/JOLRg5p8mbpf+sRpuYCIgm3Y=; b=P6SaHO90Y1ZO/1IlmR2u7tvYuG43vsasF8CreXCd2G7snMPqv8sauQAF7h5eVld9EP a7EE7sf1yev5cfSq86fL7GqG6meKs6FCBLE5CkfOCNi55KRxMBJD7AvWXahNHG2hQuWy uIzczDdF5KFLQbvfBjDCc94L7X+AW8bdaslN59iTBjn7w+4kDyceqr6k6iHaAKvlSquc bRfKkOIE8koAY8p5zhpikayUX+EKU9Pf4ypwWiTQilCfM5eH2zv/2V/F4hX4rd0nPBO9 YrbbQVhm+cIm+dV6xO3DgHdlfVhkEwKcFD+5dauqZxf5ZFmsmaYmObZwW3esylmpCI+T r+Bg== X-Forwarded-Encrypted: i=1; AJvYcCXRQELoynrJz4Dhwu8Knfhn7Jq1fCiJLvvOFxEkuwmdan7WCzeGXhI+acRyVsuJN+VO7rGdMjHEEJ+caAdS4BTEhOO5ITyDXpY= X-Gm-Message-State: AOJu0YxUoG4iDNxLLvVjXxRml4iqTdgneffr8uO09RxzZaFcRQUYlAFy JdiEL2pMzddcnORFrwCDH0ao8WKlWi7OahGIhxzjeNuT5K1DbIMtrfwByTgK1w4= X-Google-Smtp-Source: AGHT+IF7/aGVxXhF2RySsqAiYYS1dDcsua5Tgb5FyRD6ODYvExfEBCQAP8YxA2bFkOZsnio1gLRMdw== X-Received: by 2002:adf:ef0b:0:b0:367:8a3b:2098 with SMTP id ffacd0b85a97d-37177768eb3mr2492404f8f.3.1723665510787; Wed, 14 Aug 2024 12:58:30 -0700 (PDT) Received: from krzk-bin.. ([178.197.215.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36e4cfeef76sm13482263f8f.59.2024.08.14.12.58.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 12:58:30 -0700 (PDT) From: Krzysztof Kozlowski To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH 3/3] thermal: of: Fix OF node leak in of_thermal_zone_find() error paths Date: Wed, 14 Aug 2024 21:58:23 +0200 Message-ID: <20240814195823.437597-3-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240814195823.437597-1-krzysztof.kozlowski@linaro.org> References: <20240814195823.437597-1-krzysztof.kozlowski@linaro.org> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Terminating for_each_available_child_of_node() loop requires dropping OF node reference, so bailing out on errors misses this. Solve the OF node reference leak with scoped for_each_available_child_of_node_scoped(). Fixes: 3fd6d6e2b4e8 ("thermal/of: Rework the thermal device tree initialization") Cc: Signed-off-by: Krzysztof Kozlowski Reviewed-by: Chen-Yu Tsai Reviewed-by: Daniel Lezcano --- drivers/thermal/thermal_of.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index b08a9b64718d..1f252692815a 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -184,14 +184,14 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int * Search for each thermal zone, a defined sensor * corresponding to the one passed as parameter */ - for_each_available_child_of_node(np, tz) { + for_each_available_child_of_node_scoped(np, child) { int count, i; - count = of_count_phandle_with_args(tz, "thermal-sensors", + count = of_count_phandle_with_args(child, "thermal-sensors", "#thermal-sensor-cells"); if (count <= 0) { - pr_err("%pOFn: missing thermal sensor\n", tz); + pr_err("%pOFn: missing thermal sensor\n", child); tz = ERR_PTR(-EINVAL); goto out; } @@ -200,18 +200,19 @@ static struct device_node *of_thermal_zone_find(struct device_node *sensor, int int ret; - ret = of_parse_phandle_with_args(tz, "thermal-sensors", + ret = of_parse_phandle_with_args(child, "thermal-sensors", "#thermal-sensor-cells", i, &sensor_specs); if (ret < 0) { - pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", tz, ret); + pr_err("%pOFn: Failed to read thermal-sensors cells: %d\n", child, ret); tz = ERR_PTR(ret); goto out; } if ((sensor == sensor_specs.np) && id == (sensor_specs.args_count ? sensor_specs.args[0] : 0)) { - pr_debug("sensor %pOFn id=%d belongs to %pOFn\n", sensor, id, tz); + pr_debug("sensor %pOFn id=%d belongs to %pOFn\n", sensor, id, child); + tz = no_free_ptr(child); goto out; } }