/** * sh_wdt_open - Open the Device * * @inode: inode of device * @file: file handle of device * * Watchdog device is opened and started. */ static int sh_wdt_open(struct inode *inode, struct file *file) { if (test_and_set_bit(0, &sh_is_open)) return -EBUSY; sh_wdt_start(); return 0; }
/** * sh_wdt_ioctl - Query Device * * @inode: inode of device * @file: file handle of device * @cmd: watchdog command * @arg: argument * * Query basic information from the device or ping it, as outlined by the * watchdog API. */ static int sh_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { int new_timeout; switch (cmd) { case WDIOC_GETSUPPORT: if (copy_to_user((struct watchdog_info *)arg, &sh_wdt_info, sizeof(sh_wdt_info))) { return -EFAULT; } break; case WDIOC_GETSTATUS: case WDIOC_GETBOOTSTATUS: return put_user(0, (int *)arg); case WDIOC_KEEPALIVE: next_heartbeat = jiffies + (sh_heartbeat * HZ); break; case WDIOC_SETTIMEOUT: if (get_user(new_timeout, (int *)arg)) return -EFAULT; if (new_timeout < 1 || new_timeout > 3600) /* arbitrary upper limit */ return -EINVAL; sh_heartbeat = new_timeout; next_heartbeat = jiffies + (sh_heartbeat * HZ); /* Fall */ case WDIOC_GETTIMEOUT: return put_user(sh_heartbeat, (int *)arg); case WDIOC_SETOPTIONS: { int options, retval = -EINVAL; if (get_user(options, (int *)arg)) return -EFAULT; if (options & WDIOS_DISABLECARD) { sh_wdt_stop(); retval = 0; } if (options & WDIOS_ENABLECARD) { sh_wdt_start(); retval = 0; } return retval; } default: return -ENOTTY; } return 0; }
/** * sh_wdt_open - Open the Device * * @inode: inode of device * @file: file handle of device * * Watchdog device is opened and started. */ static int sh_wdt_open(struct inode *inode, struct file *file) { if (test_and_set_bit(0, &shwdt_is_open)) return -EBUSY; if (nowayout) __module_get(THIS_MODULE); sh_wdt_start(); return 0; }
/** * sh_wdt_ioctl - Query Device * * @inode: inode of device * @file: file handle of device * @cmd: watchdog command * @arg: argument * * Query basic information from the device or ping it, as outlined by the * watchdog API. */ static int sh_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { int new_heartbeat; int options, retval = -EINVAL; switch (cmd) { case WDIOC_GETSUPPORT: return copy_to_user((struct watchdog_info *)arg, &sh_wdt_info, sizeof(sh_wdt_info)) ? -EFAULT : 0; case WDIOC_GETSTATUS: case WDIOC_GETBOOTSTATUS: return put_user(0, (int *)arg); case WDIOC_KEEPALIVE: sh_wdt_keepalive(); return 0; case WDIOC_SETTIMEOUT: if (get_user(new_heartbeat, (int *)arg)) return -EFAULT; if (sh_wdt_set_heartbeat(new_heartbeat)) return -EINVAL; sh_wdt_keepalive(); /* Fall */ case WDIOC_GETTIMEOUT: return put_user(heartbeat, (int *)arg); case WDIOC_SETOPTIONS: if (get_user(options, (int *)arg)) return -EFAULT; if (options & WDIOS_DISABLECARD) { sh_wdt_stop(); retval = 0; } if (options & WDIOS_ENABLECARD) { sh_wdt_start(); retval = 0; } return retval; default: return -ENOIOCTLCMD; } return 0; }
static int sh_wdt_open(struct inode *inode, struct file *file) { struct sh_wdt *wdt = platform_get_drvdata(sh_wdt_dev); if (test_and_set_bit(0, &wdt->enabled)) return -EBUSY; if (nowayout) __module_get(THIS_MODULE); file->private_data = wdt; sh_wdt_start(wdt); return nonseekable_open(inode, file); }