Example #1
0
static int pc87413_open(struct inode *inode, struct file *file)
{
    /* /dev/watchdog can only be opened once */

    if (test_and_set_bit(0, &timer_enabled))
        return -EBUSY;

    if (nowayout)
        __module_get(THIS_MODULE);

    /* Reload and activate timer */
    pc87413_refresh();

    printk(KERN_INFO MODNAME "Watchdog enabled. Timeout set to"
                             " %d minute(s).\n", timeout);

    return nonseekable_open(inode, file);
}
Example #2
0
static int sc1200wdt_open(struct inode *inode, struct file *file)
{
	/* allow one at a time */
	if (test_and_set_bit(0, &open_flag))
		return -EBUSY;

	if (timeout > MAX_TIMEOUT)
		timeout = MAX_TIMEOUT;

	sc1200wdt_start();
#ifdef CONFIG_DEBUG_PRINTK
	printk(KERN_INFO PFX "Watchdog enabled, timeout = %d min(s)", timeout);
#else
	;
#endif

	return nonseekable_open(inode, file);
}
static int ipmi_open(struct inode *ino, struct file *filep)
{
	switch (iminor(ino)) {
	case WATCHDOG_MINOR:
		if (test_and_set_bit(0, &ipmi_wdog_open))
			return -EBUSY;

		/*
		 * Don't start the timer now, let it start on the
		 * first heartbeat.
		 */
		ipmi_start_timer_on_heartbeat = 1;
		return nonseekable_open(ino, filep);

	default:
		return (-ENODEV);
	}
}
Example #4
0
static int akm_aot_open(struct inode *inode, struct file *file)
{
	int ret = -1;

	FUNCDBG("called");
	if (atomic_cmpxchg(&open_flag, 0, 1) == 0) {
		wake_up(&open_wq);
		ret = 0;
	}

	ret = nonseekable_open(inode, file);
	if (ret)
		return ret;

	file->private_data = akmd_data;

	return ret;
}
Example #5
0
/*
 *	Allow only one person to hold it open
 */
static int pnx833x_wdt_open(struct inode *inode, struct file *file)
{
	if (test_and_set_bit(0, &pnx833x_wdt_alive))
		return -EBUSY;

	if (nowayout)
		__module_get(THIS_MODULE);

	/* Activate timer */
	if (!start_enabled)
		pnx833x_wdt_start();

	pnx833x_wdt_ping();

	printk(KERN_INFO "Started watchdog timer.\n");

	return nonseekable_open(inode, file);
}
static int tmc_open(struct inode *inode, struct file *file)
{
	struct tmc_drvdata *drvdata = container_of(file->private_data,
						   struct tmc_drvdata, miscdev);
	int ret = 0;

	if (drvdata->read_count++)
		goto out;

	ret = tmc_read_prepare(drvdata);
	if (ret)
		return ret;
out:
	nonseekable_open(inode, file);

	dev_dbg(drvdata->dev, "%s: successfully opened\n", __func__);
	return 0;
}
static int wb_smsc_wdt_open(struct inode *inode, struct file *file)
{
	/* /dev/watchdog can only be opened once */

	if (test_and_set_bit(0, &timer_enabled))
		return -EBUSY;

	if (nowayout)
		__module_get(THIS_MODULE);

	/* Reload and activate timer */
	wb_smsc_wdt_enable();

	pr_info("Watchdog enabled. Timeout set to %d %s\n",
		timeout, (unit == UNIT_SECOND) ? "second(s)" : "minute(s)");

	return nonseekable_open(inode, file);
}
Example #8
0
static int vmcp_open(struct inode *inode, struct file *file)
{
	struct vmcp_session *session;

	if (!capable(CAP_SYS_ADMIN))
		return -EPERM;

	session = kmalloc(sizeof(*session), GFP_KERNEL);
	if (!session)
		return -ENOMEM;

	session->bufsize = PAGE_SIZE;
	session->response = NULL;
	session->resp_size = 0;
	mutex_init(&session->mutex);
	file->private_data = session;
	return nonseekable_open(inode, file);
}
Example #9
0
/*
 *	/dev/watchdog handling
 */
