From patchwork Sat May 15 13:34:41 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 99819 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4FDZblZ013450 for ; Sat, 15 May 2010 13:35:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752677Ab0EONfg (ORCPT ); Sat, 15 May 2010 09:35:36 -0400 Received: from fg-out-1718.google.com ([72.14.220.159]:14652 "EHLO fg-out-1718.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752472Ab0EONff (ORCPT ); Sat, 15 May 2010 09:35:35 -0400 Received: by fg-out-1718.google.com with SMTP id d23so2061589fga.1 for ; Sat, 15 May 2010 06:35:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=4ubpRjyUHfEJSMKfz9lq3010it2zO5w4YYa3uVLDdOI=; b=RuprN7KZog7SNQAuGwBjwSwXU4KPXjCydvmmi5t3WwH8O2TCYurZd4hxCjXrhYCSHE CsrgWHvr/v+yBalYvf14yVnONTw5W9F6oDVgkxm+R9S4NFfoJVE1Yww+tQtauSbrFJxP QfcOobvB7y6HMvwJ8RrpMxo4nUryL9Pq4apRA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=J2zT0rLMoWjssClm39niVDkzy3cxMEbN6REzDqyblucSROhRfVVDvzxlLTeqwLnKnx oberDgRhCFt1jFJ628mBcvD9sFCdgcapkEI+YpQqHdlZFlyH7nN/DC8Q/DqfEX1Zn+9r GciTVb/f/K6Q27DoCQBjvEc7PY6VGLoIiHWDU= Received: by 10.223.22.145 with SMTP id n17mr3233614fab.23.1273930534003; Sat, 15 May 2010 06:35:34 -0700 (PDT) Received: from bicker ([217.113.76.242]) by mx.google.com with ESMTPS id 13sm15917265fad.19.2010.05.15.06.35.17 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 15 May 2010 06:35:32 -0700 (PDT) Date: Sat, 15 May 2010 15:34:41 +0200 From: Dan Carpenter To: "Luis R. Rodriguez" Cc: Jouni Malinen , Sujith Manoharan , Vasanthakumar Thiagarajan , Senthil Balasubramanian , "John W. Linville" , Felix Fietkau , Jeff Hansen , linux-wireless@vger.kernel.org, ath9k-devel@venema.h4ckr.net Subject: [patch -next 1/2 v2] ath9k/debug: improve the snprintf() handling Message-ID: <20100515133441.GB5381@bicker> References: <20100514132437.GG5695@bicker> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20100514132437.GG5695@bicker> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sat, 15 May 2010 13:35:37 +0000 (UTC) diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c index 2ca9bba..fad1c85 100644 --- a/drivers/net/wireless/ath/ath9k/debug.c +++ b/drivers/net/wireless/ath/ath9k/debug.c @@ -41,8 +41,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf, char buf[32]; unsigned int len; - len = snprintf(buf, sizeof(buf), "0x%08x\n", common->debug_mask); - return simple_read_from_buffer(user_buf, count, ppos, buf, len); + len = sprintf(buf, "0x%08x\n", common->debug_mask); + return simple_read_from_buffer(user_buf, count, ppos, buf, len + 1); } static ssize_t write_file_debug(struct file *file, const char __user *user_buf, @@ -85,8 +85,8 @@ static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf, char buf[32]; unsigned int len; - len = snprintf(buf, sizeof(buf), "0x%08x\n", common->tx_chainmask); - return simple_read_from_buffer(user_buf, count, ppos, buf, len); + len = sprintf(buf, "0x%08x\n", common->tx_chainmask); + return simple_read_from_buffer(user_buf, count, ppos, buf, len + 1); } static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf, @@ -127,8 +127,8 @@ static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf, char buf[32]; unsigned int len; - len = snprintf(buf, sizeof(buf), "0x%08x\n", common->rx_chainmask); - return simple_read_from_buffer(user_buf, count, ppos, buf, len); + len = sprintf(buf, "0x%08x\n", common->rx_chainmask); + return simple_read_from_buffer(user_buf, count, ppos, buf, len + 1); } static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf, @@ -247,6 +247,10 @@ static ssize_t read_file_dma(struct file *file, char __user *user_buf, ath9k_ps_restore(sc); + len++; + if (len > DMA_BUF_LEN) + len = DMA_BUF_LEN; + retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); kfree(buf); return retval; @@ -357,6 +361,10 @@ static ssize_t read_file_interrupt(struct file *file, char __user *user_buf, len += snprintf(buf + len, sizeof(buf) - len, "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total); + len++; + if (len > sizeof(buf)) + len = sizeof(buf); + return simple_read_from_buffer(user_buf, count, ppos, buf, len); } @@ -396,11 +404,10 @@ static ssize_t read_file_rcstat(struct file *file, char __user *user_buf, if (sc->cur_rate_table == NULL) return 0; - max = 80 + sc->cur_rate_table->rate_cnt * 1024; - buf = kmalloc(max + 1, GFP_KERNEL); + max = 80 + sc->cur_rate_table->rate_cnt * 1024 + 1; + buf = kmalloc(max, GFP_KERNEL); if (buf == NULL) return 0; - buf[max] = 0; len += sprintf(buf, "%6s %6s %6s " "%10s %10s %10s %10s\n", @@ -442,6 +449,10 @@ static ssize_t read_file_rcstat(struct file *file, char __user *user_buf, stats->per); } + len++; + if (len > max) + len = max; + retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); kfree(buf); return retval; @@ -504,6 +515,10 @@ static ssize_t read_file_wiphy(struct file *file, char __user *user_buf, len += snprintf(buf + len, sizeof(buf) - len, "addrmask: %pM\n", addr); + len++; + if (len > sizeof(buf)) + len = sizeof(buf); + return simple_read_from_buffer(user_buf, count, ppos, buf, len); } @@ -647,6 +662,10 @@ static ssize_t read_file_xmit(struct file *file, char __user *user_buf, PR("DATA Underrun: ", data_underrun); PR("DELIM Underrun: ", delim_underrun); + len++; + if (len > size) + len = size; + retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); kfree(buf); @@ -750,6 +769,10 @@ static ssize_t read_file_recv(struct file *file, char __user *user_buf, PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL); PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL); + len++; + if (len > size) + len = size; + retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); kfree(buf); @@ -801,8 +824,8 @@ static ssize_t read_file_regidx(struct file *file, char __user *user_buf, char buf[32]; unsigned int len; - len = snprintf(buf, sizeof(buf), "0x%08x\n", sc->debug.regidx); - return simple_read_from_buffer(user_buf, count, ppos, buf, len); + len = sprintf(buf, "0x%08x\n", sc->debug.regidx); + return simple_read_from_buffer(user_buf, count, ppos, buf, len + 1); } static ssize_t write_file_regidx(struct file *file, const char __user *user_buf, @@ -842,8 +865,8 @@ static ssize_t read_file_regval(struct file *file, char __user *user_buf, u32 regval; regval = REG_READ_D(ah, sc->debug.regidx); - len = snprintf(buf, sizeof(buf), "0x%08x\n", regval); - return simple_read_from_buffer(user_buf, count, ppos, buf, len); + len = sprintf(buf, "0x%08x\n", regval); + return simple_read_from_buffer(user_buf, count, ppos, buf, len + 1); } static ssize_t write_file_regval(struct file *file, const char __user *user_buf,