/**
 * ecryptfs_send_miscdev
 * @data: Data to send to daemon; may be NULL
 * @data_size: Amount of data to send to daemon
 * @msg_ctx: Message context, which is used to handle the reply. If
 *           this is NULL, then we do not expect a reply.
 * @msg_type: Type of message
 * @msg_flags: Flags for message
 * @daemon: eCryptfs daemon object
 *
 * Add msg_ctx to queue and then, if it exists, notify the blocked
 * miscdevess about the data being available. Must be called with
 * ecryptfs_daemon_hash_mux held.
 *
 * Returns zero on success; non-zero otherwise
 */
int ecryptfs_send_miscdev(char *data, size_t data_size,
                          struct ecryptfs_msg_ctx *msg_ctx, u8 msg_type,
                          u16 msg_flags, struct ecryptfs_daemon *daemon)
{
    struct ecryptfs_message *msg;

    msg = kmalloc((sizeof(*msg) + data_size), GFP_KERNEL);
    if (!msg) {
        printk(KERN_ERR "%s: Out of memory whilst attempting "
               "to kmalloc(%zd, GFP_KERNEL)\n", __func__,
               (sizeof(*msg) + data_size));
        return -ENOMEM;
    }

    mutex_lock(&msg_ctx->mux);
    msg_ctx->msg = msg;
    msg_ctx->msg->index = msg_ctx->index;
    msg_ctx->msg->data_len = data_size;
    msg_ctx->type = msg_type;
    memcpy(msg_ctx->msg->data, data, data_size);
    msg_ctx->msg_size = (sizeof(*msg_ctx->msg) + data_size);
    list_add_tail(&msg_ctx->daemon_out_list, &daemon->msg_ctx_out_queue);
    mutex_unlock(&msg_ctx->mux);

    mutex_lock(&daemon->mux);
    daemon->num_queued_msg_ctx++;
    wake_up_interruptible(&daemon->wait);
    mutex_unlock(&daemon->mux);

    return 0;
}
/**
 * ecryptfs_miscdev_release
 * @inode: inode of fs/ecryptfs/euid handle (ignored)
 * @file: file for fs/ecryptfs/euid handle (ignored)
 *
 * This keeps the daemon registered until the daemon sends another
 * ioctl to fs/ecryptfs/ctl or until the kernel module unregisters.
 *
 * Returns zero on success; non-zero otherwise
 */
static int
ecryptfs_miscdev_release(struct inode *inode, struct file *file)
{
    struct ecryptfs_daemon *daemon = NULL;
    uid_t euid = current_euid();
    int rc;

    mutex_lock(&ecryptfs_daemon_hash_mux);
    rc = ecryptfs_find_daemon_by_euid(&daemon, euid, current_user_ns());
    if (rc || !daemon)
        daemon = file->private_data;
    mutex_lock(&daemon->mux);
    BUG_ON(!(daemon->flags & ECRYPTFS_DAEMON_MISCDEV_OPEN));
    daemon->flags &= ~ECRYPTFS_DAEMON_MISCDEV_OPEN;
    atomic_dec(&ecryptfs_num_miscdev_opens);
    mutex_unlock(&daemon->mux);
    rc = ecryptfs_exorcise_daemon(daemon);
    if (rc) {
        printk(KERN_CRIT "%s: Fatal error whilst attempting to "
               "shut down daemon; rc = [%d]. Please report this "
               "bug.\n", __func__, rc);
        BUG();
    }
    module_put(THIS_MODULE);
    mutex_unlock(&ecryptfs_daemon_hash_mux);
    return rc;
}
Example #3
0
/**
 * ecryptfs_lookup
 * @ecryptfs_dir_inode: The eCryptfs directory inode
 * @ecryptfs_dentry: The eCryptfs dentry that we are looking up
 * @ecryptfs_nd: nameidata; may be NULL
 *
 * Find a file on disk. If the file does not exist, then we'll add it to the
 * dentry cache and continue on to read it from the disk.
 */
