forked from mirrors/linux
		
	sysctl: add proc_dointvec_ms_jiffies_minmax
add proc_dointvec_ms_jiffies_minmax to fit read msecs value to jiffies with a limited range of values Signed-off-by: Yuwei Wang <wangyuweihx@gmail.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
		
							parent
							
								
									d19b4c52f7
								
							
						
					
					
						commit
						c381d02b2f
					
				
					 2 changed files with 43 additions and 0 deletions
				
			
		|  | @ -75,6 +75,8 @@ int proc_douintvec_minmax(struct ctl_table *table, int write, void *buffer, | ||||||
| int proc_dou8vec_minmax(struct ctl_table *table, int write, void *buffer, | int proc_dou8vec_minmax(struct ctl_table *table, int write, void *buffer, | ||||||
| 			size_t *lenp, loff_t *ppos); | 			size_t *lenp, loff_t *ppos); | ||||||
| int proc_dointvec_jiffies(struct ctl_table *, int, void *, size_t *, loff_t *); | int proc_dointvec_jiffies(struct ctl_table *, int, void *, size_t *, loff_t *); | ||||||
|  | int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write, | ||||||
|  | 		void *buffer, size_t *lenp, loff_t *ppos); | ||||||
| int proc_dointvec_userhz_jiffies(struct ctl_table *, int, void *, size_t *, | int proc_dointvec_userhz_jiffies(struct ctl_table *, int, void *, size_t *, | ||||||
| 		loff_t *); | 		loff_t *); | ||||||
| int proc_dointvec_ms_jiffies(struct ctl_table *, int, void *, size_t *, | int proc_dointvec_ms_jiffies(struct ctl_table *, int, void *, size_t *, | ||||||
|  |  | ||||||
|  | @ -1237,6 +1237,30 @@ static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp, | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static int do_proc_dointvec_ms_jiffies_minmax_conv(bool *negp, unsigned long *lvalp, | ||||||
|  | 						int *valp, int write, void *data) | ||||||
|  | { | ||||||
|  | 	int tmp, ret; | ||||||
|  | 	struct do_proc_dointvec_minmax_conv_param *param = data; | ||||||
|  | 	/*
 | ||||||
|  | 	 * If writing, first do so via a temporary local int so we can | ||||||
|  | 	 * bounds-check it before touching *valp. | ||||||
|  | 	 */ | ||||||
|  | 	int *ip = write ? &tmp : valp; | ||||||
|  | 
 | ||||||
|  | 	ret = do_proc_dointvec_ms_jiffies_conv(negp, lvalp, ip, write, data); | ||||||
|  | 	if (ret) | ||||||
|  | 		return ret; | ||||||
|  | 
 | ||||||
|  | 	if (write) { | ||||||
|  | 		if ((param->min && *param->min > tmp) || | ||||||
|  | 				(param->max && *param->max < tmp)) | ||||||
|  | 			return -EINVAL; | ||||||
|  | 		*valp = tmp; | ||||||
|  | 	} | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /**
 | /**
 | ||||||
|  * proc_dointvec_jiffies - read a vector of integers as seconds |  * proc_dointvec_jiffies - read a vector of integers as seconds | ||||||
|  * @table: the sysctl table |  * @table: the sysctl table | ||||||
|  | @ -1259,6 +1283,17 @@ int proc_dointvec_jiffies(struct ctl_table *table, int write, | ||||||
| 		    	    do_proc_dointvec_jiffies_conv,NULL); | 		    	    do_proc_dointvec_jiffies_conv,NULL); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write, | ||||||
|  | 			  void *buffer, size_t *lenp, loff_t *ppos) | ||||||
|  | { | ||||||
|  | 	struct do_proc_dointvec_minmax_conv_param param = { | ||||||
|  | 		.min = (int *) table->extra1, | ||||||
|  | 		.max = (int *) table->extra2, | ||||||
|  | 	}; | ||||||
|  | 	return do_proc_dointvec(table, write, buffer, lenp, ppos, | ||||||
|  | 			do_proc_dointvec_ms_jiffies_minmax_conv, ¶m); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /**
 | /**
 | ||||||
|  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds |  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds | ||||||
|  * @table: the sysctl table |  * @table: the sysctl table | ||||||
|  | @ -1523,6 +1558,12 @@ int proc_dointvec_jiffies(struct ctl_table *table, int write, | ||||||
| 	return -ENOSYS; | 	return -ENOSYS; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write, | ||||||
|  | 				    void *buffer, size_t *lenp, loff_t *ppos) | ||||||
|  | { | ||||||
|  | 	return -ENOSYS; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, | int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, | ||||||
| 		    void *buffer, size_t *lenp, loff_t *ppos) | 		    void *buffer, size_t *lenp, loff_t *ppos) | ||||||
| { | { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Yuwei Wang
						Yuwei Wang