这篇教程C++ try_module_get函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中try_module_get函数的典型用法代码示例。如果您正苦于以下问题:C++ try_module_get函数的具体用法?C++ try_module_get怎么用?C++ try_module_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了try_module_get函数的21个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: snd_hwdep_openstatic int snd_hwdep_open(struct inode *inode, struct file * file){ int major = imajor(inode); int cardnum; int device; snd_hwdep_t *hw; int err; wait_queue_t wait; if (major == snd_major) { cardnum = SNDRV_MINOR_CARD(iminor(inode)); device = SNDRV_MINOR_DEVICE(iminor(inode)) - SNDRV_MINOR_HWDEP;#ifdef CONFIG_SND_OSSEMUL } else if (major == SOUND_MAJOR) { cardnum = SNDRV_MINOR_OSS_CARD(iminor(inode)); device = 0;#endif } else return -ENXIO; cardnum %= SNDRV_CARDS; device %= SNDRV_MINOR_HWDEPS; hw = snd_hwdep_devices[(cardnum * SNDRV_MINOR_HWDEPS) + device]; if (hw == NULL) return -ENODEV; if (!hw->ops.open) return -ENXIO;#ifdef CONFIG_SND_OSSEMUL if (major == SOUND_MAJOR && hw->oss_type < 0) return -ENXIO;#endif if (!try_module_get(hw->card->module)) return -EFAULT; init_waitqueue_entry(&wait, current); add_wait_queue(&hw->open_wait, &wait); down(&hw->open_mutex); while (1) { if (hw->exclusive && hw->used > 0) { err = -EBUSY; break; } err = hw->ops.open(hw, file); if (err >= 0) break; if (err == -EAGAIN) { if (file->f_flags & O_NONBLOCK) { err = -EBUSY; break; } } else break; set_current_state(TASK_INTERRUPTIBLE); up(&hw->open_mutex); schedule(); down(&hw->open_mutex); if (signal_pending(current)) { err = -ERESTARTSYS; break; } } remove_wait_queue(&hw->open_wait, &wait); if (err >= 0) { err = snd_card_file_add(hw->card, file); if (err >= 0) { file->private_data = hw; hw->used++; } else { if (hw->ops.release) hw->ops.release(hw, file); } } up(&hw->open_mutex); if (err < 0) module_put(hw->card->module); return err;}
开发者ID:BackupTheBerlios,项目名称:tew632-brp-svn,代码行数:78,
示例2: edac_device_register_sysfs_main_kobj/* * edac_device_register_sysfs_main_kobj * * perform the high level setup for the new edac_device instance * * Return: 0 SUCCESS * !0 FAILURE */int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev){ struct sysdev_class *edac_class; int err; debugf1("%s()/n", __func__); /* get the /sys/devices/system/edac reference */ edac_class = edac_get_sysfs_class(); if (edac_class == NULL) { debugf1("%s() no edac_class error/n", __func__); err = -ENODEV; goto err_out; } /* Point to the 'edac_class' this instance 'reports' to */ edac_dev->edac_class = edac_class; /* Init the devices's kobject */ memset(&edac_dev->kobj, 0, sizeof(struct kobject)); /* Record which module 'owns' this control structure * and bump the ref count of the module */ edac_dev->owner = THIS_MODULE; if (!try_module_get(edac_dev->owner)) { err = -ENODEV; goto err_mod_get; } /* register */ err = kobject_init_and_add(&edac_dev->kobj, &ktype_device_ctrl, &edac_class->kset.kobj, "%s", edac_dev->name); if (err) { debugf1("%s()Failed to register '.../edac/%s'/n", __func__, edac_dev->name); goto err_kobj_reg; } kobject_uevent(&edac_dev->kobj, KOBJ_ADD); /* At this point, to 'free' the control struct, * edac_device_unregister_sysfs_main_kobj() must be used */ debugf4("%s() Registered '.../edac/%s' kobject/n", __func__, edac_dev->name); return 0; /* Error exit stack */err_kobj_reg: module_put(edac_dev->owner);err_mod_get: edac_put_sysfs_class();err_out: return err;}
开发者ID:ANFS,项目名称:ANFS-kernel,代码行数:69,
示例3: procfs_open/* file is opened we don't care but increment the module's reference count returns 0 for success//*/int procfs_open(struct inode* inode, struct file* file){ try_module_get(THIS_MODULE); return 0;}
开发者ID:Rubusch,项目名称:kernel,代码行数:12,
示例4: ERR_PTR/* * This creates a new process as a copy of the old one, * but does not actually start it yet. * * It copies the registers, and all the appropriate * parts of the process environment (as per the clone * flags). The actual kick-off is left to the caller. */static struct task_struct *copy_process(unsigned long clone_flags, unsigned long stack_start, struct pt_regs *regs, unsigned long stack_size, int __user *parent_tidptr, int __user *child_tidptr, int pid){ int retval; struct task_struct *p = NULL; if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS)) return ERR_PTR(-EINVAL); /* * Thread groups must share signals as well, and detached threads * can only be started up within the thread group. */ if ((clone_flags & CLONE_THREAD) && !(clone_flags & CLONE_SIGHAND)) return ERR_PTR(-EINVAL); /* * Shared signal handlers imply shared VM. By way of the above, * thread groups also imply shared VM. Blocking this case allows * for various simplifications in other code. */ if ((clone_flags & CLONE_SIGHAND) && !(clone_flags & CLONE_VM)) return ERR_PTR(-EINVAL); retval = security_task_create(clone_flags); if (retval) goto fork_out; retval = -ENOMEM; p = dup_task_struct(current); if (!p) goto fork_out;#ifdef CONFIG_TRACE_IRQFLAGS DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled); DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);#endif retval = -EAGAIN; if (atomic_read(&p->user->processes) >= p->signal->rlim[RLIMIT_NPROC].rlim_cur) { if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) && p->user != &root_user) goto bad_fork_free; } atomic_inc(&p->user->__count); atomic_inc(&p->user->processes); get_group_info(p->group_info); /* * If multiple threads are within copy_process(), then this check * triggers too late. This doesn't hurt, the check is only there * to stop root fork bombs. */ if (nr_threads >= max_threads) goto bad_fork_cleanup_count; if (!try_module_get(task_thread_info(p)->exec_domain->module)) goto bad_fork_cleanup_count; if (p->binfmt && !try_module_get(p->binfmt->module)) goto bad_fork_cleanup_put_domain; p->did_exec = 0; delayacct_tsk_init(p); /* Must remain after dup_task_struct() */ copy_flags(clone_flags, p); p->pid = pid; retval = -EFAULT; if (clone_flags & CLONE_PARENT_SETTID) if (put_user(p->pid, parent_tidptr)) goto bad_fork_cleanup_delays_binfmt; INIT_LIST_HEAD(&p->children); INIT_LIST_HEAD(&p->sibling); p->vfork_done = NULL; spin_lock_init(&p->alloc_lock); clear_tsk_thread_flag(p, TIF_SIGPENDING); init_sigpending(&p->pending); p->utime = cputime_zero; p->stime = cputime_zero; p->sched_time = 0; p->rchar = 0; /* I/O counter: bytes read */ p->wchar = 0; /* I/O counter: bytes written */ p->syscr = 0; /* I/O counter: read syscalls */ p->syscw = 0; /* I/O counter: write syscalls *///.........这里部分代码省略.........
开发者ID:FatSunHYS,项目名称:OSCourseDesign,代码行数:101,
示例5: pty_common_install/** * pty_common_install - set up the pty pair * @driver: the pty driver * @tty: the tty being instantiated * @bool: legacy, true if this is BSD style * * Perform the initial set up for the tty/pty pair. Called from the * tty layer when the port is first opened. * * Locking: the caller must hold the tty_mutex */static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty, bool legacy){ struct tty_struct *o_tty; struct tty_port *ports[2]; int idx = tty->index; int retval = -ENOMEM; o_tty = alloc_tty_struct(); if (!o_tty) goto err; ports[0] = kmalloc(sizeof **ports, GFP_KERNEL); ports[1] = kmalloc(sizeof **ports, GFP_KERNEL); if (!ports[0] || !ports[1]) goto err_free_tty; if (!try_module_get(driver->other->owner)) { /* This cannot in fact currently happen */ goto err_free_tty; } initialize_tty_struct(o_tty, driver->other, idx); if (legacy) { /* We always use new tty termios data so we can do this the easy way .. */ retval = tty_init_termios(tty); if (retval) goto err_deinit_tty; retval = tty_init_termios(o_tty); if (retval) goto err_free_termios; driver->other->ttys[idx] = o_tty; driver->ttys[idx] = tty; } else { memset(&tty->termios_locked, 0, sizeof(tty->termios_locked)); tty->termios = driver->init_termios; memset(&o_tty->termios_locked, 0, sizeof(tty->termios_locked)); o_tty->termios = driver->other->init_termios; } /* * Everything allocated ... set up the o_tty structure. */ tty_driver_kref_get(driver->other); if (driver->subtype == PTY_TYPE_MASTER) o_tty->count++; /* Establish the links in both directions */ tty->link = o_tty; o_tty->link = tty; tty_port_init(ports[0]); tty_port_init(ports[1]); o_tty->port = ports[0]; tty->port = ports[1]; o_tty->port->itty = o_tty; tty_driver_kref_get(driver); tty->count++; return 0;err_free_termios: if (legacy) tty_free_termios(tty);err_deinit_tty: deinitialize_tty_struct(o_tty); module_put(o_tty->driver->owner);err_free_tty: kfree(ports[0]); kfree(ports[1]); free_tty_struct(o_tty);err: return retval;}
开发者ID:7799,项目名称:linux,代码行数:83,
示例6: pty_common_install/** * pty_common_install - set up the pty pair * @driver: the pty driver * @tty: the tty being instantiated * @legacy: true if this is BSD style * * Perform the initial set up for the tty/pty pair. Called from the * tty layer when the port is first opened. * * Locking: the caller must hold the tty_mutex */static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty, bool legacy){ struct tty_struct *o_tty; struct tty_port *ports[2]; int idx = tty->index; int retval = -ENOMEM; /* Opening the slave first has always returned -EIO */ if (driver->subtype != PTY_TYPE_MASTER) return -EIO; ports[0] = kmalloc(sizeof **ports, GFP_KERNEL); ports[1] = kmalloc(sizeof **ports, GFP_KERNEL); if (!ports[0] || !ports[1]) goto err; if (!try_module_get(driver->other->owner)) { /* This cannot in fact currently happen */ goto err; } o_tty = alloc_tty_struct(driver->other, idx); if (!o_tty) goto err_put_module; tty_set_lock_subclass(o_tty); lockdep_set_subclass(&o_tty->termios_rwsem, TTY_LOCK_SLAVE); if (legacy) { /* We always use new tty termios data so we can do this the easy way .. */ retval = tty_init_termios(tty); if (retval) goto err_deinit_tty; retval = tty_init_termios(o_tty); if (retval) goto err_free_termios; driver->other->ttys[idx] = o_tty; driver->ttys[idx] = tty; } else { memset(&tty->termios_locked, 0, sizeof(tty->termios_locked)); tty->termios = driver->init_termios; memset(&o_tty->termios_locked, 0, sizeof(tty->termios_locked)); o_tty->termios = driver->other->init_termios; } /* * Everything allocated ... set up the o_tty structure. */ tty_driver_kref_get(driver->other); /* Establish the links in both directions */ tty->link = o_tty; o_tty->link = tty; tty_port_init(ports[0]); tty_port_init(ports[1]); tty_buffer_set_limit(ports[0], 8192); tty_buffer_set_limit(ports[1], 8192); o_tty->port = ports[0]; tty->port = ports[1]; o_tty->port->itty = o_tty; tty_buffer_set_lock_subclass(o_tty->port); tty_driver_kref_get(driver); tty->count++; o_tty->count++; return 0;err_free_termios: if (legacy) tty_free_termios(tty);err_deinit_tty: deinitialize_tty_struct(o_tty); free_tty_struct(o_tty);err_put_module: module_put(driver->other->owner);err: kfree(ports[0]); kfree(ports[1]); return retval;}
开发者ID:DenisLug,项目名称:mptcp,代码行数:92,
示例7: snd_info_entry_openstatic int snd_info_entry_open(struct inode *inode, struct file *file){ struct snd_info_entry *entry; struct snd_info_private_data *data; struct snd_info_buffer *buffer; struct proc_dir_entry *p; int mode, err; mutex_lock(&info_mutex); p = PDE(inode); entry = p == NULL ? NULL : (struct snd_info_entry *)p->data; if (entry == NULL || ! entry->p) { mutex_unlock(&info_mutex); return -ENODEV; } if (!try_module_get(entry->module)) { err = -EFAULT; goto __error1; } mode = file->f_flags & O_ACCMODE; if (mode == O_RDONLY || mode == O_RDWR) { if ((entry->content == SNDRV_INFO_CONTENT_DATA && entry->c.ops->read == NULL)) { err = -ENODEV; goto __error; } } if (mode == O_WRONLY || mode == O_RDWR) { if ((entry->content == SNDRV_INFO_CONTENT_DATA && entry->c.ops->write == NULL)) { err = -ENODEV; goto __error; } } data = kzalloc(sizeof(*data), GFP_KERNEL); if (data == NULL) { err = -ENOMEM; goto __error; } data->entry = entry; switch (entry->content) { case SNDRV_INFO_CONTENT_TEXT: if (mode == O_RDONLY || mode == O_RDWR) { buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); if (buffer == NULL) goto __nomem; data->rbuffer = buffer; buffer->len = PAGE_SIZE; buffer->buffer = kmalloc(buffer->len, GFP_KERNEL); if (buffer->buffer == NULL) goto __nomem; } if (mode == O_WRONLY || mode == O_RDWR) { buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); if (buffer == NULL) goto __nomem; data->wbuffer = buffer; buffer->len = PAGE_SIZE; buffer->buffer = kmalloc(buffer->len, GFP_KERNEL); if (buffer->buffer == NULL) goto __nomem; } break; case SNDRV_INFO_CONTENT_DATA: /* data */ if (entry->c.ops->open) { if ((err = entry->c.ops->open(entry, mode, &data->file_private_data)) < 0) { kfree(data); goto __error; } } break; } file->private_data = data; mutex_unlock(&info_mutex); if (entry->content == SNDRV_INFO_CONTENT_TEXT && (mode == O_RDONLY || mode == O_RDWR)) { if (entry->c.text.read) { mutex_lock(&entry->access); entry->c.text.read(entry, data->rbuffer); mutex_unlock(&entry->access); } } return 0; __nomem: if (data->rbuffer) { kfree(data->rbuffer->buffer); kfree(data->rbuffer); } if (data->wbuffer) { kfree(data->wbuffer->buffer); kfree(data->wbuffer); } kfree(data); err = -ENOMEM; __error: module_put(entry->module); __error1: mutex_unlock(&info_mutex);//.........这里部分代码省略.........
开发者ID:B-Rich,项目名称:linux_drivers,代码行数:101,
示例8: i2s_openstatic int i2s_open(struct inode *inode, struct file *filp){ int Ret; unsigned long data; int minor = iminor(inode); if (minor >= I2S_MAX_DEV) return -ENODEV; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) MOD_INC_USE_COUNT;#else try_module_get(THIS_MODULE);#endif if (filp->f_flags & O_NONBLOCK) { MSG("filep->f_flags O_NONBLOCK set/n"); return -EAGAIN; } /* set i2s_config */ pi2s_config = (i2s_config_type*)kmalloc(sizeof(i2s_config_type), GFP_KERNEL); if(pi2s_config==NULL) return -1; filp->private_data = pi2s_config; memset(pi2s_config, 0, sizeof(i2s_config_type)); #ifdef I2S_STATISTIC pi2s_status = (i2s_status_type*)kmalloc(sizeof(i2s_status_type), GFP_KERNEL); if(pi2s_status==NULL) return -1; memset(pi2s_status, 0, sizeof(i2s_status_type)); #endif pi2s_config->flag = 0; pi2s_config->dmach = GDMA_I2S_TX0; pi2s_config->tx_ff_thres = CONFIG_I2S_TFF_THRES; pi2s_config->tx_ch_swap = CONFIG_I2S_CH_SWAP; pi2s_config->rx_ff_thres = CONFIG_I2S_TFF_THRES; pi2s_config->rx_ch_swap = CONFIG_I2S_CH_SWAP; pi2s_config->slave_en = CONFIG_I2S_SLAVE_EN; pi2s_config->srate = 44100; pi2s_config->txvol = 0; pi2s_config->rxvol = 0; pi2s_config->lbk = CONFIG_I2S_INLBK; pi2s_config->extlbk = CONFIG_I2S_EXLBK; pi2s_config->fmt = CONFIG_I2S_FMT; #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35) Ret = request_irq(SURFBOARDINT_I2S, i2s_irq_isr, IRQF_DISABLED, "Ralink_I2S", NULL);#else Ret = request_irq(SURFBOARDINT_I2S, i2s_irq_isr, SA_INTERRUPT, "Ralink_I2S", NULL);#endif if(Ret){ MSG("IRQ %d is not free./n", SURFBOARDINT_I2S); i2s_release(inode, filp); return -1; } pi2s_config->dmach = GDMA_I2S_TX0; init_waitqueue_head(&(pi2s_config->i2s_tx_qh)); init_waitqueue_head(&(pi2s_config->i2s_rx_qh));/*#if defined(CONFIG_RALINK_RT63365) data = i2s_inw(RALINK_SYSCTL_BASE+0x834); data |=1<<17; i2s_outw(RALINK_SYSCTL_BASE+0x834, data); data = i2s_inw(RALINK_SYSCTL_BASE+0x834); data &=~(1<<17); i2s_outw(RALINK_SYSCTL_BASE+0x834, data); audiohw_preinit();#endif */ return 0;}
开发者ID:jhbsz,项目名称:wifiaudio,代码行数:79,
示例9: dbg_gen/** * ubi_open_volume - open UBI volume. * @ubi_num: UBI device number * @vol_id: volume ID * @mode: open mode * * The @mode parameter specifies if the volume should be opened in read-only * mode, read-write mode, or exclusive mode. The exclusive mode guarantees that * nobody else will be able to open this volume. UBI allows to have many volume * readers and one writer at a time. * * If a static volume is being opened for the first time since boot, it will be * checked by this function, which means it will be fully read and the CRC * checksum of each logical eraseblock will be checked. * * This function returns volume descriptor in case of success and a negative * error code in case of failure. */struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode){ int err; struct ubi_volume_desc *desc; struct ubi_device *ubi; struct ubi_volume *vol; dbg_gen("open device %d, volume %d, mode %d", ubi_num, vol_id, mode); if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES) return ERR_PTR(-EINVAL); if (mode != UBI_READONLY && mode != UBI_READWRITE && mode != UBI_EXCLUSIVE && mode != UBI_METAONLY) return ERR_PTR(-EINVAL); /* * First of all, we have to get the UBI device to prevent its removal. */ ubi = ubi_get_device(ubi_num); if (!ubi) return ERR_PTR(-ENODEV); if (vol_id < 0 || vol_id >= ubi->vtbl_slots) { err = -EINVAL; goto out_put_ubi; } desc = kmalloc(sizeof(struct ubi_volume_desc), GFP_KERNEL); if (!desc) { err = -ENOMEM; goto out_put_ubi; } err = -ENODEV; if (!try_module_get(THIS_MODULE)) goto out_free; spin_lock(&ubi->volumes_lock); vol = ubi->volumes[vol_id]; if (!vol) goto out_unlock; err = -EBUSY; switch (mode) { case UBI_READONLY: if (vol->exclusive) goto out_unlock; vol->readers += 1; break; case UBI_READWRITE: if (vol->exclusive || vol->writers > 0) goto out_unlock; vol->writers += 1; break; case UBI_EXCLUSIVE: if (vol->exclusive || vol->writers || vol->readers || vol->metaonly) goto out_unlock; vol->exclusive = 1; break; case UBI_METAONLY: if (vol->metaonly || vol->exclusive) goto out_unlock; vol->metaonly = 1; break; } get_device(&vol->dev); vol->ref_count += 1; spin_unlock(&ubi->volumes_lock); desc->vol = vol; desc->mode = mode; mutex_lock(&ubi->ckvol_mutex); if (!vol->checked) { /* This is the first open - check the volume */ err = ubi_check_volume(ubi, vol_id); if (err < 0) {//.........这里部分代码省略.........
开发者ID:Noltari,项目名称:u-boot,代码行数:101,
示例10: k_looper_openstatic int k_looper_open(struct inode * inode, struct file *filp){ return try_module_get(THIS_MODULE)? 0 : -EINVAL;}
开发者ID:starp128,项目名称:debian_config_files,代码行数:4,
示例11: load_exeso_binary//.........这里部分代码省略......... /* Init KThreaad */ ethread_init(thread, process, current); sema_init(&thread->exec_semaphore,0); if (is_win32 == TRUE) //parent is a windows process { down(&thread->exec_semaphore); //wait for the parent child_w32process = process->win32process; parent_w32process = parent_eprocess->win32process; info = child_w32process->startup_info; //now parent has finished its work if(thread->inherit_all) { create_handle_table(parent_eprocess, TRUE, process); child_w32process = create_w32process(parent_w32process, TRUE, process); } } deref_object(process); deref_object(thread); set_teb_selector(current, (long)thread->tcb.teb); thread->start_address = (void *)pe_entry; /* FIXME */ /* save current trap frame */ thread->tcb.trap_frame = (struct ktrap_frame *)regs; /* init apc, to call LdrInitializeThunk */#if 0 thread_apc = kmalloc(sizeof(KAPC), GFP_KERNEL); if (!thread_apc) { retval = -ENOMEM; goto out_free_thread_cid; } apc_init(thread_apc, &thread->tcb, OriginalApcEnvironment, thread_special_apc, NULL, (PKNORMAL_ROUTINE)ntdll_entry, UserMode, (void *)(bprm->p + 12)); insert_queue_apc(thread_apc, (void *)interp_entry, (void *)extra_page, IO_NO_INCREMENT);#ifndef TIF_APC#define TIF_APC 13#endif set_tsk_thread_flag(current, TIF_APC);#endif#ifdef ELF_PLAT_INIT /* * The ABI may specify that certain registers be set up in special * ways (on i386 %edx is the address of a DT_FINI function, for * example. In addition, it may also specify (eg, PowerPC64 ELF) * that the e_entry field is the address of the function descriptor * for the startup routine, rather than the address of the startup * routine itself. This macro performs whatever initialization to * the regs structure is required as well as any relocations to the * function descriptor entries when executing dynamically links apps. */ ELF_PLAT_INIT(regs, reloc_func_desc);#endif start_thread(regs, interp_entry, bprm->p); if (unlikely(current->ptrace & PT_PTRACED)) { if (current->ptrace & PT_TRACE_EXEC) ptrace_notify ((PTRACE_EVENT_EXEC << 8) | SIGTRAP); else send_sig(SIGTRAP, current, 0); } retval = 0; try_module_get(THIS_MODULE); /* return from w32syscall_exit, not syscall_exit */ ((unsigned long *)regs)[-1] = (unsigned long)w32syscall_exit; regs->fs = TEB_SELECTOR;out: if(elf_phdata) kfree(elf_phdata); return retval; /* error cleanup */out_free_thread_cid: delete_cid_handle(thread->cid.unique_thread, thread_object_type);out_free_ethread: deref_object(thread);out_free_process_cid: delete_cid_handle(process->unique_processid, process_object_type);out_free_eproc: deref_object(process);out_free_file: send_sig(SIGKILL, current, 0); goto out;}
开发者ID:kerneltravel,项目名称:longene,代码行数:101,
示例12: nfnl_compat_get_rcustatic int nfnl_compat_get_rcu(struct net *net, struct sock *nfnl, struct sk_buff *skb, const struct nlmsghdr *nlh, const struct nlattr * const tb[], struct netlink_ext_ack *extack){ int ret = 0, target; struct nfgenmsg *nfmsg; const char *fmt; const char *name; u32 rev; struct sk_buff *skb2; if (tb[NFTA_COMPAT_NAME] == NULL || tb[NFTA_COMPAT_REV] == NULL || tb[NFTA_COMPAT_TYPE] == NULL) return -EINVAL; name = nla_data(tb[NFTA_COMPAT_NAME]); rev = ntohl(nla_get_be32(tb[NFTA_COMPAT_REV])); target = ntohl(nla_get_be32(tb[NFTA_COMPAT_TYPE])); nfmsg = nlmsg_data(nlh); switch(nfmsg->nfgen_family) { case AF_INET: fmt = "ipt_%s"; break; case AF_INET6: fmt = "ip6t_%s"; break; case NFPROTO_BRIDGE: fmt = "ebt_%s"; break; case NFPROTO_ARP: fmt = "arpt_%s"; break; default: pr_err("nft_compat: unsupported protocol %d/n", nfmsg->nfgen_family); return -EINVAL; } if (!try_module_get(THIS_MODULE)) return -EINVAL; rcu_read_unlock(); try_then_request_module(xt_find_revision(nfmsg->nfgen_family, name, rev, target, &ret), fmt, name); if (ret < 0) goto out_put; skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (skb2 == NULL) { ret = -ENOMEM; goto out_put; } /* include the best revision for this extension in the message */ if (nfnl_compat_fill_info(skb2, NETLINK_CB(skb).portid, nlh->nlmsg_seq, NFNL_MSG_TYPE(nlh->nlmsg_type), NFNL_MSG_COMPAT_GET, nfmsg->nfgen_family, name, ret, target) <= 0) { kfree_skb(skb2); goto out_put; } ret = netlink_unicast(nfnl, skb2, NETLINK_CB(skb).portid, MSG_DONTWAIT); if (ret > 0) ret = 0;out_put: rcu_read_lock(); module_put(THIS_MODULE); return ret == -EAGAIN ? -ENOBUFS : ret;}
开发者ID:avagin,项目名称:linux,代码行数:78,
示例13: check_permstatic int check_perm(struct inode * inode, struct file * file){ struct config_item *item = configfs_get_config_item(file->f_path.dentry->d_parent); struct configfs_attribute * attr = to_attr(file->f_path.dentry); struct configfs_buffer * buffer; struct configfs_item_operations * ops = NULL; int error = 0; if (!item || !attr) goto Einval; /* Grab the module reference for this attribute if we have one */ if (!try_module_get(attr->ca_owner)) { error = -ENODEV; goto Done; } if (item->ci_type) ops = item->ci_type->ct_item_ops; else goto Eaccess; /* File needs write support. * The inode's perms must say it's ok, * and we must have a store method. */ if (file->f_mode & FMODE_WRITE) { if (!(inode->i_mode & S_IWUGO) || !ops->store_attribute) goto Eaccess; } /* File needs read support. * The inode's perms must say it's ok, and we there * must be a show method for it. */ if (file->f_mode & FMODE_READ) { if (!(inode->i_mode & S_IRUGO) || !ops->show_attribute) goto Eaccess; } /* No error? Great, allocate a buffer for the file, and store it * it in file->private_data for easy access. */ buffer = kzalloc(sizeof(struct configfs_buffer),GFP_KERNEL); if (!buffer) { error = -ENOMEM; goto Enomem; } mutex_init(&buffer->mutex); buffer->needs_read_fill = 1; buffer->ops = ops; file->private_data = buffer; goto Done; Einval: error = -EINVAL; goto Done; Eaccess: error = -EACCES; Enomem: module_put(attr->ca_owner); Done: if (error && item) config_item_put(item); return error;}
开发者ID:383530895,项目名称:linux,代码行数:68,
示例14: find_peripheralvoid *pil_get(const char *name){ int ret; struct pil_device *pil; struct pil_device *pil_d; void *retval;#ifdef CONFIG_MSM8960_ONLY static int modem_initialized = 0; int loop_count = 0;#endif if (!name) return NULL; pil = retval = find_peripheral(name); if (!pil) return ERR_PTR(-ENODEV); if (!try_module_get(pil->owner)) { put_device(&pil->dev); return ERR_PTR(-ENODEV); } pil_d = pil_get(pil->desc->depends_on); if (IS_ERR(pil_d)) { retval = pil_d; goto err_depends; }#ifdef CONFIG_MSM8960_ONLY if (!strcmp("modem", name)) { while (unlikely(!modem_initialized && strcmp("rmt_storage", current->comm) && loop_count++ < 10)) { printk("%s: %s(%d) waiting for rmt_storage %d/n", __func__, current->comm, current->pid, loop_count); msleep(500); } }#endif mutex_lock(&pil->lock); if (!pil->count) { if (!strcmp("modem", name)) { printk("%s: %s(%d) for %s/n", __func__, current->comm, current->pid, name);#ifdef CONFIG_MSM8960_ONLY modem_initialized = 1;#endif } ret = load_image(pil); if (ret) { retval = ERR_PTR(ret); goto err_load; } } pil->count++; pil_set_state(pil, PIL_ONLINE); mutex_unlock(&pil->lock);#if defined(CONFIG_MSM8930_ONLY) if (!strcmp("modem", name)) { complete_all(&pil_work_finished); }#elif defined(CONFIG_ARCH_APQ8064) complete_all(&pil_work_finished);#endifout: return retval;err_load: mutex_unlock(&pil->lock); pil_put(pil_d);err_depends: put_device(&pil->dev); module_put(pil->owner); goto out;}
开发者ID:Buckmarble,项目名称:Lunar_kernel_sense_m7,代码行数:71,
示例15: isert_cm_conn_req_handlerstatic int isert_cm_conn_req_handler(struct rdma_cm_id *cm_id, struct rdma_cm_event *event){ /* passed in rdma_create_id */ struct isert_portal *portal = cm_id->context; struct ib_device *ib_dev = cm_id->device; struct isert_device *isert_dev; struct isert_connection *isert_conn; struct rdma_conn_param *ini_conn_param; struct rdma_conn_param tgt_conn_param; struct isert_cm_hdr cm_hdr = { 0 }; int err; TRACE_ENTRY(); if (unlikely(!try_module_get(THIS_MODULE))) { err = -EINVAL; goto fail_get; } mutex_lock(&dev_list_mutex); isert_dev = isert_device_find(ib_dev); if (!isert_dev) { isert_dev = isert_device_create(ib_dev); if (unlikely(IS_ERR(isert_dev))) { err = PTR_ERR(isert_dev); mutex_unlock(&dev_list_mutex); goto fail_dev_create; } } isert_dev->refcnt++; mutex_unlock(&dev_list_mutex); isert_conn = isert_conn_create(cm_id, isert_dev); if (unlikely(IS_ERR(isert_conn))) { err = PTR_ERR(isert_conn); goto fail_conn_create; } isert_conn->state = ISER_CONN_HANDSHAKE; isert_conn->portal = portal; mutex_lock(&dev_list_mutex); list_add_tail(&isert_conn->portal_node, &portal->conn_list); mutex_unlock(&dev_list_mutex); /* initiator is dst, target is src */ memcpy(&isert_conn->peer_addr, &cm_id->route.addr.dst_addr, sizeof(isert_conn->peer_addr)); memcpy(&isert_conn->self_addr, &cm_id->route.addr.src_addr, sizeof(isert_conn->self_addr)); ini_conn_param = &event->param.conn; memset(&tgt_conn_param, 0, sizeof(tgt_conn_param)); tgt_conn_param.flow_control = ini_conn_param->flow_control; tgt_conn_param.rnr_retry_count = ini_conn_param->rnr_retry_count; tgt_conn_param.initiator_depth = isert_dev->device_attr.max_qp_init_rd_atom; if (tgt_conn_param.initiator_depth > ini_conn_param->initiator_depth) tgt_conn_param.initiator_depth = ini_conn_param->initiator_depth; tgt_conn_param.private_data_len = sizeof(cm_hdr); tgt_conn_param.private_data = &cm_hdr; cm_hdr.flags = ISER_ZBVA_NOT_SUPPORTED | ISER_SEND_W_INV_NOT_SUPPORTED; kref_get(&isert_conn->kref); err = rdma_accept(cm_id, &tgt_conn_param); if (unlikely(err)) { pr_err("Failed to accept conn request, err:%d/n", err); goto fail_accept; } switch (isert_conn->peer_addr.ss_family) { case AF_INET:#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33) pr_info("iser accepted connection cm_id:%p " NIPQUAD_FMT "->" NIPQUAD_FMT "/n", cm_id, NIPQUAD(((struct sockaddr_in *)&isert_conn->peer_addr)->sin_addr.s_addr), NIPQUAD(((struct sockaddr_in *)&isert_conn->self_addr)->sin_addr.s_addr));#else pr_info("iser accepted connection cm_id:%p " "%pI4->%pI4/n", cm_id, &((struct sockaddr_in *)&isert_conn->peer_addr)->sin_addr.s_addr, &((struct sockaddr_in *)&isert_conn->self_addr)->sin_addr.s_addr);#endif break; case AF_INET6:#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29) pr_info("iser accepted connection cm_id:%p " NIP6_FMT "->" NIP6_FMT "/n", cm_id, NIP6(((struct sockaddr_in6 *)&isert_conn->peer_addr)->sin6_addr), NIP6(((struct sockaddr_in6 *)&isert_conn->self_addr)->sin6_addr));#else pr_info("iser accepted connection cm_id:%p " "%pI6->%pI6/n", cm_id, &((struct sockaddr_in6 *)&isert_conn->peer_addr)->sin6_addr, &((struct sockaddr_in6 *)&isert_conn->self_addr)->sin6_addr);//.........这里部分代码省略.........
开发者ID:christopherdion,项目名称:scst,代码行数:101,
示例16: sh_mobile_lcdc_start//.........这里部分代码省略......... break; case 32: lcdc_write(priv, _LDDDSR, ldddsr | 4); break; } } for (k = 0; k < ARRAY_SIZE(priv->ch); k++) { ch = &priv->ch[k]; if (!priv->ch[k].enabled) continue; /* set bpp format in PKF[4:0] */ tmp = lcdc_read_chan(ch, LDDFR); tmp &= ~0x0003031f; if (ch->info->var.nonstd) { tmp |= (ch->info->var.nonstd << 16); switch (ch->info->var.bits_per_pixel) { case 12: break; case 16: tmp |= (0x1 << 8); break; case 24: tmp |= (0x2 << 8); break; } } else { switch (ch->info->var.bits_per_pixel) { case 16: tmp |= 0x03; break; case 24: tmp |= 0x0b; break; case 32: break; } } lcdc_write_chan(ch, LDDFR, tmp); /* point out our frame buffer */ lcdc_write_chan(ch, LDSA1R, ch->info->fix.smem_start); if (ch->info->var.nonstd) lcdc_write_chan(ch, LDSA2R, ch->info->fix.smem_start + ch->info->var.xres * ch->info->var.yres_virtual); /* set line size */ lcdc_write_chan(ch, LDMLSR, ch->info->fix.line_length); /* setup deferred io if SYS bus */ tmp = ch->cfg.sys_bus_cfg.deferred_io_msec; if (ch->ldmt1r_value & (1 << 12) && tmp) { ch->defio.deferred_io = sh_mobile_lcdc_deferred_io; ch->defio.delay = msecs_to_jiffies(tmp); ch->info->fbdefio = &ch->defio; fb_deferred_io_init(ch->info); /* one-shot mode */ lcdc_write_chan(ch, LDSM1R, 1); /* enable "Frame End Interrupt Enable" bit */ lcdc_write(priv, _LDINTR, LDINTR_FE); } else { /* continuous read mode */ lcdc_write_chan(ch, LDSM1R, 0); } } /* display output */ lcdc_write(priv, _LDCNT1R, LCDC_ENABLE); /* start the lcdc */ sh_mobile_lcdc_start_stop(priv, 1); priv->started = 1; /* tell the board code to enable the panel */ for (k = 0; k < ARRAY_SIZE(priv->ch); k++) { ch = &priv->ch[k]; if (!ch->enabled) continue; board_cfg = &ch->cfg.board_cfg; if (board_cfg->display_on && try_module_get(board_cfg->owner)) { board_cfg->display_on(board_cfg->board_data, ch->info); module_put(board_cfg->owner); } if (ch->bl) { ch->bl->props.power = FB_BLANK_UNBLANK; backlight_update_status(ch->bl); } } return 0;}
开发者ID:kozmikkick,项目名称:eternityprj-kernel-endeavoru-128,代码行数:101,
示例17: ksnd_pcm_openint ksnd_pcm_open(ksnd_pcm_t **kpcm, int card, int device, snd_pcm_stream_t stream){ int err = 0; ksnd_pcm_t *xkpcm; int minor; int stream_type, device_type; snd_pcm_t *pcm; xkpcm = kzalloc(sizeof(ksnd_pcm_t), GFP_KERNEL); if (!xkpcm) { err = -ENOMEM; goto _error_do_nothing; } if (stream == SND_PCM_STREAM_PLAYBACK) { stream_type = SNDRV_PCM_STREAM_PLAYBACK; device_type = SNDRV_DEVICE_TYPE_PCM_PLAYBACK; } else if (stream == SND_PCM_STREAM_CAPTURE) { stream_type = SNDRV_PCM_STREAM_CAPTURE; device_type = SNDRV_DEVICE_TYPE_PCM_CAPTURE; } else { err = -ENODEV; goto _error_do_free; }#if defined(__TDT__)#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17) minor = snd_get_minor(device_type, card, device);#else minor = SNDRV_MINOR(card, device_type + device);#endif#else /* TDT */#if defined (CONFIG_KERNELVERSION) minor = snd_find_minor(device_type, card, device);#else /* STLinux 2.2 */ minor = SNDRV_MINOR(card, device_type + device);#endif#endif if (minor < 0) { err = -ENODEV; goto _error_do_free; }#if 0 printk(KERN_DEBUG "Opening ALSA device hw:%d,%d for %s.../n", card, device, stream == SND_PCM_STREAM_PLAYBACK ? "playback" : "capture");#endif pcm = snd_lookup_minor_data(minor, device_type); if (pcm == NULL) { err = -ENODEV; goto _error_do_free; } if (!try_module_get(pcm->card->module)) { err = -EFAULT; goto _error_do_free; } mutex_lock(&pcm->open_mutex); err = snd_pcm_open_substream(pcm, stream_type, &default_file, &(xkpcm->substream)); /* We don't support blocking open here, just fail if busy */ if (err == -EAGAIN) { err = -EBUSY; } mutex_unlock(&pcm->open_mutex); if (err < 0) goto _error_do_put_and_free; *kpcm = xkpcm; return err;_error_do_put_and_free: module_put(pcm->card->module);_error_do_free: kfree(xkpcm);_error_do_nothing: return err;}
开发者ID:Audioniek,项目名称:Fortis-4G,代码行数:84,
示例18: snd_gus_use_incint snd_gus_use_inc(struct snd_gus_card * gus){ if (!try_module_get(gus->card->module)) return 0; return 1;}
开发者ID:adis1313,项目名称:android_kernel_samsung_msm8974,代码行数:6,
示例19: acpi_processor_notify_smmint acpi_processor_notify_smm(struct module *calling_module){ acpi_status status; static int is_done = 0; ACPI_FUNCTION_TRACE("acpi_processor_notify_smm"); if (!(acpi_processor_ppc_status & PPC_REGISTERED)) return_VALUE(-EBUSY); if (!try_module_get(calling_module)) return_VALUE(-EINVAL); /* is_done is set to negative if an error occured, * and to postitive if _no_ error occured, but SMM * was already notified. This avoids double notification * which might lead to unexpected results... */ if (is_done > 0) { module_put(calling_module); return_VALUE(0); } else if (is_done < 0) { module_put(calling_module); return_VALUE(is_done); } is_done = -EIO; /* Can't write pstate_cnt to smi_cmd if either value is zero */ if ((!acpi_fadt.smi_cmd) || (!acpi_fadt.pstate_cnt)) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No SMI port or pstate_cnt/n")); module_put(calling_module); return_VALUE(0); } ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Writing pstate_cnt [0x%x] to smi_cmd [0x%x]/n", acpi_fadt.pstate_cnt, acpi_fadt.smi_cmd)); /* FADT v1 doesn't support pstate_cnt, many BIOS vendors use * it anyway, so we need to support it... */ if (acpi_fadt_is_v1) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Using v1.0 FADT reserved value for pstate_cnt/n")); } status = acpi_os_write_port(acpi_fadt.smi_cmd, (u32) acpi_fadt.pstate_cnt, 8); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Failed to write pstate_cnt [0x%x] to " "smi_cmd [0x%x]/n", acpi_fadt.pstate_cnt, acpi_fadt.smi_cmd)); module_put(calling_module); return_VALUE(status); } /* Success. If there's no _PPC, we need to fear nothing, so * we can allow the cpufreq driver to be rmmod'ed. */ is_done = 1; if (!(acpi_processor_ppc_status & PPC_IN_USE)) module_put(calling_module); return_VALUE(0);}
开发者ID:mahyarmd,项目名称:unifi-gpl,代码行数:66,
示例20: tc_ctl_tfilter//.........这里部分代码省略......... } /* Find head of filter chain. */ /* Find link */ if ((dev = __dev_get_by_index(t->tcm_ifindex)) == NULL) return -ENODEV; /* Find qdisc */ if (!parent) { q = dev->qdisc_sleeping; parent = q->handle; } else if ((q = qdisc_lookup(dev, TC_H_MAJ(t->tcm_parent))) == NULL) return -EINVAL; /* Is it classful? */ if ((cops = q->ops->cl_ops) == NULL) return -EINVAL; /* Do we search for filter, attached to class? */ if (TC_H_MIN(parent)) { cl = cops->get(q, parent); if (cl == 0) return -ENOENT; } /* And the last stroke */ chain = cops->tcf_chain(q, cl); err = -EINVAL; if (chain == NULL) goto errout; /* Check the chain for existence of proto-tcf with this priority */ for (back = chain; (tp=*back) != NULL; back = &tp->next) { if (tp->prio >= prio) { if (tp->prio == prio) { if (!nprio || (tp->protocol != protocol && protocol)) goto errout; } else tp = NULL; break; } } if (tp == NULL) { /* Proto-tcf does not exist, create new one */ if (tca[TCA_KIND-1] == NULL || !protocol) goto errout; err = -ENOENT; if (n->nlmsg_type != RTM_NEWTFILTER || !(n->nlmsg_flags&NLM_F_CREATE)) goto errout; /* Create new proto tcf */ err = -ENOBUFS; if ((tp = kmalloc(sizeof(*tp), GFP_KERNEL)) == NULL) goto errout; tp_ops = tcf_proto_lookup_ops(tca[TCA_KIND-1]);#ifdef CONFIG_KMOD if (tp_ops==NULL && tca[TCA_KIND-1] != NULL) { struct rtattr *kind = tca[TCA_KIND-1]; if (RTA_PAYLOAD(kind) <= IFNAMSIZ) { request_module("cls_%s", (char*)RTA_DATA(kind)); tp_ops = tcf_proto_lookup_ops(kind); } }#endif if (tp_ops == NULL) { err = -EINVAL; kfree(tp); goto errout; } memset(tp, 0, sizeof(*tp)); tp->ops = tp_ops; tp->protocol = protocol; tp->prio = nprio ? : tcf_auto_prio(*back); tp->q = q; tp->classify = tp_ops->classify; tp->classid = parent; err = -EBUSY; if (!try_module_get(tp_ops->owner)) { kfree(tp); goto errout; } if ((err = tp_ops->init(tp)) != 0) { module_put(tp_ops->owner); kfree(tp); goto errout; } qdisc_lock_tree(dev); tp->next = *back; *back = tp; qdisc_unlock_tree(dev); } else if (tca[TCA_KIND-1] && rtattr_strcmp(tca[TCA_KIND-1], tp->ops->kind))
开发者ID:BackupTheBerlios,项目名称:tuxap,代码行数:101,
示例21: hecubafb_probestatic int __devinit hecubafb_probe(struct platform_device *dev){ struct fb_info *info; struct hecuba_board *board; int retval = -ENOMEM; int videomemorysize; unsigned char *videomemory; struct hecubafb_par *par; board = dev->dev.platform_data; if (!board) return -EINVAL; if (!try_module_get(board->owner)) return -ENODEV; videomemorysize = (DPY_W*DPY_H)/8; videomemory = vzalloc(videomemorysize); if (!videomemory) goto err_videomem_alloc; info = framebuffer_alloc(sizeof(struct hecubafb_par), &dev->dev); if (!info) goto err_fballoc; info->screen_base = (char __force __iomem *)videomemory; info->fbops = &hecubafb_ops; info->var = hecubafb_var; info->fix = hecubafb_fix; info->fix.smem_len = videomemorysize; par = info->par; par->info = info; par->board = board; par->send_command = apollo_send_command; par->send_data = apollo_send_data; info->flags = FBINFO_FLAG_DEFAULT | FBINFO_VIRTFB; info->fbdefio = &hecubafb_defio; fb_deferred_io_init(info); retval = register_framebuffer(info); if (retval < 0) goto err_fbreg; platform_set_drvdata(dev, info); printk(KERN_INFO "fb%d: Hecuba frame buffer device, using %dK of video memory/n", info->node, videomemorysize >> 10); retval = par->board->init(par); if (retval < 0) goto err_fbreg; return 0;err_fbreg: framebuffer_release(info);err_fballoc: vfree(videomemory);err_videomem_alloc: module_put(board->owner); return retval;}
开发者ID:MiniBlu,项目名称:cm11_kernel_htc_msm8974a3ul,代码行数:68,
注:本文中的try_module_get函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ try_return函数代码示例 C++ tryObjectEncoding函数代码示例 |