static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
                                      struct dentry *ecryptfs_dentry,
                                      unsigned int flags)
{
    char *encrypted_and_encoded_name = NULL;
    size_t encrypted_and_encoded_name_size;
    struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL;
    struct dentry *lower_dir_dentry, *lower_dentry;
    int rc = 0;

    lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent);
    mutex_lock(&lower_dir_dentry->d_inode->i_mutex);
    lower_dentry = lookup_one_len(ecryptfs_dentry->d_name.name,
                                  lower_dir_dentry,
                                  ecryptfs_dentry->d_name.len);
    mutex_unlock(&lower_dir_dentry->d_inode->i_mutex);
    if (IS_ERR(lower_dentry)) {
        rc = PTR_ERR(lower_dentry);
        ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
                        "[%d] on lower_dentry = [%s]\n", __func__, rc,
                        ecryptfs_dentry->d_name.name);
        goto out;
    }
    if (lower_dentry->d_inode)
        goto interpose;
    mount_crypt_stat = &ecryptfs_superblock_to_private(
                           ecryptfs_dentry->d_sb)->mount_crypt_stat;
    if (!(mount_crypt_stat
            && (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)))
        goto interpose;
    dput(lower_dentry);
    rc = ecryptfs_encrypt_and_encode_filename(
             &encrypted_and_encoded_name, &encrypted_and_encoded_name_size,
             NULL, mount_crypt_stat, ecryptfs_dentry->d_name.name,
             ecryptfs_dentry->d_name.len);
    if (rc) {
        printk(KERN_ERR "%s: Error attempting to encrypt and encode "
               "filename; rc = [%d]\n", __func__, rc);
        goto out;
    }
    mutex_lock(&lower_dir_dentry->d_inode->i_mutex);
    lower_dentry = lookup_one_len(encrypted_and_encoded_name,
                                  lower_dir_dentry,
                                  encrypted_and_encoded_name_size);
    mutex_unlock(&lower_dir_dentry->d_inode->i_mutex);
    if (IS_ERR(lower_dentry)) {
        rc = PTR_ERR(lower_dentry);
        ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
                        "[%d] on lower_dentry = [%s]\n", __func__, rc,
                        encrypted_and_encoded_name);
        goto out;
    }
interpose:
    rc = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry,
                                   ecryptfs_dir_inode);
out:
    kfree(encrypted_and_encoded_name);
    return ERR_PTR(rc);
}
Example #4
0
static ssize_t hidraw_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
{
    struct hidraw_list *list = file->private_data;
    int ret = 0, len;
    DECLARE_WAITQUEUE(wait, current);

    mutex_lock(&list->read_mutex);

    while (ret == 0) {
        if (list->head == list->tail) {
            add_wait_queue(&list->hidraw->wait, &wait);
            set_current_state(TASK_INTERRUPTIBLE);

            while (list->head == list->tail) {
                if (file->f_flags & O_NONBLOCK) {
                    ret = -EAGAIN;
                    break;
                }
                if (signal_pending(current)) {
                    ret = -ERESTARTSYS;
                    break;
                }
                if (!list->hidraw->exist) {
                    ret = -EIO;
                    break;
                }

                /* allow O_NONBLOCK to work well from other threads */
                mutex_unlock(&list->read_mutex);
                schedule();
                mutex_lock(&list->read_mutex);
                set_current_state(TASK_INTERRUPTIBLE);
            }

            set_current_state(TASK_RUNNING);
            remove_wait_queue(&list->hidraw->wait, &wait);
        }

        if (ret)
            goto out;

        len = list->buffer[list->tail].len > count ?
              count : list->buffer[list->tail].len;

        if (copy_to_user(buffer, list->buffer[list->tail].value, len)) {
            ret = -EFAULT;
            goto out;
        }
        ret = len;

        kfree(list->buffer[list->tail].value);
        list->tail = (list->tail + 1) & (HIDRAW_BUFFER_SIZE - 1);
    }
out:
    mutex_unlock(&list->read_mutex);
    return ret;
}
/**
 * ecryptfs_miscdev_open
 * @inode: inode of miscdev handle (ignored)
 * @file: file for miscdev handle (ignored)
 *
 * Returns zero on success; non-zero otherwise
 */
