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: 34676 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E99AD20540 for ; Thu, 31 Jul 2014 15:18:59 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id kx10sf18512861pab.4 for ; Thu, 31 Jul 2014 08:18:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id:cc :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=4U5ujHlsNZBtNCgjjIxa/wnyV1zZyjUi2O/Dlz+Yh8c=; b=hOPsM/t1mPcCFOhoxBgZpS5Wzw1ISgyT/TZ6JBZgD3Y9ohVyBTlWWUonj79uB6QS9T 7UcEN7n7Def2yiv/JCiRbpIsf0pJk14Zy62PyBQhowwgv2ZB5a5ErQqR3eO5yULmuGqH tCNoUZn62+lMxwchrC54M3RFkbEf4odUzLWYUDKat0HiFp032oQr9+Gy/t73AecWqgOw 2bIrLk4E2S8nWzkI30VfIon+u+CB6A2EvFRKpN/4k6eM34T8FT0PHXVtWWSZGEh3jhXv HHzbbYJMopmaj5uHvxjnKm5Bc/1zvNLN4Jucce/pxEAH5kytJAwP/eqFio11hNRXCTgM drqA== X-Gm-Message-State: ALoCoQmxCz6Ft2Cl3lOiaJqtRtcOetfL1yzVPS2fa7fnr6PzwrOLaPxuEkDlqP7Wq0QUW2bnPE1H X-Received: by 10.67.5.39 with SMTP id cj7mr674864pad.17.1406819937269; Thu, 31 Jul 2014 08:18:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.37.6 with SMTP id q6ls971603qgq.49.gmail; Thu, 31 Jul 2014 08:18:57 -0700 (PDT) X-Received: by 10.52.160.10 with SMTP id xg10mr3744206vdb.1.1406819937143; Thu, 31 Jul 2014 08:18:57 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id l7si4694108vel.22.2014.07.31.08.18.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 31 Jul 2014 08:18:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id lf12so4378817vcb.40 for ; Thu, 31 Jul 2014 08:18:55 -0700 (PDT) X-Received: by 10.221.26.10 with SMTP id rk10mr13901337vcb.0.1406819935448; Thu, 31 Jul 2014 08:18:55 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp26294vcb; Thu, 31 Jul 2014 08:18:55 -0700 (PDT) X-Received: by 10.70.132.1 with SMTP id oq1mr13008743pdb.45.1406819934544; Thu, 31 Jul 2014 08:18:54 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id ag5si6323049pbc.9.2014.07.31.08.18.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Jul 2014 08:18:51 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; 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 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record 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+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pawel.moll@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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;