Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db0589f3 authored by Abhijeet Kolekar's avatar Abhijeet Kolekar Committed by John W. Linville
Browse files

iwlwifi: replace sprintf with scnprintf for debugfs output



The buffersize allocated is not accurate.
Writing to these buffers with scnprintf is safer.

Signed-off-by: default avatarAbhijeet Kolekar <abhijeet.kolekar@intel.com>
Signed-off-by: default avatarReinette Chatre <reinette.chatre@intel.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 57aab75a
Loading
Loading
Loading
Loading
+43 −28
Original line number Original line Diff line number Diff line
@@ -102,10 +102,14 @@ static ssize_t iwl_dbgfs_tx_statistics_read(struct file *file,
	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
	char buf[256];
	char buf[256];
	int pos = 0;
	int pos = 0;
	const size_t bufsz = sizeof(buf);


	pos += sprintf(buf+pos, "mgmt: %u\n", priv->tx_stats[0].cnt);
	pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
	pos += sprintf(buf+pos, "ctrl: %u\n", priv->tx_stats[1].cnt);
						priv->tx_stats[0].cnt);
	pos += sprintf(buf+pos, "data: %u\n", priv->tx_stats[2].cnt);
	pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
						priv->tx_stats[1].cnt);
	pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
						priv->tx_stats[2].cnt);


	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
}
}
@@ -117,10 +121,14 @@ static ssize_t iwl_dbgfs_rx_statistics_read(struct file *file,
	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
	char buf[256];
	char buf[256];
	int pos = 0;
	int pos = 0;
	const size_t bufsz = sizeof(buf);


	pos += sprintf(buf+pos, "mgmt: %u\n", priv->rx_stats[0].cnt);
	pos += scnprintf(buf + pos, bufsz - pos, "mgmt: %u\n",
	pos += sprintf(buf+pos, "ctrl: %u\n", priv->rx_stats[1].cnt);
						priv->rx_stats[0].cnt);
	pos += sprintf(buf+pos, "data: %u\n", priv->rx_stats[2].cnt);
	pos += scnprintf(buf + pos, bufsz - pos, "ctrl: %u\n",
						priv->rx_stats[1].cnt);
	pos += scnprintf(buf + pos, bufsz - pos, "data: %u\n",
						priv->rx_stats[2].cnt);


	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
}
}
@@ -138,6 +146,7 @@ static ssize_t iwl_dbgfs_sram_read(struct file *file,
	int i;
	int i;
	int pos = 0;
	int pos = 0;
	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
	struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
	const size_t bufsz = sizeof(buf);


	printk(KERN_DEBUG "offset is: 0x%x\tlen is: 0x%x\n",
	printk(KERN_DEBUG "offset is: 0x%x\tlen is: 0x%x\n",
	priv->dbgfs->sram_offset, priv->dbgfs->sram_len);
	priv->dbgfs->sram_offset, priv->dbgfs->sram_len);
@@ -159,9 +168,9 @@ static ssize_t iwl_dbgfs_sram_read(struct file *file,
				break;
				break;
			}
			}
		}
		}
		pos += sprintf(buf+pos, "0x%08x ", val);
		pos += scnprintf(buf + pos, bufsz - pos, "0x%08x ", val);
	}
	}
	pos += sprintf(buf+pos, "\n");
	pos += scnprintf(buf + pos, bufsz - pos, "\n");
	iwl_release_nic_access(priv);
	iwl_release_nic_access(priv);


	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
	ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