static int
ecryptfs_miscdev_open(struct inode *inode, struct file *file)
{
    struct ecryptfs_daemon *daemon = NULL;
    uid_t euid = current_euid();
    int rc;

    mutex_lock(&ecryptfs_daemon_hash_mux);
    rc = try_module_get(THIS_MODULE);
    if (rc == 0) {
        rc = -EIO;
        printk(KERN_ERR "%s: Error attempting to increment module use "
               "count; rc = [%d]\n", __func__, rc);
        goto out_unlock_daemon_list;
    }
    rc = ecryptfs_find_daemon_by_euid(&daemon, euid, current_user_ns());
    if (rc || !daemon) {
        rc = ecryptfs_spawn_daemon(&daemon, euid, current_user_ns(),
                                   task_pid(current));
        if (rc) {
            printk(KERN_ERR "%s: Error attempting to spawn daemon; "
                   "rc = [%d]\n", __func__, rc);
            goto out_module_put_unlock_daemon_list;
        }
    }
    mutex_lock(&daemon->mux);
    if (daemon->pid != task_pid(current)) {
        rc = -EINVAL;
        printk(KERN_ERR "%s: pid [0x%p] has registered with euid [%d], "
               "but pid [0x%p] has attempted to open the handle "
               "instead\n", __func__, daemon->pid, daemon->euid,
               task_pid(current));
        goto out_unlock_daemon;
    }
    if (daemon->flags & ECRYPTFS_DAEMON_MISCDEV_OPEN) {
        rc = -EBUSY;
        printk(KERN_ERR "%s: Miscellaneous device handle may only be "
               "opened once per daemon; pid [0x%p] already has this "
               "handle open\n", __func__, daemon->pid);
        goto out_unlock_daemon;
    }
    daemon->flags |= ECRYPTFS_DAEMON_MISCDEV_OPEN;
    file->private_data = daemon;
    atomic_inc(&ecryptfs_num_miscdev_opens);
out_unlock_daemon:
    mutex_unlock(&daemon->mux);
out_module_put_unlock_daemon_list:
    if (rc)
        module_put(THIS_MODULE);
out_unlock_daemon_list:
    mutex_unlock(&ecryptfs_daemon_hash_mux);
    return rc;
}
Example #6
0
static void ctl_server_cleanup(struct ctl_server_state *state)
{
    void *ret;

    mutex_lock(&state->lock);

    state->exiting = true;

    if (state->thread_created) {
        thread_cancel(state->thread);

        mutex_unlock(&state->lock);
        thread_join(state->thread, &ret);
        mutex_lock(&state->lock);

        while (state->clients) {
            struct ctl_client_state *current = state->clients;
            if (current->thread_created) {
                const thread_t client_thread = current->thread;
                thread_cancel(client_thread);

                mutex_unlock(&state->lock);
                thread_join(client_thread, &ret);
                mutex_lock(&state->lock);
            }

            if (state->clients == current) {
                ctl_client_cleanup(current);
            }
        }

        state->clients = NULL;

        if (state->fd >= 0) {
            close(state->fd);
            state->fd = -1;
        }

        if (state->binded) {
            if (remove(HAKA_CTL_SOCKET_FILE)) {
                messagef(HAKA_LOG_ERROR, MODULE, L"cannot remove socket file: %s", errno_error(errno));
            }

            state->binded = false;
        }
    }

    mutex_unlock(&state->lock);

    mutex_destroy(&state->lock);
}
Example #7
0
/**
 * adreno_drawctxt_invalidate() - Invalidate an adreno draw context
 * @device: Pointer to the KGSL device structure for the GPU
 * @context: Pointer to the KGSL context structure
 *
 * Invalidate the context and remove all queued commands and cancel any pending
 * waiters
 */
void adreno_drawctxt_invalidate(struct kgsl_device *device,
                                struct kgsl_context *context)
{
    struct adreno_context *drawctxt = ADRENO_CONTEXT(context);

    trace_adreno_drawctxt_invalidate(drawctxt);

    drawctxt->state = ADRENO_CONTEXT_STATE_INVALID;

    /* Clear the pending queue */
    mutex_lock(&drawctxt->mutex);

    /*
     * set the timestamp to the last value since the context is invalidated
     * and we want the pending events for this context to go away
     */
    kgsl_sharedmem_writel(device, &device->memstore,
                          KGSL_MEMSTORE_OFFSET(context->id, soptimestamp),
                          drawctxt->timestamp);

    kgsl_sharedmem_writel(device, &device->memstore,
                          KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp),
                          drawctxt->timestamp);

    while (drawctxt->cmdqueue_head != drawctxt->cmdqueue_tail) {
        struct kgsl_cmdbatch *cmdbatch =
                drawctxt->cmdqueue[drawctxt->cmdqueue_head];

        drawctxt->cmdqueue_head = (drawctxt->cmdqueue_head + 1) %
                                  ADRENO_CONTEXT_CMDQUEUE_SIZE;

        mutex_unlock(&drawctxt->mutex);

        mutex_lock(&device->mutex);
        kgsl_cancel_events_timestamp(device, context,
                                     cmdbatch->timestamp);
        mutex_unlock(&device->mutex);

        kgsl_cmdbatch_destroy(cmdbatch);
        mutex_lock(&drawctxt->mutex);
    }

    mutex_unlock(&drawctxt->mutex);

    /* Give the bad news to everybody waiting around */
    wake_up_interruptible_all(&drawctxt->waiting);
    wake_up_interruptible_all(&drawctxt->wq);
}
Example #8
0
/*
 * omap3isp_stat_request_statistics - Request statistics.
 * @data: Pointer to return statistics data.
 *
 * Returns 0 if successful.
 */
