/* This function implements reading and resetting an atomic_t stat variable through read/write to a proc file. Any write to the file resets the associated statistic to zero. Any read returns it's current value.  */
static int read_reset_stat(ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
/* This function implements reading and resetting an atomic_t stat variable through read/write to a proc file. Any write to the file resets the associated statistic to zero. Any read returns it's current value.  */
static int read_reset_stat(ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
{
	atomic_t *stat = (atomic_t *)table->data;
	if (!stat)
		return -EINVAL;
	if (write)
		atomic_set(stat, 0);
	else {
		char str_buf[32];
		char *data;
		int len = snprintf(str_buf, 32, "%d\n", atomic_read(stat));
		if (len >= 32)
			return -EFAULT;
		len = strlen(str_buf);
		if (*ppos > len) {
			*lenp = 0;
			return 0;
		}
		data = &str_buf[*ppos];
		len -= *ppos;
		if (len > *lenp)
			len = *lenp;
		if (len && copy_to_user(buffer, str_buf, len))
			return -EFAULT;
		*lenp = len;
		*ppos += len;
	}
	return 0;
}