hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/scsi/qedf/qedf_debugfs.c
....@@ -8,6 +8,7 @@
88 #include <linux/uaccess.h>
99 #include <linux/debugfs.h>
1010 #include <linux/module.h>
11
+#include <linux/vmalloc.h>
1112
1213 #include "qedf.h"
1314 #include "qedf_dbg.h"
....@@ -98,7 +99,9 @@
9899 qedf_dbg_fp_int_cmd_read(struct file *filp, char __user *buffer, size_t count,
99100 loff_t *ppos)
100101 {
102
+ ssize_t ret;
101103 size_t cnt = 0;
104
+ char *cbuf;
102105 int id;
103106 struct qedf_fastpath *fp = NULL;
104107 struct qedf_dbg_ctx *qedf_dbg =
....@@ -108,19 +111,25 @@
108111
109112 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
110113
111
- cnt = sprintf(buffer, "\nFastpath I/O completions\n\n");
114
+ cbuf = vmalloc(QEDF_DEBUGFS_LOG_LEN);
115
+ if (!cbuf)
116
+ return 0;
117
+
118
+ cnt += scnprintf(cbuf + cnt, QEDF_DEBUGFS_LOG_LEN - cnt, "\nFastpath I/O completions\n\n");
112119
113120 for (id = 0; id < qedf->num_queues; id++) {
114121 fp = &(qedf->fp_array[id]);
115122 if (fp->sb_id == QEDF_SB_ID_NULL)
116123 continue;
117
- cnt += sprintf((buffer + cnt), "#%d: %lu\n", id,
118
- fp->completions);
124
+ cnt += scnprintf(cbuf + cnt, QEDF_DEBUGFS_LOG_LEN - cnt,
125
+ "#%d: %lu\n", id, fp->completions);
119126 }
120127
121
- cnt = min_t(int, count, cnt - *ppos);
122
- *ppos += cnt;
123
- return cnt;
128
+ ret = simple_read_from_buffer(buffer, count, ppos, cbuf, cnt);
129
+
130
+ vfree(cbuf);
131
+
132
+ return ret;
124133 }
125134
126135 static ssize_t
....@@ -138,15 +147,14 @@
138147 loff_t *ppos)
139148 {
140149 int cnt;
150
+ char cbuf[32];
141151 struct qedf_dbg_ctx *qedf_dbg =
142152 (struct qedf_dbg_ctx *)filp->private_data;
143153
144154 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "debug mask=0x%x\n", qedf_debug);
145
- cnt = sprintf(buffer, "debug mask = 0x%x\n", qedf_debug);
155
+ cnt = scnprintf(cbuf, sizeof(cbuf), "debug mask = 0x%x\n", qedf_debug);
146156
147
- cnt = min_t(int, count, cnt - *ppos);
148
- *ppos += cnt;
149
- return cnt;
157
+ return simple_read_from_buffer(buffer, count, ppos, cbuf, cnt);
150158 }
151159
152160 static ssize_t
....@@ -185,18 +193,17 @@
185193 size_t count, loff_t *ppos)
186194 {
187195 int cnt;
196
+ char cbuf[7];
188197 struct qedf_dbg_ctx *qedf_dbg =
189198 (struct qedf_dbg_ctx *)filp->private_data;
190199 struct qedf_ctx *qedf = container_of(qedf_dbg,
191200 struct qedf_ctx, dbg_ctx);
192201
193202 QEDF_INFO(qedf_dbg, QEDF_LOG_DEBUGFS, "entered\n");
194
- cnt = sprintf(buffer, "%s\n",
203
+ cnt = scnprintf(cbuf, sizeof(cbuf), "%s\n",
195204 qedf->stop_io_on_error ? "true" : "false");
196205
197
- cnt = min_t(int, count, cnt - *ppos);
198
- *ppos += cnt;
199
- return cnt;
206
+ return simple_read_from_buffer(buffer, count, ppos, cbuf, cnt);
200207 }
201208
202209 static ssize_t