@@ -210,44 +219,50 @@ static ssize_t iwl_dbgfs_stations_read(struct file *file, char __user *user_buf,
	if(!buf)
	if(!buf)
		return -ENOMEM;
		return -ENOMEM;


	pos += sprintf(buf+pos, "num of stations: %d\n\n",
	pos += scnprintf(buf + pos, bufsz - pos, "num of stations: %d\n\n",
			priv->num_stations);
			priv->num_stations);


	for (i = 0; i < max_sta; i++) {
	for (i = 0; i < max_sta; i++) {
		station = &priv->stations[i];
		station = &priv->stations[i];
		if (station->used) {
		if (station->used) {
			pos += sprintf(buf+pos, "station %d:\ngeneral data:\n",
			pos += scnprintf(buf + pos, bufsz - pos,
					i+1);
					"station %d:\ngeneral data:\n", i+1);
			print_mac(mac, station->sta.sta.addr);
			print_mac(mac, station->sta.sta.addr);
			pos += sprintf(buf+pos, "id: %u\n",
			pos += scnprintf(buf + pos, bufsz - pos, "id: %u\n",
					station->sta.sta.sta_id);
					station->sta.sta.sta_id);
			pos += sprintf(buf+pos, "mode: %u\n",
			pos += scnprintf(buf + pos, bufsz - pos, "mode: %u\n",
					station->sta.mode);
					station->sta.mode);
			pos += sprintf(buf+pos, "flags: 0x%x\n",
			pos += scnprintf(buf + pos, bufsz - pos,
					"flags: 0x%x\n",
					station->sta.station_flags_msk);
					station->sta.station_flags_msk);
			pos += sprintf(buf+pos, "ps_status: %u\n",
			pos += scnprintf(buf + pos, bufsz - pos,
					station->ps_status);
					"ps_status: %u\n", station->ps_status);

			pos += scnprintf(buf + pos, bufsz - pos, "tid data:\n");
			pos += sprintf(buf+pos, "tid data:\n");
			pos += scnprintf(buf + pos, bufsz - pos,

					"seq_num\t\ttxq_id\t");
			pos += sprintf(buf+pos, "seq_num\t\ttxq_id\t");
			pos += scnprintf(buf + pos, bufsz - pos,
			pos += sprintf(buf+pos, "frame_count\twait_for_ba\t");
					"frame_count\twait_for_ba\t");
			pos += sprintf(buf+pos, "start_idx\tbitmap0\t");
			pos += scnprintf(buf + pos, bufsz - pos,
			pos += sprintf(buf+pos, "bitmap1\trate_n_flags\n");
					"start_idx\tbitmap0\t");
			pos += scnprintf(buf + pos, bufsz - pos,
					"bitmap1\trate_n_flags\n");


			for (j = 0; j < MAX_TID_COUNT; j++) {
			for (j = 0; j < MAX_TID_COUNT; j++) {
				pos += sprintf(buf+pos, "[%d]:\t\t%u\t",
				pos += scnprintf(buf + pos, bufsz - pos,
						j, station->tid[j].seq_number);
						"[%d]:\t\t%u\t", j,
				pos += sprintf(buf+pos, "%u\t\t%u\t\t%u\t\t",
						station->tid[j].seq_number);
				pos += scnprintf(buf + pos, bufsz - pos,
						"%u\t\t%u\t\t%u\t\t",
						station->tid[j].agg.txq_id,
						station->tid[j].agg.txq_id,
						station->tid[j].agg.frame_count,
						station->tid[j].agg.frame_count,
						station->tid[j].agg.wait_for_ba);
						station->tid[j].agg.wait_for_ba);
				pos += sprintf(buf+pos, "%u\t%llu\t%u\n",
				pos += scnprintf(buf + pos, bufsz - pos,
						"%u\t%llu\t%u\n",
						station->tid[j].agg.start_idx,
						station->tid[j].agg.start_idx,
						(unsigned long long)station->tid[j].agg.bitmap,
						(unsigned long long)station->tid[j].agg.bitmap,
						station->tid[j].agg.rate_n_flags);
						station->tid[j].agg.rate_n_flags);
			}
			}
			pos += sprintf(buf+pos, "\n");
			pos += scnprintf(buf + pos, bufsz - pos, "\n");
		}
		}
	}
	}