linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Anju T Sudhakar <anju@linux.vnet.ibm.com>
To: mpe@ellerman.id.au
Cc: maddy@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org,
	anju@linux.vnet.ibm.com, dan.carpenter@oracle.com
Subject: [PATCH] powerpc/perf: Fix loop exit condition in nest_imc_event_init
Date: Tue, 27 Nov 2018 13:54:51 +0530	[thread overview]
Message-ID: <20181127082452.8307-1-anju@linux.vnet.ibm.com> (raw)

The data structure (i.e struct imc_mem_info) to hold the memory address
information for nest imc units is allocated based on the number of nodes
in the system.

nest_imc_event_init() traverse this struct array to calculate the memory
base address for the event-cpu. If we fail to find a match for the event
cpu's chip-id in imc_mem_info struct array, then the do-while loop will
iterate until we crash.

Fix this by changing the loop exit condition based on the number of
nodes in the system.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com> 
Fixes: 885dcd709ba91 ( powerpc/perf: Add nest IMC PMU support)
Signed-off-by: Anju T Sudhakar <anju@linux.vnet.ibm.com>
---
 arch/powerpc/perf/imc-pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
index 78514170cf71..e9dc771f3e3d 100644
--- a/arch/powerpc/perf/imc-pmu.c
+++ b/arch/powerpc/perf/imc-pmu.c
@@ -459,7 +459,7 @@ static void nest_imc_counters_release(struct perf_event *event)
 
 static int nest_imc_event_init(struct perf_event *event)
 {
-	int chip_id, rc, node_id;
+	int chip_id, rc, node_id, nr_chips = num_possible_nodes();
 	u32 l_config, config = event->attr.config;
 	struct imc_mem_info *pcni;
 	struct imc_pmu *pmu;
@@ -508,7 +508,7 @@ static int nest_imc_event_init(struct perf_event *event)
 			break;
 		}
 		pcni++;
-	} while (pcni);
+	} while (--nr_chips);
 
 	if (!flag)
 		return -ENODEV;
-- 
2.17.1


             reply	other threads:[~2018-11-27  8:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-27  8:24 Anju T Sudhakar [this message]
2018-11-27  8:24 ` [PATCH] powerpc/perf: Return accordingly on invalid chip-id in Anju T Sudhakar
2019-05-03  6:59   ` 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=20181127082452.8307-1-anju@linux.vnet.ibm.com \
    --to=anju@linux.vnet.ibm.com \
    --cc=dan.carpenter@oracle.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.vnet.ibm.com \
    --cc=mpe@ellerman.id.au \
    /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).