static int mpcore_wdt_open(struct inode *inode, struct file *file)
{
	struct mpcore_wdt *wdt = platform_get_drvdata(mpcore_wdt_dev);

	if (test_and_set_bit(0, &wdt->timer_alive))
		return -EBUSY;

	if (nowayout)
		__module_get(THIS_MODULE);

	file->private_data = wdt;

	/*
	 *	Activate timer
	 */
	mpcore_wdt_start(wdt);

	return nonseekable_open(inode, file);
}
Example #10
0
/**
 * mei_open - the open function
 *
 * @inode: pointer to inode structure
 * @file: pointer to file structure
 *
 * returns 0 on success, <0 on error
 */
static int mei_open(struct inode *inode, struct file *file)
{
	struct mei_device *dev;
	struct mei_cl *cl;

	int err;

	dev = container_of(inode->i_cdev, struct mei_device, cdev);
	if (!dev)
		return -ENODEV;

	mutex_lock(&dev->device_lock);

	cl = NULL;

	err = -ENODEV;
	if (dev->dev_state != MEI_DEV_ENABLED) {
		dev_dbg(&dev->pdev->dev, "dev_state != MEI_ENABLED  dev_state = %s\n",
		    mei_dev_state_str(dev->dev_state));
		goto err_unlock;
	}

	err = -ENOMEM;
	cl = mei_cl_allocate(dev);
	if (!cl)
		goto err_unlock;

	/* open_handle_count check is handled in the mei_cl_link */
	err = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY);
	if (err)
		goto err_unlock;

	file->private_data = cl;

	mutex_unlock(&dev->device_lock);

	return nonseekable_open(inode, file);

err_unlock:
	mutex_unlock(&dev->device_lock);
	kfree(cl);
	return err;
}
Example #11
0
/*
 * Watchdog device is opened, and watchdog starts running.
 */
