Skip to content

Commit

Permalink
bus: arm-ccn: Fix error handling at event allocation
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Pawel Moll <[email protected]>
Signed-off-by: Olof Johansson <[email protected]>
  • Loading branch information
pawelmoll authored and olofj committed Aug 1, 2014
1 parent f64a3c8 commit 3e528cb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions drivers/bus/arm-ccn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 3e528cb

Please sign in to comment.