mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-26 05:34:13 +08:00
234e340582
Many users of debugfs copy the implementation of default_open() when they want to support a custom read/write function op. This leads to a proliferation of the default_open() implementation across the entire tree. Now that the common implementation has been consolidated into libfs we can replace all the users of this function with simple_open(). This replacement was done with the following semantic patch: <smpl> @ open @ identifier open_f != simple_open; identifier i, f; @@ -int open_f(struct inode *i, struct file *f) -{ ( -if (i->i_private) -f->private_data = i->i_private; | -f->private_data = i->i_private; ) -return 0; -} @ has_open depends on open @ identifier fops; identifier open.open_f; @@ struct file_operations fops = { ... -.open = open_f, +.open = simple_open, ... }; </smpl> [akpm@linux-foundation.org: checkpatch fixes] Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Julia Lawall <Julia.Lawall@lip6.fr> Acked-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
153 lines
3.2 KiB
C
153 lines
3.2 KiB
C
/*
|
|
* ec_sys.c
|
|
*
|
|
* Copyright (C) 2010 SUSE Products GmbH/Novell
|
|
* Author:
|
|
* Thomas Renninger <trenn@suse.de>
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2.
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/acpi.h>
|
|
#include <linux/debugfs.h>
|
|
#include <linux/module.h>
|
|
#include "internal.h"
|
|
|
|
MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
|
|
MODULE_DESCRIPTION("ACPI EC sysfs access driver");
|
|
MODULE_LICENSE("GPL");
|
|
|
|
static bool write_support;
|
|
module_param(write_support, bool, 0644);
|
|
MODULE_PARM_DESC(write_support, "Dangerous, reboot and removal of battery may "
|
|
"be needed.");
|
|
|
|
#define EC_SPACE_SIZE 256
|
|
|
|
static struct dentry *acpi_ec_debugfs_dir;
|
|
|
|
static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
|
|
size_t count, loff_t *off)
|
|
{
|
|
/* Use this if support reading/writing multiple ECs exists in ec.c:
|
|
* struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
|
|
*/
|
|
unsigned int size = EC_SPACE_SIZE;
|
|
u8 *data = (u8 *) buf;
|
|
loff_t init_off = *off;
|
|
int err = 0;
|
|
|
|
if (*off >= size)
|
|
return 0;
|
|
if (*off + count >= size) {
|
|
size -= *off;
|
|
count = size;
|
|
} else
|
|
size = count;
|
|
|
|
while (size) {
|
|
err = ec_read(*off, &data[*off - init_off]);
|
|
if (err)
|
|
return err;
|
|
*off += 1;
|
|
size--;
|
|
}
|
|
return count;
|
|
}
|
|
|
|
static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
|
|
size_t count, loff_t *off)
|
|
{
|
|
/* Use this if support reading/writing multiple ECs exists in ec.c:
|
|
* struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
|
|
*/
|
|
|
|
unsigned int size = count;
|
|
loff_t init_off = *off;
|
|
u8 *data = (u8 *) buf;
|
|
int err = 0;
|
|
|
|
if (*off >= EC_SPACE_SIZE)
|
|
return 0;
|
|
if (*off + count >= EC_SPACE_SIZE) {
|
|
size = EC_SPACE_SIZE - *off;
|
|
count = size;
|
|
}
|
|
|
|
while (size) {
|
|
u8 byte_write = data[*off - init_off];
|
|
err = ec_write(*off, byte_write);
|
|
if (err)
|
|
return err;
|
|
|
|
*off += 1;
|
|
size--;
|
|
}
|
|
return count;
|
|
}
|
|
|
|
static const struct file_operations acpi_ec_io_ops = {
|
|
.owner = THIS_MODULE,
|
|
.open = simple_open,
|
|
.read = acpi_ec_read_io,
|
|
.write = acpi_ec_write_io,
|
|
.llseek = default_llseek,
|
|
};
|
|
|
|
int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count)
|
|
{
|
|
struct dentry *dev_dir;
|
|
char name[64];
|
|
umode_t mode = 0400;
|
|
|
|
if (ec_device_count == 0) {
|
|
acpi_ec_debugfs_dir = debugfs_create_dir("ec", NULL);
|
|
if (!acpi_ec_debugfs_dir)
|
|
return -ENOMEM;
|
|
}
|
|
|
|
sprintf(name, "ec%u", ec_device_count);
|
|
dev_dir = debugfs_create_dir(name, acpi_ec_debugfs_dir);
|
|
if (!dev_dir) {
|
|
if (ec_device_count != 0)
|
|
goto error;
|
|
return -ENOMEM;
|
|
}
|
|
|
|
if (!debugfs_create_x32("gpe", 0444, dev_dir, (u32 *)&first_ec->gpe))
|
|
goto error;
|
|
if (!debugfs_create_bool("use_global_lock", 0444, dev_dir,
|
|
(u32 *)&first_ec->global_lock))
|
|
goto error;
|
|
|
|
if (write_support)
|
|
mode = 0600;
|
|
if (!debugfs_create_file("io", mode, dev_dir, ec, &acpi_ec_io_ops))
|
|
goto error;
|
|
|
|
return 0;
|
|
|
|
error:
|
|
debugfs_remove_recursive(acpi_ec_debugfs_dir);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
static int __init acpi_ec_sys_init(void)
|
|
{
|
|
int err = 0;
|
|
if (first_ec)
|
|
err = acpi_ec_add_debugfs(first_ec, 0);
|
|
else
|
|
err = -ENODEV;
|
|
return err;
|
|
}
|
|
|
|
static void __exit acpi_ec_sys_exit(void)
|
|
{
|
|
debugfs_remove_recursive(acpi_ec_debugfs_dir);
|
|
}
|
|
|
|
module_init(acpi_ec_sys_init);
|
|
module_exit(acpi_ec_sys_exit);
|