static int ds1374_wdt_open(struct inode *inode, struct file *file)
{
	struct ds1374 *ds1374 = i2c_get_clientdata(save_client);

	if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) {
		mutex_lock(&ds1374->mutex);
		if (test_and_set_bit(0, &wdt_is_open)) {
			mutex_unlock(&ds1374->mutex);
			return -EBUSY;
		}
		/*
		 *      Activate
		 */
		wdt_is_open = 1;
		mutex_unlock(&ds1374->mutex);
		return nonseekable_open(inode, file);
	}
	return -ENODEV;
}
static int mce_chrdev_open(struct inode *inode, struct file *file)
{
	spin_lock(&mce_chrdev_state_lock);

	if (mce_chrdev_open_exclu ||
	    (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
		spin_unlock(&mce_chrdev_state_lock);

		return -EBUSY;
	}

	if (file->f_flags & O_EXCL)
		mce_chrdev_open_exclu = 1;
	mce_chrdev_open_count++;

	spin_unlock(&mce_chrdev_state_lock);

	return nonseekable_open(inode, file);
}
int cctdatadev_open(struct inode *inode, struct file *filp)
{
	struct cctdatadev_dev *dev;
	F_ENTER();
#if 1
	dev = container_of(inode->i_cdev, struct cctdatadev_dev, cdev);

	filp->private_data = dev;	/* for other methods */

	/* used to keep track of how many readers */
	if (filp->f_mode & FMODE_READ)
		dev->nreaders++;
	if (filp->f_mode & FMODE_WRITE)
		dev->nwriters++;
#endif
	F_LEAVE();

	return nonseekable_open(inode, filp);	/* success */
}
Example #14
0
static int uinput_open(struct inode *inode, struct file *file)
{
	struct uinput_device *newdev;

	newdev = kzalloc(sizeof(struct uinput_device), GFP_KERNEL);
	if (!newdev)
		return -ENOMEM;

	mutex_init(&newdev->mutex);
	spin_lock_init(&newdev->requests_lock);
	init_waitqueue_head(&newdev->requests_waitq);
	init_waitqueue_head(&newdev->waitq);
	newdev->state = UIST_NEW_DEVICE;

	file->private_data = newdev;
	nonseekable_open(inode, file);

	return 0;
}
Example #15
0
static int vhci_open(struct inode *inode, struct file *file)
{
	struct vhci_data *data;
	struct hci_dev *hdev;

	data = kzalloc(sizeof(struct vhci_data), GFP_KERNEL);
	if (!data)
		return -ENOMEM;

	skb_queue_head_init(&data->readq);
	init_waitqueue_head(&data->read_wait);

	hdev = hci_alloc_dev();
	if (!hdev) {
		kfree(data);
		return -ENOMEM;
	}

	data->hdev = hdev;

	hdev->bus = HCI_VIRTUAL;
	hci_set_drvdata(hdev, data);

	if (amp)
		hdev->dev_type = HCI_AMP;

	hdev->open     = vhci_open_dev;
	hdev->close    = vhci_close_dev;
	hdev->flush    = vhci_flush;
	hdev->send     = vhci_send_frame;

	if (hci_register_dev(hdev) < 0) {
		BT_ERR("Can't register HCI device");
		kfree(data);
		hci_free_dev(hdev);
		return -EBUSY;
	}

	file->private_data = data;
	nonseekable_open(inode, file);

	return 0;
}
Example #16
0
static int pnx4008_wdt_open(struct inode *inode, struct file *file)
{
	int ret;

	if (test_and_set_bit(WDT_IN_USE, &wdt_status))
		return -EBUSY;

	clear_bit(WDT_OK_TO_CLOSE, &wdt_status);

	ret = clk_enable(wdt_clk);
	if (ret) {
		clear_bit(WDT_IN_USE, &wdt_status);
		return ret;
	}

	wdt_enable();

	return nonseekable_open(inode, file);
}
Example #17
0
static int
minstrel_ht_stats_open(struct inode *inode, struct file *file)
{
	struct minstrel_ht_sta_priv *msp = inode->i_private;
	struct minstrel_ht_sta *mi = &msp->ht;
	struct minstrel_debugfs_info *ms;
	unsigned int i;
	unsigned int max_mcs = MINSTREL_MAX_STREAMS * MINSTREL_STREAM_GROUPS;
	char *p;
	int ret;

	if (!msp->is_ht) {
		inode->i_private = &msp->legacy;
		ret = minstrel_stats_open(inode, file);
		inode->i_private = msp;
		return ret;
	}

	ms = kmalloc(sizeof(*ms) + 8192, GFP_KERNEL);
	if (!ms)
		return -ENOMEM;

	file->private_data = ms;
	p = ms->buf;
	p += sprintf(p, "type           rate     throughput  ewma prob   "
		     "this prob  retry   this succ/attempt   success    attempts\n");

	p = minstrel_ht_stats_dump(mi, max_mcs, p);
	for (i = 0; i < max_mcs; i++)
		p = minstrel_ht_stats_dump(mi, i, p);

	p += sprintf(p, "\nTotal packet count::    ideal %d      "
			"lookaround %d\n",
			max(0, (int) mi->total_packets - (int) mi->sample_packets),
			mi->sample_packets);
	p += sprintf(p, "Average A-MPDU length: %d.%d\n",
		MINSTREL_TRUNC(mi->avg_ampdu_len),
		MINSTREL_TRUNC(mi->avg_ampdu_len * 10) % 10);
	ms->len = p - ms->buf;

	return nonseekable_open(inode, file);
}
Example #18
0
int IO_mem_open(struct inode *inode, struct file *filp)
{
	struct IO_mem_dev *dev; /* device information */

	spin_lock(&IO_mem_lock);

	while (! atomic_dec_and_test (&IO_mem_available)) {
		atomic_inc(&IO_mem_available);
		spin_unlock(&IO_mem_lock);
		if (filp->f_flags & O_NONBLOCK) return -EAGAIN;
		if (wait_event_interruptible (IO_mem_wait, atomic_read (&IO_mem_available)))
			return -ERESTARTSYS; /* tell the fs layer to handle it */
		
		spin_lock(&IO_mem_lock);
	}

	spin_unlock(&IO_mem_lock);

	dev = container_of(inode->i_cdev, struct IO_mem_dev, cdev);

	io_addr =(unsigned long) ioremap_nocache(0x560000d0 , 0x0c); 
//	io_addr =(unsigned long) ioport_map(0x560000d0 , 0x0c);  /*WARNING: "ioport_map"  undefined!  Don't use it*/
	printk( "io_addr : %lx\n", io_addr);

	/* now trim to 0 the length of the device if open was write-only */
	gpjcon_old = ioread32 (io_addr);
	gpjdat_old = ioread32 (io_addr+4);
	gpjup_old = ioread32 (io_addr+8);

	
	mb();

	iowrite32(0x01555555,io_addr);
	iowrite32(0x1fff,io_addr+8);
	
	wmb();

	iowrite32(0x0,io_addr+4);
	filp->private_data = dev; /* for other methods */

	return nonseekable_open(inode, filp);          /* success */
}
Example #19
0
static int hci_vhci_chr_open(struct inode *inode, struct file * file)
{
	struct hci_vhci_struct *hci_vhci = NULL; 
	struct hci_dev *hdev;

	if (!(hci_vhci = kmalloc(sizeof(struct hci_vhci_struct), GFP_KERNEL)))
		return -ENOMEM;

	memset(hci_vhci, 0, sizeof(struct hci_vhci_struct));

	skb_queue_head_init(&hci_vhci->readq);
	init_waitqueue_head(&hci_vhci->read_wait);

	/* Initialize and register HCI device */
	hdev = hci_alloc_dev();
	if (!hdev) {
		kfree(hci_vhci);
		return -ENOMEM;
	}

	hci_vhci->hdev = hdev;

	hdev->type = HCI_VHCI;
	hdev->driver_data = hci_vhci;

	hdev->open  = hci_vhci_open;
	hdev->close = hci_vhci_close;
	hdev->flush = hci_vhci_flush;
	hdev->send  = hci_vhci_send_frame;
	hdev->destruct = hci_vhci_destruct;

	hdev->owner = THIS_MODULE;
	
	if (hci_register_dev(hdev) < 0) {
		kfree(hci_vhci);
		hci_free_dev(hdev);
		return -EBUSY;
	}

	file->private_data = hci_vhci;
	return nonseekable_open(inode, file);   
}
Example #20
0
static int ramips_wdt_open(struct inode *inode, struct file *file)
{
	u32 t;

	if (test_and_set_bit(WDT_FLAGS_BUSY, &ramips_wdt_flags))
		return -EBUSY;

	clear_bit(WDT_FLAGS_EXPECT_CLOSE, &ramips_wdt_flags);

	t = ramips_wdt_rr(TIMER_REG_TMR1CTL);
	t &= ~(TMR1CTL_MODE_MASK << TMR1CTL_MODE_SHIFT |
	       TMR1CTL_PRESCALE_MASK);
	t |= (TMR1CTL_MODE_WDT << TMR1CTL_MODE_SHIFT |
	      TMR1CTL_PRESCALE_65536);
	ramips_wdt_wr(TIMER_REG_TMR1CTL, t);

	ramips_wdt_enable();

	return nonseekable_open(inode, file);
}
Example #21
0
static int vhci_open(struct inode *inode, struct file *file)
{
	struct vhci_data *data;

	data = kzalloc(sizeof(struct vhci_data), GFP_KERNEL);
	if (!data)
		return -ENOMEM;

	skb_queue_head_init(&data->readq);
	init_waitqueue_head(&data->read_wait);

	INIT_DELAYED_WORK(&data->open_timeout, vhci_open_timeout);

	file->private_data = data;
	nonseekable_open(inode, file);

	schedule_delayed_work(&data->open_timeout, msecs_to_jiffies(1000));

	return 0;
}
Example #22
0
static int
hysdn_log_open(struct inode *ino, struct file *filep)
{
    hysdn_card *card;
    struct procdata *pd = NULL;
    ulong flags;

    lock_kernel();
    card = card_root;
    while (card) {
        pd = card->proclog;
        if (pd->log == PDE(ino))
            break;
        card = card->next;	/* search next entry */
    }
    if (!card) {
        unlock_kernel();
        return (-ENODEV);	/* device is unknown/invalid */
    }
    filep->private_data = card;	/* remember our own card */

    if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) {
        /* write only access -> write log level only */
    } else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) {

        /* read access -> log/debug read */
        save_flags(flags);
        cli();
        pd->if_used++;
        if (pd->log_head)
            filep->private_data = &pd->log_tail->next;
        else
            filep->private_data = &pd->log_head;
        restore_flags(flags);
    } else {		/* simultaneous read/write access forbidden ! */
        unlock_kernel();
        return (-EPERM);	/* no permission this time */
    }
    unlock_kernel();
    return nonseekable_open(ino, filep);
}				/* hysdn_log_open */
static ssize_t tsif_open(struct inode *inode, struct file *file)
{
	int rc;

#ifdef FEATURE_TSIF_DEBUG_MSG
	pr_info("[%s] !!!!!!!\n", __func__);
#endif

	struct tsif_chrdev *the_dev =
	       container_of(inode->i_cdev, struct tsif_chrdev, cdev);
	if (!the_dev->cookie)  /* not bound yet */
		return -ENODEV;
	file->private_data = the_dev;
	rc = tsif_start(the_dev->cookie);
	if (rc)
		return rc;
	tsif_get_info(the_dev->cookie, &the_dev->data_buffer,
		      &the_dev->buf_size_packets);
	the_dev->rptr = 0;
	return nonseekable_open(inode, file);
}
static int dw_wdt_open(struct inode *inode, struct file *filp)
{
	if (test_and_set_bit(0, &dw_wdt.in_use))
		return -EBUSY;

	
	__module_get(THIS_MODULE);

	spin_lock(&dw_wdt.lock);
	if (!dw_wdt_is_enabled()) {
		dw_wdt_set_top(DW_WDT_MAX_TOP);
		writel(WDOG_CONTROL_REG_WDT_EN_MASK,
		       dw_wdt.regs + WDOG_CONTROL_REG_OFFSET);
	}

	dw_wdt_set_next_heartbeat();

	spin_unlock(&dw_wdt.lock);

	return nonseekable_open(inode, filp);
}
Example #25
0
static int uhid_char_open(struct inode *inode, struct file *file)
{
	struct uhid_device *uhid;

	uhid = kzalloc(sizeof(*uhid), GFP_KERNEL);
	if (!uhid)
		return -ENOMEM;

	mutex_init(&uhid->devlock);
	mutex_init(&uhid->report_lock);
	spin_lock_init(&uhid->qlock);
	init_waitqueue_head(&uhid->waitq);
	init_waitqueue_head(&uhid->report_wait);
	uhid->running = false;
	atomic_set(&uhid->report_done, 1);

	file->private_data = uhid;
	nonseekable_open(inode, file);

	return 0;
}
Example #26
0
static int mpc83xx_wdt_open(struct inode *inode, struct file *file)
{
	u32 tmp = SWCRR_SWEN;
	if (test_and_set_bit(0, &wdt_is_open))
		return -EBUSY;

	/* Once we start the watchdog we can't stop it */
	__module_get(THIS_MODULE);

	/* Good, fire up the show */
	if (prescale)
		tmp |= SWCRR_SWPR;
	if (reset)
		tmp |= SWCRR_SWRI;

	tmp |= timeout << 16;

	out_be32(&wd_base->swcrr, tmp);

	return nonseekable_open(inode, file);
}
/*
 * This is not used by anonymous file descriptors. This code is left
 * there if we ever want to implement an inode with open() operation.
 */
