linux.conf.au 2003
File operations - write

static ssize_t power_write_file (struct file *file, const char *ubuff,
                                    size_t count, loff_t *offset)
{
        struct hotplug_slot *slot = file->private_data;
        char *buff;
        unsigned long lpower;
        u8 power;
        int retval = 0;

        if (*offset < 0) return -EINVAL;
        if (count == 0 || count > 16384) return 0;
        if (*offset != 0) return 0;

        if (slot == NULL)
                return -ENODEV;

        buff = kmalloc (count + 1, GFP_KERNEL);
        if (!buff)
                return -ENOMEM;
        memset (buff, 0x00, count + 1);

        if (copy_from_user ((void *)buff, (void *)ubuff, count)) {
                retval = -EFAULT;
                goto exit;
        }
