Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 94da1e2e authored by Alan Cox's avatar Alan Cox Committed by Wim Van Sebroeck
Browse files

[WATCHDOG 01/57] Clean acquirewdt and check for BKL dependancies



This brings the file into line with coding style.

Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent e490517a
Loading
Loading
Loading
Loading
+58 −61
Original line number Original line Diff line number Diff line
@@ -58,39 +58,46 @@
#include <linux/types.h>		/* For standard types (like size_t) */
#include <linux/types.h>		/* For standard types (like size_t) */
#include <linux/errno.h>		/* For the -ENODEV/... values */
#include <linux/errno.h>		/* For the -ENODEV/... values */
#include <linux/kernel.h>		/* For printk/panic/... */
#include <linux/kernel.h>		/* For printk/panic/... */
#include <linux/miscdevice.h>		/* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */
#include <linux/miscdevice.h>		/* For MODULE_ALIAS_MISCDEV
							(WATCHDOG_MINOR) */
#include <linux/watchdog.h>		/* For the watchdog specific items */
#include <linux/watchdog.h>		/* For the watchdog specific items */
#include <linux/fs.h>			/* For file operations */
#include <linux/fs.h>			/* For file operations */
#include <linux/ioport.h>		/* For io-port access */
#include <linux/ioport.h>		/* For io-port access */
#include <linux/platform_device.h>	/* For platform_driver framework */
#include <linux/platform_device.h>	/* For platform_driver framework */
#include <linux/init.h>			/* For __init/__exit/... */
#include <linux/init.h>			/* For __init/__exit/... */


#include <asm/uaccess.h>		/* For copy_to_user/put_user/... */
#include <linux/uaccess.h>		/* For copy_to_user/put_user/... */
#include <asm/io.h>			/* For inb/outb/... */
#include <linux/io.h>			/* For inb/outb/... */


/* Module information */
/* Module information */
#define DRV_NAME "acquirewdt"
#define DRV_NAME "acquirewdt"
#define PFX DRV_NAME ": "
#define PFX DRV_NAME ": "
#define WATCHDOG_NAME "Acquire WDT"
#define WATCHDOG_NAME "Acquire WDT"
#define WATCHDOG_HEARTBEAT 0	/* There is no way to see what the correct time-out period is */
/* There is no way to see what the correct time-out period is */
#define WATCHDOG_HEARTBEAT 0


/* internal variables */
/* internal variables */
static struct platform_device *acq_platform_device;	/* the watchdog platform device */
/* the watchdog platform device */
static struct platform_device *acq_platform_device;
static unsigned long acq_is_open;
static unsigned long acq_is_open;
static char expect_close;
static char expect_close;


/* module parameters */
/* module parameters */
static int wdt_stop = 0x43;	/* You must set this - there is no sane way to probe for this board. */
/* You must set this - there is no sane way to probe for this board. */
static int wdt_stop = 0x43;
module_param(wdt_stop, int, 0);
module_param(wdt_stop, int, 0);
MODULE_PARM_DESC(wdt_stop, "Acquire WDT 'stop' io port (default 0x43)");
MODULE_PARM_DESC(wdt_stop, "Acquire WDT 'stop' io port (default 0x43)");


static int wdt_start = 0x443;	/* You must set this - there is no sane way to probe for this board. */
/* You must set this - there is no sane way to probe for this board. */
static int wdt_start = 0x443;
module_param(wdt_start, int, 0);
module_param(wdt_start, int, 0);
MODULE_PARM_DESC(wdt_start, "Acquire WDT 'start' io port (default 0x443)");
MODULE_PARM_DESC(wdt_start, "Acquire WDT 'start' io port (default 0x443)");


static int nowayout = WATCHDOG_NOWAYOUT;
static int nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, int, 0);
module_param(nowayout, int, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
MODULE_PARM_DESC(nowayout,
	"Watchdog cannot be stopped once started (default="
	__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");


/*
/*
 *	Watchdog Operations
 *	Watchdog Operations
@@ -112,18 +119,18 @@ static void acq_stop(void)
 *	/dev/watchdog handling
 *	/dev/watchdog handling
 */
 */


static ssize_t acq_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
static ssize_t acq_write(struct file *file, const char __user *buf,
						size_t count, loff_t *ppos)
{
{
	/* See if we got the magic character 'V' and reload the timer */
	/* See if we got the magic character 'V' and reload the timer */
	if (count) {
	if (count) {
		if (!nowayout) {
		if (!nowayout) {
			size_t i;
			size_t i;

			/* note: just in case someone wrote the magic character
			/* note: just in case someone wrote the magic character
			 * five months ago... */
			 * five months ago... */
			expect_close = 0;
			expect_close = 0;

			/* scan to see whether or not we got the
			/* scan to see whether or not we got the magic character */
			   magic character */
			for (i = 0; i != count; i++) {
			for (i = 0; i != count; i++) {
				char c;
				char c;
				if (get_user(c, buf + i))
				if (get_user(c, buf + i))
@@ -132,28 +139,25 @@ static ssize_t acq_write(struct file *file, const char __user *buf, size_t count
					expect_close = 42;
					expect_close = 42;
			}
			}
		}
		}

		/* Well, anyhow someone wrote to us, we should
		/* Well, anyhow someone wrote to us, we should return that favour */
				return that favour */
		acq_keepalive();
		acq_keepalive();
	}
	}
	return count;
	return count;
}
}


static int acq_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
static long acq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
	unsigned long arg)
{
{
	int options, retval = -EINVAL;
	int options, retval = -EINVAL;
	void __user *argp = (void __user *)arg;
	void __user *argp = (void __user *)arg;
	int __user *p = argp;
	int __user *p = argp;
	static struct watchdog_info ident =
	static struct watchdog_info ident = {
	{
		.options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
		.options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
		.firmware_version = 1,
		.firmware_version = 1,
		.identity = WATCHDOG_NAME,
		.identity = WATCHDOG_NAME,
	};
	};


	switch(cmd)
	switch (cmd) {
	{
	case WDIOC_GETSUPPORT:
	case WDIOC_GETSUPPORT:
		return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
		return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;


@@ -172,22 +176,16 @@ static int acq_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
	{
	{
		if (get_user(options, p))
		if (get_user(options, p))
			return -EFAULT;
			return -EFAULT;

		if (options & WDIOS_DISABLECARD) {
	    if (options & WDIOS_DISABLECARD)
	    {
			acq_stop();
			acq_stop();
			retval = 0;
			retval = 0;
		}
		}

		if (options & WDIOS_ENABLECARD) {
	    if (options & WDIOS_ENABLECARD)
	    {
			acq_keepalive();
			acq_keepalive();
			retval = 0;
			retval = 0;
		}
		}

		return retval;
		return retval;
	}
	}

	default:
	default:
		return -ENOTTY;
		return -ENOTTY;
	}
	}
@@ -211,7 +209,8 @@ static int acq_close(struct inode *inode, struct file *file)
	if (expect_close == 42) {
	if (expect_close == 42) {
		acq_stop();
		acq_stop();
	} else {
	} else {
		printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
		printk(KERN_CRIT PFX
			"Unexpected close, not stopping watchdog!\n");
		acq_keepalive();
		acq_keepalive();
	}
	}
	clear_bit(0, &acq_is_open);
	clear_bit(0, &acq_is_open);
@@ -227,7 +226,7 @@ static const struct file_operations acq_fops = {
	.owner		= THIS_MODULE,
	.owner		= THIS_MODULE,
	.llseek		= no_llseek,
	.llseek		= no_llseek,
	.write		= acq_write,
	.write		= acq_write,
	.ioctl		= acq_ioctl,
	.unlocked_ioctl	= acq_ioctl,
	.open		= acq_open,
	.open		= acq_open,
	.release	= acq_close,
	.release	= acq_close,
};
};
@@ -248,8 +247,8 @@ static int __devinit acq_probe(struct platform_device *dev)


	if (wdt_stop != wdt_start) {
	if (wdt_stop != wdt_start) {
		if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) {
		if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) {
			printk (KERN_ERR PFX "I/O address 0x%04x already in use\n",
			printk(KERN_ERR PFX
				wdt_stop);
			    "I/O address 0x%04x already in use\n", wdt_stop);
			ret = -EIO;
			ret = -EIO;
			goto out;
			goto out;
		}
		}
@@ -261,19 +260,16 @@ static int __devinit acq_probe(struct platform_device *dev)
		ret = -EIO;
		ret = -EIO;
		goto unreg_stop;
		goto unreg_stop;
	}
	}

	ret = misc_register(&acq_miscdev);
	ret = misc_register(&acq_miscdev);
	if (ret != 0) {
	if (ret != 0) {
		printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
		printk(KERN_ERR PFX
			"cannot register miscdev on minor=%d (err=%d)\n",
							WATCHDOG_MINOR, ret);
							WATCHDOG_MINOR, ret);
		goto unreg_regions;
		goto unreg_regions;
	}
	}

	printk(KERN_INFO PFX "initialized. (nowayout=%d)\n", nowayout);
	printk (KERN_INFO PFX "initialized. (nowayout=%d)\n",
		nowayout);


	return 0;
	return 0;

unreg_regions:
unreg_regions:
	release_region(wdt_start, 1);
	release_region(wdt_start, 1);
unreg_stop:
unreg_stop:
@@ -313,18 +309,19 @@ static int __init acq_init(void)
{
{
	int err;
	int err;


	printk(KERN_INFO "WDT driver for Acquire single board computer initialising.\n");
	printk(KERN_INFO
	      "WDT driver for Acquire single board computer initialising.\n");


	err = platform_driver_register(&acquirewdt_driver);
	err = platform_driver_register(&acquirewdt_driver);
	if (err)
	if (err)
		return err;
		return err;


	acq_platform_device = platform_device_register_simple(DRV_NAME, -1, NULL, 0);
	acq_platform_device = platform_device_register_simple(DRV_NAME,
								-1, NULL, 0);
	if (IS_ERR(acq_platform_device)) {
	if (IS_ERR(acq_platform_device)) {
		err = PTR_ERR(acq_platform_device);
		err = PTR_ERR(acq_platform_device);
		goto unreg_platform_driver;
		goto unreg_platform_driver;
	}
	}

	return 0;
	return 0;


unreg_platform_driver:
unreg_platform_driver: