Lines Matching +full:left +full:-

1 // SPDX-License-Identifier: GPL-2.0-only
27 const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 };
42 * enum sysctl_writes_mode - supported sysctl write modes
61 SYSCTL_WRITES_LEGACY = -1,
91 if (len > maxlen - 1) in _proc_do_string()
92 len = maxlen - 1; in _proc_do_string()
104 while ((p - buffer) < *lenp && len < maxlen - 1) { in _proc_do_string()
122 len -= *ppos; in _proc_do_string()
142 "warning, set kernel.sysctl_writes_strict = -1\n", in warn_sysctl_write()
143 current->comm, table->procname); in warn_sysctl_write()
147 * proc_first_pos_non_zero_ignore - check if first position is allowed
151 * Returns true if the first position is non-zero and the sysctl_writes_strict
173 * proc_dostring - read a string sysctl
182 * string is truncated. The copied string is %NULL-terminated.
195 return _proc_do_string(table->data, table->maxlen, write, buffer, lenp, in proc_dostring()
204 (*size)--; in proc_skip_spaces()
214 (*size)--; in proc_skip_char()
220 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
243 return -ERANGE; in strtoul_lenient()
256 * proc_get_long - reads an ASCII formatted integer from a user buffer
267 * the amount of bytes read. If @tr is non-NULL and a trailing
268 * character exists (size is non-zero after returning from this
279 return -EINVAL; in proc_get_long()
281 if (len > TMPBUFLEN - 1) in proc_get_long()
282 len = TMPBUFLEN - 1; in proc_get_long()
288 if (*p == '-' && *size > 1) { in proc_get_long()
294 return -EINVAL; in proc_get_long()
297 return -EINVAL; in proc_get_long()
299 len = p - tmp; in proc_get_long()
304 if (len == TMPBUFLEN - 1) in proc_get_long()
305 return -EINVAL; in proc_get_long()
308 return -EINVAL; in proc_get_long()
314 *size -= len; in proc_get_long()
320 * proc_put_long - converts an integer to a decimal ASCII formatted string
335 sprintf(p, "%s%lu", neg ? "-" : "", val); in proc_put_long()
340 *size -= len; in proc_put_long()
351 (*size)--; in proc_put_char()
364 return -EINVAL; in do_proc_dointvec_conv()
365 WRITE_ONCE(*valp, -*lvalp); in do_proc_dointvec_conv()
368 return -EINVAL; in do_proc_dointvec_conv()
375 *lvalp = -(unsigned long)val; in do_proc_dointvec_conv()
390 return -EINVAL; in do_proc_douintvec_conv()
409 size_t left; in __do_proc_dointvec() local
412 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { in __do_proc_dointvec()
418 vleft = table->maxlen / sizeof(*i); in __do_proc_dointvec()
419 left = *lenp; in __do_proc_dointvec()
428 if (left > PAGE_SIZE - 1) in __do_proc_dointvec()
429 left = PAGE_SIZE - 1; in __do_proc_dointvec()
433 for (; left && vleft--; i++, first=0) { in __do_proc_dointvec()
438 proc_skip_spaces(&p, &left); in __do_proc_dointvec()
440 if (!left) in __do_proc_dointvec()
442 err = proc_get_long(&p, &left, &lval, &neg, in __do_proc_dointvec()
448 err = -EINVAL; in __do_proc_dointvec()
453 err = -EINVAL; in __do_proc_dointvec()
457 proc_put_char(&buffer, &left, '\t'); in __do_proc_dointvec()
458 proc_put_long(&buffer, &left, lval, neg); in __do_proc_dointvec()
462 if (!write && !first && left && !err) in __do_proc_dointvec()
463 proc_put_char(&buffer, &left, '\n'); in __do_proc_dointvec()
464 if (write && !err && left) in __do_proc_dointvec()
465 proc_skip_spaces(&p, &left); in __do_proc_dointvec()
467 return err ? : -EINVAL; in __do_proc_dointvec()
468 *lenp -= left; in __do_proc_dointvec()
480 return __do_proc_dointvec(table->data, table, write, in do_proc_dointvec()
495 size_t left; in do_proc_douintvec_w() local
499 left = *lenp; in do_proc_douintvec_w()
504 if (left > PAGE_SIZE - 1) in do_proc_douintvec_w()
505 left = PAGE_SIZE - 1; in do_proc_douintvec_w()
507 proc_skip_spaces(&p, &left); in do_proc_douintvec_w()
508 if (!left) { in do_proc_douintvec_w()
509 err = -EINVAL; in do_proc_douintvec_w()
513 err = proc_get_long(&p, &left, &lval, &neg, in do_proc_douintvec_w()
517 err = -EINVAL; in do_proc_douintvec_w()
522 err = -EINVAL; in do_proc_douintvec_w()
526 if (!err && left) in do_proc_douintvec_w()
527 proc_skip_spaces(&p, &left); in do_proc_douintvec_w()
531 return -EINVAL; in do_proc_douintvec_w()
550 size_t left; in do_proc_douintvec_r() local
552 left = *lenp; in do_proc_douintvec_r()
555 err = -EINVAL; in do_proc_douintvec_r()
559 proc_put_long(&buffer, &left, lval, false); in do_proc_douintvec_r()
560 if (!left) in do_proc_douintvec_r()
563 proc_put_char(&buffer, &left, '\n'); in do_proc_douintvec_r()
566 *lenp -= left; in do_proc_douintvec_r()
582 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { in __do_proc_douintvec()
588 vleft = table->maxlen / sizeof(*i); in __do_proc_douintvec()
596 return -EINVAL; in __do_proc_douintvec()
615 return __do_proc_douintvec(table->data, table, write, in do_proc_douintvec()
620 * proc_dobool - read/write a bool
630 * table->data must point to a bool variable and table->maxlen must
639 bool *data = table->data; in proc_dobool()
643 if (table->maxlen != sizeof(bool)) in proc_dobool()
644 return -EINVAL; in proc_dobool()
660 * proc_dointvec - read a vector of integers
667 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
679 * proc_douintvec - read a vector of unsigned integers
686 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
699 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
720 * bounds-check it before touching *valp. in do_proc_dointvec_minmax_conv()
729 if ((param->min && *param->min > tmp) || in do_proc_dointvec_minmax_conv()
730 (param->max && *param->max < tmp)) in do_proc_dointvec_minmax_conv()
731 return -EINVAL; in do_proc_dointvec_minmax_conv()
739 * proc_dointvec_minmax - read a vector of integers with min/max values
746 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
750 * table->extra1 (min) and table->extra2 (max).
752 * Returns 0 on success or -EINVAL on write when the range check fails.
758 .min = (int *) table->extra1, in proc_dointvec_minmax()
759 .max = (int *) table->extra2, in proc_dointvec_minmax()
766 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
786 /* write via temporary local uint for bounds-checking */ in do_proc_douintvec_minmax_conv()
794 if ((param->min && *param->min > tmp) || in do_proc_douintvec_minmax_conv()
795 (param->max && *param->max < tmp)) in do_proc_douintvec_minmax_conv()
796 return -ERANGE; in do_proc_douintvec_minmax_conv()
805 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
812 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
817 * table->extra1 (min) and table->extra2 (max). There is a final sanity
821 * Returns 0 on success or -ERANGE on write when the range check fails.
827 .min = (unsigned int *) table->extra1, in proc_douintvec_minmax()
828 .max = (unsigned int *) table->extra2, in proc_douintvec_minmax()
835 * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
842 * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
847 * table->extra1 (min) and table->extra2 (max).
856 u8 *data = table->data; in proc_dou8vec_minmax()
864 if (table->maxlen != sizeof(u8)) in proc_dou8vec_minmax()
865 return -EINVAL; in proc_dou8vec_minmax()
867 if (table->extra1) in proc_dou8vec_minmax()
868 min = *(unsigned int *) table->extra1; in proc_dou8vec_minmax()
869 if (table->extra2) in proc_dou8vec_minmax()
870 max = *(unsigned int *) table->extra2; in proc_dou8vec_minmax()
894 size_t left; in __do_proc_doulongvec_minmax() local
897 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) { in __do_proc_doulongvec_minmax()
903 min = table->extra1; in __do_proc_doulongvec_minmax()
904 max = table->extra2; in __do_proc_doulongvec_minmax()
905 vleft = table->maxlen / sizeof(unsigned long); in __do_proc_doulongvec_minmax()
906 left = *lenp; in __do_proc_doulongvec_minmax()
912 if (left > PAGE_SIZE - 1) in __do_proc_doulongvec_minmax()
913 left = PAGE_SIZE - 1; in __do_proc_doulongvec_minmax()
917 for (; left && vleft--; i++, first = 0) { in __do_proc_doulongvec_minmax()
923 proc_skip_spaces(&p, &left); in __do_proc_doulongvec_minmax()
924 if (!left) in __do_proc_doulongvec_minmax()
927 err = proc_get_long(&p, &left, &val, &neg, in __do_proc_doulongvec_minmax()
931 err = -EINVAL; in __do_proc_doulongvec_minmax()
937 err = -EINVAL; in __do_proc_doulongvec_minmax()
944 proc_put_char(&buffer, &left, '\t'); in __do_proc_doulongvec_minmax()
945 proc_put_long(&buffer, &left, val, false); in __do_proc_doulongvec_minmax()
949 if (!write && !first && left && !err) in __do_proc_doulongvec_minmax()
950 proc_put_char(&buffer, &left, '\n'); in __do_proc_doulongvec_minmax()
952 proc_skip_spaces(&p, &left); in __do_proc_doulongvec_minmax()
954 return err ? : -EINVAL; in __do_proc_doulongvec_minmax()
955 *lenp -= left; in __do_proc_doulongvec_minmax()
965 return __do_proc_doulongvec_minmax(table->data, table, write, in do_proc_doulongvec_minmax()
970 * proc_doulongvec_minmax - read a vector of long integers with min/max values
977 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
981 * table->extra1 (min) and table->extra2 (max).
992 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
999 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1004 * table->extra1 (min) and table->extra2 (max).
1024 WRITE_ONCE(*valp, -*lvalp * HZ); in do_proc_dointvec_jiffies_conv()
1032 lval = -(unsigned long)val; in do_proc_dointvec_jiffies_conv()
1049 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); in do_proc_dointvec_userhz_jiffies_conv()
1055 lval = -(unsigned long)val; in do_proc_dointvec_userhz_jiffies_conv()
1070 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); in do_proc_dointvec_ms_jiffies_conv()
1080 lval = -(unsigned long)val; in do_proc_dointvec_ms_jiffies_conv()
1097 * bounds-check it before touching *valp. in do_proc_dointvec_ms_jiffies_minmax_conv()
1106 if ((param->min && *param->min > tmp) || in do_proc_dointvec_ms_jiffies_minmax_conv()
1107 (param->max && *param->max < tmp)) in do_proc_dointvec_ms_jiffies_minmax_conv()
1108 return -EINVAL; in do_proc_dointvec_ms_jiffies_minmax_conv()
1115 * proc_dointvec_jiffies - read a vector of integers as seconds
1122 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1140 .min = (int *) table->extra1, in proc_dointvec_ms_jiffies_minmax()
1141 .max = (int *) table->extra2, in proc_dointvec_ms_jiffies_minmax()
1148 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1155 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1170 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1177 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1192 * proc_do_large_bitmap - read/write from/to a large bitmap
1199 * The bitmap is stored at table->data and the bitmap length (in bits)
1200 * in table->maxlen.
1202 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1212 size_t left = *lenp; in proc_do_large_bitmap() local
1213 unsigned long bitmap_len = table->maxlen; in proc_do_large_bitmap()
1214 unsigned long *bitmap = *(unsigned long **) table->data; in proc_do_large_bitmap()
1216 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c; in proc_do_large_bitmap()
1218 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) { in proc_do_large_bitmap()
1227 if (left > PAGE_SIZE - 1) { in proc_do_large_bitmap()
1228 left = PAGE_SIZE - 1; in proc_do_large_bitmap()
1230 skipped = *lenp - left; in proc_do_large_bitmap()
1235 return -ENOMEM; in proc_do_large_bitmap()
1236 proc_skip_char(&p, &left, '\n'); in proc_do_large_bitmap()
1237 while (!err && left) { in proc_do_large_bitmap()
1242 /* In case we stop parsing mid-number, we can reset */ in proc_do_large_bitmap()
1243 saved_left = left; in proc_do_large_bitmap()
1244 err = proc_get_long(&p, &left, &val_a, &neg, tr_a, in proc_do_large_bitmap()
1248 * only one char is left (may be a "-"), then stop here, in proc_do_large_bitmap()
1251 if ((left <= 1) && skipped) { in proc_do_large_bitmap()
1252 left = saved_left; in proc_do_large_bitmap()
1259 err = -EINVAL; in proc_do_large_bitmap()
1264 if (left) { in proc_do_large_bitmap()
1266 left--; in proc_do_large_bitmap()
1269 if (c == '-') { in proc_do_large_bitmap()
1270 err = proc_get_long(&p, &left, &val_b, in proc_do_large_bitmap()
1277 if (!left && skipped) { in proc_do_large_bitmap()
1278 left = saved_left; in proc_do_large_bitmap()
1286 err = -EINVAL; in proc_do_large_bitmap()
1289 if (left) { in proc_do_large_bitmap()
1291 left--; in proc_do_large_bitmap()
1295 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1); in proc_do_large_bitmap()
1296 proc_skip_char(&p, &left, '\n'); in proc_do_large_bitmap()
1298 left += skipped; in proc_do_large_bitmap()
1303 while (left) { in proc_do_large_bitmap()
1308 bit_a + 1) - 1; in proc_do_large_bitmap()
1311 proc_put_char(&buffer, &left, ','); in proc_do_large_bitmap()
1312 proc_put_long(&buffer, &left, bit_a, false); in proc_do_large_bitmap()
1314 proc_put_char(&buffer, &left, '-'); in proc_do_large_bitmap()
1315 proc_put_long(&buffer, &left, bit_b, false); in proc_do_large_bitmap()
1320 proc_put_char(&buffer, &left, '\n'); in proc_do_large_bitmap()
1330 *lenp -= left; in proc_do_large_bitmap()
1343 return -ENOSYS; in proc_dostring()
1349 return -ENOSYS; in proc_dobool()
1355 return -ENOSYS; in proc_dointvec()
1361 return -ENOSYS; in proc_douintvec()
1367 return -ENOSYS; in proc_dointvec_minmax()
1373 return -ENOSYS; in proc_douintvec_minmax()
1379 return -ENOSYS; in proc_dou8vec_minmax()
1385 return -ENOSYS; in proc_dointvec_jiffies()
1391 return -ENOSYS; in proc_dointvec_ms_jiffies_minmax()
1397 return -ENOSYS; in proc_dointvec_userhz_jiffies()
1403 return -ENOSYS; in proc_dointvec_ms_jiffies()
1409 return -ENOSYS; in proc_doulongvec_minmax()
1415 return -ENOSYS; in proc_doulongvec_ms_jiffies_minmax()
1421 return -ENOSYS; in proc_do_large_bitmap()
1430 struct static_key *key = (struct static_key *)table->data; in proc_do_static_key()
1436 .mode = table->mode, in proc_do_static_key()
1442 return -EPERM; in proc_do_static_key()
1485 .procname = "unaligned-trap",
1494 .procname = "ignore-unaligned-usertrap",
1512 * exception granted :-)