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 Diff line number Diff line
@@ -58,39 +58,46 @@
#include <linux/types.h>		/* For standard types (like size_t) */
#include <linux/errno.h>		/* For the -ENODEV/... values */
#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/fs.h>			/* For file operations */
#include <linux/ioport.h>		/* For io-port access */
#include <linux/platform_device.h>	/* For platform_driver framework */
#include <linux/init.h>			/* For __init/__exit/... */

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

/* Module information */
#define DRV_NAME "acquirewdt"
#define PFX DRV_NAME ": "
#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 */
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 char expect_close;

/* 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_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_PARM_DESC(wdt_start, "Acquire WDT 'start' io port (default 0x443)");

static int nowayout = WATCHDOG_NOWAYOUT;
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
@@ -112,18 +119,18 @@ static void acq_stop(void)
 *	/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 */
	if (count) {
		if (!nowayout) {
			size_t i;

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

			/* scan to see whether or not we got the magic character */
			/* scan to see whether or not we got the
			   magic character */
			for (i = 0; i != count; i++) {
				char c;
				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;
			}
		}

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

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

	switch(cmd)
	{
	switch (cmd) {
	case WDIOC_GETSUPPORT:
		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))
			return -EFAULT;

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

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

		return retval;
	}

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

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

	ret = misc_register(&acq_miscdev);
	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);
		goto unreg_regions;
	}

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

	return 0;

unreg_regions:
	release_region(wdt_start, 1);
unreg_stop:
@@ -313,18 +309,19 @@ static int __init acq_init(void)
{
	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);
	if (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)) {
		err = PTR_ERR(acq_platform_device);
		goto unreg_platform_driver;
	}

	return 0;

unreg_platform_driver: