From patchwork Tue Aug 20 09:40: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: 13769760 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.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 E7D8618C32B for ; Tue, 20 Aug 2024 09:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724146830; cv=none; b=SZbxsJvW+y604tlBYaePGMIanwTnSJnZzIUtl0aUQQ7hKEFqBp83JoFQhSYqeQsXOdmlBx6ndV3g63Ga3qdZ+qwXnTcPUua+LWdqo4v305FHPhpq3lZ3/7Mr+YAwVtfvXk3a0gDPY7geaBjqtKWfNz0I5p1F2Lq+JfB5u/mvP2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724146830; c=relaxed/simple; bh=EoJtIsmmU9SrguY88s76AA2qh+Iy9f5umyZmJzjJwKE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FBYRgYqSG0lte7aoadA/1n7Pw+2ROkeZZn3KFJhC1hXt2YvqeQELUvqwUhX3jLrlZ0i8pQPpmFnonkAWlxo3CCbwuCIfDskQ9GxkOUVud3VkqZ+xyzRDWofP+oDW83VIk9xOiYp0pj7otQ6hQTy9D9FhCaozWCS7VSXAhHBwMRE= 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=hS8TOmDU; arc=none smtp.client-ip=209.85.218.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="hS8TOmDU" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a8647056026so77638666b.0 for ; Tue, 20 Aug 2024 02:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724146827; x=1724751627; 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=ml5kmP2AZ4rRTo1ml+BArOzT8EmV3i5O4Bq4nH6wu1k=; b=hS8TOmDU8+WcrlVNcsMtWg4G0Q3xKdeNqb8Oki82bIESDLoknHE94gRzJj3HybvF7a 97aewSFE0PWzUboXdSjkjETAClQR5am4dO3RYBPr4Ilyiz84Ia+RtZsKL8L7cD8PVs4I wSeX4vkweWNgK1ayA6T+icQY08lDhyyyk/ts/qsm6PWHx4DSCB/LMsEWlZQiUuqC0uYN OTjmNj0/yyyUToEM94qPWpsbyDN4ldwFFJodumftLeFAND32sSsdhagV5IoEshgpj9HP qpJ7VGM3DgrqOnePdvbgMO4HC81yIZTneN4vBysftc1ffLpimvXpC0eLINQ6McpLQMMI bwtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724146827; x=1724751627; 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=ml5kmP2AZ4rRTo1ml+BArOzT8EmV3i5O4Bq4nH6wu1k=; b=W1JV4iKydFjg1ICtyHTtNoa3RqrHRVvygMlOucTQEzb6A7QRV20zyOYzjX0rJlgSEG IqbFjBNBA4PyjxZW2RNW6ZC5KXYt1BXdcGEOy8NQAGcjUWe7QapE6vq4wmjgGA63AmaE j67SplgOs983mOPVvF9Ojl2c5R8VMIxrvacd7Kp0/PEzKAkVv/yNpNyOMWLOU9QvRNAv 5oGdEgPC0mHTtjtEtocnzaALUORFZ8FMqJynIwKj07793Ni0LNWC1C8IKzLejNLZhP4+ LvZZGZh1o+mYR5KPwpsYEmDU2VIQzO32fyeP2fg+dikNb0WRcVW5SmRRDtLloFoE1fAw 8QvA== X-Forwarded-Encrypted: i=1; AJvYcCXVG6ZduOcMloxdugRW3oGRuTwb6HOnxD5un/ThvStN+ii/eLHFP7s7YLMzc1w1TjucGFIIiZu2tFIpvdv+RuThSKmlqzv0t3M= X-Gm-Message-State: AOJu0Yx1M3ynsPdU+whMqhkeYV8kGyyDY/hYUykn/rQfAYS/wRqElsFK 7H/6aPsKpLTRfEMliHBUe29mZUP3QrICKaYw+Syo9PFt2TMU+ZyI5ucOzLLbFrg= X-Google-Smtp-Source: AGHT+IFWIcPWJD7AezJob3CaaT6BEKEOeCZ2xK2iLUqEJ3Fjit54kT8/4nWS9N5eeGL5wXOTPMbcfw== X-Received: by 2002:a17:907:e207:b0:a7a:bad3:e5b9 with SMTP id a640c23a62f3a-a83928a9ea4mr984286166b.11.1724146827093; Tue, 20 Aug 2024 02:40:27 -0700 (PDT) Received: from krzk-bin.. ([178.197.215.209]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a83838d023dsm733613366b.64.2024.08.20.02.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 02:40:26 -0700 (PDT) From: Krzysztof Kozlowski To: Anup Patel , "Rafael J. Wysocki" , Daniel Lezcano , Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , linux-pm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , stable@vger.kernel.org Subject: [PATCH v2 1/2] cpuidle: riscv-sbi: Use scoped device node handling to fix missing of_node_put Date: Tue, 20 Aug 2024 11:40:22 +0200 Message-ID: <20240820094023.61155-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 Two return statements in sbi_cpuidle_dt_init_states() did not drop the OF node reference count. Solve the issue and simplify entire error handling with scoped/cleanup.h. Fixes: 6abf32f1d9c5 ("cpuidle: Add RISC-V SBI CPU idle driver") Cc: Signed-off-by: Krzysztof Kozlowski Reviewed-by: Anup Patel --- Changes in v2: 1. Re-write commit msg, because this is actually a fix. --- drivers/cpuidle/cpuidle-riscv-sbi.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c index a6e123dfe394..5bb3401220d2 100644 --- a/drivers/cpuidle/cpuidle-riscv-sbi.c +++ b/drivers/cpuidle/cpuidle-riscv-sbi.c @@ -8,6 +8,7 @@ #define pr_fmt(fmt) "cpuidle-riscv-sbi: " fmt +#include #include #include #include @@ -236,19 +237,16 @@ static int sbi_cpuidle_dt_init_states(struct device *dev, { struct sbi_cpuidle_data *data = per_cpu_ptr(&sbi_cpuidle_data, cpu); struct device_node *state_node; - struct device_node *cpu_node; u32 *states; int i, ret; - cpu_node = of_cpu_device_node_get(cpu); + struct device_node *cpu_node __free(device_node) = of_cpu_device_node_get(cpu); if (!cpu_node) return -ENODEV; states = devm_kcalloc(dev, state_count, sizeof(*states), GFP_KERNEL); - if (!states) { - ret = -ENOMEM; - goto fail; - } + if (!states) + return -ENOMEM; /* Parse SBI specific details from state DT nodes */ for (i = 1; i < state_count; i++) { @@ -264,10 +262,8 @@ static int sbi_cpuidle_dt_init_states(struct device *dev, pr_debug("sbi-state %#x index %d\n", states[i], i); } - if (i != state_count) { - ret = -ENODEV; - goto fail; - } + if (i != state_count) + return -ENODEV; /* Initialize optional data, used for the hierarchical topology. */ ret = sbi_dt_cpu_init_topology(drv, data, state_count, cpu); @@ -277,10 +273,7 @@ static int sbi_cpuidle_dt_init_states(struct device *dev, /* Store states in the per-cpu struct. */ data->states = states; -fail: - of_node_put(cpu_node); - - return ret; + return 0; } static void sbi_cpuidle_deinit_cpu(int cpu) From patchwork Tue Aug 20 09:40: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: 13769761 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.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 3997118CC19 for ; Tue, 20 Aug 2024 09:40:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724146831; cv=none; b=O6J1teQF7ZQ0qfgeDfvjMtZd8hiUGIr0MgTxZ8Q7DwKba6Tib2gMeoarTO5f0S3Zi8CQNoBO08ghCqjaRmG1HgrdyddN6FdRT/DzAvKft4cyPXLacg8+dqCVa5cBQIphu0BwV95KjOFHpAQrLxkpI9Q27O7aKsa27vUhuXfX4bI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724146831; c=relaxed/simple; bh=H/85Dy5COYZB9qMaqlUeCg4Y7LWkvndb2zLPGbCpOxY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SVvu0aphYN3GBi0w9BW7ZNBWEPrJHlcyDLw2MvqGJAUnFbzTgYkcwIt2Hn/58XiQVwV6+ZOiDYI7RKRoE3/8MWT59LPqbRJyGVFVdQ5GYK1fLRFTD8JY4zXI7vSBHnMGJimwrerIhbG0SGMRF9AcwPKOB7tGITTS0JA19CbK7T8= 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=aCn7YXbK; arc=none smtp.client-ip=209.85.218.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="aCn7YXbK" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a83562f9be9so476319866b.0 for ; Tue, 20 Aug 2024 02:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724146828; x=1724751628; 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=ZY/iGek7oJwLxPJ1JKwoSRK1o1gPKN3vGl9eBXs8wms=; b=aCn7YXbKsBWuxmWshX9Rx7VSkMFLFMltE11Hj374T0LbMCmNHSfjSftUE6z+aGzSb7 NeSQ1bjUk6QPr/F1ZqYWuyZlYIpfkZPZPUhxCN0Kdj4YJW9MYSvdzy/vxipxw0Erv9rq VrQ51DX/kSXjQwG2/hp7qgqqXkkxlpblkVRXG8FLIhUGH56S1nwHWLLdaA/25E6ae9PB RF3NLPknjq8uI0P67xuNWBfs83+pOtkxhiHHvJlPbarGgeGej8bXuyljwK4TnVYf1FJx 8VrijD1FkhUOgrP6hE6tRBHFxhRmigzC4TUAbOMY8UtmReGhHcJTBShuPKUZ1cMDyzlT BerA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724146828; x=1724751628; 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=ZY/iGek7oJwLxPJ1JKwoSRK1o1gPKN3vGl9eBXs8wms=; b=agEEjWuDBXtiTwXjitEtwyXAa9XwGjbDjHyprZFz7fDV1p4yuaAfQUhSQDNCLXbIeP AY/+NJGY/xgSfbSRwOuiQQj/0ODjj7+cF833MMhEGcFUO+CDyYbHbL1OvaNYkY/q2Ok3 ZtKek5jVLtTamzpBGdOfm6gKSmiGYHiwd6mqXoR3ljTu3wyHQKwMu3fpfxNq9QlshjAl upghZvFKVyTpEjYGPks7puZ+WNZhYYG8xp2ataEFS1/z4v/A1aAWIPuFgb5yTvIcou+K aaP33f9RNiRz5Zqr/Z0Z8fT5X5GQzBdq2Gx3PjlauXXZhW63WdAen1olz3vQWAg8awBZ hyGA== X-Forwarded-Encrypted: i=1; AJvYcCVNKsnA8cLLXQJFkJVcjMNJc2OQeBVVmVstp25yQjDdJifmETq0ueS404p8lZrO/JTBevKei5Qrmg==@vger.kernel.org X-Gm-Message-State: AOJu0YwCy4CX+Q/RfgeIkG5dDugpeg9xXKXJrct47q2n5SV6owWJb4/j HvYHbHUi43T2h5966kZNkjeZGhwGiMVuEBxDdKhDKDf5bK46u5WB7j7j838wg1U= X-Google-Smtp-Source: AGHT+IG+nLIH5fnCkD0hF9cIx7+KS2wkkUp+2yCqq4ti9srWQVHwWsENFCJzq2xptsWju6FvoZxRiQ== X-Received: by 2002:a17:907:70a:b0:a83:a85b:ed40 with SMTP id a640c23a62f3a-a83a85bedb0mr774398566b.6.1724146828420; Tue, 20 Aug 2024 02:40:28 -0700 (PDT) Received: from krzk-bin.. ([178.197.215.209]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a83838d023dsm733613366b.64.2024.08.20.02.40.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 02:40:27 -0700 (PDT) From: Krzysztof Kozlowski To: Anup Patel , "Rafael J. Wysocki" , Daniel Lezcano , Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , linux-pm@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski , Jonathan Cameron Subject: [PATCH v2 2/2] cpuidle: riscv-sbi: Simplify with scoped for each OF child loop Date: Tue, 20 Aug 2024 11:40:23 +0200 Message-ID: <20240820094023.61155-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820094023.61155-1-krzysztof.kozlowski@linaro.org> References: <20240820094023.61155-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 Use scoped for_each_child_of_node_scoped() when iterating over device nodes to make code a bit simpler. Reviewed-by: Jonathan Cameron Signed-off-by: Krzysztof Kozlowski Reviewed-by: Anup Patel --- Changes in v2: 1. None, only Rb tag. Other patches from the set were applied. --- drivers/cpuidle/cpuidle-riscv-sbi.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c index 5bb3401220d2..d228b4d18d56 100644 --- a/drivers/cpuidle/cpuidle-riscv-sbi.c +++ b/drivers/cpuidle/cpuidle-riscv-sbi.c @@ -448,7 +448,6 @@ static void sbi_pd_remove(void) static int sbi_genpd_probe(struct device_node *np) { - struct device_node *node; int ret = 0, pd_count = 0; if (!np) @@ -458,13 +457,13 @@ static int sbi_genpd_probe(struct device_node *np) * Parse child nodes for the "#power-domain-cells" property and * initialize a genpd/genpd-of-provider pair when it's found. */ - for_each_child_of_node(np, node) { + for_each_child_of_node_scoped(np, node) { if (!of_property_present(node, "#power-domain-cells")) continue; ret = sbi_pd_init(node); if (ret) - goto put_node; + goto remove_pd; pd_count++; } @@ -480,8 +479,6 @@ static int sbi_genpd_probe(struct device_node *np) return 0; -put_node: - of_node_put(node); remove_pd: sbi_pd_remove(); pr_err("failed to create CPU PM domains ret=%d\n", ret);