From patchwork Sun Aug 5 19:35:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Kossifidis X-Patchwork-Id: 1275581 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id F2019DF27F for ; Sun, 5 Aug 2012 19:36:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754992Ab2HETgL (ORCPT ); Sun, 5 Aug 2012 15:36:11 -0400 Received: from mail-wg0-f44.google.com ([74.125.82.44]:46299 "EHLO mail-wg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754991Ab2HETgK (ORCPT ); Sun, 5 Aug 2012 15:36:10 -0400 Received: by mail-wg0-f44.google.com with SMTP id dr13so2122688wgb.1 for ; Sun, 05 Aug 2012 12:36:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=iPJ+sv/zE8YknFYqxnTpvxPMwKT3FMEv/PZU22PV+nY=; b=JXBMzWxdy1BdCEsxQwQW4RA9NNqJ/lQ3wsbkQP9f3zmzFkPcJbrpc/j9aCHJdsvwu4 xOa9bWra0NtoMhlmuFQOwvXAKjQfCv4dB4pCyAy+CwquIOrH6RwESj9NivN6+JeAOJJI ZfBDT6E0IFZcn/qmHwj5U4K8SJ/0xt96/HoYI4XrnncOD0LK5v79smlaCO8WmAhv1k/Q wGa6Z3VloieZkVnctIGevJOGUpk5FbbAUrn3CK4g9xPZyhVKxlEFxRUrEJ6glI6yEpdO SyzDzrPe30n9Uuoq4EviQsvOP510IdDDokicXUrAjhzuvHccME9TaLIlKY2m7cpPcCId AA6Q== Received: by 10.216.233.25 with SMTP id o25mr4659336weq.130.1344195370007; Sun, 05 Aug 2012 12:36:10 -0700 (PDT) Received: from localhost.localdomain (athedsl-133041.home.otenet.gr. [85.75.95.80]) by mx.google.com with ESMTPS id b7sm16708044wiz.9.2012.08.05.12.36.04 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 05 Aug 2012 12:36:09 -0700 (PDT) From: Nick Kossifidis To: ath5k-devel@lists.ath5k.org, linux-wireless@vger.kernel.org Cc: linville@tuxdriver.com, mcgrof@gmail.com, jirislaby@gmail.com, thomas@net.t-labs.tu-berlin.de, nbd@openwrt.org, Nick Kossifidis Subject: [PATCH v2 2/5] ath5k: Fix range scaling when setting rate power table Date: Sun, 5 Aug 2012 22:35:34 +0300 Message-Id: <1344195337-27461-3-git-send-email-mickflemm@gmail.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1344195337-27461-1-git-send-email-mickflemm@gmail.com> References: <1344195337-27461-1-git-send-email-mickflemm@gmail.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org rates[i] is unsigned but txp_offset can be negative for newer parts with PDADC table. We cover the case when rates[i] + txp_offset > 63 but we must also cover the case when its < 0 or else rates[i] will overflow. Signed-off-by: Nick Kossifidis --- drivers/net/wireless/ath/ath5k/phy.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/ath/ath5k/phy.c b/drivers/net/wireless/ath/ath5k/phy.c index aa1a77d..84a9aaf 100644 --- a/drivers/net/wireless/ath/ath5k/phy.c +++ b/drivers/net/wireless/ath/ath5k/phy.c @@ -3516,6 +3516,7 @@ ath5k_setup_rate_powertable(struct ath5k_hw *ah, u16 max_pwr, { unsigned int i; u16 *rates; + s16 rate_idx_scaled = 0; /* max_pwr is power level we got from driver/user in 0.5dB * units, switch to 0.25dB units so we can compare */ @@ -3580,10 +3581,13 @@ ath5k_setup_rate_powertable(struct ath5k_hw *ah, u16 max_pwr, * match the power range set by user with the power indices * on PCDAC/PDADC table */ for (i = 0; i < 16; i++) { - rates[i] += ah->ah_txpower.txp_offset; + rate_idx_scaled = rates[i] + ah->ah_txpower.txp_offset; /* Don't get out of bounds */ - if (rates[i] > 63) - rates[i] = 63; + if (rate_idx_scaled > 63) + rate_idx_scaled = 63; + if (rate_idx_scaled < 0) + rate_idx_scaled = 0; + rates[i] = rate_idx_scaled; } }