From patchwork Thu Jul 31 15:16:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Moll X-Patchwork-Id: 4656721 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CBD299F2B8 for ; Thu, 31 Jul 2014 15:19:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1C4C420138 for ; Thu, 31 Jul 2014 15:19:38 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1470E20120 for ; Thu, 31 Jul 2014 15:19:37 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XCs6S-0000Lk-F9; Thu, 31 Jul 2014 15:17:12 +0000 Received: from fw-tnat.austin.arm.com ([217.140.110.23] helo=collaborate-mta1.arm.com) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XCs6I-0000Dy-At for linux-arm-kernel@lists.infradead.org; Thu, 31 Jul 2014 15:17:02 +0000 Received: from hornet.Cambridge.Arm.com (hornet.cambridge.arm.com [10.2.201.42]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 6D8ED13F717; Thu, 31 Jul 2014 10:16:38 -0500 (CDT) From: Pawel Moll To: arm@kernel.org Subject: [PATCH] bus: arm-ccn: Fix error handling at event allocation Date: Thu, 31 Jul 2014 16:16:37 +0100 Message-Id: <1406819797-8372-1-git-send-email-pawel.moll@arm.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140731_081702_440888_9851B8CA X-CRM114-Status: UNSURE ( 9.81 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.7 (/) Cc: Pawel Moll , Dan Carpenter , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The bitfield allocation function returns error condition as a negative value, but in two cases its result was assigned to an unsigned member of the hw_perf_event structure, thus the error would not be ever detected. Fixed by using an intermediate, signed variable. Reported-by: Dan Carpenter Signed-off-by: Pawel Moll --- Dan discovered the problem using his static checker. Thanks, Dan! Arnd, would you pick up the patch as it is or do you want me to send a pull request for a "ccn/fixes" branch? drivers/bus/arm-ccn.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/bus/arm-ccn.c b/drivers/bus/arm-ccn.c index 4f86bbb..3266f8f 100644 --- a/drivers/bus/arm-ccn.c +++ b/drivers/bus/arm-ccn.c @@ -591,7 +591,7 @@ static int arm_ccn_pmu_event_init(struct perf_event *event) struct arm_ccn *ccn; struct hw_perf_event *hw = &event->hw; u32 node_xp, type, event_id; - int valid; + int valid, bit; struct arm_ccn_component *source; int i; @@ -713,17 +713,18 @@ static int arm_ccn_pmu_event_init(struct perf_event *event) /* Allocate an event source or a watchpoint */ if (type == CCN_TYPE_XP && event_id == CCN_EVENT_WATCHPOINT) - hw->config_base = arm_ccn_pmu_alloc_bit(source->xp.dt_cmp_mask, + bit = arm_ccn_pmu_alloc_bit(source->xp.dt_cmp_mask, CCN_NUM_XP_WATCHPOINTS); else - hw->config_base = arm_ccn_pmu_alloc_bit(source->pmu_events_mask, + bit = arm_ccn_pmu_alloc_bit(source->pmu_events_mask, CCN_NUM_PMU_EVENTS); - if (hw->config_base < 0) { + if (bit < 0) { dev_warn(ccn->dev, "No more event sources/watchpoints on node/XP %d!\n", node_xp); clear_bit(hw->idx, ccn->dt.pmu_counters_mask); return -EAGAIN; } + hw->config_base = bit; ccn->dt.pmu_counters[hw->idx].event = event;