[PATCH] USB: serial: fix memleak on error path in usb-serial
udriver struct allocated by kzalloc() will not be freed if usb_register() and next calls fail. This patch fixes this by adding one more step with kfree(udriver) in error path. Cc: Alan Stern Signed-off-by: Alexey Klimov --- drivers/usb/serial/usb-serial.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index b1b9bac..d213cf4 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c @@ -1433,7 +1433,7 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[] rc = usb_register(udriver); if (rc) - return rc; + goto failed_usb_register; for (sd = serial_drivers; *sd; ++sd) { (*sd)->usb_driver = udriver; @@ -1451,6 +1451,8 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[] while (sd-- > serial_drivers) usb_serial_deregister(*sd); usb_deregister(udriver); +failed_usb_register: + kfree(udriver); return rc; } EXPORT_SYMBOL_GPL(usb_serial_register_drivers); -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH] watchdog: add driver for StreamLabs USB watchdog device
This patch creates new driver that supports StreamLabs usb watchdog device. This device plugs into 9-pin usb header and connects to reset pin and reset button on common PC. USB commands used to communicate with device were reverse engineered using usbmon. Signed-off-by: Alexey Klimov --- drivers/watchdog/Kconfig | 15 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/streamlabs_wdt.c | 370 ++ 3 files changed, 386 insertions(+) create mode 100644 drivers/watchdog/streamlabs_wdt.c diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 80825a7..95d8f72 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -1705,4 +1705,19 @@ config USBPCWATCHDOG Most people will say N. +config USB_STREAMLABS_WATCHDOG + tristate "StreamLabs USB watchdog driver" + depends on USB + ---help--- + This is the driver for the USB Watchdog dongle from StreamLabs. + If you correctly connect reset pins to motherboard Reset pin and + to Reset button then this device will simply watch your kernel to make + sure it doesn't freeze, and if it does, it reboots your computer + after a certain amount of time. + + + To compile this driver as a module, choose M here: the + module will be called streamlabs_wdt. + + Most people will say N. Say yes or M if you want to use such usb device. endif # WATCHDOG diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index f6a6a38..d54fd31 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_WDTPCI) += wdt_pci.o # USB-based Watchdog Cards obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o +obj-$(CONFIG_USB_STREAMLABS_WATCHDOG) += streamlabs_wdt.o # ALPHA Architecture diff --git a/drivers/watchdog/streamlabs_wdt.c b/drivers/watchdog/streamlabs_wdt.c new file mode 100644 index 000..031dbc35 --- /dev/null +++ b/drivers/watchdog/streamlabs_wdt.c @@ -0,0 +1,370 @@ +/* + * StreamLabs USB Watchdog driver + * + * Copyright (c) 2016 Alexey Klimov + * + * This program is free software; you may redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include + +/* + * USB Watchdog device from Streamlabs + * http://www.stream-labs.com/products/devices/watchdog/ + * + * USB commands have been reverse engineered using usbmon. + */ + +#define DRIVER_AUTHOR "Alexey Klimov " +#define DRIVER_DESC "StreamLabs USB watchdog driver" +#define DRIVER_NAME "usb_streamlabs_wdt" + +MODULE_AUTHOR(DRIVER_AUTHOR); +MODULE_DESCRIPTION(DRIVER_DESC); +MODULE_LICENSE("GPL"); + +#define USB_STREAMLABS_WATCHDOG_VENDOR 0x13c0 +#define USB_STREAMLABS_WATCHDOG_PRODUCT0x0011 + +/* one buffer is used for communication, however transmitted message is only + * 32 bytes long */ +#define BUFFER_TRANSFER_LENGTH 32 +#define BUFFER_LENGTH 64 +#define USB_TIMEOUT350 + +#define STREAMLABS_CMD_START 0 +#define STREAMLABS_CMD_STOP1 + +#define STREAMLABS_WDT_MIN_TIMEOUT 1 +#define STREAMLABS_WDT_MAX_TIMEOUT 46 + +struct streamlabs_wdt { + struct watchdog_device wdt_dev; + struct usb_device *usbdev; + struct usb_interface *intf; + + struct kref kref; + struct mutex lock; + u8 *buffer; +}; + +static bool nowayout = WATCHDOG_NOWAYOUT; + +static int usb_streamlabs_wdt_validate_response(u8 *buf) +{ + /* If watchdog device understood the command it will acknowledge +* with values 1,2,3,4 at indexes 10, 11, 12, 13 in response message. +*/ + if (buf[10] != 1 || buf[11] != 2 || buf[12] != 3 || buf[13] != 4) + return -EINVAL; + + return 0; +} + +static int usb_streamlabs_wdt_command(struct watchdog_device *wdt_dev, int cmd) +{ + struct streamlabs_wdt *streamlabs_wdt = watchdog_get_drvdata(wdt_dev); + int retval; + int size; + unsigned long timeout_msec; + int retry_counter = 10; /* how many times to re-send stop cmd */ + + mutex_lock(&streamlabs_wdt->lock); + + timeout_msec = wdt_dev->timeout * MSEC_PER_SEC; + + /* Prepare message that will be sent to device. +* This buffer is allocated by kzalloc(). Only initialize required +* fields. +*/ + if (cmd == STREAMLABS_CMD_START) { + streamlabs_wdt->buffer[0] = 0xcc; + streamlabs_wdt-
Re: [PATCH] watchdog: add driver for StreamLabs USB watchdog device
Hi Guenter, On Thu, Mar 10, 2016 at 3:54 AM, Guenter Roeck wrote: > On 03/09/2016 06:29 PM, Alexey Klimov wrote: >> >> This patch creates new driver that supports StreamLabs usb watchdog >> device. This device plugs into 9-pin usb header and connects to >> reset pin and reset button on common PC. >> >> USB commands used to communicate with device were reverse >> engineered using usbmon. >> >> Signed-off-by: Alexey Klimov >> --- >> drivers/watchdog/Kconfig | 15 ++ >> drivers/watchdog/Makefile | 1 + >> drivers/watchdog/streamlabs_wdt.c | 370 >> ++ >> 3 files changed, 386 insertions(+) >> create mode 100644 drivers/watchdog/streamlabs_wdt.c >> >> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig >> index 80825a7..95d8f72 100644 >> --- a/drivers/watchdog/Kconfig >> +++ b/drivers/watchdog/Kconfig >> @@ -1705,4 +1705,19 @@ config USBPCWATCHDOG >> >> Most people will say N. >> >> +config USB_STREAMLABS_WATCHDOG >> + tristate "StreamLabs USB watchdog driver" >> + depends on USB >> + ---help--- >> + This is the driver for the USB Watchdog dongle from StreamLabs. >> + If you correctly connect reset pins to motherboard Reset pin and >> + to Reset button then this device will simply watch your kernel >> to make >> + sure it doesn't freeze, and if it does, it reboots your computer >> + after a certain amount of time. >> + >> + >> + To compile this driver as a module, choose M here: the >> + module will be called streamlabs_wdt. >> + >> + Most people will say N. Say yes or M if you want to use such usb >> device. >> endif # WATCHDOG >> diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile >> index f6a6a38..d54fd31 100644 >> --- a/drivers/watchdog/Makefile >> +++ b/drivers/watchdog/Makefile >> @@ -25,6 +25,7 @@ obj-$(CONFIG_WDTPCI) += wdt_pci.o >> >> # USB-based Watchdog Cards >> obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o >> +obj-$(CONFIG_USB_STREAMLABS_WATCHDOG) += streamlabs_wdt.o >> >> # ALPHA Architecture >> >> diff --git a/drivers/watchdog/streamlabs_wdt.c >> b/drivers/watchdog/streamlabs_wdt.c >> new file mode 100644 >> index 000..031dbc35 >> --- /dev/null >> +++ b/drivers/watchdog/streamlabs_wdt.c >> @@ -0,0 +1,370 @@ >> +/* >> + * StreamLabs USB Watchdog driver >> + * >> + * Copyright (c) 2016 Alexey Klimov >> + * >> + * This program is free software; you may redistribute it and/or modify >> + * it under the terms of the GNU General Public License as published by >> + * the Free Software Foundation; either version 2 of the License, or >> + * (at your option) any later version. >> + * >> + * This program is distributed in the hope that it will be useful, >> + * but WITHOUT ANY WARRANTY; without even the implied warranty of >> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> + * GNU General Public License for more details. >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +/* >> + * USB Watchdog device from Streamlabs >> + * http://www.stream-labs.com/products/devices/watchdog/ >> + * >> + * USB commands have been reverse engineered using usbmon. >> + */ >> + >> +#define DRIVER_AUTHOR "Alexey Klimov " >> +#define DRIVER_DESC "StreamLabs USB watchdog driver" >> +#define DRIVER_NAME "usb_streamlabs_wdt" >> + >> +MODULE_AUTHOR(DRIVER_AUTHOR); >> +MODULE_DESCRIPTION(DRIVER_DESC); >> +MODULE_LICENSE("GPL"); >> + >> +#define USB_STREAMLABS_WATCHDOG_VENDOR 0x13c0 >> +#define USB_STREAMLABS_WATCHDOG_PRODUCT0x0011 >> + >> +/* one buffer is used for communication, however transmitted message is >> only >> + * 32 bytes long */ > > > /* > * Please use proper multi-line comments throughout. > > */ Ok, will fix them all. >> +#define BUFFER_TRANSFER_LENGTH 32 >> +#define BUFFER_LENGTH 64 >> +#define USB_TIMEOUT350 >> + >> +#define STREAMLABS_CMD_START 0 >> +#define STREAMLABS_CMD_STOP1 >> + >> +#define STREAMLABS_WDT_MIN_TIMEOUT 1 >> +#define STREAMLABS_WDT_MAX_TIMEOUT 46 >> + >> +struct streamlabs_wdt { >> + s
Re: [PATCH] watchdog: add driver for StreamLabs USB watchdog device
Hi Oliver, On Thu, Mar 10, 2016 at 9:23 AM, Oliver Neukum wrote: > On Thu, 2016-03-10 at 02:29 +0000, Alexey Klimov wrote: >> This patch creates new driver that supports StreamLabs usb watchdog >> device. This device plugs into 9-pin usb header and connects to >> reset pin and reset button on common PC. > > Hi, > > a few remarks. > > Regards > Oliver > >> >> USB commands used to communicate with device were reverse >> engineered using usbmon. >> >> Signed-off-by: Alexey Klimov >> --- >> drivers/watchdog/Kconfig | 15 ++ >> drivers/watchdog/Makefile | 1 + >> drivers/watchdog/streamlabs_wdt.c | 370 >> ++ >> 3 files changed, 386 insertions(+) >> create mode 100644 drivers/watchdog/streamlabs_wdt.c >> >> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig >> index 80825a7..95d8f72 100644 >> --- a/drivers/watchdog/Kconfig >> +++ b/drivers/watchdog/Kconfig >> @@ -1705,4 +1705,19 @@ config USBPCWATCHDOG >> >> Most people will say N. >> >> +config USB_STREAMLABS_WATCHDOG >> + tristate "StreamLabs USB watchdog driver" >> + depends on USB >> + ---help--- >> + This is the driver for the USB Watchdog dongle from StreamLabs. >> + If you correctly connect reset pins to motherboard Reset pin and >> + to Reset button then this device will simply watch your kernel to >> make >> + sure it doesn't freeze, and if it does, it reboots your computer >> + after a certain amount of time. >> + >> + >> + To compile this driver as a module, choose M here: the >> + module will be called streamlabs_wdt. >> + >> + Most people will say N. Say yes or M if you want to use such usb >> device. >> endif # WATCHDOG >> diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile >> index f6a6a38..d54fd31 100644 >> --- a/drivers/watchdog/Makefile >> +++ b/drivers/watchdog/Makefile >> @@ -25,6 +25,7 @@ obj-$(CONFIG_WDTPCI) += wdt_pci.o >> >> # USB-based Watchdog Cards >> obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o >> +obj-$(CONFIG_USB_STREAMLABS_WATCHDOG) += streamlabs_wdt.o >> >> # ALPHA Architecture >> >> diff --git a/drivers/watchdog/streamlabs_wdt.c >> b/drivers/watchdog/streamlabs_wdt.c >> new file mode 100644 >> index 000..031dbc35 >> --- /dev/null >> +++ b/drivers/watchdog/streamlabs_wdt.c >> @@ -0,0 +1,370 @@ >> +/* >> + * StreamLabs USB Watchdog driver >> + * >> + * Copyright (c) 2016 Alexey Klimov >> + * >> + * This program is free software; you may redistribute it and/or modify >> + * it under the terms of the GNU General Public License as published by >> + * the Free Software Foundation; either version 2 of the License, or >> + * (at your option) any later version. >> + * >> + * This program is distributed in the hope that it will be useful, >> + * but WITHOUT ANY WARRANTY; without even the implied warranty of >> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> + * GNU General Public License for more details. >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +/* >> + * USB Watchdog device from Streamlabs >> + * http://www.stream-labs.com/products/devices/watchdog/ >> + * >> + * USB commands have been reverse engineered using usbmon. >> + */ >> + >> +#define DRIVER_AUTHOR "Alexey Klimov " >> +#define DRIVER_DESC "StreamLabs USB watchdog driver" >> +#define DRIVER_NAME "usb_streamlabs_wdt" >> + >> +MODULE_AUTHOR(DRIVER_AUTHOR); >> +MODULE_DESCRIPTION(DRIVER_DESC); >> +MODULE_LICENSE("GPL"); >> + >> +#define USB_STREAMLABS_WATCHDOG_VENDOR 0x13c0 >> +#define USB_STREAMLABS_WATCHDOG_PRODUCT 0x0011 >> + >> +/* one buffer is used for communication, however transmitted message is only >> + * 32 bytes long */ >> +#define BUFFER_TRANSFER_LENGTH 32 >> +#define BUFFER_LENGTH64 >> +#define USB_TIMEOUT 350 >> + >> +#define STREAMLABS_CMD_START 0 >> +#define STREAMLABS_CMD_STOP 1 >> + >> +#define STREAMLABS_WDT_MIN_TIMEOUT 1 >> +#define STREAMLABS_WDT_MAX_TIMEOUT 46 >> + >> +struct streamlabs_wdt { >> + struct watchdog_device wdt_dev; >>
Re: [PATCH] watchdog: add driver for StreamLabs USB watchdog device
Hi Guenter, On Tue, Mar 15, 2016 at 2:24 AM, Guenter Roeck wrote: > Hi Alexey, > > > On 03/14/2016 06:02 PM, Alexey Klimov wrote: >> >> Hi Guenter, >> >> On Thu, Mar 10, 2016 at 3:54 AM, Guenter Roeck wrote: >>> >>> On 03/09/2016 06:29 PM, Alexey Klimov wrote: >>>> >>>> >>>> This patch creates new driver that supports StreamLabs usb watchdog >>>> device. This device plugs into 9-pin usb header and connects to >>>> reset pin and reset button on common PC. >>>> >>>> USB commands used to communicate with device were reverse >>>> engineered using usbmon. >>>> >>>> Signed-off-by: Alexey Klimov >>>> --- >>>>drivers/watchdog/Kconfig | 15 ++ >>>>drivers/watchdog/Makefile | 1 + >>>>drivers/watchdog/streamlabs_wdt.c | 370 >>>> ++ >>>>3 files changed, 386 insertions(+) [...] >>>> +static int usb_streamlabs_wdt_command(struct watchdog_device *wdt_dev, >>>> int cmd) >>>> +{ >>>> + struct streamlabs_wdt *streamlabs_wdt = >>>> watchdog_get_drvdata(wdt_dev); >>>> + int retval; >>>> + int size; >>>> + unsigned long timeout_msec; >>>> + int retry_counter = 10; /* how many times to re-send >>>> stop >>>> cmd */ >>>> + >>>> + mutex_lock(&streamlabs_wdt->lock); >>>> + >>>> + timeout_msec = wdt_dev->timeout * MSEC_PER_SEC; >>>> + >>>> + /* Prepare message that will be sent to device. >>>> +* This buffer is allocated by kzalloc(). Only initialize >>>> required >>>> +* fields. >>> >>> >>> >>> But only once, and overwritten by the response. So the comment is quite >>> pointless >>> and misleading. >> >> >> Ok, I will do something with this comment during re-work and rebase. >> >>>> +*/ >>>> + if (cmd == STREAMLABS_CMD_START) { >>>> + streamlabs_wdt->buffer[0] = 0xcc; >>>> + streamlabs_wdt->buffer[1] = 0xaa; >>>> + } else {/* assume stop command if it's not start */ >>>> + streamlabs_wdt->buffer[0] = 0xff; >>>> + streamlabs_wdt->buffer[1] = 0xbb; >>>> + } >>>> + >>>> + streamlabs_wdt->buffer[3] = 0x80; >>>> + >>>> + streamlabs_wdt->buffer[6] = (timeout_msec & 0xff) << 8; >>>> + streamlabs_wdt->buffer[7] = (timeout_msec & 0xff00) >> 8; >>>> +retry: >>>> + streamlabs_wdt->buffer[10] = 0x00; >>>> + streamlabs_wdt->buffer[11] = 0x00; >>>> + streamlabs_wdt->buffer[12] = 0x00; >>>> + streamlabs_wdt->buffer[13] = 0x00; >>>> + >>>> + /* send command to watchdog */ >>>> + retval = usb_interrupt_msg(streamlabs_wdt->usbdev, >>>> + usb_sndintpipe(streamlabs_wdt->usbdev, >>>> 0x02), >>>> + streamlabs_wdt->buffer, >>>> BUFFER_TRANSFER_LENGTH, >>>> + &size, USB_TIMEOUT); >>>> + >>>> + if (retval || size != BUFFER_TRANSFER_LENGTH) { >>>> + dev_err(&streamlabs_wdt->intf->dev, >>>> + "error %i when submitting interrupt msg\n", >>>> retval); >>> >>> >>> >>> Please no error messages if something goes wrong. We don't want to >>> fill the kernel log with those messages. >> >> >> Ok, will remove them. Or is it fine to convert them to dev_dbg? >> > > If you think the messages might be useful for debugging, sure. Well, definetely they help me now. >>>> + retval = -EIO; >>>> + goto out; >>>> + } >>>> + >>>> + /* and read response from watchdog */ >>>> + retval = usb_interrupt_msg(streamlabs_wdt->usbdev, >>>> + usb_rcvintpipe(streamlabs_wdt->usbdev, >>>> 0x81), >>>> + streamlabs_wdt->buffer, BUFFER_LENGTH, >>>>
[PATCH v2] watchdog: add driver for StreamLabs USB watchdog device
This patch creates new driver that supports StreamLabs usb watchdog device. This device plugs into 9-pin usb header and connects to reset pin and reset button on common PC. USB commands used to communicate with device were reverse engineered using usbmon. Signed-off-by: Alexey Klimov --- Changes in v2: -- coding style cleanups -- turn some dev_err messages to dev_dbg -- reimplemented usb_streamlabs_wdt_command() to use loop -- re-worked disconnect routine -- rebased to 4.6-rc2, removed set_timeout method -- removed braces in .options field in streamlabs_wdt_indent -- mem allocation migrated to devm_kzalloc -- buffer for device struct moved inside main struct to avoid additional memory allocation -- removed watchdog_init_timeout() -- re-worked usb_streamlabs_wdt_{resume,suspend} -- removed struct usb_device pointer from main driver struct -- buffer preparation for communication migrated to cpu_to_le16() functions, also buffer is filled in as u16 elements to make this byteorder usable -- added stop command in usb_streamlabs_wdt_disconnect() drivers/watchdog/Kconfig | 15 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/streamlabs_wdt.c | 313 ++ 3 files changed, 329 insertions(+) create mode 100644 drivers/watchdog/streamlabs_wdt.c diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index fb94765..130cf54 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -1766,4 +1766,19 @@ config USBPCWATCHDOG Most people will say N. +config USB_STREAMLABS_WATCHDOG + tristate "StreamLabs USB watchdog driver" + depends on USB + ---help--- + This is the driver for the USB Watchdog dongle from StreamLabs. + If you correctly connect reset pins to motherboard Reset pin and + to Reset button then this device will simply watch your kernel to make + sure it doesn't freeze, and if it does, it reboots your computer + after a certain amount of time. + + + To compile this driver as a module, choose M here: the + module will be called streamlabs_wdt. + + Most people will say N. Say yes or M if you want to use such usb device. endif # WATCHDOG diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index feb6270..9d36929 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_WDTPCI) += wdt_pci.o # USB-based Watchdog Cards obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o +obj-$(CONFIG_USB_STREAMLABS_WATCHDOG) += streamlabs_wdt.o # ALPHA Architecture diff --git a/drivers/watchdog/streamlabs_wdt.c b/drivers/watchdog/streamlabs_wdt.c new file mode 100644 index 000..3e34cd8 --- /dev/null +++ b/drivers/watchdog/streamlabs_wdt.c @@ -0,0 +1,313 @@ +/* + * StreamLabs USB Watchdog driver + * + * Copyright (c) 2016 Alexey Klimov + * + * This program is free software; you may redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * USB Watchdog device from Streamlabs + * http://www.stream-labs.com/products/devices/watchdog/ + * + * USB commands have been reverse engineered using usbmon. + */ + +#define DRIVER_AUTHOR "Alexey Klimov " +#define DRIVER_DESC "StreamLabs USB watchdog driver" +#define DRIVER_NAME "usb_streamlabs_wdt" + +MODULE_AUTHOR(DRIVER_AUTHOR); +MODULE_DESCRIPTION(DRIVER_DESC); +MODULE_LICENSE("GPL"); + +#define USB_STREAMLABS_WATCHDOG_VENDOR 0x13c0 +#define USB_STREAMLABS_WATCHDOG_PRODUCT0x0011 + +/* + * one buffer is used for communication, however transmitted message is only + * 32 bytes long + */ +#define BUFFER_TRANSFER_LENGTH 32 +#define BUFFER_LENGTH 64 +#define USB_TIMEOUT350 + +#define STREAMLABS_CMD_START 0xaacc +#define STREAMLABS_CMD_STOP0xbbff + +#define STREAMLABS_WDT_MIN_TIMEOUT 1 +#define STREAMLABS_WDT_MAX_TIMEOUT 46 + +struct streamlabs_wdt { + struct watchdog_device wdt_dev; + struct usb_interface *intf; + + struct mutex lock; + u8 buffer[BUFFER_LENGTH]; +}; + +static bool nowayout = WATCHDOG_NOWAYOUT; + +/* + * This function is used to check if watchdog actually changed + * its state to disabled that is reported in first two bytes of response + * message. + */ +static int usb_streamlabs_wdt_check_stop(u16 *buf) +{ + if (buf[0] != cpu_to_le16(STREAMLABS_CMD_STOP)) +
[PATCH v3] watchdog: add driver for StreamLabs USB watchdog device
This patch creates new driver that supports StreamLabs usb watchdog device. This device plugs into 9-pin usb header and connects to reset pin and reset button on common PC. USB commands used to communicate with device were reverse engineered using usbmon. Signed-off-by: Alexey Klimov --- Changes in v3: -- coding style cleanups and rebase; -- buffer is allocated with separate allocation; -- adding comments about max/min limits; -- rework start/stop commands implementation; -- fix first if-check in probe() function; Previous version: https://www.spinics.net/lists/linux-watchdog/msg09092.html drivers/watchdog/Kconfig | 16 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/streamlabs_wdt.c | 321 ++ 3 files changed, 338 insertions(+) create mode 100644 drivers/watchdog/streamlabs_wdt.c diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index acb00b53a520..6a2195d8cc5c 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -1852,6 +1852,22 @@ config USBPCWATCHDOG Most people will say N. +config USB_STREAMLABS_WATCHDOG + tristate "StreamLabs USB watchdog driver" + depends on USB + ---help--- + This is the driver for the USB Watchdog dongle from StreamLabs. + If you correctly connect reset pins to motherboard Reset pin and + to Reset button then this device will simply watch your kernel to make + sure it doesn't freeze, and if it does, it reboots your computer + after a certain amount of time. + + + To compile this driver as a module, choose M here: the + module will be called streamlabs_wdt. + + Most people will say N. Say yes or M if you want to use such usb device. + comment "Watchdog Pretimeout Governors" config WATCHDOG_PRETIMEOUT_GOV diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index 0c3d35e3c334..d4a61222ccd2 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -31,6 +31,7 @@ obj-$(CONFIG_WDTPCI) += wdt_pci.o # USB-based Watchdog Cards obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o +obj-$(CONFIG_USB_STREAMLABS_WATCHDOG) += streamlabs_wdt.o # ALPHA Architecture diff --git a/drivers/watchdog/streamlabs_wdt.c b/drivers/watchdog/streamlabs_wdt.c new file mode 100644 index ..4442d053d9f7 --- /dev/null +++ b/drivers/watchdog/streamlabs_wdt.c @@ -0,0 +1,321 @@ +/* + * StreamLabs USB Watchdog driver + * + * Copyright (c) 2016-2017 Alexey Klimov + * + * This program is free software; you may redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * USB Watchdog device from Streamlabs: + * https://www.stream-labs.com/en/catalog/?cat_id=1203&item_id=323 + * + * USB commands have been reverse engineered using usbmon. + */ + +#define DRIVER_AUTHOR "Alexey Klimov " +#define DRIVER_DESC "StreamLabs USB watchdog driver" +#define DRIVER_NAME "usb_streamlabs_wdt" + +MODULE_AUTHOR(DRIVER_AUTHOR); +MODULE_DESCRIPTION(DRIVER_DESC); +MODULE_LICENSE("GPL"); + +#define USB_STREAMLABS_WATCHDOG_VENDOR 0x13c0 +#define USB_STREAMLABS_WATCHDOG_PRODUCT0x0011 + +/* + * one buffer is used for communication, however transmitted message is only + * 32 bytes long + */ +#define BUFFER_TRANSFER_LENGTH 32 +#define BUFFER_LENGTH 64 +#define USB_TIMEOUT350 + +#define STREAMLABS_CMD_START 0xaacc +#define STREAMLABS_CMD_STOP0xbbff + +/* timeouts values are taken from windows program */ +#define STREAMLABS_WDT_MIN_TIMEOUT 1 +#define STREAMLABS_WDT_MAX_TIMEOUT 46 + +struct streamlabs_wdt { + struct watchdog_device wdt_dev; + struct usb_interface *intf; + + struct mutex lock; + u8 *buffer; +}; + +static bool nowayout = WATCHDOG_NOWAYOUT; + +/* + * This function is used to check if watchdog actually changed + * its state to disabled that is reported in first two bytes of response + * message. + */ +static int usb_streamlabs_wdt_check_stop(u16 *buf) +{ + if (buf[0] != cpu_to_le16(STREAMLABS_CMD_STOP)) + return -EINVAL; + + return 0; +} + +static int usb_streamlabs_wdt_validate_response(u8 *buf) +{ + /* +* If watchdog device understood the command it will acknowledge +* with values 1,2,3,4 at indexes 10, 11, 12, 13 in response message +* when response treated as 8bit message. +
Re: [PATCH RESEND (1-3)/4] Add usb interface authorization
Hi Stefan, On Tue, Jun 9, 2015 at 6:38 PM, Stefan Koch wrote: > Am Dienstag, den 09.06.2015, 07:49 -0700 schrieb Greg KH: >> On Tue, Jun 09, 2015 at 03:48:47PM +0200, Stefan Koch wrote: >> > Am Montag, den 08.06.2015, 07:40 -0700 schrieb Greg KH: >> > > On Mon, Jun 08, 2015 at 03:24:26PM +0200, Stefan Koch wrote: <..snip..> >> > > >> > > Care to resend this in a format that it could be applied in (i.e. broken >> > > up into logical chunks with the proper Signed-off-by: lines)? >> > > >> > > As this is, there's nothing we can do with it. >> > > >> > > thanks, >> > > >> > > greg k-h >> > >> > Hi >> > >> > I think whitespaces should be ok now. I have tested now three mail >> > clients... >> > >> > This patch series enables the interface authorization. The description >> > is improved now. Is the series correct now? >> >> I need these in a one-patch-per-email format, with the subject fixed up. >> These need to be in a format where I don't have to edit anything in the >> email by hand in order to apply them, that hasn't happened yet :( >> >> thanks, >> >> greg k-h > > Do you mean this should like the patches 1/4 2/4 3/4 4/4 with the wrong > whitspaces? > > Should the patch mail not include any text like Hi and thanks and so on? Could you please read and check Documentation/SubmittingPatches? It gives answers on some of you questions. Chapter 14 "The canonical patch format" will help. Please also don't forget to run checkpatch.pl. I see some bad style comments in one of your patches. Well, you can add "Hi" to [PATCH 0/12] email, for example. -- Best regards, Alexey Klimov -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html