int omap3isp_stat_request_statistics(struct ispstat *stat,
                                     struct omap3isp_stat_data *data)
{
    struct ispstat_buffer *buf;

    if (stat->state != ISPSTAT_ENABLED) {
        dev_dbg(stat->isp->dev, "%s: engine not enabled.\n",
                stat->subdev.name);
        return -EINVAL;
    }

    mutex_lock(&stat->ioctl_lock);
    buf = isp_stat_buf_get(stat, data);
    if (IS_ERR(buf)) {
        mutex_unlock(&stat->ioctl_lock);
        return PTR_ERR(buf);
    }

    data->ts = buf->ts;
    data->config_counter = buf->config_counter;
    data->frame_number = buf->frame_number;
    data->buf_size = buf->buf_size;

    buf->empty = 1;
    isp_stat_buf_release(stat);
    mutex_unlock(&stat->ioctl_lock);

    return 0;
}
int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
{
    size_t read;
    int err;
    loff_t addr = (loff_t)pnum * ubi->peb_size + offset;

    mutex_lock(&ubi->dbg_buf_mutex);
    err = ubi->mtd->read(ubi->mtd, addr, len, &read, ubi->dbg_peb_buf);
    if (err && err != -EUCLEAN) {
        ubi_err("error %d while reading %d bytes from PEB %d:%d, "
                "read %zd bytes", err, len, pnum, offset, read);
        goto error;
    }

    err = check_pattern(ubi->dbg_peb_buf, 0xFF, len);
    if (err == 0) {
        ubi_err("flash region at PEB %d:%d, length %d does not "
                "contain all 0xFF bytes", pnum, offset, len);
        goto fail;
    }
    mutex_unlock(&ubi->dbg_buf_mutex);

    return 0;

fail:
    ubi_err("paranoid check failed for PEB %d", pnum);
    ubi_msg("hex dump of the %d-%d region", offset, offset + len);
    print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
                   ubi->dbg_peb_buf, len, 1);
    err = 1;
error:
    ubi_dbg_dump_stack();
    mutex_unlock(&ubi->dbg_buf_mutex);
    return err;
}
static int torture_peb(struct ubi_device *ubi, int pnum)
{
    int err, i, patt_count;

    ubi_msg("run torture test for PEB %d", pnum);
    patt_count = ARRAY_SIZE(patterns);
    ubi_assert(patt_count > 0);

    mutex_lock(&ubi->buf_mutex);
    for (i = 0; i < patt_count; i++) {
        err = do_sync_erase(ubi, pnum);
        if (err)
            goto out;


        err = ubi_io_read(ubi, ubi->peb_buf1, pnum, 0, ubi->peb_size);
        if (err)
            goto out;

        err = check_pattern(ubi->peb_buf1, 0xFF, ubi->peb_size);
        if (err == 0) {
            ubi_err("erased PEB %d, but a non-0xFF byte found",
                    pnum);
            err = -EIO;
            goto out;
        }


        memset(ubi->peb_buf1, patterns[i], ubi->peb_size);
        err = ubi_io_write(ubi, ubi->peb_buf1, pnum, 0, ubi->peb_size);
        if (err)
            goto out;

        memset(ubi->peb_buf1, ~patterns[i], ubi->peb_size);
        err = ubi_io_read(ubi, ubi->peb_buf1, pnum, 0, ubi->peb_size);
        if (err)
            goto out;

        err = check_pattern(ubi->peb_buf1, patterns[i], ubi->peb_size);
        if (err == 0) {
            ubi_err("pattern %x checking failed for PEB %d",
                    patterns[i], pnum);
            err = -EIO;
            goto out;
        }
    }

    err = patt_count;
    ubi_msg("PEB %d passed torture test, do not mark it a bad", pnum);

out:
    mutex_unlock(&ubi->buf_mutex);
    if (err == UBI_IO_BITFLIPS || err == -EBADMSG) {

        ubi_err("read problems on freshly erased PEB %d, must be bad",
                pnum);
        err = -EIO;
    }
    return err;
}
/*
 * mdp4_lcdc_pipe_queue:
 * called from thread context
 */
void mdp4_lcdc_pipe_queue(int cndx, struct mdp4_overlay_pipe *pipe)
{
    struct vsycn_ctrl *vctrl;
    struct vsync_update *vp;
    struct mdp4_overlay_pipe *pp;
    int undx;

    if (cndx >= MAX_CONTROLLER) {
        pr_err("%s: out or range: cndx=%d\n", __func__, cndx);
        return;
    }

    vctrl = &vsync_ctrl_db[cndx];

    if (atomic_read(&vctrl->suspend) > 0)
        return;

    mutex_lock(&vctrl->update_lock);
    undx =  vctrl->update_ndx;
    vp = &vctrl->vlist[undx];

    pp = &vp->plist[pipe->pipe_ndx - 1];	/* ndx start form 1 */

    pr_debug("%s: vndx=%d pipe_ndx=%d pid=%d\n", __func__,
             undx, pipe->pipe_ndx, current->pid);

    *pp = *pipe;	/* clone it */
    vp->update_cnt++;
    mutex_unlock(&vctrl->update_lock);
    mdp4_stat.overlay_play[pipe->mixer_num]++;
}
Example #12
0
static int bt_rfkill_set_block(void *data, bool blocked)
{
    struct toshiba_acpi_dev *dev = data;
    u32 result1, result2;
    u32 value;
    int err;
    bool radio_state;

    value = (blocked == false);

    mutex_lock(&dev->mutex);
    if (hci_get_radio_state(dev, &radio_state) != HCI_SUCCESS) {
        err = -EIO;
        goto out;
    }

    if (!radio_state) {
        err = 0;
        goto out;
    }

    hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
    hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);

    if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS)
        err = -EIO;
    else
        err = 0;
out:
    mutex_unlock(&dev->mutex);
    return err;
}
Example #13
0
static ssize_t
anslcd_write( struct file * file, const char __user * buf,
              size_t count, loff_t *ppos )
{
    const char __user *p = buf;
    int i;

#ifdef DEBUG
    printk(KERN_DEBUG "LCD: write\n");
#endif

    if (!access_ok(VERIFY_READ, buf, count))
        return -EFAULT;

    mutex_lock(&anslcd_mutex);
    for ( i = *ppos; count > 0; ++i, ++p, --count )
    {
        char c;
        __get_user(c, p);
        anslcd_write_byte_data( c );
    }
    mutex_unlock(&anslcd_mutex);
    *ppos = i;
    return p - buf;
}
Example #14
0
static void retire_worker(struct work_struct *work)
{
    struct msm_gpu *gpu = container_of(work, struct msm_gpu, retire_work);
    struct drm_device *dev = gpu->dev;
    uint32_t fence = gpu->funcs->last_fence(gpu);

    msm_update_fence(gpu->dev, fence);

    mutex_lock(&dev->struct_mutex);

    while (!list_empty(&gpu->active_list)) {
        struct msm_gem_object *obj;

        obj = list_first_entry(&gpu->active_list,
                               struct msm_gem_object, mm_list);

        if ((obj->read_fence <= fence) &&
                (obj->write_fence <= fence)) {
            /* move to inactive: */
            msm_gem_move_to_inactive(&obj->base);
            msm_gem_put_iova(&obj->base, gpu->id);
            drm_gem_object_unreference(&obj->base);
        } else {
            break;
        }
    }

    mutex_unlock(&dev->struct_mutex);

    if (!msm_gpu_active(gpu))
        inactive_start(gpu);
}
Example #15
0
static int
printer_open(struct inode *inode, struct file *fd)
{
    struct printer_dev	*dev;
    unsigned long		flags;
    int			ret = -EBUSY;

    mutex_lock(&printer_mutex);
    dev = container_of(inode->i_cdev, struct printer_dev, printer_cdev);

    spin_lock_irqsave(&dev->lock, flags);

    if (!dev->printer_cdev_open) {
        dev->printer_cdev_open = 1;
        fd->private_data = dev;
        ret = 0;
        /* Change the printer status to show that it's on-line. */
        dev->printer_status |= PRINTER_SELECTED;
    }

    spin_unlock_irqrestore(&dev->lock, flags);

    DBG(dev, "printer_open returned %x\n", ret);
    mutex_unlock(&printer_mutex);
    return ret;
}
Example #16
0
static int chown_common(struct path *path, uid_t user, gid_t group)
{
    struct inode *inode = path->dentry->d_inode;
    int error;
    struct iattr newattrs;

    newattrs.ia_valid =  ATTR_CTIME;
    if (user != (uid_t) -1) {
        newattrs.ia_valid |= ATTR_UID;
        newattrs.ia_uid = user;
    }
    if (group != (gid_t) -1) {
        newattrs.ia_valid |= ATTR_GID;
        newattrs.ia_gid = group;
    }
    if (!S_ISDIR(inode->i_mode))
        newattrs.ia_valid |=
            ATTR_KILL_SUID | ATTR_KILL_SGID | ATTR_KILL_PRIV;
    mutex_lock(&inode->i_mutex);
    error = security_path_chown(path, user, group);
    if (!error)
        error = notify_change(path->dentry, &newattrs);
    mutex_unlock(&inode->i_mutex);

    return error;
}
Example #17
0
int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
                struct file *filp)
{
    int ret;
    struct iattr newattrs;

    /* Not pretty: "inode->i_size" shouldn't really be signed. But it is. */
    if (length < 0)
        return -EINVAL;

    newattrs.ia_size = length;
    newattrs.ia_valid = ATTR_SIZE | time_attrs;
    if (filp) {
        newattrs.ia_file = filp;
        newattrs.ia_valid |= ATTR_FILE;
    }

    /* Remove suid/sgid on truncate too */
    ret = should_remove_suid(dentry);
    if (ret)
        newattrs.ia_valid |= ret | ATTR_FORCE;

    mutex_lock(&dentry->d_inode->i_mutex);
    ret = notify_change(dentry, &newattrs);
    mutex_unlock(&dentry->d_inode->i_mutex);
    return ret;
}
void supersonic_analog_init(void)
{
    D("%s\n", __func__);
    /* stereo pmic init */
    pmic_spkr_set_gain(LEFT_SPKR, SPKR_GAIN_PLUS12DB);
    pmic_spkr_set_gain(RIGHT_SPKR, SPKR_GAIN_00DB);
    pmic_spkr_en_right_chan(OFF_CMD);
    pmic_spkr_en_left_chan(OFF_CMD);
    pmic_spkr_add_right_left_chan(OFF_CMD);
    pmic_spkr_en_stereo(OFF_CMD);
    pmic_spkr_select_usb_with_hpf_20hz(OFF_CMD);
    pmic_spkr_bypass_mux(OFF_CMD);
    pmic_spkr_en_hpf(ON_CMD);
    pmic_spkr_en_sink_curr_from_ref_volt_cir(OFF_CMD);
    pmic_spkr_set_mux_hpf_corner_freq(SPKR_FREQ_0_73KHZ);
    pmic_mic_set_volt(MIC_VOLT_1_80V);
    pmic_set_speaker_delay(SPKR_DLY_100MS);

    gpio_request(SUPERSONIC_AUD_JACKHP_EN, "aud_jackhp_en");
    gpio_direction_output(SUPERSONIC_AUD_JACKHP_EN, 0);
    gpio_set_value(SUPERSONIC_AUD_JACKHP_EN, 0);

    mutex_lock(&bt_sco_lock);
    config_gpio_table(bt_sco_disable, ARRAY_SIZE(bt_sco_disable));
    gpio_set_value(SUPERSONIC_BT_PCM_OUT, 0);
    gpio_set_value(SUPERSONIC_BT_PCM_SYNC,0);
    gpio_set_value(SUPERSONIC_BT_PCM_CLK,0);
    mutex_unlock(&bt_sco_lock);
}
static ssize_t vol_wakeup_store(struct device *dev,
                                struct device_attribute *attr,
                                const char *buf, size_t count)
{
    unsigned char bitmask = 0;
    bitmask = simple_strtoull(buf, NULL, 10);
    mutex_lock(&wakeup_mutex);
    if (bitmask) {
        if (bitmask == 127)
            wakeup_bitmask &= bitmask;
        else if (bitmask > 128)
            wakeup_bitmask &= bitmask;
        else
            wakeup_bitmask |= bitmask;
    }

    if (wakeup_bitmask && (!set_wakeup)) {
        enable_irq_wake(vol_up_irq);
        enable_irq_wake(vol_down_irq);
        set_wakeup = 1;
        KEY_LOGD("%s:change to wake up function(%d, %d)\n", __func__, vol_up_irq, vol_down_irq);
    } else if ((!wakeup_bitmask) && set_wakeup) {
        disable_irq_wake(vol_up_irq);
        disable_irq_wake(vol_down_irq);
        set_wakeup = 0;
        KEY_LOGD("%s:change to non-wake up function(%d, %d)\n", __func__, vol_up_irq, vol_down_irq);
    }
    mutex_unlock(&wakeup_mutex);
    return count;
}
 static int h2w_debug_set(void *data, u64 val)
 {
     mutex_lock(&hi->mutex_lock);
     switch_set_state(&hi->sdev, (int)val);
     mutex_unlock(&hi->mutex_lock);
     return 0;
 }
Example #21
0
/**
 * write_maxblksize - Set or report the current NFS blksize
 *
 * Input:
 *			buf:		ignored
 *			size:		zero
 *
 * OR
 *
 * Input:
 * 			buf:		C string containing an unsigned
 * 					integer value representing the new
 * 					NFS blksize
 *			size:		non-zero length of C string in @buf
 * Output:
 *	On success:	passed-in buffer filled with '\n'-terminated C string
 *			containing numeric value of the current NFS blksize
 *			setting;
 *			return code is the size in bytes of the string
 *	On error:	return code is zero or a negative errno value
 */
static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
{
    char *mesg = buf;
    if (size > 0) {
        int bsize;
        int rv = get_int(&mesg, &bsize);
        if (rv)
            return rv;
        /* force bsize into allowed range and
         * required alignment.
         */
        if (bsize < 1024)
            bsize = 1024;
        if (bsize > NFSSVC_MAXBLKSIZE)
            bsize = NFSSVC_MAXBLKSIZE;
        bsize &= ~(1024-1);
        mutex_lock(&nfsd_mutex);
        if (nfsd_serv) {
            mutex_unlock(&nfsd_mutex);
            return -EBUSY;
        }
        nfsd_max_blksize = bsize;
        mutex_unlock(&nfsd_mutex);
    }

    return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n",
                     nfsd_max_blksize);
}
static int lme2510_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
{
    struct lme2510_state *st = adap->dev->priv;
    static u8 clear_reg_3[] = LME_ALL_PIDS;
    static u8 rbuf[1];
    int ret = 0, rlen = sizeof(rbuf);

    deb_info(1, "STM  (%02x)", onoff);

    /* Streaming is started by FE_HAS_LOCK */
    if (onoff == 1)
        st->stream_on = 1;
    else {
        deb_info(1, "STM Steam Off");
        /* mutex is here only to avoid collision with I2C */
        mutex_lock(&adap->dev->i2c_mutex);

        ret = lme2510_usb_talk(adap->dev, clear_reg_3,
                               sizeof(clear_reg_3), rbuf, rlen);
        st->stream_on = 0;
        st->i2c_talk_onoff = 1;

        mutex_unlock(&adap->dev->i2c_mutex);
    }

    return (ret < 0) ? -ENODEV : 0;
}
Example #23
0
static ssize_t tpm_read(struct file *file, char __user *buf,
                        size_t size, loff_t *off)
{
    struct file_priv *priv = file->private_data;
    ssize_t ret_size;
    int rc;

    del_singleshot_timer_sync(&priv->user_read_timer);
    flush_work(&priv->work);
    ret_size = atomic_read(&priv->data_pending);
    if (ret_size > 0) {	/* relay data */
        ssize_t orig_ret_size = ret_size;
        if (size < ret_size)
            ret_size = size;

        mutex_lock(&priv->buffer_mutex);
        rc = copy_to_user(buf, priv->data_buffer, ret_size);
        memset(priv->data_buffer, 0, orig_ret_size);
        if (rc)
            ret_size = -EFAULT;

        mutex_unlock(&priv->buffer_mutex);
    }

    atomic_set(&priv->data_pending, 0);

    return ret_size;
}
Example #24
0
static ssize_t snapshot_read(struct file *filp, char __user *buf,
                             size_t count, loff_t *offp)
{
    struct snapshot_data *data;
    ssize_t res;

    mutex_lock(&pm_mutex);

    data = filp->private_data;
    if (!data->ready) {
        res = -ENODATA;
        goto Unlock;
    }
    res = snapshot_read_next(&data->handle, count);
    if (res > 0) {
        if (copy_to_user(buf, data_of(data->handle), res))
            res = -EFAULT;
        else
            *offp = data->handle.offset;
    }

Unlock:
    mutex_unlock(&pm_mutex);

    return res;
}
Example #25
0
static int au0828_dvb_start_feed(struct dvb_demux_feed *feed)
{
    struct dvb_demux *demux = feed->demux;
    struct au0828_dev *dev = (struct au0828_dev *) demux->priv;
    struct au0828_dvb *dvb = &dev->dvb;
    int ret = 0;

    dprintk(1, "%s()\n", __func__);

    if (!demux->dmx.frontend)
        return -EINVAL;

    if (dvb) {
        mutex_lock(&dvb->lock);
        if (dvb->feeding++ == 0) {
            /* Start transport */
            au0828_write(dev, 0x608, 0x90);
            au0828_write(dev, 0x609, 0x72);
            au0828_write(dev, 0x60a, 0x71);
            au0828_write(dev, 0x60b, 0x01);
            ret = start_urb_transfer(dev);
        }
        mutex_unlock(&dvb->lock);
    }

    return ret;
}
Example #26
0
/*{{{  PlaybackDelete*/
int PlaybackDelete     (struct PlaybackContext_s*       Playback)
{
    int         Result  = 0;

    if (Playback == NULL)
        return -EINVAL;

    BACKEND_TRACE("Playback %p, Usage = %d\n", Playback, Playback->UsageCount);

    mutex_lock (&(Playback->Lock));

    if (Playback->UsageCount != 0)
    {
        BACKEND_TRACE("Cannot delete playback - usage = %d\n", Playback->UsageCount);
        mutex_unlock (&(Playback->Lock));
        return -EINVAL;
    }

    if (Playback->Handle != NULL)
    {
        Result = Backend->Ops->playback_terminate (Playback->Handle);
        if (Result < 0)
            BACKEND_ERROR("Failed to delete playback context\n");
    }
    mutex_unlock (&(Playback->Lock));

    if (Result == 0)
        kfree (Playback);
    return Result;
}
static int dm04_lme2510_set_voltage(struct dvb_frontend *fe,
                                    fe_sec_voltage_t voltage)
{
    struct dvb_usb_adapter *adap = fe->dvb->priv;
    static u8 voltage_low[]	= LME_VOLTAGE_L;
    static u8 voltage_high[] = LME_VOLTAGE_H;
    static u8 rbuf[1];
    int ret = 0, len = 3, rlen = 1;

    mutex_lock(&adap->dev->i2c_mutex);

    switch (voltage) {
    case SEC_VOLTAGE_18:
        ret |= lme2510_usb_talk(adap->dev,
                                voltage_high, len, rbuf, rlen);
        break;

    case SEC_VOLTAGE_OFF:
    case SEC_VOLTAGE_13:
    default:
        ret |= lme2510_usb_talk(adap->dev,
                                voltage_low, len, rbuf, rlen);
        break;
    }

    mutex_unlock(&adap->dev->i2c_mutex);

    return (ret < 0) ? -ENODEV : 0;
}
Example #28
0
/*{{{  PlaybackRemoveStream*/
int PlaybackRemoveStream       (struct PlaybackContext_s*       Playback,
                                struct StreamContext_s*         Stream)
{
    int         Result  = 0;

    BACKEND_DEBUG ("%p: Usage = %d\n", Playback, Playback->UsageCount);

    if ((Playback == NULL) || (Stream == NULL))
    {
        BACKEND_ERROR("Unable to remove stream (%p) from playback (%p) if either is NULL\n", Stream, Playback);
        return -EINVAL;
    }

    mutex_lock (&(Playback->Lock));

    if (Stream->Handle != NULL)
    {
        Result = Stream->Delete (Playback->Handle, Stream->Handle);
        if (Result < 0)
            BACKEND_ERROR("Failed to remove stream from playback\n");
    }

    if (Stream->Buffer != NULL)
        bigphysarea_free_pages (Stream->Buffer);
    kfree (Stream);

    Playback->UsageCount--;
    mutex_unlock (&(Playback->Lock));

    return Result;
}
Example #29
0
int vga_switcheroo_register_client(struct pci_dev *pdev,
                                   void (*set_gpu_state)(struct pci_dev *pdev, enum vga_switcheroo_state),
                                   void (*reprobe)(struct pci_dev *pdev),
                                   bool (*can_switch)(struct pci_dev *pdev))
{
    int index;

    mutex_lock(&vgasr_mutex);
    /* don't do IGD vs DIS here */
    if (vgasr_priv.registered_clients & 1)
        index = 1;
    else
        index = 0;

    vgasr_priv.clients[index].pwr_state = VGA_SWITCHEROO_ON;
    vgasr_priv.clients[index].pdev = pdev;
    vgasr_priv.clients[index].set_gpu_state = set_gpu_state;
    vgasr_priv.clients[index].reprobe = reprobe;
    vgasr_priv.clients[index].can_switch = can_switch;
    vgasr_priv.clients[index].id = -1;
    if (pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW)
        vgasr_priv.clients[index].active = true;

    vgasr_priv.registered_clients |= (1 << index);

    /* if we get two clients + handler */
    if (vgasr_priv.registered_clients == 0x3 && vgasr_priv.handler) {
        printk(KERN_INFO "vga_switcheroo: enabled\n");
        vga_switcheroo_enable();
    }
    mutex_unlock(&vgasr_mutex);
    return 0;
}
Example #30
0
bool FileInfo::CheckIfProcessHasLocks(int process_id) {
    boost::mutex::scoped_lock mutex_lock(active_locks_mutex_);

    // There may be only up to one lock per process_id. No loop required.
    map<unsigned int, Lock*>::const_iterator it = active_locks_.find(process_id);
    return it != active_locks_.end();
}