int lib_ring_buffer_open(struct inode *inode, struct file *file,
		struct lib_ring_buffer *buf)
{
	int ret;

	if (!buf)
		return -EINVAL;

	ret = lib_ring_buffer_open_read(buf);
	if (ret)
		return ret;

	ret = nonseekable_open(inode, file);
	if (ret)
		goto release_read;
	return 0;

release_read:
	lib_ring_buffer_release_read(buf);
	return ret;
}
Example #28
0
static int __ptmx_open(struct inode *inode, struct file *filp)
{
	struct tty_struct *tty;
	int retval;
	int index;

	nonseekable_open(inode, filp);

	/* find a device that is not in use. */
	index = devpts_new_index(inode);
	if (index < 0)
		return index;

	mutex_lock(&tty_mutex);
	tty = tty_init_dev(ptm_driver, index, 1);
	mutex_unlock(&tty_mutex);

	if (IS_ERR(tty)) {
		retval = PTR_ERR(tty);
		goto out;
	}

	set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
	filp->private_data = tty;
	file_move(filp, &tty->tty_files);

	retval = devpts_pty_new(inode, tty->link);
	if (retval)
		goto out1;

	retval = ptm_driver->ops->open(tty, filp);
	if (!retval)
		return 0;
out1:
	tty_release(inode, filp);
	return retval;
out:
	devpts_kill_index(inode, index);
	return retval;
}
Example #29
0
static int watchdog_open(struct inode *inode, struct file *file)
{
	int err = -EBUSY;
	struct watchdog_device *wdd;

	/* Get the corresponding watchdog device */
	if (imajor(inode) == MISC_MAJOR)
		wdd = old_wdd;
	else
		wdd = container_of(inode->i_cdev, struct watchdog_device, cdev);

	/* the watchdog is single open! */
	if (test_and_set_bit(WDOG_DEV_OPEN, &wdd->status))
		return -EBUSY;

	/*
	 * If the /dev/watchdog device is open, we don't want the module
	 * to be unloaded.
	 */
	if (!try_module_get(wdd->ops->owner))
		goto out;

	err = watchdog_start(wdd);
	if (err < 0)
		goto out_mod;

	file->private_data = wdd;

	if (wdd->ops->ref)
		wdd->ops->ref(wdd);

	/* dev/watchdog is a virtual (and thus non-seekable) filesystem */
	return nonseekable_open(inode, file);

out_mod:
	module_put(wdd->ops->owner);
out:
	clear_bit(WDOG_DEV_OPEN, &wdd->status);
	return err;
}
 static int hisik3_wdt_open(struct inode *inode, struct file *file)
 {
         int ret = 0;
         if (test_and_set_bit(WDT_BUSY, &wdt->status))
                 return -EBUSY;
         ret = clk_enable(wdt->clk);
         if (ret) {
                 dev_err(&wdt->pdev->dev, "clock enable fail");
                 goto err;
         }

         wdt_enable();
         /* can not be closed, once enabled */
         clear_bit(WDT_CAN_BE_CLOSED, &wdt->status);
         return nonseekable_open(inode, file);

 err:
         dev_warn(&wdt->pdev->dev,"open watchdog file node failed\n");

         clear_bit(WDT_BUSY, &wdt->status);
         return ret;
 }