* mm/damon/dbgfs.c:76 dbgfs_attrs_write() warn: passing a valid pointer to 'PTR_ERR'
@ 2022-03-10 17:46 kernel test robot
0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2022-03-10 17:46 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 13647 bytes --]
CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
CC: linux-kernel(a)vger.kernel.org
TO: SeongJae Park <sjpark@amazon.de>
CC: Leonard Foerster <foersleo@amazon.de>
CC: Fernand Sieber <sieberf@amazon.com>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Linux Memory Management List <linux-mm@kvack.org>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 1db333d9a51f3459fba1bcaa564d95befe79f0b3
commit: 4bc05954d0076655cfaf6f0135585bdc20cd6b11 mm/damon: implement a debugfs-based user space interface
date: 6 months ago
:::::: branch date: 5 hours ago
:::::: commit date: 6 months ago
config: arc-randconfig-m031-20220310 (https://download.01.org/0day-ci/archive/20220311/202203110114.13aHC38i-lkp(a)intel.com/config)
compiler: arceb-elf-gcc (GCC) 11.2.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch warnings:
mm/damon/dbgfs.c:76 dbgfs_attrs_write() warn: passing a valid pointer to 'PTR_ERR'
mm/damon/dbgfs.c:196 dbgfs_target_ids_write() warn: passing a valid pointer to 'PTR_ERR'
mm/damon/dbgfs.c:319 dbgfs_monitor_on_write() warn: passing a valid pointer to 'PTR_ERR'
vim +/PTR_ERR +76 mm/damon/dbgfs.c
4bc05954d007665 SeongJae Park 2021-09-07 64
4bc05954d007665 SeongJae Park 2021-09-07 65 static ssize_t dbgfs_attrs_write(struct file *file,
4bc05954d007665 SeongJae Park 2021-09-07 66 const char __user *buf, size_t count, loff_t *ppos)
4bc05954d007665 SeongJae Park 2021-09-07 67 {
4bc05954d007665 SeongJae Park 2021-09-07 68 struct damon_ctx *ctx = file->private_data;
4bc05954d007665 SeongJae Park 2021-09-07 69 unsigned long s, a, r, minr, maxr;
4bc05954d007665 SeongJae Park 2021-09-07 70 char *kbuf;
4bc05954d007665 SeongJae Park 2021-09-07 71 ssize_t ret = count;
4bc05954d007665 SeongJae Park 2021-09-07 72 int err;
4bc05954d007665 SeongJae Park 2021-09-07 73
4bc05954d007665 SeongJae Park 2021-09-07 74 kbuf = user_input_str(buf, count, ppos);
4bc05954d007665 SeongJae Park 2021-09-07 75 if (IS_ERR(kbuf))
4bc05954d007665 SeongJae Park 2021-09-07 @76 return PTR_ERR(kbuf);
4bc05954d007665 SeongJae Park 2021-09-07 77
4bc05954d007665 SeongJae Park 2021-09-07 78 if (sscanf(kbuf, "%lu %lu %lu %lu %lu",
4bc05954d007665 SeongJae Park 2021-09-07 79 &s, &a, &r, &minr, &maxr) != 5) {
4bc05954d007665 SeongJae Park 2021-09-07 80 ret = -EINVAL;
4bc05954d007665 SeongJae Park 2021-09-07 81 goto out;
4bc05954d007665 SeongJae Park 2021-09-07 82 }
4bc05954d007665 SeongJae Park 2021-09-07 83
4bc05954d007665 SeongJae Park 2021-09-07 84 mutex_lock(&ctx->kdamond_lock);
4bc05954d007665 SeongJae Park 2021-09-07 85 if (ctx->kdamond) {
4bc05954d007665 SeongJae Park 2021-09-07 86 ret = -EBUSY;
4bc05954d007665 SeongJae Park 2021-09-07 87 goto unlock_out;
4bc05954d007665 SeongJae Park 2021-09-07 88 }
4bc05954d007665 SeongJae Park 2021-09-07 89
4bc05954d007665 SeongJae Park 2021-09-07 90 err = damon_set_attrs(ctx, s, a, r, minr, maxr);
4bc05954d007665 SeongJae Park 2021-09-07 91 if (err)
4bc05954d007665 SeongJae Park 2021-09-07 92 ret = err;
4bc05954d007665 SeongJae Park 2021-09-07 93 unlock_out:
4bc05954d007665 SeongJae Park 2021-09-07 94 mutex_unlock(&ctx->kdamond_lock);
4bc05954d007665 SeongJae Park 2021-09-07 95 out:
4bc05954d007665 SeongJae Park 2021-09-07 96 kfree(kbuf);
4bc05954d007665 SeongJae Park 2021-09-07 97 return ret;
4bc05954d007665 SeongJae Park 2021-09-07 98 }
4bc05954d007665 SeongJae Park 2021-09-07 99
4bc05954d007665 SeongJae Park 2021-09-07 100 static inline bool targetid_is_pid(const struct damon_ctx *ctx)
4bc05954d007665 SeongJae Park 2021-09-07 101 {
4bc05954d007665 SeongJae Park 2021-09-07 102 return ctx->primitive.target_valid == damon_va_target_valid;
4bc05954d007665 SeongJae Park 2021-09-07 103 }
4bc05954d007665 SeongJae Park 2021-09-07 104
4bc05954d007665 SeongJae Park 2021-09-07 105 static ssize_t sprint_target_ids(struct damon_ctx *ctx, char *buf, ssize_t len)
4bc05954d007665 SeongJae Park 2021-09-07 106 {
4bc05954d007665 SeongJae Park 2021-09-07 107 struct damon_target *t;
4bc05954d007665 SeongJae Park 2021-09-07 108 unsigned long id;
4bc05954d007665 SeongJae Park 2021-09-07 109 int written = 0;
4bc05954d007665 SeongJae Park 2021-09-07 110 int rc;
4bc05954d007665 SeongJae Park 2021-09-07 111
4bc05954d007665 SeongJae Park 2021-09-07 112 damon_for_each_target(t, ctx) {
4bc05954d007665 SeongJae Park 2021-09-07 113 id = t->id;
4bc05954d007665 SeongJae Park 2021-09-07 114 if (targetid_is_pid(ctx))
4bc05954d007665 SeongJae Park 2021-09-07 115 /* Show pid numbers to debugfs users */
4bc05954d007665 SeongJae Park 2021-09-07 116 id = (unsigned long)pid_vnr((struct pid *)id);
4bc05954d007665 SeongJae Park 2021-09-07 117
4bc05954d007665 SeongJae Park 2021-09-07 118 rc = scnprintf(&buf[written], len - written, "%lu ", id);
4bc05954d007665 SeongJae Park 2021-09-07 119 if (!rc)
4bc05954d007665 SeongJae Park 2021-09-07 120 return -ENOMEM;
4bc05954d007665 SeongJae Park 2021-09-07 121 written += rc;
4bc05954d007665 SeongJae Park 2021-09-07 122 }
4bc05954d007665 SeongJae Park 2021-09-07 123 if (written)
4bc05954d007665 SeongJae Park 2021-09-07 124 written -= 1;
4bc05954d007665 SeongJae Park 2021-09-07 125 written += scnprintf(&buf[written], len - written, "\n");
4bc05954d007665 SeongJae Park 2021-09-07 126 return written;
4bc05954d007665 SeongJae Park 2021-09-07 127 }
4bc05954d007665 SeongJae Park 2021-09-07 128
4bc05954d007665 SeongJae Park 2021-09-07 129 static ssize_t dbgfs_target_ids_read(struct file *file,
4bc05954d007665 SeongJae Park 2021-09-07 130 char __user *buf, size_t count, loff_t *ppos)
4bc05954d007665 SeongJae Park 2021-09-07 131 {
4bc05954d007665 SeongJae Park 2021-09-07 132 struct damon_ctx *ctx = file->private_data;
4bc05954d007665 SeongJae Park 2021-09-07 133 ssize_t len;
4bc05954d007665 SeongJae Park 2021-09-07 134 char ids_buf[320];
4bc05954d007665 SeongJae Park 2021-09-07 135
4bc05954d007665 SeongJae Park 2021-09-07 136 mutex_lock(&ctx->kdamond_lock);
4bc05954d007665 SeongJae Park 2021-09-07 137 len = sprint_target_ids(ctx, ids_buf, 320);
4bc05954d007665 SeongJae Park 2021-09-07 138 mutex_unlock(&ctx->kdamond_lock);
4bc05954d007665 SeongJae Park 2021-09-07 139 if (len < 0)
4bc05954d007665 SeongJae Park 2021-09-07 140 return len;
4bc05954d007665 SeongJae Park 2021-09-07 141
4bc05954d007665 SeongJae Park 2021-09-07 142 return simple_read_from_buffer(buf, count, ppos, ids_buf, len);
4bc05954d007665 SeongJae Park 2021-09-07 143 }
4bc05954d007665 SeongJae Park 2021-09-07 144
4bc05954d007665 SeongJae Park 2021-09-07 145 /*
4bc05954d007665 SeongJae Park 2021-09-07 146 * Converts a string into an array of unsigned long integers
4bc05954d007665 SeongJae Park 2021-09-07 147 *
4bc05954d007665 SeongJae Park 2021-09-07 148 * Returns an array of unsigned long integers if the conversion success, or
4bc05954d007665 SeongJae Park 2021-09-07 149 * NULL otherwise.
4bc05954d007665 SeongJae Park 2021-09-07 150 */
4bc05954d007665 SeongJae Park 2021-09-07 151 static unsigned long *str_to_target_ids(const char *str, ssize_t len,
4bc05954d007665 SeongJae Park 2021-09-07 152 ssize_t *nr_ids)
4bc05954d007665 SeongJae Park 2021-09-07 153 {
4bc05954d007665 SeongJae Park 2021-09-07 154 unsigned long *ids;
4bc05954d007665 SeongJae Park 2021-09-07 155 const int max_nr_ids = 32;
4bc05954d007665 SeongJae Park 2021-09-07 156 unsigned long id;
4bc05954d007665 SeongJae Park 2021-09-07 157 int pos = 0, parsed, ret;
4bc05954d007665 SeongJae Park 2021-09-07 158
4bc05954d007665 SeongJae Park 2021-09-07 159 *nr_ids = 0;
4bc05954d007665 SeongJae Park 2021-09-07 160 ids = kmalloc_array(max_nr_ids, sizeof(id), GFP_KERNEL);
4bc05954d007665 SeongJae Park 2021-09-07 161 if (!ids)
4bc05954d007665 SeongJae Park 2021-09-07 162 return NULL;
4bc05954d007665 SeongJae Park 2021-09-07 163 while (*nr_ids < max_nr_ids && pos < len) {
4bc05954d007665 SeongJae Park 2021-09-07 164 ret = sscanf(&str[pos], "%lu%n", &id, &parsed);
4bc05954d007665 SeongJae Park 2021-09-07 165 pos += parsed;
4bc05954d007665 SeongJae Park 2021-09-07 166 if (ret != 1)
4bc05954d007665 SeongJae Park 2021-09-07 167 break;
4bc05954d007665 SeongJae Park 2021-09-07 168 ids[*nr_ids] = id;
4bc05954d007665 SeongJae Park 2021-09-07 169 *nr_ids += 1;
4bc05954d007665 SeongJae Park 2021-09-07 170 }
4bc05954d007665 SeongJae Park 2021-09-07 171
4bc05954d007665 SeongJae Park 2021-09-07 172 return ids;
4bc05954d007665 SeongJae Park 2021-09-07 173 }
4bc05954d007665 SeongJae Park 2021-09-07 174
4bc05954d007665 SeongJae Park 2021-09-07 175 static void dbgfs_put_pids(unsigned long *ids, int nr_ids)
4bc05954d007665 SeongJae Park 2021-09-07 176 {
4bc05954d007665 SeongJae Park 2021-09-07 177 int i;
4bc05954d007665 SeongJae Park 2021-09-07 178
4bc05954d007665 SeongJae Park 2021-09-07 179 for (i = 0; i < nr_ids; i++)
4bc05954d007665 SeongJae Park 2021-09-07 180 put_pid((struct pid *)ids[i]);
4bc05954d007665 SeongJae Park 2021-09-07 181 }
4bc05954d007665 SeongJae Park 2021-09-07 182
4bc05954d007665 SeongJae Park 2021-09-07 183 static ssize_t dbgfs_target_ids_write(struct file *file,
4bc05954d007665 SeongJae Park 2021-09-07 184 const char __user *buf, size_t count, loff_t *ppos)
4bc05954d007665 SeongJae Park 2021-09-07 185 {
4bc05954d007665 SeongJae Park 2021-09-07 186 struct damon_ctx *ctx = file->private_data;
4bc05954d007665 SeongJae Park 2021-09-07 187 char *kbuf, *nrs;
4bc05954d007665 SeongJae Park 2021-09-07 188 unsigned long *targets;
4bc05954d007665 SeongJae Park 2021-09-07 189 ssize_t nr_targets;
4bc05954d007665 SeongJae Park 2021-09-07 190 ssize_t ret = count;
4bc05954d007665 SeongJae Park 2021-09-07 191 int i;
4bc05954d007665 SeongJae Park 2021-09-07 192 int err;
4bc05954d007665 SeongJae Park 2021-09-07 193
4bc05954d007665 SeongJae Park 2021-09-07 194 kbuf = user_input_str(buf, count, ppos);
4bc05954d007665 SeongJae Park 2021-09-07 195 if (IS_ERR(kbuf))
4bc05954d007665 SeongJae Park 2021-09-07 @196 return PTR_ERR(kbuf);
4bc05954d007665 SeongJae Park 2021-09-07 197
4bc05954d007665 SeongJae Park 2021-09-07 198 nrs = kbuf;
4bc05954d007665 SeongJae Park 2021-09-07 199
4bc05954d007665 SeongJae Park 2021-09-07 200 targets = str_to_target_ids(nrs, ret, &nr_targets);
4bc05954d007665 SeongJae Park 2021-09-07 201 if (!targets) {
4bc05954d007665 SeongJae Park 2021-09-07 202 ret = -ENOMEM;
4bc05954d007665 SeongJae Park 2021-09-07 203 goto out;
4bc05954d007665 SeongJae Park 2021-09-07 204 }
4bc05954d007665 SeongJae Park 2021-09-07 205
4bc05954d007665 SeongJae Park 2021-09-07 206 if (targetid_is_pid(ctx)) {
4bc05954d007665 SeongJae Park 2021-09-07 207 for (i = 0; i < nr_targets; i++) {
4bc05954d007665 SeongJae Park 2021-09-07 208 targets[i] = (unsigned long)find_get_pid(
4bc05954d007665 SeongJae Park 2021-09-07 209 (int)targets[i]);
4bc05954d007665 SeongJae Park 2021-09-07 210 if (!targets[i]) {
4bc05954d007665 SeongJae Park 2021-09-07 211 dbgfs_put_pids(targets, i);
4bc05954d007665 SeongJae Park 2021-09-07 212 ret = -EINVAL;
4bc05954d007665 SeongJae Park 2021-09-07 213 goto free_targets_out;
4bc05954d007665 SeongJae Park 2021-09-07 214 }
4bc05954d007665 SeongJae Park 2021-09-07 215 }
4bc05954d007665 SeongJae Park 2021-09-07 216 }
4bc05954d007665 SeongJae Park 2021-09-07 217
4bc05954d007665 SeongJae Park 2021-09-07 218 mutex_lock(&ctx->kdamond_lock);
4bc05954d007665 SeongJae Park 2021-09-07 219 if (ctx->kdamond) {
4bc05954d007665 SeongJae Park 2021-09-07 220 if (targetid_is_pid(ctx))
4bc05954d007665 SeongJae Park 2021-09-07 221 dbgfs_put_pids(targets, nr_targets);
4bc05954d007665 SeongJae Park 2021-09-07 222 ret = -EBUSY;
4bc05954d007665 SeongJae Park 2021-09-07 223 goto unlock_out;
4bc05954d007665 SeongJae Park 2021-09-07 224 }
4bc05954d007665 SeongJae Park 2021-09-07 225
4bc05954d007665 SeongJae Park 2021-09-07 226 err = damon_set_targets(ctx, targets, nr_targets);
4bc05954d007665 SeongJae Park 2021-09-07 227 if (err) {
4bc05954d007665 SeongJae Park 2021-09-07 228 if (targetid_is_pid(ctx))
4bc05954d007665 SeongJae Park 2021-09-07 229 dbgfs_put_pids(targets, nr_targets);
4bc05954d007665 SeongJae Park 2021-09-07 230 ret = err;
4bc05954d007665 SeongJae Park 2021-09-07 231 }
4bc05954d007665 SeongJae Park 2021-09-07 232
4bc05954d007665 SeongJae Park 2021-09-07 233 unlock_out:
4bc05954d007665 SeongJae Park 2021-09-07 234 mutex_unlock(&ctx->kdamond_lock);
4bc05954d007665 SeongJae Park 2021-09-07 235 free_targets_out:
4bc05954d007665 SeongJae Park 2021-09-07 236 kfree(targets);
4bc05954d007665 SeongJae Park 2021-09-07 237 out:
4bc05954d007665 SeongJae Park 2021-09-07 238 kfree(kbuf);
4bc05954d007665 SeongJae Park 2021-09-07 239 return ret;
4bc05954d007665 SeongJae Park 2021-09-07 240 }
4bc05954d007665 SeongJae Park 2021-09-07 241
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
^ permalink raw reply [flat|nested] 5+ messages in thread
* mm/damon/dbgfs.c:76 dbgfs_attrs_write() warn: passing a valid pointer to 'PTR_ERR'
@ 2022-08-21 5:18 kernel test robot
0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2022-08-21 5:18 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 13414 bytes --]
BCC: lkp(a)intel.com
CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: SeongJae Park <sjpark@amazon.de>
CC: Leonard Foerster <foersleo@amazon.de>
CC: Fernand Sieber <sieberf@amazon.com>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Linux Memory Management List <linux-mm@kvack.org>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 15b3f48a4339e3c16acf18624e2b7f60bc5e9a2c
commit: 4bc05954d0076655cfaf6f0135585bdc20cd6b11 mm/damon: implement a debugfs-based user space interface
date: 12 months ago
:::::: branch date: 7 hours ago
:::::: commit date: 12 months ago
config: parisc-randconfig-m031-20220821 (https://download.01.org/0day-ci/archive/20220821/202208211352.4zTbA9ny-lkp(a)intel.com/config)
compiler: hppa-linux-gcc (GCC) 12.1.0
If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch warnings:
mm/damon/dbgfs.c:76 dbgfs_attrs_write() warn: passing a valid pointer to 'PTR_ERR'
mm/damon/dbgfs.c:196 dbgfs_target_ids_write() warn: passing a valid pointer to 'PTR_ERR'
mm/damon/dbgfs.c:319 dbgfs_monitor_on_write() warn: passing a valid pointer to 'PTR_ERR'
vim +/PTR_ERR +76 mm/damon/dbgfs.c
4bc05954d00766 SeongJae Park 2021-09-07 64
4bc05954d00766 SeongJae Park 2021-09-07 65 static ssize_t dbgfs_attrs_write(struct file *file,
4bc05954d00766 SeongJae Park 2021-09-07 66 const char __user *buf, size_t count, loff_t *ppos)
4bc05954d00766 SeongJae Park 2021-09-07 67 {
4bc05954d00766 SeongJae Park 2021-09-07 68 struct damon_ctx *ctx = file->private_data;
4bc05954d00766 SeongJae Park 2021-09-07 69 unsigned long s, a, r, minr, maxr;
4bc05954d00766 SeongJae Park 2021-09-07 70 char *kbuf;
4bc05954d00766 SeongJae Park 2021-09-07 71 ssize_t ret = count;
4bc05954d00766 SeongJae Park 2021-09-07 72 int err;
4bc05954d00766 SeongJae Park 2021-09-07 73
4bc05954d00766 SeongJae Park 2021-09-07 74 kbuf = user_input_str(buf, count, ppos);
4bc05954d00766 SeongJae Park 2021-09-07 75 if (IS_ERR(kbuf))
4bc05954d00766 SeongJae Park 2021-09-07 @76 return PTR_ERR(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 77
4bc05954d00766 SeongJae Park 2021-09-07 78 if (sscanf(kbuf, "%lu %lu %lu %lu %lu",
4bc05954d00766 SeongJae Park 2021-09-07 79 &s, &a, &r, &minr, &maxr) != 5) {
4bc05954d00766 SeongJae Park 2021-09-07 80 ret = -EINVAL;
4bc05954d00766 SeongJae Park 2021-09-07 81 goto out;
4bc05954d00766 SeongJae Park 2021-09-07 82 }
4bc05954d00766 SeongJae Park 2021-09-07 83
4bc05954d00766 SeongJae Park 2021-09-07 84 mutex_lock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 85 if (ctx->kdamond) {
4bc05954d00766 SeongJae Park 2021-09-07 86 ret = -EBUSY;
4bc05954d00766 SeongJae Park 2021-09-07 87 goto unlock_out;
4bc05954d00766 SeongJae Park 2021-09-07 88 }
4bc05954d00766 SeongJae Park 2021-09-07 89
4bc05954d00766 SeongJae Park 2021-09-07 90 err = damon_set_attrs(ctx, s, a, r, minr, maxr);
4bc05954d00766 SeongJae Park 2021-09-07 91 if (err)
4bc05954d00766 SeongJae Park 2021-09-07 92 ret = err;
4bc05954d00766 SeongJae Park 2021-09-07 93 unlock_out:
4bc05954d00766 SeongJae Park 2021-09-07 94 mutex_unlock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 95 out:
4bc05954d00766 SeongJae Park 2021-09-07 96 kfree(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 97 return ret;
4bc05954d00766 SeongJae Park 2021-09-07 98 }
4bc05954d00766 SeongJae Park 2021-09-07 99
4bc05954d00766 SeongJae Park 2021-09-07 100 static inline bool targetid_is_pid(const struct damon_ctx *ctx)
4bc05954d00766 SeongJae Park 2021-09-07 101 {
4bc05954d00766 SeongJae Park 2021-09-07 102 return ctx->primitive.target_valid == damon_va_target_valid;
4bc05954d00766 SeongJae Park 2021-09-07 103 }
4bc05954d00766 SeongJae Park 2021-09-07 104
4bc05954d00766 SeongJae Park 2021-09-07 105 static ssize_t sprint_target_ids(struct damon_ctx *ctx, char *buf, ssize_t len)
4bc05954d00766 SeongJae Park 2021-09-07 106 {
4bc05954d00766 SeongJae Park 2021-09-07 107 struct damon_target *t;
4bc05954d00766 SeongJae Park 2021-09-07 108 unsigned long id;
4bc05954d00766 SeongJae Park 2021-09-07 109 int written = 0;
4bc05954d00766 SeongJae Park 2021-09-07 110 int rc;
4bc05954d00766 SeongJae Park 2021-09-07 111
4bc05954d00766 SeongJae Park 2021-09-07 112 damon_for_each_target(t, ctx) {
4bc05954d00766 SeongJae Park 2021-09-07 113 id = t->id;
4bc05954d00766 SeongJae Park 2021-09-07 114 if (targetid_is_pid(ctx))
4bc05954d00766 SeongJae Park 2021-09-07 115 /* Show pid numbers to debugfs users */
4bc05954d00766 SeongJae Park 2021-09-07 116 id = (unsigned long)pid_vnr((struct pid *)id);
4bc05954d00766 SeongJae Park 2021-09-07 117
4bc05954d00766 SeongJae Park 2021-09-07 118 rc = scnprintf(&buf[written], len - written, "%lu ", id);
4bc05954d00766 SeongJae Park 2021-09-07 119 if (!rc)
4bc05954d00766 SeongJae Park 2021-09-07 120 return -ENOMEM;
4bc05954d00766 SeongJae Park 2021-09-07 121 written += rc;
4bc05954d00766 SeongJae Park 2021-09-07 122 }
4bc05954d00766 SeongJae Park 2021-09-07 123 if (written)
4bc05954d00766 SeongJae Park 2021-09-07 124 written -= 1;
4bc05954d00766 SeongJae Park 2021-09-07 125 written += scnprintf(&buf[written], len - written, "\n");
4bc05954d00766 SeongJae Park 2021-09-07 126 return written;
4bc05954d00766 SeongJae Park 2021-09-07 127 }
4bc05954d00766 SeongJae Park 2021-09-07 128
4bc05954d00766 SeongJae Park 2021-09-07 129 static ssize_t dbgfs_target_ids_read(struct file *file,
4bc05954d00766 SeongJae Park 2021-09-07 130 char __user *buf, size_t count, loff_t *ppos)
4bc05954d00766 SeongJae Park 2021-09-07 131 {
4bc05954d00766 SeongJae Park 2021-09-07 132 struct damon_ctx *ctx = file->private_data;
4bc05954d00766 SeongJae Park 2021-09-07 133 ssize_t len;
4bc05954d00766 SeongJae Park 2021-09-07 134 char ids_buf[320];
4bc05954d00766 SeongJae Park 2021-09-07 135
4bc05954d00766 SeongJae Park 2021-09-07 136 mutex_lock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 137 len = sprint_target_ids(ctx, ids_buf, 320);
4bc05954d00766 SeongJae Park 2021-09-07 138 mutex_unlock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 139 if (len < 0)
4bc05954d00766 SeongJae Park 2021-09-07 140 return len;
4bc05954d00766 SeongJae Park 2021-09-07 141
4bc05954d00766 SeongJae Park 2021-09-07 142 return simple_read_from_buffer(buf, count, ppos, ids_buf, len);
4bc05954d00766 SeongJae Park 2021-09-07 143 }
4bc05954d00766 SeongJae Park 2021-09-07 144
4bc05954d00766 SeongJae Park 2021-09-07 145 /*
4bc05954d00766 SeongJae Park 2021-09-07 146 * Converts a string into an array of unsigned long integers
4bc05954d00766 SeongJae Park 2021-09-07 147 *
4bc05954d00766 SeongJae Park 2021-09-07 148 * Returns an array of unsigned long integers if the conversion success, or
4bc05954d00766 SeongJae Park 2021-09-07 149 * NULL otherwise.
4bc05954d00766 SeongJae Park 2021-09-07 150 */
4bc05954d00766 SeongJae Park 2021-09-07 151 static unsigned long *str_to_target_ids(const char *str, ssize_t len,
4bc05954d00766 SeongJae Park 2021-09-07 152 ssize_t *nr_ids)
4bc05954d00766 SeongJae Park 2021-09-07 153 {
4bc05954d00766 SeongJae Park 2021-09-07 154 unsigned long *ids;
4bc05954d00766 SeongJae Park 2021-09-07 155 const int max_nr_ids = 32;
4bc05954d00766 SeongJae Park 2021-09-07 156 unsigned long id;
4bc05954d00766 SeongJae Park 2021-09-07 157 int pos = 0, parsed, ret;
4bc05954d00766 SeongJae Park 2021-09-07 158
4bc05954d00766 SeongJae Park 2021-09-07 159 *nr_ids = 0;
4bc05954d00766 SeongJae Park 2021-09-07 160 ids = kmalloc_array(max_nr_ids, sizeof(id), GFP_KERNEL);
4bc05954d00766 SeongJae Park 2021-09-07 161 if (!ids)
4bc05954d00766 SeongJae Park 2021-09-07 162 return NULL;
4bc05954d00766 SeongJae Park 2021-09-07 163 while (*nr_ids < max_nr_ids && pos < len) {
4bc05954d00766 SeongJae Park 2021-09-07 164 ret = sscanf(&str[pos], "%lu%n", &id, &parsed);
4bc05954d00766 SeongJae Park 2021-09-07 165 pos += parsed;
4bc05954d00766 SeongJae Park 2021-09-07 166 if (ret != 1)
4bc05954d00766 SeongJae Park 2021-09-07 167 break;
4bc05954d00766 SeongJae Park 2021-09-07 168 ids[*nr_ids] = id;
4bc05954d00766 SeongJae Park 2021-09-07 169 *nr_ids += 1;
4bc05954d00766 SeongJae Park 2021-09-07 170 }
4bc05954d00766 SeongJae Park 2021-09-07 171
4bc05954d00766 SeongJae Park 2021-09-07 172 return ids;
4bc05954d00766 SeongJae Park 2021-09-07 173 }
4bc05954d00766 SeongJae Park 2021-09-07 174
4bc05954d00766 SeongJae Park 2021-09-07 175 static void dbgfs_put_pids(unsigned long *ids, int nr_ids)
4bc05954d00766 SeongJae Park 2021-09-07 176 {
4bc05954d00766 SeongJae Park 2021-09-07 177 int i;
4bc05954d00766 SeongJae Park 2021-09-07 178
4bc05954d00766 SeongJae Park 2021-09-07 179 for (i = 0; i < nr_ids; i++)
4bc05954d00766 SeongJae Park 2021-09-07 180 put_pid((struct pid *)ids[i]);
4bc05954d00766 SeongJae Park 2021-09-07 181 }
4bc05954d00766 SeongJae Park 2021-09-07 182
4bc05954d00766 SeongJae Park 2021-09-07 183 static ssize_t dbgfs_target_ids_write(struct file *file,
4bc05954d00766 SeongJae Park 2021-09-07 184 const char __user *buf, size_t count, loff_t *ppos)
4bc05954d00766 SeongJae Park 2021-09-07 185 {
4bc05954d00766 SeongJae Park 2021-09-07 186 struct damon_ctx *ctx = file->private_data;
4bc05954d00766 SeongJae Park 2021-09-07 187 char *kbuf, *nrs;
4bc05954d00766 SeongJae Park 2021-09-07 188 unsigned long *targets;
4bc05954d00766 SeongJae Park 2021-09-07 189 ssize_t nr_targets;
4bc05954d00766 SeongJae Park 2021-09-07 190 ssize_t ret = count;
4bc05954d00766 SeongJae Park 2021-09-07 191 int i;
4bc05954d00766 SeongJae Park 2021-09-07 192 int err;
4bc05954d00766 SeongJae Park 2021-09-07 193
4bc05954d00766 SeongJae Park 2021-09-07 194 kbuf = user_input_str(buf, count, ppos);
4bc05954d00766 SeongJae Park 2021-09-07 195 if (IS_ERR(kbuf))
4bc05954d00766 SeongJae Park 2021-09-07 @196 return PTR_ERR(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 197
4bc05954d00766 SeongJae Park 2021-09-07 198 nrs = kbuf;
4bc05954d00766 SeongJae Park 2021-09-07 199
4bc05954d00766 SeongJae Park 2021-09-07 200 targets = str_to_target_ids(nrs, ret, &nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 201 if (!targets) {
4bc05954d00766 SeongJae Park 2021-09-07 202 ret = -ENOMEM;
4bc05954d00766 SeongJae Park 2021-09-07 203 goto out;
4bc05954d00766 SeongJae Park 2021-09-07 204 }
4bc05954d00766 SeongJae Park 2021-09-07 205
4bc05954d00766 SeongJae Park 2021-09-07 206 if (targetid_is_pid(ctx)) {
4bc05954d00766 SeongJae Park 2021-09-07 207 for (i = 0; i < nr_targets; i++) {
4bc05954d00766 SeongJae Park 2021-09-07 208 targets[i] = (unsigned long)find_get_pid(
4bc05954d00766 SeongJae Park 2021-09-07 209 (int)targets[i]);
4bc05954d00766 SeongJae Park 2021-09-07 210 if (!targets[i]) {
4bc05954d00766 SeongJae Park 2021-09-07 211 dbgfs_put_pids(targets, i);
4bc05954d00766 SeongJae Park 2021-09-07 212 ret = -EINVAL;
4bc05954d00766 SeongJae Park 2021-09-07 213 goto free_targets_out;
4bc05954d00766 SeongJae Park 2021-09-07 214 }
4bc05954d00766 SeongJae Park 2021-09-07 215 }
4bc05954d00766 SeongJae Park 2021-09-07 216 }
4bc05954d00766 SeongJae Park 2021-09-07 217
4bc05954d00766 SeongJae Park 2021-09-07 218 mutex_lock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 219 if (ctx->kdamond) {
4bc05954d00766 SeongJae Park 2021-09-07 220 if (targetid_is_pid(ctx))
4bc05954d00766 SeongJae Park 2021-09-07 221 dbgfs_put_pids(targets, nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 222 ret = -EBUSY;
4bc05954d00766 SeongJae Park 2021-09-07 223 goto unlock_out;
4bc05954d00766 SeongJae Park 2021-09-07 224 }
4bc05954d00766 SeongJae Park 2021-09-07 225
4bc05954d00766 SeongJae Park 2021-09-07 226 err = damon_set_targets(ctx, targets, nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 227 if (err) {
4bc05954d00766 SeongJae Park 2021-09-07 228 if (targetid_is_pid(ctx))
4bc05954d00766 SeongJae Park 2021-09-07 229 dbgfs_put_pids(targets, nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 230 ret = err;
4bc05954d00766 SeongJae Park 2021-09-07 231 }
4bc05954d00766 SeongJae Park 2021-09-07 232
4bc05954d00766 SeongJae Park 2021-09-07 233 unlock_out:
4bc05954d00766 SeongJae Park 2021-09-07 234 mutex_unlock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 235 free_targets_out:
4bc05954d00766 SeongJae Park 2021-09-07 236 kfree(targets);
4bc05954d00766 SeongJae Park 2021-09-07 237 out:
4bc05954d00766 SeongJae Park 2021-09-07 238 kfree(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 239 return ret;
4bc05954d00766 SeongJae Park 2021-09-07 240 }
4bc05954d00766 SeongJae Park 2021-09-07 241
--
0-DAY CI Kernel Test Service
https://01.org/lkp
^ permalink raw reply [flat|nested] 5+ messages in thread
* mm/damon/dbgfs.c:76 dbgfs_attrs_write() warn: passing a valid pointer to 'PTR_ERR'
@ 2021-12-05 0:50 kernel test robot
0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-12-05 0:50 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 13451 bytes --]
CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: SeongJae Park <sjpark@amazon.de>
CC: Leonard Foerster <foersleo@amazon.de>
CC: Fernand Sieber <sieberf@amazon.com>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Linux Memory Management List <linux-mm@kvack.org>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 23b55d673d7527b093cd97b7c217c82e70cd1af0
commit: 4bc05954d0076655cfaf6f0135585bdc20cd6b11 mm/damon: implement a debugfs-based user space interface
date: 3 months ago
:::::: branch date: 3 hours ago
:::::: commit date: 3 months ago
config: nios2-randconfig-m031-20211202 (https://download.01.org/0day-ci/archive/20211205/202112050835.m79siExT-lkp(a)intel.com/config)
compiler: nios2-linux-gcc (GCC) 11.2.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch warnings:
mm/damon/dbgfs.c:76 dbgfs_attrs_write() warn: passing a valid pointer to 'PTR_ERR'
mm/damon/dbgfs.c:196 dbgfs_target_ids_write() warn: passing a valid pointer to 'PTR_ERR'
mm/damon/dbgfs.c:319 dbgfs_monitor_on_write() warn: passing a valid pointer to 'PTR_ERR'
vim +/PTR_ERR +76 mm/damon/dbgfs.c
4bc05954d00766 SeongJae Park 2021-09-07 64
4bc05954d00766 SeongJae Park 2021-09-07 65 static ssize_t dbgfs_attrs_write(struct file *file,
4bc05954d00766 SeongJae Park 2021-09-07 66 const char __user *buf, size_t count, loff_t *ppos)
4bc05954d00766 SeongJae Park 2021-09-07 67 {
4bc05954d00766 SeongJae Park 2021-09-07 68 struct damon_ctx *ctx = file->private_data;
4bc05954d00766 SeongJae Park 2021-09-07 69 unsigned long s, a, r, minr, maxr;
4bc05954d00766 SeongJae Park 2021-09-07 70 char *kbuf;
4bc05954d00766 SeongJae Park 2021-09-07 71 ssize_t ret = count;
4bc05954d00766 SeongJae Park 2021-09-07 72 int err;
4bc05954d00766 SeongJae Park 2021-09-07 73
4bc05954d00766 SeongJae Park 2021-09-07 74 kbuf = user_input_str(buf, count, ppos);
4bc05954d00766 SeongJae Park 2021-09-07 75 if (IS_ERR(kbuf))
4bc05954d00766 SeongJae Park 2021-09-07 @76 return PTR_ERR(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 77
4bc05954d00766 SeongJae Park 2021-09-07 78 if (sscanf(kbuf, "%lu %lu %lu %lu %lu",
4bc05954d00766 SeongJae Park 2021-09-07 79 &s, &a, &r, &minr, &maxr) != 5) {
4bc05954d00766 SeongJae Park 2021-09-07 80 ret = -EINVAL;
4bc05954d00766 SeongJae Park 2021-09-07 81 goto out;
4bc05954d00766 SeongJae Park 2021-09-07 82 }
4bc05954d00766 SeongJae Park 2021-09-07 83
4bc05954d00766 SeongJae Park 2021-09-07 84 mutex_lock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 85 if (ctx->kdamond) {
4bc05954d00766 SeongJae Park 2021-09-07 86 ret = -EBUSY;
4bc05954d00766 SeongJae Park 2021-09-07 87 goto unlock_out;
4bc05954d00766 SeongJae Park 2021-09-07 88 }
4bc05954d00766 SeongJae Park 2021-09-07 89
4bc05954d00766 SeongJae Park 2021-09-07 90 err = damon_set_attrs(ctx, s, a, r, minr, maxr);
4bc05954d00766 SeongJae Park 2021-09-07 91 if (err)
4bc05954d00766 SeongJae Park 2021-09-07 92 ret = err;
4bc05954d00766 SeongJae Park 2021-09-07 93 unlock_out:
4bc05954d00766 SeongJae Park 2021-09-07 94 mutex_unlock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 95 out:
4bc05954d00766 SeongJae Park 2021-09-07 96 kfree(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 97 return ret;
4bc05954d00766 SeongJae Park 2021-09-07 98 }
4bc05954d00766 SeongJae Park 2021-09-07 99
4bc05954d00766 SeongJae Park 2021-09-07 100 static inline bool targetid_is_pid(const struct damon_ctx *ctx)
4bc05954d00766 SeongJae Park 2021-09-07 101 {
4bc05954d00766 SeongJae Park 2021-09-07 102 return ctx->primitive.target_valid == damon_va_target_valid;
4bc05954d00766 SeongJae Park 2021-09-07 103 }
4bc05954d00766 SeongJae Park 2021-09-07 104
4bc05954d00766 SeongJae Park 2021-09-07 105 static ssize_t sprint_target_ids(struct damon_ctx *ctx, char *buf, ssize_t len)
4bc05954d00766 SeongJae Park 2021-09-07 106 {
4bc05954d00766 SeongJae Park 2021-09-07 107 struct damon_target *t;
4bc05954d00766 SeongJae Park 2021-09-07 108 unsigned long id;
4bc05954d00766 SeongJae Park 2021-09-07 109 int written = 0;
4bc05954d00766 SeongJae Park 2021-09-07 110 int rc;
4bc05954d00766 SeongJae Park 2021-09-07 111
4bc05954d00766 SeongJae Park 2021-09-07 112 damon_for_each_target(t, ctx) {
4bc05954d00766 SeongJae Park 2021-09-07 113 id = t->id;
4bc05954d00766 SeongJae Park 2021-09-07 114 if (targetid_is_pid(ctx))
4bc05954d00766 SeongJae Park 2021-09-07 115 /* Show pid numbers to debugfs users */
4bc05954d00766 SeongJae Park 2021-09-07 116 id = (unsigned long)pid_vnr((struct pid *)id);
4bc05954d00766 SeongJae Park 2021-09-07 117
4bc05954d00766 SeongJae Park 2021-09-07 118 rc = scnprintf(&buf[written], len - written, "%lu ", id);
4bc05954d00766 SeongJae Park 2021-09-07 119 if (!rc)
4bc05954d00766 SeongJae Park 2021-09-07 120 return -ENOMEM;
4bc05954d00766 SeongJae Park 2021-09-07 121 written += rc;
4bc05954d00766 SeongJae Park 2021-09-07 122 }
4bc05954d00766 SeongJae Park 2021-09-07 123 if (written)
4bc05954d00766 SeongJae Park 2021-09-07 124 written -= 1;
4bc05954d00766 SeongJae Park 2021-09-07 125 written += scnprintf(&buf[written], len - written, "\n");
4bc05954d00766 SeongJae Park 2021-09-07 126 return written;
4bc05954d00766 SeongJae Park 2021-09-07 127 }
4bc05954d00766 SeongJae Park 2021-09-07 128
4bc05954d00766 SeongJae Park 2021-09-07 129 static ssize_t dbgfs_target_ids_read(struct file *file,
4bc05954d00766 SeongJae Park 2021-09-07 130 char __user *buf, size_t count, loff_t *ppos)
4bc05954d00766 SeongJae Park 2021-09-07 131 {
4bc05954d00766 SeongJae Park 2021-09-07 132 struct damon_ctx *ctx = file->private_data;
4bc05954d00766 SeongJae Park 2021-09-07 133 ssize_t len;
4bc05954d00766 SeongJae Park 2021-09-07 134 char ids_buf[320];
4bc05954d00766 SeongJae Park 2021-09-07 135
4bc05954d00766 SeongJae Park 2021-09-07 136 mutex_lock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 137 len = sprint_target_ids(ctx, ids_buf, 320);
4bc05954d00766 SeongJae Park 2021-09-07 138 mutex_unlock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 139 if (len < 0)
4bc05954d00766 SeongJae Park 2021-09-07 140 return len;
4bc05954d00766 SeongJae Park 2021-09-07 141
4bc05954d00766 SeongJae Park 2021-09-07 142 return simple_read_from_buffer(buf, count, ppos, ids_buf, len);
4bc05954d00766 SeongJae Park 2021-09-07 143 }
4bc05954d00766 SeongJae Park 2021-09-07 144
4bc05954d00766 SeongJae Park 2021-09-07 145 /*
4bc05954d00766 SeongJae Park 2021-09-07 146 * Converts a string into an array of unsigned long integers
4bc05954d00766 SeongJae Park 2021-09-07 147 *
4bc05954d00766 SeongJae Park 2021-09-07 148 * Returns an array of unsigned long integers if the conversion success, or
4bc05954d00766 SeongJae Park 2021-09-07 149 * NULL otherwise.
4bc05954d00766 SeongJae Park 2021-09-07 150 */
4bc05954d00766 SeongJae Park 2021-09-07 151 static unsigned long *str_to_target_ids(const char *str, ssize_t len,
4bc05954d00766 SeongJae Park 2021-09-07 152 ssize_t *nr_ids)
4bc05954d00766 SeongJae Park 2021-09-07 153 {
4bc05954d00766 SeongJae Park 2021-09-07 154 unsigned long *ids;
4bc05954d00766 SeongJae Park 2021-09-07 155 const int max_nr_ids = 32;
4bc05954d00766 SeongJae Park 2021-09-07 156 unsigned long id;
4bc05954d00766 SeongJae Park 2021-09-07 157 int pos = 0, parsed, ret;
4bc05954d00766 SeongJae Park 2021-09-07 158
4bc05954d00766 SeongJae Park 2021-09-07 159 *nr_ids = 0;
4bc05954d00766 SeongJae Park 2021-09-07 160 ids = kmalloc_array(max_nr_ids, sizeof(id), GFP_KERNEL);
4bc05954d00766 SeongJae Park 2021-09-07 161 if (!ids)
4bc05954d00766 SeongJae Park 2021-09-07 162 return NULL;
4bc05954d00766 SeongJae Park 2021-09-07 163 while (*nr_ids < max_nr_ids && pos < len) {
4bc05954d00766 SeongJae Park 2021-09-07 164 ret = sscanf(&str[pos], "%lu%n", &id, &parsed);
4bc05954d00766 SeongJae Park 2021-09-07 165 pos += parsed;
4bc05954d00766 SeongJae Park 2021-09-07 166 if (ret != 1)
4bc05954d00766 SeongJae Park 2021-09-07 167 break;
4bc05954d00766 SeongJae Park 2021-09-07 168 ids[*nr_ids] = id;
4bc05954d00766 SeongJae Park 2021-09-07 169 *nr_ids += 1;
4bc05954d00766 SeongJae Park 2021-09-07 170 }
4bc05954d00766 SeongJae Park 2021-09-07 171
4bc05954d00766 SeongJae Park 2021-09-07 172 return ids;
4bc05954d00766 SeongJae Park 2021-09-07 173 }
4bc05954d00766 SeongJae Park 2021-09-07 174
4bc05954d00766 SeongJae Park 2021-09-07 175 static void dbgfs_put_pids(unsigned long *ids, int nr_ids)
4bc05954d00766 SeongJae Park 2021-09-07 176 {
4bc05954d00766 SeongJae Park 2021-09-07 177 int i;
4bc05954d00766 SeongJae Park 2021-09-07 178
4bc05954d00766 SeongJae Park 2021-09-07 179 for (i = 0; i < nr_ids; i++)
4bc05954d00766 SeongJae Park 2021-09-07 180 put_pid((struct pid *)ids[i]);
4bc05954d00766 SeongJae Park 2021-09-07 181 }
4bc05954d00766 SeongJae Park 2021-09-07 182
4bc05954d00766 SeongJae Park 2021-09-07 183 static ssize_t dbgfs_target_ids_write(struct file *file,
4bc05954d00766 SeongJae Park 2021-09-07 184 const char __user *buf, size_t count, loff_t *ppos)
4bc05954d00766 SeongJae Park 2021-09-07 185 {
4bc05954d00766 SeongJae Park 2021-09-07 186 struct damon_ctx *ctx = file->private_data;
4bc05954d00766 SeongJae Park 2021-09-07 187 char *kbuf, *nrs;
4bc05954d00766 SeongJae Park 2021-09-07 188 unsigned long *targets;
4bc05954d00766 SeongJae Park 2021-09-07 189 ssize_t nr_targets;
4bc05954d00766 SeongJae Park 2021-09-07 190 ssize_t ret = count;
4bc05954d00766 SeongJae Park 2021-09-07 191 int i;
4bc05954d00766 SeongJae Park 2021-09-07 192 int err;
4bc05954d00766 SeongJae Park 2021-09-07 193
4bc05954d00766 SeongJae Park 2021-09-07 194 kbuf = user_input_str(buf, count, ppos);
4bc05954d00766 SeongJae Park 2021-09-07 195 if (IS_ERR(kbuf))
4bc05954d00766 SeongJae Park 2021-09-07 @196 return PTR_ERR(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 197
4bc05954d00766 SeongJae Park 2021-09-07 198 nrs = kbuf;
4bc05954d00766 SeongJae Park 2021-09-07 199
4bc05954d00766 SeongJae Park 2021-09-07 200 targets = str_to_target_ids(nrs, ret, &nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 201 if (!targets) {
4bc05954d00766 SeongJae Park 2021-09-07 202 ret = -ENOMEM;
4bc05954d00766 SeongJae Park 2021-09-07 203 goto out;
4bc05954d00766 SeongJae Park 2021-09-07 204 }
4bc05954d00766 SeongJae Park 2021-09-07 205
4bc05954d00766 SeongJae Park 2021-09-07 206 if (targetid_is_pid(ctx)) {
4bc05954d00766 SeongJae Park 2021-09-07 207 for (i = 0; i < nr_targets; i++) {
4bc05954d00766 SeongJae Park 2021-09-07 208 targets[i] = (unsigned long)find_get_pid(
4bc05954d00766 SeongJae Park 2021-09-07 209 (int)targets[i]);
4bc05954d00766 SeongJae Park 2021-09-07 210 if (!targets[i]) {
4bc05954d00766 SeongJae Park 2021-09-07 211 dbgfs_put_pids(targets, i);
4bc05954d00766 SeongJae Park 2021-09-07 212 ret = -EINVAL;
4bc05954d00766 SeongJae Park 2021-09-07 213 goto free_targets_out;
4bc05954d00766 SeongJae Park 2021-09-07 214 }
4bc05954d00766 SeongJae Park 2021-09-07 215 }
4bc05954d00766 SeongJae Park 2021-09-07 216 }
4bc05954d00766 SeongJae Park 2021-09-07 217
4bc05954d00766 SeongJae Park 2021-09-07 218 mutex_lock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 219 if (ctx->kdamond) {
4bc05954d00766 SeongJae Park 2021-09-07 220 if (targetid_is_pid(ctx))
4bc05954d00766 SeongJae Park 2021-09-07 221 dbgfs_put_pids(targets, nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 222 ret = -EBUSY;
4bc05954d00766 SeongJae Park 2021-09-07 223 goto unlock_out;
4bc05954d00766 SeongJae Park 2021-09-07 224 }
4bc05954d00766 SeongJae Park 2021-09-07 225
4bc05954d00766 SeongJae Park 2021-09-07 226 err = damon_set_targets(ctx, targets, nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 227 if (err) {
4bc05954d00766 SeongJae Park 2021-09-07 228 if (targetid_is_pid(ctx))
4bc05954d00766 SeongJae Park 2021-09-07 229 dbgfs_put_pids(targets, nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 230 ret = err;
4bc05954d00766 SeongJae Park 2021-09-07 231 }
4bc05954d00766 SeongJae Park 2021-09-07 232
4bc05954d00766 SeongJae Park 2021-09-07 233 unlock_out:
4bc05954d00766 SeongJae Park 2021-09-07 234 mutex_unlock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 235 free_targets_out:
4bc05954d00766 SeongJae Park 2021-09-07 236 kfree(targets);
4bc05954d00766 SeongJae Park 2021-09-07 237 out:
4bc05954d00766 SeongJae Park 2021-09-07 238 kfree(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 239 return ret;
4bc05954d00766 SeongJae Park 2021-09-07 240 }
4bc05954d00766 SeongJae Park 2021-09-07 241
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
^ permalink raw reply [flat|nested] 5+ messages in thread
* mm/damon/dbgfs.c:76 dbgfs_attrs_write() warn: passing a valid pointer to 'PTR_ERR'
@ 2021-11-24 9:03 kernel test robot
0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-11-24 9:03 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 13452 bytes --]
CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: SeongJae Park <sjpark@amazon.de>
CC: Leonard Foerster <foersleo@amazon.de>
CC: Fernand Sieber <sieberf@amazon.com>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Linux Memory Management List <linux-mm@kvack.org>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: 5d9f4cf36721aba199975a9be7863a3ff5cd4b59
commit: 4bc05954d0076655cfaf6f0135585bdc20cd6b11 mm/damon: implement a debugfs-based user space interface
date: 3 months ago
:::::: branch date: 11 hours ago
:::::: commit date: 3 months ago
config: nios2-randconfig-m031-20211123 (https://download.01.org/0day-ci/archive/20211124/202111241705.MxwRmAdL-lkp(a)intel.com/config)
compiler: nios2-linux-gcc (GCC) 11.2.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch warnings:
mm/damon/dbgfs.c:76 dbgfs_attrs_write() warn: passing a valid pointer to 'PTR_ERR'
mm/damon/dbgfs.c:196 dbgfs_target_ids_write() warn: passing a valid pointer to 'PTR_ERR'
mm/damon/dbgfs.c:319 dbgfs_monitor_on_write() warn: passing a valid pointer to 'PTR_ERR'
vim +/PTR_ERR +76 mm/damon/dbgfs.c
4bc05954d00766 SeongJae Park 2021-09-07 64
4bc05954d00766 SeongJae Park 2021-09-07 65 static ssize_t dbgfs_attrs_write(struct file *file,
4bc05954d00766 SeongJae Park 2021-09-07 66 const char __user *buf, size_t count, loff_t *ppos)
4bc05954d00766 SeongJae Park 2021-09-07 67 {
4bc05954d00766 SeongJae Park 2021-09-07 68 struct damon_ctx *ctx = file->private_data;
4bc05954d00766 SeongJae Park 2021-09-07 69 unsigned long s, a, r, minr, maxr;
4bc05954d00766 SeongJae Park 2021-09-07 70 char *kbuf;
4bc05954d00766 SeongJae Park 2021-09-07 71 ssize_t ret = count;
4bc05954d00766 SeongJae Park 2021-09-07 72 int err;
4bc05954d00766 SeongJae Park 2021-09-07 73
4bc05954d00766 SeongJae Park 2021-09-07 74 kbuf = user_input_str(buf, count, ppos);
4bc05954d00766 SeongJae Park 2021-09-07 75 if (IS_ERR(kbuf))
4bc05954d00766 SeongJae Park 2021-09-07 @76 return PTR_ERR(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 77
4bc05954d00766 SeongJae Park 2021-09-07 78 if (sscanf(kbuf, "%lu %lu %lu %lu %lu",
4bc05954d00766 SeongJae Park 2021-09-07 79 &s, &a, &r, &minr, &maxr) != 5) {
4bc05954d00766 SeongJae Park 2021-09-07 80 ret = -EINVAL;
4bc05954d00766 SeongJae Park 2021-09-07 81 goto out;
4bc05954d00766 SeongJae Park 2021-09-07 82 }
4bc05954d00766 SeongJae Park 2021-09-07 83
4bc05954d00766 SeongJae Park 2021-09-07 84 mutex_lock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 85 if (ctx->kdamond) {
4bc05954d00766 SeongJae Park 2021-09-07 86 ret = -EBUSY;
4bc05954d00766 SeongJae Park 2021-09-07 87 goto unlock_out;
4bc05954d00766 SeongJae Park 2021-09-07 88 }
4bc05954d00766 SeongJae Park 2021-09-07 89
4bc05954d00766 SeongJae Park 2021-09-07 90 err = damon_set_attrs(ctx, s, a, r, minr, maxr);
4bc05954d00766 SeongJae Park 2021-09-07 91 if (err)
4bc05954d00766 SeongJae Park 2021-09-07 92 ret = err;
4bc05954d00766 SeongJae Park 2021-09-07 93 unlock_out:
4bc05954d00766 SeongJae Park 2021-09-07 94 mutex_unlock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 95 out:
4bc05954d00766 SeongJae Park 2021-09-07 96 kfree(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 97 return ret;
4bc05954d00766 SeongJae Park 2021-09-07 98 }
4bc05954d00766 SeongJae Park 2021-09-07 99
4bc05954d00766 SeongJae Park 2021-09-07 100 static inline bool targetid_is_pid(const struct damon_ctx *ctx)
4bc05954d00766 SeongJae Park 2021-09-07 101 {
4bc05954d00766 SeongJae Park 2021-09-07 102 return ctx->primitive.target_valid == damon_va_target_valid;
4bc05954d00766 SeongJae Park 2021-09-07 103 }
4bc05954d00766 SeongJae Park 2021-09-07 104
4bc05954d00766 SeongJae Park 2021-09-07 105 static ssize_t sprint_target_ids(struct damon_ctx *ctx, char *buf, ssize_t len)
4bc05954d00766 SeongJae Park 2021-09-07 106 {
4bc05954d00766 SeongJae Park 2021-09-07 107 struct damon_target *t;
4bc05954d00766 SeongJae Park 2021-09-07 108 unsigned long id;
4bc05954d00766 SeongJae Park 2021-09-07 109 int written = 0;
4bc05954d00766 SeongJae Park 2021-09-07 110 int rc;
4bc05954d00766 SeongJae Park 2021-09-07 111
4bc05954d00766 SeongJae Park 2021-09-07 112 damon_for_each_target(t, ctx) {
4bc05954d00766 SeongJae Park 2021-09-07 113 id = t->id;
4bc05954d00766 SeongJae Park 2021-09-07 114 if (targetid_is_pid(ctx))
4bc05954d00766 SeongJae Park 2021-09-07 115 /* Show pid numbers to debugfs users */
4bc05954d00766 SeongJae Park 2021-09-07 116 id = (unsigned long)pid_vnr((struct pid *)id);
4bc05954d00766 SeongJae Park 2021-09-07 117
4bc05954d00766 SeongJae Park 2021-09-07 118 rc = scnprintf(&buf[written], len - written, "%lu ", id);
4bc05954d00766 SeongJae Park 2021-09-07 119 if (!rc)
4bc05954d00766 SeongJae Park 2021-09-07 120 return -ENOMEM;
4bc05954d00766 SeongJae Park 2021-09-07 121 written += rc;
4bc05954d00766 SeongJae Park 2021-09-07 122 }
4bc05954d00766 SeongJae Park 2021-09-07 123 if (written)
4bc05954d00766 SeongJae Park 2021-09-07 124 written -= 1;
4bc05954d00766 SeongJae Park 2021-09-07 125 written += scnprintf(&buf[written], len - written, "\n");
4bc05954d00766 SeongJae Park 2021-09-07 126 return written;
4bc05954d00766 SeongJae Park 2021-09-07 127 }
4bc05954d00766 SeongJae Park 2021-09-07 128
4bc05954d00766 SeongJae Park 2021-09-07 129 static ssize_t dbgfs_target_ids_read(struct file *file,
4bc05954d00766 SeongJae Park 2021-09-07 130 char __user *buf, size_t count, loff_t *ppos)
4bc05954d00766 SeongJae Park 2021-09-07 131 {
4bc05954d00766 SeongJae Park 2021-09-07 132 struct damon_ctx *ctx = file->private_data;
4bc05954d00766 SeongJae Park 2021-09-07 133 ssize_t len;
4bc05954d00766 SeongJae Park 2021-09-07 134 char ids_buf[320];
4bc05954d00766 SeongJae Park 2021-09-07 135
4bc05954d00766 SeongJae Park 2021-09-07 136 mutex_lock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 137 len = sprint_target_ids(ctx, ids_buf, 320);
4bc05954d00766 SeongJae Park 2021-09-07 138 mutex_unlock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 139 if (len < 0)
4bc05954d00766 SeongJae Park 2021-09-07 140 return len;
4bc05954d00766 SeongJae Park 2021-09-07 141
4bc05954d00766 SeongJae Park 2021-09-07 142 return simple_read_from_buffer(buf, count, ppos, ids_buf, len);
4bc05954d00766 SeongJae Park 2021-09-07 143 }
4bc05954d00766 SeongJae Park 2021-09-07 144
4bc05954d00766 SeongJae Park 2021-09-07 145 /*
4bc05954d00766 SeongJae Park 2021-09-07 146 * Converts a string into an array of unsigned long integers
4bc05954d00766 SeongJae Park 2021-09-07 147 *
4bc05954d00766 SeongJae Park 2021-09-07 148 * Returns an array of unsigned long integers if the conversion success, or
4bc05954d00766 SeongJae Park 2021-09-07 149 * NULL otherwise.
4bc05954d00766 SeongJae Park 2021-09-07 150 */
4bc05954d00766 SeongJae Park 2021-09-07 151 static unsigned long *str_to_target_ids(const char *str, ssize_t len,
4bc05954d00766 SeongJae Park 2021-09-07 152 ssize_t *nr_ids)
4bc05954d00766 SeongJae Park 2021-09-07 153 {
4bc05954d00766 SeongJae Park 2021-09-07 154 unsigned long *ids;
4bc05954d00766 SeongJae Park 2021-09-07 155 const int max_nr_ids = 32;
4bc05954d00766 SeongJae Park 2021-09-07 156 unsigned long id;
4bc05954d00766 SeongJae Park 2021-09-07 157 int pos = 0, parsed, ret;
4bc05954d00766 SeongJae Park 2021-09-07 158
4bc05954d00766 SeongJae Park 2021-09-07 159 *nr_ids = 0;
4bc05954d00766 SeongJae Park 2021-09-07 160 ids = kmalloc_array(max_nr_ids, sizeof(id), GFP_KERNEL);
4bc05954d00766 SeongJae Park 2021-09-07 161 if (!ids)
4bc05954d00766 SeongJae Park 2021-09-07 162 return NULL;
4bc05954d00766 SeongJae Park 2021-09-07 163 while (*nr_ids < max_nr_ids && pos < len) {
4bc05954d00766 SeongJae Park 2021-09-07 164 ret = sscanf(&str[pos], "%lu%n", &id, &parsed);
4bc05954d00766 SeongJae Park 2021-09-07 165 pos += parsed;
4bc05954d00766 SeongJae Park 2021-09-07 166 if (ret != 1)
4bc05954d00766 SeongJae Park 2021-09-07 167 break;
4bc05954d00766 SeongJae Park 2021-09-07 168 ids[*nr_ids] = id;
4bc05954d00766 SeongJae Park 2021-09-07 169 *nr_ids += 1;
4bc05954d00766 SeongJae Park 2021-09-07 170 }
4bc05954d00766 SeongJae Park 2021-09-07 171
4bc05954d00766 SeongJae Park 2021-09-07 172 return ids;
4bc05954d00766 SeongJae Park 2021-09-07 173 }
4bc05954d00766 SeongJae Park 2021-09-07 174
4bc05954d00766 SeongJae Park 2021-09-07 175 static void dbgfs_put_pids(unsigned long *ids, int nr_ids)
4bc05954d00766 SeongJae Park 2021-09-07 176 {
4bc05954d00766 SeongJae Park 2021-09-07 177 int i;
4bc05954d00766 SeongJae Park 2021-09-07 178
4bc05954d00766 SeongJae Park 2021-09-07 179 for (i = 0; i < nr_ids; i++)
4bc05954d00766 SeongJae Park 2021-09-07 180 put_pid((struct pid *)ids[i]);
4bc05954d00766 SeongJae Park 2021-09-07 181 }
4bc05954d00766 SeongJae Park 2021-09-07 182
4bc05954d00766 SeongJae Park 2021-09-07 183 static ssize_t dbgfs_target_ids_write(struct file *file,
4bc05954d00766 SeongJae Park 2021-09-07 184 const char __user *buf, size_t count, loff_t *ppos)
4bc05954d00766 SeongJae Park 2021-09-07 185 {
4bc05954d00766 SeongJae Park 2021-09-07 186 struct damon_ctx *ctx = file->private_data;
4bc05954d00766 SeongJae Park 2021-09-07 187 char *kbuf, *nrs;
4bc05954d00766 SeongJae Park 2021-09-07 188 unsigned long *targets;
4bc05954d00766 SeongJae Park 2021-09-07 189 ssize_t nr_targets;
4bc05954d00766 SeongJae Park 2021-09-07 190 ssize_t ret = count;
4bc05954d00766 SeongJae Park 2021-09-07 191 int i;
4bc05954d00766 SeongJae Park 2021-09-07 192 int err;
4bc05954d00766 SeongJae Park 2021-09-07 193
4bc05954d00766 SeongJae Park 2021-09-07 194 kbuf = user_input_str(buf, count, ppos);
4bc05954d00766 SeongJae Park 2021-09-07 195 if (IS_ERR(kbuf))
4bc05954d00766 SeongJae Park 2021-09-07 @196 return PTR_ERR(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 197
4bc05954d00766 SeongJae Park 2021-09-07 198 nrs = kbuf;
4bc05954d00766 SeongJae Park 2021-09-07 199
4bc05954d00766 SeongJae Park 2021-09-07 200 targets = str_to_target_ids(nrs, ret, &nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 201 if (!targets) {
4bc05954d00766 SeongJae Park 2021-09-07 202 ret = -ENOMEM;
4bc05954d00766 SeongJae Park 2021-09-07 203 goto out;
4bc05954d00766 SeongJae Park 2021-09-07 204 }
4bc05954d00766 SeongJae Park 2021-09-07 205
4bc05954d00766 SeongJae Park 2021-09-07 206 if (targetid_is_pid(ctx)) {
4bc05954d00766 SeongJae Park 2021-09-07 207 for (i = 0; i < nr_targets; i++) {
4bc05954d00766 SeongJae Park 2021-09-07 208 targets[i] = (unsigned long)find_get_pid(
4bc05954d00766 SeongJae Park 2021-09-07 209 (int)targets[i]);
4bc05954d00766 SeongJae Park 2021-09-07 210 if (!targets[i]) {
4bc05954d00766 SeongJae Park 2021-09-07 211 dbgfs_put_pids(targets, i);
4bc05954d00766 SeongJae Park 2021-09-07 212 ret = -EINVAL;
4bc05954d00766 SeongJae Park 2021-09-07 213 goto free_targets_out;
4bc05954d00766 SeongJae Park 2021-09-07 214 }
4bc05954d00766 SeongJae Park 2021-09-07 215 }
4bc05954d00766 SeongJae Park 2021-09-07 216 }
4bc05954d00766 SeongJae Park 2021-09-07 217
4bc05954d00766 SeongJae Park 2021-09-07 218 mutex_lock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 219 if (ctx->kdamond) {
4bc05954d00766 SeongJae Park 2021-09-07 220 if (targetid_is_pid(ctx))
4bc05954d00766 SeongJae Park 2021-09-07 221 dbgfs_put_pids(targets, nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 222 ret = -EBUSY;
4bc05954d00766 SeongJae Park 2021-09-07 223 goto unlock_out;
4bc05954d00766 SeongJae Park 2021-09-07 224 }
4bc05954d00766 SeongJae Park 2021-09-07 225
4bc05954d00766 SeongJae Park 2021-09-07 226 err = damon_set_targets(ctx, targets, nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 227 if (err) {
4bc05954d00766 SeongJae Park 2021-09-07 228 if (targetid_is_pid(ctx))
4bc05954d00766 SeongJae Park 2021-09-07 229 dbgfs_put_pids(targets, nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 230 ret = err;
4bc05954d00766 SeongJae Park 2021-09-07 231 }
4bc05954d00766 SeongJae Park 2021-09-07 232
4bc05954d00766 SeongJae Park 2021-09-07 233 unlock_out:
4bc05954d00766 SeongJae Park 2021-09-07 234 mutex_unlock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 235 free_targets_out:
4bc05954d00766 SeongJae Park 2021-09-07 236 kfree(targets);
4bc05954d00766 SeongJae Park 2021-09-07 237 out:
4bc05954d00766 SeongJae Park 2021-09-07 238 kfree(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 239 return ret;
4bc05954d00766 SeongJae Park 2021-09-07 240 }
4bc05954d00766 SeongJae Park 2021-09-07 241
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
^ permalink raw reply [flat|nested] 5+ messages in thread
* mm/damon/dbgfs.c:76 dbgfs_attrs_write() warn: passing a valid pointer to 'PTR_ERR'
@ 2021-09-10 11:07 kernel test robot
0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2021-09-10 11:07 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 13376 bytes --]
CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: SeongJae Park <sjpark@amazon.de>
CC: Leonard Foerster <foersleo@amazon.de>
CC: Fernand Sieber <sieberf@amazon.com>
CC: Andrew Morton <akpm@linux-foundation.org>
CC: Linux Memory Management List <linux-mm@kvack.org>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: bf9f243f23e6623f310ba03fbb14e10ec3a61290
commit: 4bc05954d0076655cfaf6f0135585bdc20cd6b11 mm/damon: implement a debugfs-based user space interface
date: 2 days ago
:::::: branch date: 12 hours ago
:::::: commit date: 2 days ago
config: i386-randconfig-m031-20210910 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch warnings:
mm/damon/dbgfs.c:76 dbgfs_attrs_write() warn: passing a valid pointer to 'PTR_ERR'
mm/damon/dbgfs.c:196 dbgfs_target_ids_write() warn: passing a valid pointer to 'PTR_ERR'
mm/damon/dbgfs.c:319 dbgfs_monitor_on_write() warn: passing a valid pointer to 'PTR_ERR'
vim +/PTR_ERR +76 mm/damon/dbgfs.c
4bc05954d00766 SeongJae Park 2021-09-07 64
4bc05954d00766 SeongJae Park 2021-09-07 65 static ssize_t dbgfs_attrs_write(struct file *file,
4bc05954d00766 SeongJae Park 2021-09-07 66 const char __user *buf, size_t count, loff_t *ppos)
4bc05954d00766 SeongJae Park 2021-09-07 67 {
4bc05954d00766 SeongJae Park 2021-09-07 68 struct damon_ctx *ctx = file->private_data;
4bc05954d00766 SeongJae Park 2021-09-07 69 unsigned long s, a, r, minr, maxr;
4bc05954d00766 SeongJae Park 2021-09-07 70 char *kbuf;
4bc05954d00766 SeongJae Park 2021-09-07 71 ssize_t ret = count;
4bc05954d00766 SeongJae Park 2021-09-07 72 int err;
4bc05954d00766 SeongJae Park 2021-09-07 73
4bc05954d00766 SeongJae Park 2021-09-07 74 kbuf = user_input_str(buf, count, ppos);
4bc05954d00766 SeongJae Park 2021-09-07 75 if (IS_ERR(kbuf))
4bc05954d00766 SeongJae Park 2021-09-07 @76 return PTR_ERR(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 77
4bc05954d00766 SeongJae Park 2021-09-07 78 if (sscanf(kbuf, "%lu %lu %lu %lu %lu",
4bc05954d00766 SeongJae Park 2021-09-07 79 &s, &a, &r, &minr, &maxr) != 5) {
4bc05954d00766 SeongJae Park 2021-09-07 80 ret = -EINVAL;
4bc05954d00766 SeongJae Park 2021-09-07 81 goto out;
4bc05954d00766 SeongJae Park 2021-09-07 82 }
4bc05954d00766 SeongJae Park 2021-09-07 83
4bc05954d00766 SeongJae Park 2021-09-07 84 mutex_lock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 85 if (ctx->kdamond) {
4bc05954d00766 SeongJae Park 2021-09-07 86 ret = -EBUSY;
4bc05954d00766 SeongJae Park 2021-09-07 87 goto unlock_out;
4bc05954d00766 SeongJae Park 2021-09-07 88 }
4bc05954d00766 SeongJae Park 2021-09-07 89
4bc05954d00766 SeongJae Park 2021-09-07 90 err = damon_set_attrs(ctx, s, a, r, minr, maxr);
4bc05954d00766 SeongJae Park 2021-09-07 91 if (err)
4bc05954d00766 SeongJae Park 2021-09-07 92 ret = err;
4bc05954d00766 SeongJae Park 2021-09-07 93 unlock_out:
4bc05954d00766 SeongJae Park 2021-09-07 94 mutex_unlock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 95 out:
4bc05954d00766 SeongJae Park 2021-09-07 96 kfree(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 97 return ret;
4bc05954d00766 SeongJae Park 2021-09-07 98 }
4bc05954d00766 SeongJae Park 2021-09-07 99
4bc05954d00766 SeongJae Park 2021-09-07 100 static inline bool targetid_is_pid(const struct damon_ctx *ctx)
4bc05954d00766 SeongJae Park 2021-09-07 101 {
4bc05954d00766 SeongJae Park 2021-09-07 102 return ctx->primitive.target_valid == damon_va_target_valid;
4bc05954d00766 SeongJae Park 2021-09-07 103 }
4bc05954d00766 SeongJae Park 2021-09-07 104
4bc05954d00766 SeongJae Park 2021-09-07 105 static ssize_t sprint_target_ids(struct damon_ctx *ctx, char *buf, ssize_t len)
4bc05954d00766 SeongJae Park 2021-09-07 106 {
4bc05954d00766 SeongJae Park 2021-09-07 107 struct damon_target *t;
4bc05954d00766 SeongJae Park 2021-09-07 108 unsigned long id;
4bc05954d00766 SeongJae Park 2021-09-07 109 int written = 0;
4bc05954d00766 SeongJae Park 2021-09-07 110 int rc;
4bc05954d00766 SeongJae Park 2021-09-07 111
4bc05954d00766 SeongJae Park 2021-09-07 112 damon_for_each_target(t, ctx) {
4bc05954d00766 SeongJae Park 2021-09-07 113 id = t->id;
4bc05954d00766 SeongJae Park 2021-09-07 114 if (targetid_is_pid(ctx))
4bc05954d00766 SeongJae Park 2021-09-07 115 /* Show pid numbers to debugfs users */
4bc05954d00766 SeongJae Park 2021-09-07 116 id = (unsigned long)pid_vnr((struct pid *)id);
4bc05954d00766 SeongJae Park 2021-09-07 117
4bc05954d00766 SeongJae Park 2021-09-07 118 rc = scnprintf(&buf[written], len - written, "%lu ", id);
4bc05954d00766 SeongJae Park 2021-09-07 119 if (!rc)
4bc05954d00766 SeongJae Park 2021-09-07 120 return -ENOMEM;
4bc05954d00766 SeongJae Park 2021-09-07 121 written += rc;
4bc05954d00766 SeongJae Park 2021-09-07 122 }
4bc05954d00766 SeongJae Park 2021-09-07 123 if (written)
4bc05954d00766 SeongJae Park 2021-09-07 124 written -= 1;
4bc05954d00766 SeongJae Park 2021-09-07 125 written += scnprintf(&buf[written], len - written, "\n");
4bc05954d00766 SeongJae Park 2021-09-07 126 return written;
4bc05954d00766 SeongJae Park 2021-09-07 127 }
4bc05954d00766 SeongJae Park 2021-09-07 128
4bc05954d00766 SeongJae Park 2021-09-07 129 static ssize_t dbgfs_target_ids_read(struct file *file,
4bc05954d00766 SeongJae Park 2021-09-07 130 char __user *buf, size_t count, loff_t *ppos)
4bc05954d00766 SeongJae Park 2021-09-07 131 {
4bc05954d00766 SeongJae Park 2021-09-07 132 struct damon_ctx *ctx = file->private_data;
4bc05954d00766 SeongJae Park 2021-09-07 133 ssize_t len;
4bc05954d00766 SeongJae Park 2021-09-07 134 char ids_buf[320];
4bc05954d00766 SeongJae Park 2021-09-07 135
4bc05954d00766 SeongJae Park 2021-09-07 136 mutex_lock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 137 len = sprint_target_ids(ctx, ids_buf, 320);
4bc05954d00766 SeongJae Park 2021-09-07 138 mutex_unlock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 139 if (len < 0)
4bc05954d00766 SeongJae Park 2021-09-07 140 return len;
4bc05954d00766 SeongJae Park 2021-09-07 141
4bc05954d00766 SeongJae Park 2021-09-07 142 return simple_read_from_buffer(buf, count, ppos, ids_buf, len);
4bc05954d00766 SeongJae Park 2021-09-07 143 }
4bc05954d00766 SeongJae Park 2021-09-07 144
4bc05954d00766 SeongJae Park 2021-09-07 145 /*
4bc05954d00766 SeongJae Park 2021-09-07 146 * Converts a string into an array of unsigned long integers
4bc05954d00766 SeongJae Park 2021-09-07 147 *
4bc05954d00766 SeongJae Park 2021-09-07 148 * Returns an array of unsigned long integers if the conversion success, or
4bc05954d00766 SeongJae Park 2021-09-07 149 * NULL otherwise.
4bc05954d00766 SeongJae Park 2021-09-07 150 */
4bc05954d00766 SeongJae Park 2021-09-07 151 static unsigned long *str_to_target_ids(const char *str, ssize_t len,
4bc05954d00766 SeongJae Park 2021-09-07 152 ssize_t *nr_ids)
4bc05954d00766 SeongJae Park 2021-09-07 153 {
4bc05954d00766 SeongJae Park 2021-09-07 154 unsigned long *ids;
4bc05954d00766 SeongJae Park 2021-09-07 155 const int max_nr_ids = 32;
4bc05954d00766 SeongJae Park 2021-09-07 156 unsigned long id;
4bc05954d00766 SeongJae Park 2021-09-07 157 int pos = 0, parsed, ret;
4bc05954d00766 SeongJae Park 2021-09-07 158
4bc05954d00766 SeongJae Park 2021-09-07 159 *nr_ids = 0;
4bc05954d00766 SeongJae Park 2021-09-07 160 ids = kmalloc_array(max_nr_ids, sizeof(id), GFP_KERNEL);
4bc05954d00766 SeongJae Park 2021-09-07 161 if (!ids)
4bc05954d00766 SeongJae Park 2021-09-07 162 return NULL;
4bc05954d00766 SeongJae Park 2021-09-07 163 while (*nr_ids < max_nr_ids && pos < len) {
4bc05954d00766 SeongJae Park 2021-09-07 164 ret = sscanf(&str[pos], "%lu%n", &id, &parsed);
4bc05954d00766 SeongJae Park 2021-09-07 165 pos += parsed;
4bc05954d00766 SeongJae Park 2021-09-07 166 if (ret != 1)
4bc05954d00766 SeongJae Park 2021-09-07 167 break;
4bc05954d00766 SeongJae Park 2021-09-07 168 ids[*nr_ids] = id;
4bc05954d00766 SeongJae Park 2021-09-07 169 *nr_ids += 1;
4bc05954d00766 SeongJae Park 2021-09-07 170 }
4bc05954d00766 SeongJae Park 2021-09-07 171
4bc05954d00766 SeongJae Park 2021-09-07 172 return ids;
4bc05954d00766 SeongJae Park 2021-09-07 173 }
4bc05954d00766 SeongJae Park 2021-09-07 174
4bc05954d00766 SeongJae Park 2021-09-07 175 static void dbgfs_put_pids(unsigned long *ids, int nr_ids)
4bc05954d00766 SeongJae Park 2021-09-07 176 {
4bc05954d00766 SeongJae Park 2021-09-07 177 int i;
4bc05954d00766 SeongJae Park 2021-09-07 178
4bc05954d00766 SeongJae Park 2021-09-07 179 for (i = 0; i < nr_ids; i++)
4bc05954d00766 SeongJae Park 2021-09-07 180 put_pid((struct pid *)ids[i]);
4bc05954d00766 SeongJae Park 2021-09-07 181 }
4bc05954d00766 SeongJae Park 2021-09-07 182
4bc05954d00766 SeongJae Park 2021-09-07 183 static ssize_t dbgfs_target_ids_write(struct file *file,
4bc05954d00766 SeongJae Park 2021-09-07 184 const char __user *buf, size_t count, loff_t *ppos)
4bc05954d00766 SeongJae Park 2021-09-07 185 {
4bc05954d00766 SeongJae Park 2021-09-07 186 struct damon_ctx *ctx = file->private_data;
4bc05954d00766 SeongJae Park 2021-09-07 187 char *kbuf, *nrs;
4bc05954d00766 SeongJae Park 2021-09-07 188 unsigned long *targets;
4bc05954d00766 SeongJae Park 2021-09-07 189 ssize_t nr_targets;
4bc05954d00766 SeongJae Park 2021-09-07 190 ssize_t ret = count;
4bc05954d00766 SeongJae Park 2021-09-07 191 int i;
4bc05954d00766 SeongJae Park 2021-09-07 192 int err;
4bc05954d00766 SeongJae Park 2021-09-07 193
4bc05954d00766 SeongJae Park 2021-09-07 194 kbuf = user_input_str(buf, count, ppos);
4bc05954d00766 SeongJae Park 2021-09-07 195 if (IS_ERR(kbuf))
4bc05954d00766 SeongJae Park 2021-09-07 @196 return PTR_ERR(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 197
4bc05954d00766 SeongJae Park 2021-09-07 198 nrs = kbuf;
4bc05954d00766 SeongJae Park 2021-09-07 199
4bc05954d00766 SeongJae Park 2021-09-07 200 targets = str_to_target_ids(nrs, ret, &nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 201 if (!targets) {
4bc05954d00766 SeongJae Park 2021-09-07 202 ret = -ENOMEM;
4bc05954d00766 SeongJae Park 2021-09-07 203 goto out;
4bc05954d00766 SeongJae Park 2021-09-07 204 }
4bc05954d00766 SeongJae Park 2021-09-07 205
4bc05954d00766 SeongJae Park 2021-09-07 206 if (targetid_is_pid(ctx)) {
4bc05954d00766 SeongJae Park 2021-09-07 207 for (i = 0; i < nr_targets; i++) {
4bc05954d00766 SeongJae Park 2021-09-07 208 targets[i] = (unsigned long)find_get_pid(
4bc05954d00766 SeongJae Park 2021-09-07 209 (int)targets[i]);
4bc05954d00766 SeongJae Park 2021-09-07 210 if (!targets[i]) {
4bc05954d00766 SeongJae Park 2021-09-07 211 dbgfs_put_pids(targets, i);
4bc05954d00766 SeongJae Park 2021-09-07 212 ret = -EINVAL;
4bc05954d00766 SeongJae Park 2021-09-07 213 goto free_targets_out;
4bc05954d00766 SeongJae Park 2021-09-07 214 }
4bc05954d00766 SeongJae Park 2021-09-07 215 }
4bc05954d00766 SeongJae Park 2021-09-07 216 }
4bc05954d00766 SeongJae Park 2021-09-07 217
4bc05954d00766 SeongJae Park 2021-09-07 218 mutex_lock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 219 if (ctx->kdamond) {
4bc05954d00766 SeongJae Park 2021-09-07 220 if (targetid_is_pid(ctx))
4bc05954d00766 SeongJae Park 2021-09-07 221 dbgfs_put_pids(targets, nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 222 ret = -EBUSY;
4bc05954d00766 SeongJae Park 2021-09-07 223 goto unlock_out;
4bc05954d00766 SeongJae Park 2021-09-07 224 }
4bc05954d00766 SeongJae Park 2021-09-07 225
4bc05954d00766 SeongJae Park 2021-09-07 226 err = damon_set_targets(ctx, targets, nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 227 if (err) {
4bc05954d00766 SeongJae Park 2021-09-07 228 if (targetid_is_pid(ctx))
4bc05954d00766 SeongJae Park 2021-09-07 229 dbgfs_put_pids(targets, nr_targets);
4bc05954d00766 SeongJae Park 2021-09-07 230 ret = err;
4bc05954d00766 SeongJae Park 2021-09-07 231 }
4bc05954d00766 SeongJae Park 2021-09-07 232
4bc05954d00766 SeongJae Park 2021-09-07 233 unlock_out:
4bc05954d00766 SeongJae Park 2021-09-07 234 mutex_unlock(&ctx->kdamond_lock);
4bc05954d00766 SeongJae Park 2021-09-07 235 free_targets_out:
4bc05954d00766 SeongJae Park 2021-09-07 236 kfree(targets);
4bc05954d00766 SeongJae Park 2021-09-07 237 out:
4bc05954d00766 SeongJae Park 2021-09-07 238 kfree(kbuf);
4bc05954d00766 SeongJae Park 2021-09-07 239 return ret;
4bc05954d00766 SeongJae Park 2021-09-07 240 }
4bc05954d00766 SeongJae Park 2021-09-07 241
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 34146 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-08-21 5:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-10 17:46 mm/damon/dbgfs.c:76 dbgfs_attrs_write() warn: passing a valid pointer to 'PTR_ERR' kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2022-08-21 5:18 kernel test robot
2021-12-05 0:50 kernel test robot
2021-11-24 9:03 kernel test robot
2021-09-10 11:07 kernel test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.