Commit 136a73da authored by Guan-Yu Lin's avatar Guan-Yu Lin Committed by Greg Kroah-Hartman

usb: sysfs: use kstrtobool() if possible

Replace the self-rolled implementations with kstrtobool(). This reduces
the maintenance efforts in the future.
Signed-off-by: default avatarGuan-Yu Lin <guanyulin@google.com>
Link: https://lore.kernel.org/r/20240202030301.2396374-1-guanyulin@google.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d2f4831e
...@@ -273,9 +273,10 @@ static ssize_t avoid_reset_quirk_store(struct device *dev, ...@@ -273,9 +273,10 @@ static ssize_t avoid_reset_quirk_store(struct device *dev,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct usb_device *udev = to_usb_device(dev); struct usb_device *udev = to_usb_device(dev);
int val, rc; bool val;
int rc;
if (sscanf(buf, "%d", &val) != 1 || val < 0 || val > 1) if (kstrtobool(buf, &val) != 0)
return -EINVAL; return -EINVAL;
rc = usb_lock_device_interruptible(udev); rc = usb_lock_device_interruptible(udev);
if (rc < 0) if (rc < 0)
...@@ -322,13 +323,14 @@ static ssize_t persist_store(struct device *dev, struct device_attribute *attr, ...@@ -322,13 +323,14 @@ static ssize_t persist_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct usb_device *udev = to_usb_device(dev); struct usb_device *udev = to_usb_device(dev);
int value, rc; bool value;
int rc;
/* Hubs are always enabled for USB_PERSIST */ /* Hubs are always enabled for USB_PERSIST */
if (udev->descriptor.bDeviceClass == USB_CLASS_HUB) if (udev->descriptor.bDeviceClass == USB_CLASS_HUB)
return -EPERM; return -EPERM;
if (sscanf(buf, "%d", &value) != 1) if (kstrtobool(buf, &value) != 0)
return -EINVAL; return -EINVAL;
rc = usb_lock_device_interruptible(udev); rc = usb_lock_device_interruptible(udev);
...@@ -739,14 +741,14 @@ static ssize_t authorized_store(struct device *dev, ...@@ -739,14 +741,14 @@ static ssize_t authorized_store(struct device *dev,
{ {
ssize_t result; ssize_t result;
struct usb_device *usb_dev = to_usb_device(dev); struct usb_device *usb_dev = to_usb_device(dev);
unsigned val; bool val;
result = sscanf(buf, "%u\n", &val);
if (result != 1) if (kstrtobool(buf, &val) != 0)
result = -EINVAL; result = -EINVAL;
else if (val == 0) else if (val)
result = usb_deauthorize_device(usb_dev);
else
result = usb_authorize_device(usb_dev); result = usb_authorize_device(usb_dev);
else
result = usb_deauthorize_device(usb_dev);
return result < 0 ? result : size; return result < 0 ? result : size;
} }
static DEVICE_ATTR_IGNORE_LOCKDEP(authorized, S_IRUGO | S_IWUSR, static DEVICE_ATTR_IGNORE_LOCKDEP(authorized, S_IRUGO | S_IWUSR,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment