From 143a2e54bf53216674eada16e8953f48b159e08a Mon Sep 17 00:00:00 2001 From: Wim Van Sebroeck Date: Wed, 18 Mar 2009 08:35:09 +0000 Subject: [WATCHDOG] More coding-style and trivial clean-up Some more cleaning-up of the watchdog drivers. Signed-off-by: Wim Van Sebroeck --- drivers/watchdog/pcwd_usb.c | 171 ++++++++++++++++++++++++++++---------------- 1 file changed, 108 insertions(+), 63 deletions(-) (limited to 'drivers/watchdog/pcwd_usb.c') diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c index b5320a8e7451..052fe451851f 100644 --- a/drivers/watchdog/pcwd_usb.c +++ b/drivers/watchdog/pcwd_usb.c @@ -51,12 +51,11 @@ /* Use our own dbg macro */ #undef dbg -#define dbg(format, arg...) do { if (debug) printk(KERN_DEBUG PFX format "\n" , ## arg); } while (0) - +#define dbg(format, arg...) \ + do { if (debug) printk(KERN_DEBUG PFX format "\n" , ## arg); } while (0) /* Module and Version Information */ #define DRIVER_VERSION "1.02" -#define DRIVER_DATE "21 Jan 2007" #define DRIVER_AUTHOR "Wim Van Sebroeck " #define DRIVER_DESC "Berkshire USB-PC Watchdog driver" #define DRIVER_LICENSE "GPL" @@ -73,14 +72,18 @@ MODULE_ALIAS_MISCDEV(TEMP_MINOR); module_param(debug, int, 0); MODULE_PARM_DESC(debug, "Debug enabled or not"); -#define WATCHDOG_HEARTBEAT 0 /* default heartbeat = delay-time from dip-switches */ +#define WATCHDOG_HEARTBEAT 0 /* default heartbeat = + delay-time from dip-switches */ static int heartbeat = WATCHDOG_HEARTBEAT; module_param(heartbeat, int, 0); -MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0context; + struct usb_pcwd_private *usb_pcwd = + (struct usb_pcwd_private *)urb->context; unsigned char *data = usb_pcwd->intr_buffer; int retval; @@ -178,11 +197,13 @@ static void usb_pcwd_intr_done(struct urb *urb) case -ENOENT: case -ESHUTDOWN: /* this urb is terminated, clean up */ - dbg("%s - urb shutting down with status: %d", __func__, urb->status); + dbg("%s - urb shutting down with status: %d", __func__, + urb->status); return; /* -EPIPE: should clear the halt */ default: /* error */ - dbg("%s - nonzero urb status received: %d", __func__, urb->status); + dbg("%s - nonzero urb status received: %d", __func__, + urb->status); goto resubmit; } @@ -199,22 +220,23 @@ static void usb_pcwd_intr_done(struct urb *urb) resubmit: retval = usb_submit_urb(urb, GFP_ATOMIC); if (retval) - printk(KERN_ERR PFX "can't resubmit intr, usb_submit_urb failed with result %d\n", - retval); + printk(KERN_ERR PFX "can't resubmit intr, " + "usb_submit_urb failed with result %d\n", retval); } -static int usb_pcwd_send_command(struct usb_pcwd_private *usb_pcwd, unsigned char cmd, - unsigned char *msb, unsigned char *lsb) +static int usb_pcwd_send_command(struct usb_pcwd_private *usb_pcwd, + unsigned char cmd, unsigned char *msb, unsigned char *lsb) { int got_response, count; unsigned char buf[6]; - /* We will not send any commands if the USB PCWD device does not exist */ + /* We will not send any commands if the USB PCWD device does + * not exist */ if ((!usb_pcwd) || (!usb_pcwd->exists)) return -1; - /* The USB PC Watchdog uses a 6 byte report format. The board currently uses - * only 3 of the six bytes of the report. */ + /* The USB PC Watchdog uses a 6 byte report format. + * The board currently uses only 3 of the six bytes of the report. */ buf[0] = cmd; /* Byte 0 = CMD */ buf[1] = *msb; /* Byte 1 = Data MSB */ buf[2] = *lsb; /* Byte 2 = Data LSB */ @@ -229,12 +251,14 @@ static int usb_pcwd_send_command(struct usb_pcwd_private *usb_pcwd, unsigned cha HID_REQ_SET_REPORT, HID_DT_REPORT, 0x0200, usb_pcwd->interface_number, buf, sizeof(buf), USB_COMMAND_TIMEOUT) != sizeof(buf)) { - dbg("usb_pcwd_send_command: error in usb_control_msg for cmd 0x%x 0x%x 0x%x\n", cmd, *msb, *lsb); + dbg("usb_pcwd_send_command: error in usb_control_msg for " + "cmd 0x%x 0x%x 0x%x\n", cmd, *msb, *lsb); } /* wait till the usb card processed the command, * with a max. timeout of USB_COMMAND_TIMEOUT */ got_response = 0; - for (count = 0; (count < USB_COMMAND_TIMEOUT) && (!got_response); count++) { + for (count = 0; (count < USB_COMMAND_TIMEOUT) && (!got_response); + count++) { mdelay(1); if (atomic_read(&usb_pcwd->cmd_received)) got_response = 1; @@ -256,10 +280,12 @@ static int usb_pcwd_start(struct usb_pcwd_private *usb_pcwd) int retval; /* Enable Watchdog */ - retval = usb_pcwd_send_command(usb_pcwd, CMD_ENABLE_WATCHDOG, &msb, &lsb); + retval = usb_pcwd_send_command(usb_pcwd, CMD_ENABLE_WATCHDOG, + &msb, &lsb); if ((retval == 0) || (lsb == 0)) { - printk(KERN_ERR PFX "Card did not acknowledge enable attempt\n"); + printk(KERN_ERR PFX + "Card did not acknowledge enable attempt\n"); return -1; } @@ -273,10 +299,12 @@ static int usb_pcwd_stop(struct usb_pcwd_private *usb_pcwd) int retval; /* Disable Watchdog */ - retval = usb_pcwd_send_command(usb_pcwd, CMD_DISABLE_WATCHDOG, &msb, &lsb); + retval = usb_pcwd_send_command(usb_pcwd, CMD_DISABLE_WATCHDOG, + &msb, &lsb); if ((retval == 0) || (lsb != 0)) { - printk(KERN_ERR PFX "Card did not acknowledge disable attempt\n"); + printk(KERN_ERR PFX + "Card did not acknowledge disable attempt\n"); return -1; } @@ -308,7 +336,8 @@ static int usb_pcwd_set_heartbeat(struct usb_pcwd_private *usb_pcwd, int t) return 0; } -static int usb_pcwd_get_temperature(struct usb_pcwd_private *usb_pcwd, int *temperature) +static int usb_pcwd_get_temperature(struct usb_pcwd_private *usb_pcwd, + int *temperature) { unsigned char msb, lsb; @@ -323,7 +352,8 @@ static int usb_pcwd_get_temperature(struct usb_pcwd_private *usb_pcwd, int *temp return 0; } -static int usb_pcwd_get_timeleft(struct usb_pcwd_private *usb_pcwd, int *time_left) +static int usb_pcwd_get_timeleft(struct usb_pcwd_private *usb_pcwd, + int *time_left) { unsigned char msb, lsb; @@ -341,7 +371,7 @@ static int usb_pcwd_get_timeleft(struct usb_pcwd_private *usb_pcwd, int *time_le */ static ssize_t usb_pcwd_write(struct file *file, const char __user *data, - size_t len, loff_t *ppos) + size_t len, loff_t *ppos) { /* See if we got the magic character 'V' and reload the timer */ if (len) { @@ -352,7 +382,8 @@ static ssize_t usb_pcwd_write(struct file *file, const char __user *data, * five months ago... */ expect_release = 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 != len; i++) { char c; if (get_user(c, data + i)) @@ -431,7 +462,7 @@ static long usb_pcwd_ioctl(struct file *file, unsigned int cmd, return -EFAULT; if (usb_pcwd_set_heartbeat(usb_pcwd_device, new_heartbeat)) - return -EINVAL; + return -EINVAL; usb_pcwd_keepalive(usb_pcwd_device); /* Fall */ @@ -475,7 +506,8 @@ static int usb_pcwd_release(struct inode *inode, struct file *file) if (expect_release == 42) { usb_pcwd_stop(usb_pcwd_device); } else { - printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); + printk(KERN_CRIT PFX + "Unexpected close, not stopping watchdog!\n"); usb_pcwd_keepalive(usb_pcwd_device); } expect_release = 0; @@ -515,7 +547,8 @@ static int usb_pcwd_temperature_release(struct inode *inode, struct file *file) * Notify system */ -static int usb_pcwd_notify_sys(struct notifier_block *this, unsigned long code, void *unused) +static int usb_pcwd_notify_sys(struct notifier_block *this, unsigned long code, + void *unused) { if (code == SYS_DOWN || code == SYS_HALT) usb_pcwd_stop(usb_pcwd_device); /* Turn the WDT off */ @@ -578,7 +611,8 @@ static inline void usb_pcwd_delete(struct usb_pcwd_private *usb_pcwd) * Called by the usb core when a new device is connected that it thinks * this driver might be interested in. */ -static int usb_pcwd_probe(struct usb_interface *interface, const struct usb_device_id *id) +static int usb_pcwd_probe(struct usb_interface *interface, + const struct usb_device_id *id) { struct usb_device *udev = interface_to_usbdev(interface); struct usb_host_interface *iface_desc; @@ -602,7 +636,8 @@ static int usb_pcwd_probe(struct usb_interface *interface, const struct usb_devi /* check out that we have a HID device */ if (!(iface_desc->desc.bInterfaceClass == USB_CLASS_HID)) { - printk(KERN_ERR PFX "The device isn't a Human Interface Device\n"); + printk(KERN_ERR PFX + "The device isn't a Human Interface Device\n"); return -ENODEV; } @@ -632,10 +667,12 @@ static int usb_pcwd_probe(struct usb_interface *interface, const struct usb_devi usb_pcwd->udev = udev; usb_pcwd->interface = interface; usb_pcwd->interface_number = iface_desc->desc.bInterfaceNumber; - usb_pcwd->intr_size = (le16_to_cpu(endpoint->wMaxPacketSize) > 8 ? le16_to_cpu(endpoint->wMaxPacketSize) : 8); + usb_pcwd->intr_size = (le16_to_cpu(endpoint->wMaxPacketSize) > 8 ? + le16_to_cpu(endpoint->wMaxPacketSize) : 8); /* set up the memory buffer's */ - usb_pcwd->intr_buffer = usb_buffer_alloc(udev, usb_pcwd->intr_size, GFP_ATOMIC, &usb_pcwd->intr_dma); + usb_pcwd->intr_buffer = usb_buffer_alloc(udev, usb_pcwd->intr_size, + GFP_ATOMIC, &usb_pcwd->intr_dma); if (!usb_pcwd->intr_buffer) { printk(KERN_ERR PFX "Out of memory\n"); goto error; @@ -669,7 +706,8 @@ static int usb_pcwd_probe(struct usb_interface *interface, const struct usb_devi usb_pcwd_stop(usb_pcwd); /* Get the Firmware Version */ - got_fw_rev = usb_pcwd_send_command(usb_pcwd, CMD_GET_FIRMWARE_VERSION, &fw_rev_major, &fw_rev_minor); + got_fw_rev = usb_pcwd_send_command(usb_pcwd, CMD_GET_FIRMWARE_VERSION, + &fw_rev_major, &fw_rev_minor); if (got_fw_rev) sprintf(fw_ver_str, "%u.%02u", fw_rev_major, fw_rev_minor); else @@ -679,9 +717,11 @@ static int usb_pcwd_probe(struct usb_interface *interface, const struct usb_devi fw_ver_str); /* Get switch settings */ - usb_pcwd_send_command(usb_pcwd, CMD_GET_DIP_SWITCH_SETTINGS, &dummy, &option_switches); + usb_pcwd_send_command(usb_pcwd, CMD_GET_DIP_SWITCH_SETTINGS, &dummy, + &option_switches); - printk(KERN_INFO PFX "Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n", + printk(KERN_INFO PFX "Option switches (0x%02x): " + "Temperature Reset Enable=%s, Power On Delay=%s\n", option_switches, ((option_switches & 0x10) ? "ON" : "OFF"), ((option_switches & 0x08) ? "ON" : "OFF")); @@ -690,30 +730,35 @@ static int usb_pcwd_probe(struct usb_interface *interface, const struct usb_devi if (heartbeat == 0) heartbeat = heartbeat_tbl[(option_switches & 0x07)]; - /* Check that the heartbeat value is within it's range ; if not reset to the default */ + /* Check that the heartbeat value is within it's range ; + * if not reset to the default */ if (usb_pcwd_set_heartbeat(usb_pcwd, heartbeat)) { usb_pcwd_set_heartbeat(usb_pcwd, WATCHDOG_HEARTBEAT); - printk(KERN_INFO PFX "heartbeat value must be 0