linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
To: Liang He <windhl@126.com>
Cc: linux-kernel@vger.kernel.org, paulus@samba.org,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH] powerpc: perf: Fix refcount leak bug in imc-pmu.c
Date: Mon, 27 Jun 2022 14:30:01 +0530	[thread overview]
Message-ID: <5B61320C-C37F-4B60-BE2B-461722D44742@linux.vnet.ibm.com> (raw)
In-Reply-To: <20220618071353.4059000-1-windhl@126.com>



> On 18-Jun-2022, at 12:43 PM, Liang He <windhl@126.com> wrote:
> 
> In update_events_in_group(), of_find_node_by_phandle() will return
> a node pointer with refcount incremented. We should use of_node_put()
> in fail path or when it is not used anymore.
> 
> Signed-off-by: Liang He <windhl@126.com>

Reviewed-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
> ---
> arch/powerpc/perf/imc-pmu.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
> index d7976ab40d38..d517aba94d1b 100644
> --- a/arch/powerpc/perf/imc-pmu.c
> +++ b/arch/powerpc/perf/imc-pmu.c
> @@ -240,8 +240,10 @@ static int update_events_in_group(struct device_node *node, struct imc_pmu *pmu)
> 	ct = of_get_child_count(pmu_events);
> 
> 	/* Get the event prefix */
> -	if (of_property_read_string(node, "events-prefix", &prefix))
> +	if (of_property_read_string(node, "events-prefix", &prefix)) {
> +		of_node_put(pmu_events);
> 		return 0;
> +	}
> 
> 	/* Get a global unit and scale data if available */
> 	if (of_property_read_string(node, "scale", &g_scale))
> @@ -255,8 +257,10 @@ static int update_events_in_group(struct device_node *node, struct imc_pmu *pmu)
> 
> 	/* Allocate memory for the events */
> 	pmu->events = kcalloc(ct, sizeof(struct imc_events), GFP_KERNEL);
> -	if (!pmu->events)
> +	if (!pmu->events) {
> +		of_node_put(pmu_events);
> 		return -ENOMEM;
> +	}
> 
> 	ct = 0;
> 	/* Parse the events and update the struct */
> @@ -266,6 +270,8 @@ static int update_events_in_group(struct device_node *node, struct imc_pmu *pmu)
> 			ct++;
> 	}
> 
> +	of_node_put(pmu_events);
> +
> 	/* Allocate memory for attribute group */
> 	attr_group = kzalloc(sizeof(*attr_group), GFP_KERNEL);
> 	if (!attr_group) {
> -- 
> 2.25.1
> 


  reply	other threads:[~2022-06-27  9:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-18  7:13 [PATCH] powerpc: perf: Fix refcount leak bug in imc-pmu.c Liang He
2022-06-27  9:00 ` Athira Rajeev [this message]
2022-09-09 12:07 ` Michael Ellerman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5B61320C-C37F-4B60-BE2B-461722D44742@linux.vnet.ibm.com \
    --to=atrajeev@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=paulus@samba.org \
    --cc=windhl@126.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).